nearby_shops.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="shop-street">
  3. <mescroll-body v-if="appConfig.shop_street_hide" ref="mescrollRef" @init="mescrollInit" @down="downCallback"
  4. @up="upCallback" :up="upOption">
  5. <view class="shop-street-content">
  6. <view class="search bg-white flex flex-1 flex row">
  7. <!-- 城市 -->
  8. <router-link v-if="appConfig.is_open_nearby" class="m-l-16 flex black row-center"
  9. to="/bundle_b/pages/city/city">
  10. <text class="m-r-6">{{ cityInfo.name || '选择' }}</text>
  11. <u-icon name="arrow-down" size="24" color="#000000"></u-icon>
  12. <!-- <image class="icon-md m-l-30" src="/static/images/icon_news.png">
  13. </image> -->
  14. </router-link>
  15. <view class="flex-1">
  16. <u-search v-model="keyword" @search="onReflesh" bg-color="#F4F4F4"
  17. placeholder="搜索关键词"></u-search>
  18. </view>
  19. </view>
  20. <!-- <scroll-view class="bg-white" :scroll-x="true" :scroll-with-animation="true">
  21. <view class="store-category p-t-20">
  22. <view class="category-item flex-col col-center" @tap="changeActive(-1)">
  23. <view class="icon-wrap" :style="{borderColor: active == -1 ? colorConfig.primary : ''}">
  24. <u-image width="68rpx" height="68rpx" border-radius="60rpx" src="/static/images/icon_shop_cate.png" />
  25. </view>
  26. <view class="xs m-t-10" :class="{primary: active == -1}">全部</view>
  27. </view>
  28. <view class="category-item flex-col col-center" v-for="(item,index) in shopCategory" :key="index"
  29. @tap="changeActive(index)">
  30. <view class="icon-wrap" :style="{borderColor: active == index ? colorConfig.primary : ''}">
  31. <u-image width="68rpx" height="68rpx" border-radius="60rpx" :src="item.image" />
  32. </view>
  33. <view class="xs m-t-10" :class="{primary: active == index}">{{item.name}}</view>
  34. </view>
  35. </view>
  36. </scroll-view> -->
  37. <view class="store-container">
  38. <view class="m-t-20" v-for="(item, index) in shopList" :key="index">
  39. <shop-item lx="2" :item="item"></shop-item>
  40. </view>
  41. </view>
  42. </view>
  43. </mescroll-body>
  44. <view v-else>
  45. <view class="p-b-20" v-if="hotGoods.length">
  46. <goods-list type="one" :list="hotGoods"></goods-list>
  47. </view>
  48. <!-- <view v-else class="flex-col col-center" style="margin-top: 200rpx;">
  49. <image class="img-null" src="/static/images/goods_null.png"></image>
  50. <view class="muted">
  51. 暂无数据~
  52. </view>
  53. </view> -->
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. mapGetters,
  60. mapActions
  61. } from 'vuex'
  62. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins";
  63. import {
  64. getNearbyShops,
  65. getShopCategory
  66. } from "@/api/shop"
  67. import {
  68. getHome,
  69. } from "@/api/store"
  70. export default {
  71. mixins: [MescrollMixin],
  72. data() {
  73. return {
  74. shopList: [],
  75. shopCategory: [],
  76. keyword: '',
  77. active: -1,
  78. upOption: {
  79. auto: false,
  80. empty: {
  81. icon: '/static/images/goods_null.png',
  82. tip: "暂无数据~",
  83. },
  84. },
  85. hotGoods: []
  86. }
  87. },
  88. onShow() {
  89. this.getHomeFun()
  90. if (this.cityInfo) {
  91. this.mescroll.resetUpScroll();
  92. console.log(1);
  93. }
  94. },
  95. methods: {
  96. async downCallback() {
  97. await this.getShopCategoryFun()
  98. this.mescroll.resetUpScroll();
  99. },
  100. // 获取首页数据
  101. async getHomeFun() {
  102. const {
  103. code,
  104. data
  105. } = await getHome({
  106. city_id: this.cityInfo.id
  107. });
  108. if (code == 1) {
  109. this.hotGoods = data.hots
  110. }
  111. },
  112. onReflesh() {
  113. this.shopList = []
  114. this.mescroll.resetUpScroll();
  115. },
  116. changeActive(index) {
  117. this.active = index
  118. this.onReflesh()
  119. },
  120. upCallback(page) {
  121. let pageNum = page.num;
  122. let pageSize = page.size;
  123. const {
  124. keyword,
  125. active,
  126. shopCategory
  127. } = this
  128. const cateId = active == -1 ? '' : shopCategory[active].id
  129. if (!this.cityInfo.id) {
  130. uni.showToast({
  131. title: '获取当前城市信息失败,请手动选择城市',
  132. icon: 'none',
  133. duration: 2000
  134. });
  135. return
  136. }
  137. console.log(this.cityInfo, 'city');
  138. getNearbyShops({
  139. page_no: pageNum,
  140. page_size: pageSize,
  141. name: keyword,
  142. shop_cate_id: 35,
  143. city_id: this.cityInfo.id
  144. }).then(res => {
  145. if (res.code == 1) {
  146. let curPageData = res.data.list;
  147. let curPageLen = curPageData.length;
  148. let hasNext = !!res.data.more;
  149. if (page.num == 1) {
  150. this.shopList = [];
  151. }
  152. this.shopList = this.shopList.concat(curPageData);
  153. this.mescroll.endSuccess(curPageLen, hasNext);
  154. }
  155. }).catch(err => {
  156. this.mescroll.endErr()
  157. })
  158. },
  159. async getShopCategoryFun() {
  160. const {
  161. code,
  162. data
  163. } = await getShopCategory()
  164. if (code == 1) {
  165. this.shopCategory = data
  166. }
  167. },
  168. },
  169. computed: {
  170. ...mapGetters(['cityInfo'])
  171. }
  172. }
  173. </script>
  174. <style lang="scss">
  175. .shop-street {
  176. .search {}
  177. .store-category {
  178. white-space: nowrap;
  179. padding-bottom: 10rpx;
  180. .category-item {
  181. display: inline-flex;
  182. padding: 0 30rpx;
  183. .icon-wrap {
  184. border: 1px solid transparent;
  185. border-radius: 50%;
  186. }
  187. }
  188. }
  189. .store-container {
  190. padding: 0 30rpx;
  191. }
  192. }
  193. </style>