goods.vue 3.0 KB

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