goods.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!-- 页面 -->
  2. <template>
  3. <s-layout title="推广商品" :onShareAppMessage="state.shareInfo">
  4. <view class="goods-item ss-m-20" v-for="item in state.pagination.data" :key="item.id">
  5. <s-goods-item
  6. size="lg"
  7. :img="item.image"
  8. :title="item.title"
  9. :subTitle="item.subtitle"
  10. :price="item.price[0]"
  11. :originPrice="item.original_price"
  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">预计佣金:¥{{ item.commission }}</view>
  18. <button
  19. class="ss-reset-button share-btn ui-BG-Main-Gradient"
  20. @tap.stop="onShareGoods(item)"
  21. >
  22. 分享赚
  23. </button>
  24. </view>
  25. </template>
  26. </s-goods-item>
  27. </view>
  28. <s-empty
  29. v-if="state.pagination.total === 0"
  30. icon="/static/goods-empty.png"
  31. text="暂无推广商品"
  32. ></s-empty>
  33. <!-- 加载更多 -->
  34. <uni-load-more
  35. v-if="state.pagination.total > 0"
  36. :status="state.loadStatus"
  37. :content-text="{
  38. contentdown: '上拉加载更多',
  39. }"
  40. @tap="loadmore"
  41. />
  42. </s-layout>
  43. </template>
  44. <script setup>
  45. import sheep from '@/sheep';
  46. import $share from '@/sheep/platform/share';
  47. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  48. import { computed, reactive } from 'vue';
  49. import _ from 'lodash';
  50. import { showShareModal } from '@/sheep/hooks/useModal';
  51. const state = reactive({
  52. pagination: {
  53. data: [],
  54. current_page: 1,
  55. total: 1,
  56. last_page: 1,
  57. },
  58. loadStatus: '',
  59. shareInfo: {},
  60. });
  61. function onShareGoods(goodsInfo) {
  62. state.shareInfo = $share.getShareInfo(
  63. {
  64. title: goodsInfo.title,
  65. image: sheep.$url.cdn(goodsInfo.image),
  66. desc: goodsInfo.subtitle,
  67. params: {
  68. page: '2',
  69. query: goodsInfo.id,
  70. },
  71. },
  72. {
  73. type: 'goods', // 商品海报
  74. title: goodsInfo.title, // 商品标题
  75. image: sheep.$url.cdn(goodsInfo.image), // 商品主图
  76. price: goodsInfo.price[0], // 商品价格
  77. original_price: goodsInfo.original_price, // 商品原价
  78. },
  79. );
  80. showShareModal();
  81. }
  82. async function getGoodsList(page = 1, list_rows = 8) {
  83. state.loadStatus = 'loading';
  84. let res = await sheep.$api.commission.goods({
  85. list_rows,
  86. page,
  87. });
  88. if (res.error === 0) {
  89. let orderList = _.concat(state.pagination.data, res.data.data);
  90. state.pagination = {
  91. ...res.data,
  92. data: orderList,
  93. };
  94. if (state.pagination.current_page < state.pagination.last_page) {
  95. state.loadStatus = 'more';
  96. } else {
  97. state.loadStatus = 'noMore';
  98. }
  99. }
  100. }
  101. onLoad(async () => {
  102. getGoodsList();
  103. });
  104. // 加载更多
  105. function loadmore() {
  106. if (state.loadStatus !== 'noMore') {
  107. getGoodsList(state.pagination.current_page + 1);
  108. }
  109. }
  110. // 上拉加载更多
  111. onReachBottom(() => {
  112. loadmore();
  113. });
  114. </script>
  115. <style lang="scss" scoped>
  116. .goods-item {
  117. .commission-num {
  118. font-size: 24rpx;
  119. font-weight: 500;
  120. color: $red;
  121. }
  122. .share-btn {
  123. width: 120rpx;
  124. height: 50rpx;
  125. border-radius: 25rpx;
  126. }
  127. }
  128. </style>