collection-list.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <mescroll-uni ref="mescrollRef" top="80rpx" @init="mescrollInit" @down="downCallback" @up="upCallback"
  3. :down="downOption" :up="upOption">
  4. <view class="collection-list">
  5. <view class="goods-list p-t-20" v-show="type == 1">
  6. <view v-for="(item, index) in collectionList" :key="item.id">
  7. <u-swipe-action :show="selectIndex == item.id" :index="item.id" bg-color="transparent"
  8. :btn-width="130" @click="clickBtn" @open="open" :options="options">
  9. <view class="collection-item flex bg-white" @tap="toGoods(item)">
  10. <u-image width="160rpx" height="160rpx" border-radius="6rpx" lazy-load class="m-r-20"
  11. :src="item.image" />
  12. <view class="info flex-1">
  13. <view class="flex row-between">
  14. <view class="name line-2">{{item.name}}</view>
  15. </view>
  16. <view class="flex row-between m-t-20">
  17. <price-format :first-size="30" :second-size="26" :price="item.min_price"
  18. :weight="400" :subscript-size="30" :color="colorConfig.primary" />
  19. <view class="btn primary flex row-center br60 sm"
  20. :class="{'valid muted': item.is_valid == 0}">
  21. {{ item.is_valid == 0 ? '已失效' : '去购买'}}
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </u-swipe-action>
  27. </view>
  28. </view>
  29. <view class="store-list" v-show="type == 2">
  30. <view class="m-t-20" v-for="(item, index) in collectionList" :key="item.id">
  31. <u-swipe-action :show="selectIndex == item.id" :index="item.id" bg-color="transparent"
  32. :btn-width="130" @click="clickBtn" @open="open" :options="options">
  33. <view class="store-item bg-white flex" @tap="toShop(item)">
  34. <u-image width="80rpx" height="80rpx" border-radius="60rpx" :src="item.logo" />
  35. <view class="flex-1 m-l-10">
  36. <view class="store-name lg">
  37. {{item.name}}<text class="xxs tag white m-l-10 line-1"
  38. v-if="item.type == 1">自营</text>
  39. </view>
  40. <view class="m-t-12 xs muted flex row-between">
  41. 主营行业:{{item.cid_desc}}
  42. <view class="xs" v-if="item.score!=0">
  43. 评分:
  44. <text style="color: #ffa200">
  45. {{item.score}}
  46. </text>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- <view class="flex muted xs">
  51. 评分:<view style="color: #FFA200;">{{item.score}}</view>
  52. </view> -->
  53. </view>
  54. </u-swipe-action>
  55. </view>
  56. </view>
  57. </view>
  58. </mescroll-uni>
  59. </template>
  60. <script>
  61. import {
  62. getCollectGoods,
  63. getCollectShop,
  64. collectGoods
  65. } from '@/api/user'
  66. import {
  67. changeShopFollow
  68. } from '@/api/shop'
  69. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  70. import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
  71. export default {
  72. mixins: [MescrollMixin, MescrollMoreItemMixin],
  73. name: "collection-list",
  74. props: {
  75. type: {
  76. type: [String, Number]
  77. }
  78. },
  79. data() {
  80. return {
  81. collectionList: [],
  82. downOption: {
  83. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  84. },
  85. upOption: {
  86. auto: false, // 不自动加载
  87. noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  88. empty: {
  89. icon: '/static/images/goods_null.png',
  90. tip: '暂无收藏~', // 提示
  91. fixed: true
  92. }
  93. },
  94. options: [{
  95. text: '取消收藏',
  96. style: {
  97. backgroundColor: '#FF2C3C'
  98. }
  99. }],
  100. selectIndex: -1
  101. };
  102. },
  103. methods: {
  104. async upCallback(page) {
  105. let pageNum = page.num; // 页码, 默认从1开始
  106. let pageSize = page.size; // 页长, 默认每页10条
  107. let {
  108. type,
  109. } = this;
  110. const {
  111. data,
  112. code
  113. } = type == 1 ? await getCollectGoods({
  114. page_size: pageSize,
  115. page_no: pageNum
  116. }) : await getCollectShop({
  117. page_size: pageSize,
  118. page_no: pageNum
  119. })
  120. if (code == 1) {
  121. let curPageData = data.lists;
  122. let curPageLen = curPageData.length;
  123. let hasNext = !!data.more;
  124. if (page.num == 1) this.collectionList = [];
  125. this.collectionList = this.collectionList.concat(curPageData);
  126. this.mescroll.endSuccess(curPageLen, hasNext);
  127. }
  128. },
  129. toGoods(item) {
  130. if (item.is_valid) {
  131. this.$Router.push({
  132. path: '/pages/goods_details/goods_details',
  133. query: {
  134. id: item.id
  135. }
  136. })
  137. }
  138. },
  139. toShop(item) {
  140. this.$Router.push({
  141. path: '/pages/store_index/store_index',
  142. query: {
  143. id: item.id
  144. }
  145. })
  146. },
  147. open(index) {
  148. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  149. // 原本为'false',再次设置为'false'会无效
  150. this.selectIndex = index;
  151. // }
  152. },
  153. async clickBtn(index) {
  154. const {
  155. code,
  156. data,
  157. msg
  158. } = this.type == 1 ? await collectGoods({
  159. goods_id: index
  160. }) : await changeShopFollow({
  161. shop_id: index
  162. })
  163. if (code == 1) {
  164. this.$toast({
  165. title: msg
  166. })
  167. this.downCallback()
  168. }
  169. }
  170. },
  171. }
  172. </script>
  173. <style lang="scss">
  174. .collection-list {
  175. width: 100%;
  176. .goods-list {
  177. .collection-item {
  178. padding: 20rpx;
  179. &:not(:last-of-type) {
  180. border-bottom: $-solid-border;
  181. }
  182. .btn {
  183. width: 148rpx;
  184. height: 52rpx;
  185. border: 1px solid $-color-primary;
  186. &.valid {
  187. background-color: #f2f2f2;
  188. border-color: transparent;
  189. }
  190. }
  191. }
  192. }
  193. .store-list {
  194. margin: 0 20rpx;
  195. .store-item {
  196. padding: 15rpx 20rpx;
  197. border-radius: 16rpx;
  198. .store-name {}
  199. .tag {
  200. background: linear-gradient(267deg, #FF2C3C 0%, #F52E99 100%);
  201. border-radius: 6rpx;
  202. padding: 0 9rpx;
  203. vertical-align: 5rpx;
  204. }
  205. }
  206. }
  207. }
  208. </style>