goods.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!-- 分销商品列表 -->
  2. <template>
  3. <s-layout title="推广商品" :onShareAppMessage="state.shareInfo">
  4. <view class="goods-item ss-m-20" v-for="item in state.pagination.list" :key="item.id">
  5. <s-goods-item
  6. size="lg"
  7. :img="item.picUrl"
  8. :title="item.name"
  9. :subTitle="item.introduction"
  10. :price="item.price"
  11. :originPrice="item.marketPrice"
  12. priceColor="#333"
  13. @tap="sheep.$router.go('/pages/goods/index', { id: item.id })"
  14. >
  15. <template #rightBottom>
  16. <view class="ss-flex ss-row-between">
  17. <view class="commission-num" v-if="item.brokerageMinPrice === undefined">预计佣金:计算中</view>
  18. <view class="commission-num" v-else-if="item.brokerageMinPrice === item.brokerageMaxPrice">
  19. 预计佣金:{{ fen2yuan(item.brokerageMinPrice) }}
  20. </view>
  21. <view class="commission-num" v-else>
  22. 预计佣金:{{ fen2yuan(item.brokerageMinPrice) }} ~ {{ fen2yuan(item.brokerageMaxPrice) }}
  23. </view>
  24. <button
  25. class="ss-reset-button share-btn ui-BG-Main-Gradient"
  26. @tap.stop="onShareGoods(item)"
  27. >
  28. 分享赚
  29. </button>
  30. </view>
  31. </template>
  32. </s-goods-item>
  33. </view>
  34. <s-empty
  35. v-if="state.pagination.total === 0"
  36. icon="/static/goods-empty.png"
  37. text="暂无推广商品"
  38. />
  39. <!-- 加载更多 -->
  40. <uni-load-more
  41. v-if="state.pagination.total > 0"
  42. :status="state.loadStatus"
  43. :content-text="{
  44. contentdown: '上拉加载更多',
  45. }"
  46. @tap="loadMore"
  47. />
  48. </s-layout>
  49. </template>
  50. <script setup>
  51. import sheep from '@/sheep';
  52. import $share from '@/sheep/platform/share';
  53. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  54. import { reactive } from 'vue';
  55. import _ from 'lodash';
  56. import { showShareModal } from '@/sheep/hooks/useModal';
  57. import SpuApi from '@/sheep/api/product/spu';
  58. import BrokerageApi from '@/sheep/api/trade/brokerage';
  59. import { fen2yuan } from '../../sheep/hooks/useGoods';
  60. const state = reactive({
  61. pagination: {
  62. list: [],
  63. total: 0,
  64. pageNo: 1,
  65. pageSize: 1,
  66. },
  67. loadStatus: '',
  68. shareInfo: {},
  69. });
  70. // TODO 非繁人:分享的接入
  71. function onShareGoods(goodsInfo) {
  72. state.shareInfo = $share.getShareInfo(
  73. {
  74. title: goodsInfo.title,
  75. image: sheep.$url.cdn(goodsInfo.image),
  76. desc: goodsInfo.subtitle,
  77. params: {
  78. page: '2',
  79. query: goodsInfo.id,
  80. },
  81. },
  82. {
  83. type: 'goods', // 商品海报
  84. title: goodsInfo.title, // 商品标题
  85. image: sheep.$url.cdn(goodsInfo.image), // 商品主图
  86. price: goodsInfo.price[0], // 商品价格
  87. original_price: goodsInfo.original_price, // 商品原价
  88. },
  89. );
  90. showShareModal();
  91. }
  92. async function getGoodsList() {
  93. state.loadStatus = 'loading';
  94. let { code, data } = await SpuApi.getSpuPage({
  95. pageSize: state.pagination.pageSize,
  96. pageNo: state.pagination.pageNo,
  97. });
  98. if (code !== 0) {
  99. return;
  100. }
  101. state.pagination.list = _.concat(state.pagination.list, data.list);
  102. state.pagination.total = data.total;
  103. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  104. // 补充分佣金额
  105. data.list.forEach((item) => {
  106. BrokerageApi.getProductBrokeragePrice(item.id).then((res) => {
  107. item.brokerageMinPrice = res.data.brokerageMinPrice;
  108. item.brokerageMaxPrice = res.data.brokerageMaxPrice;
  109. });
  110. });
  111. }
  112. onLoad(() => {
  113. getGoodsList();
  114. });
  115. // 加载更多
  116. function loadMore() {
  117. if (state.loadStatus === 'noMore') {
  118. return;
  119. }
  120. state.pagination.pageNo++;
  121. getGoodsList();
  122. }
  123. // 上拉加载更多
  124. onReachBottom(() => {
  125. loadMore();
  126. });
  127. </script>
  128. <style lang="scss" scoped>
  129. .goods-item {
  130. .commission-num {
  131. font-size: 24rpx;
  132. font-weight: 500;
  133. color: $red;
  134. }
  135. .share-btn {
  136. width: 120rpx;
  137. height: 50rpx;
  138. border-radius: 25rpx;
  139. }
  140. }
  141. </style>