consume.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view>
  3. <u-navbar :is-back="false" title=" ">
  4. <view class="margin-left-20 text-cut-1" style="width: 100%;z-index: 99;" @click="chooseLocation()">
  5. <view v-if="$isEmpty(location)" @click.stop="$u.toast('暂无位置信息')">
  6. <u-icon name="map-fill" color="#000" size="32"></u-icon>
  7. <text class="padding-left-sm " style="font-size: 32rpx;">暂无位置信息</text>
  8. </view>
  9. <view class="" v-else>
  10. <u-icon name="map-fill" color="#000" size="34"></u-icon>
  11. <text class="padding-left-sm " style="font-size: 34rpx;">{{location}}</text>
  12. </view>
  13. </view>
  14. </u-navbar>
  15. <tabsSwiper @currentChange="currentChange" ref="tabsSwiper" activeColor="#efc232">
  16. <view slot="swiper1">
  17. <mescroll-body :height="height" ref="mescrollRef" @init="mescrollInit" @down="downCallback"
  18. @up="upCallback" :down="downOption" :up="upOption">
  19. <card1 :list="shopList" @filter="filter"></card1>
  20. </mescroll-body>
  21. </view>
  22. <view slot="swiper2">
  23. <mescroll-body :height="height" ref="mescrollRef" @init="mescrollInit" @down="downCallback"
  24. @up="upCallback" :down="downOption" :up="upOption">
  25. <card2 :list="mallList"></card2>
  26. </mescroll-body>
  27. </view>
  28. </tabsSwiper>
  29. </view>
  30. </template>
  31. <script>
  32. import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
  33. import card2 from "./comps/card2.vue"
  34. import card1 from "./comps/card1.vue"
  35. import tabsSwiper from './comps/tabsSwiper.vue'
  36. export default {
  37. mixins: [MescrollMixin],
  38. components: {
  39. tabsSwiper,
  40. card1,
  41. card2
  42. },
  43. data() {
  44. return {
  45. background: {
  46. background: '#FF9549'
  47. },
  48. location: '',
  49. //数据列表
  50. list: [],
  51. shopList: [],
  52. mallList: [],
  53. //当前taginedx
  54. current: 0,
  55. filterValue: '',
  56. downOption: {
  57. use: false
  58. }
  59. }
  60. },
  61. onLoad() {
  62. this.getLocaltion()
  63. },
  64. methods: {
  65. downCallback() {
  66. setTimeout(() => {
  67. uni.showToast({
  68. title: "刷新成功",
  69. icon: "none"
  70. })
  71. this.mescroll.resetUpScroll();
  72. }, 1000)
  73. },
  74. upCallback(mescroll) {
  75. try {
  76. if (this.current == 0) {
  77. this.fetchShopList(mescroll)
  78. } else {
  79. this.fetchMallList(mescroll)
  80. }
  81. } catch (e) {
  82. this.mescroll.endErr()
  83. }
  84. },
  85. filter(index) {
  86. this.filterValue = ""
  87. switch (index) {
  88. case 1:
  89. this.filterValue = "sales"
  90. break;
  91. case 2:
  92. this.filterValue = "score"
  93. break;
  94. default:
  95. break;
  96. }
  97. this.mescroll.resetUpScroll();
  98. },
  99. async fetchShopList(mescroll) {
  100. let params = {
  101. current: mescroll.num,
  102. size: mescroll.size,
  103. auditStatus: 'PASS'
  104. }
  105. if (!this.$isEmpty(this.filterValue)) {
  106. params.filter = this.filterValue
  107. }
  108. let res = await this.$api.shop.list(params)
  109. let data = res.data.records
  110. let total = res.data.total
  111. mescroll.endBySize(data.length, total);
  112. if (mescroll.num == 1) this.shopList = []; //如果是第一页需手动制空列表
  113. this.shopList = this.shopList.concat(data); //追加新数据
  114. this.$forceUpdate()
  115. this.$refs.tabsSwiper.initSwiperHeight('.list0')
  116. },
  117. async fetchMallList(mescroll) {
  118. let params = {
  119. current: mescroll.num,
  120. size: mescroll.size,
  121. auditStatus: 'PASS'
  122. }
  123. let res = await this.$api.mall.list(params)
  124. let data = res.data.records
  125. let total = res.data.total
  126. mescroll.endBySize(data.length, total);
  127. if (mescroll.num == 1) this.mallList = []; //如果是第一页需手动制空列表
  128. this.mallList = this.mallList.concat(data); //追加新数据
  129. this.$forceUpdate()
  130. this.$refs.tabsSwiper.initSwiperHeight('.list1')
  131. },
  132. currentChange(index) {
  133. this.current = index
  134. this.mescroll.resetUpScroll();
  135. },
  136. getLocaltion() {
  137. let _this = this
  138. uni.getLocation({
  139. type: 'gcj02 ',
  140. success: function(res) {
  141. let params = {
  142. longitude: res.longitude,
  143. latitude: res.latitude
  144. }
  145. _this.$u.vuex('vuex_location', params)
  146. _this.$api.activity.getLocation(params).then(resp => {
  147. _this.location = resp.data.result.formatted_addresses.recommend
  148. })
  149. },
  150. fail: (err) => {
  151. console.log(err);
  152. }
  153. });
  154. },
  155. chooseLocation() {
  156. console.log("选择位置");
  157. let _this = this
  158. uni.chooseLocation({
  159. success: function(res) {
  160. let params = {
  161. longitude: res.longitude,
  162. latitude: res.latitude
  163. }
  164. _this.$u.vuex('vuex_location', params)
  165. _this.location = res.name
  166. },
  167. fail: (err) => {
  168. console.log(err);
  169. }
  170. });
  171. },
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. page {
  177. background-color: #f6f6f6;
  178. }
  179. </style>