shop.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="goods-box">
  3. <view class="search">
  4. <u-search :hideRight="true" :show-action="true" action-text="取消" :animation="true" @focus="hideRight=false"
  5. @blur="hideRight=true" @custom="handleCancel" placeholder="请输入搜索内容" height="64" @change="mescroll.resetUpScroll()"
  6. v-model="keyword"></u-search>
  7. </view>
  8. <view class="tab-control">
  9. <view v-for="(item, index) in tabsList" :key="index" :class="{'active': currentTabs == index}"
  10. @click="changeTabs(index)">{{ item.label }}</view>
  11. </view>
  12. <mescroll-uni ref="mescrollRef" top="0" height="620rpx" @init="mescrollInit" @down="downCallback"
  13. @up="upCallback" :down="downOption" :up="upOption">
  14. <block v-for="(shopItem, index) in lists" :key="index">
  15. <view class="goods-item flex row-between" @click="selectCurrentGoods(shopItem)">
  16. <u-image :src="shopItem.logo" width="160" height="160"></u-image>
  17. <view class="m-l-20 flex-1">
  18. <view class="goods-name line-1 m-b-12 nr normal">{{ shopItem.name }}</view>
  19. </view>
  20. <image :src="getCurrentSelect(shopItem)"></image>
  21. </view>
  22. </block>
  23. </mescroll-uni>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. getCommunityShop
  29. } from '@/api/community.js';
  30. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  31. import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
  32. export default {
  33. mixins: [MescrollMixin, MescrollMoreItemMixin],
  34. props: {
  35. value: {
  36. type: [Object, Array]
  37. }
  38. },
  39. data() {
  40. return {
  41. keyword: '',
  42. hideRight: true,
  43. height: '', // 高度
  44. upOption: {
  45. empty: {
  46. icon: '/static/images/goods_null.png',
  47. tip: '暂无店铺 ', // 提示
  48. fixed: true,
  49. top: "200rpx",
  50. }
  51. },
  52. tabsList: [{
  53. label: '全部',
  54. type: 'all'
  55. }, {
  56. label: '已购店铺',
  57. type: 'buy'
  58. }],
  59. currentTabs: 0,
  60. lists: [],
  61. selectData: []
  62. }
  63. },
  64. computed: {
  65. getCurrentSelect() {
  66. return (row) => {
  67. return this.selectData.filter(item => item.id == row.id).length ? '/bundle_b/static/icon_select.png' :
  68. '/bundle_b/static/icon_unselect.png'
  69. }
  70. }
  71. },
  72. watch: {
  73. value(val) {
  74. this.selectData = val
  75. }
  76. },
  77. methods: {
  78. handleCancel() {
  79. this.keyword = '';
  80. this.mescroll.resetUpScroll()
  81. },
  82. // 切换标签导航
  83. changeTabs(event) {
  84. this.currentTabs = event;
  85. uni.showLoading({title: '加载中'})
  86. this.mescroll.resetUpScroll()
  87. },
  88. // 选择当前店铺
  89. selectCurrentGoods(event) {
  90. const index = this.selectData.findIndex(item => item.id == event.id)
  91. if (index === -1) this.selectData = [...this.selectData, event]
  92. else this.selectData.splice(index, 1)
  93. this.$emit('change', this.selectData)
  94. },
  95. // 获取
  96. async upCallback(page) {
  97. const index = this.currentTabs;
  98. const pageNum = page.num
  99. const pageSize = page.size
  100. getCommunityShop({
  101. keyword: this.keyword,
  102. type: this.tabsList[index].type,
  103. page_no: pageNum,
  104. page_size: pageSize,
  105. }).then(res => {
  106. uni.hideLoading()
  107. // 如果是第一页需手动置空列表
  108. if (pageNum == 1 || this.keyword) this.lists = []
  109. // 重置列表数据
  110. const hasNext = !!res.data.more;
  111. this.lists = [...this.lists, ...res.data.list]
  112. this.mescroll.endSuccess(res.data.list.length, hasNext);
  113. }).catch((err) => {
  114. this.mescroll.endErr()
  115. uni.hideLoading()
  116. })
  117. },
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .goods-box {
  123. width: 100%;
  124. height: 700rpx;
  125. .search {
  126. width: 100%;
  127. height: 90rpx;
  128. }
  129. .tab-control {
  130. border-top: 1px solid $-color-body;
  131. border-bottom: 1px solid $-color-body;
  132. view {
  133. width: 200rpx;
  134. height: 90rpx;
  135. text-align: center;
  136. line-height: 90rpx;
  137. display: inline-block;
  138. color: $-color-normal;
  139. transition: all .2s;
  140. }
  141. .active {
  142. color: $-color-primary;
  143. }
  144. }
  145. .goods-item {
  146. padding: 20rpx;
  147. border-bottom: 1px solid $-color-body;
  148. .goods-name {
  149. width: 460rpx;
  150. }
  151. image {
  152. width: 34rpx;
  153. height: 34rpx;
  154. }
  155. }
  156. }
  157. </style>