goods.vue 6.1 KB

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