index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <!-- 指定满减送的活动列表 -->
  2. <template>
  3. <s-layout class="activity-wrap" :title="state.activityInfo.title">
  4. <!-- 活动信息 -->
  5. <su-sticky bgColor="#fff">
  6. <view class="ss-flex ss-col-top tip-box">
  7. <view class="type-text ss-flex ss-row-center">满减:</view>
  8. <view class="ss-flex-1">
  9. <view class="tip-content" v-for="item in state.activityInfo.rules" :key="item">
  10. {{ item.description }}
  11. </view>
  12. </view>
  13. <image class="activity-left-image" src="/static/activity-left.png" />
  14. <image class="activity-right-image" src="/static/activity-right.png" />
  15. </view>
  16. </su-sticky>
  17. <!-- 商品信息 -->
  18. <view class="ss-flex ss-flex-wrap ss-p-x-20 ss-m-t-20 ss-col-top">
  19. <view class="goods-list-box">
  20. <view class="left-list" v-for="item in state.leftGoodsList" :key="item.id">
  21. <s-goods-column
  22. class="goods-md-box"
  23. size="md"
  24. :data="item"
  25. @click="sheep.$router.go('/pages/goods/index', { id: item.id })"
  26. @getHeight="mountMasonry($event, 'left')"
  27. >
  28. <template v-slot:cart>
  29. <button class="ss-reset-button cart-btn"> </button>
  30. </template>
  31. </s-goods-column>
  32. </view>
  33. </view>
  34. <view class="goods-list-box">
  35. <view class="right-list" v-for="item in state.rightGoodsList" :key="item.id">
  36. <s-goods-column
  37. class="goods-md-box"
  38. size="md"
  39. :data="item"
  40. @click="sheep.$router.go('/pages/goods/index', { id: item.id })"
  41. @getHeight="mountMasonry($event, 'right')"
  42. >
  43. <template v-slot:cart>
  44. <button class="ss-reset-button cart-btn" />
  45. </template>
  46. </s-goods-column>
  47. </view>
  48. </view>
  49. </view>
  50. <uni-load-more
  51. v-if="state.pagination.total > 0"
  52. :status="state.loadStatus"
  53. :content-text="{
  54. contentdown: '上拉加载更多',
  55. }"
  56. @tap="loadMore"
  57. />
  58. </s-layout>
  59. </template>
  60. <script setup>
  61. import { reactive } from 'vue';
  62. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  63. import sheep from '@/sheep';
  64. import _ from 'lodash-es';
  65. import RewardActivityApi from '@/sheep/api/promotion/rewardActivity';
  66. import SpuApi from '@/sheep/api/product/spu';
  67. import { appendSettlementProduct } from '@/sheep/hooks/useGoods';
  68. import OrderApi from '@/sheep/api/trade/order';
  69. const state = reactive({
  70. activityId: 0, // 获得编号
  71. activityInfo: {}, // 获得信息
  72. pagination: {
  73. list: [],
  74. total: 1,
  75. pageNo: 1,
  76. pageSize: 8,
  77. },
  78. loadStatus: '',
  79. leftGoodsList: [],
  80. rightGoodsList: [],
  81. });
  82. // 加载瀑布流
  83. let count = 0;
  84. let leftHeight = 0;
  85. let rightHeight = 0;
  86. function mountMasonry(height = 0, where = 'left') {
  87. if (!state.pagination.list[count]) return;
  88. if (where === 'left') {
  89. leftHeight += height;
  90. } else {
  91. rightHeight += height;
  92. }
  93. if (leftHeight <= rightHeight) {
  94. state.leftGoodsList.push(state.pagination.list[count]);
  95. } else {
  96. state.rightGoodsList.push(state.pagination.list[count]);
  97. }
  98. count++;
  99. }
  100. // 加载商品信息
  101. async function getList() {
  102. // 处理拓展参数
  103. const params = {};
  104. if (state.activityInfo.productScope === 2) {
  105. params.ids = state.activityInfo.productSpuIds.join(',');
  106. } else if (state.activityInfo.productScope === 3) {
  107. params.categoryIds = state.activityInfo.productSpuIds.join(',');
  108. }
  109. // 请求数据
  110. state.loadStatus = 'loading';
  111. const { code, data } = await SpuApi.getSpuPage({
  112. pageNo: state.pagination.pageNo,
  113. pageSize: state.pagination.pageSize,
  114. ...params,
  115. });
  116. if (code !== 0) {
  117. return;
  118. }
  119. // 拼接结算信息(营销)
  120. if (sheep.$store('user').isLogin) { // 需要登录
  121. await OrderApi.getSettlementProduct(data.list.map((item) => item.id).join(',')).then((res) => {
  122. if (res.code !== 0) {
  123. return;
  124. }
  125. appendSettlementProduct(data.list, res.data);
  126. });
  127. }
  128. state.pagination.list = _.concat(state.pagination.list, data.list);
  129. state.pagination.total = data.total;
  130. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  131. mountMasonry();
  132. }
  133. // 加载活动信息
  134. async function getActivity(id) {
  135. const { code, data } = await RewardActivityApi.getRewardActivity(id);
  136. if (code === 0) {
  137. state.activityInfo = data;
  138. }
  139. }
  140. // 加载更多
  141. function loadMore() {
  142. if (state.loadStatus === 'noMore') {
  143. return;
  144. }
  145. state.pagination.pageNo++;
  146. getList();
  147. }
  148. // 上拉加载更多
  149. onReachBottom(() => {
  150. loadMore();
  151. });
  152. onLoad(async (options) => {
  153. state.activityId = options.activityId;
  154. await getActivity(state.activityId);
  155. await getList(state.activityId);
  156. });
  157. </script>
  158. <style lang="scss" scoped>
  159. .goods-list-box {
  160. width: 50%;
  161. box-sizing: border-box;
  162. .left-list {
  163. margin-right: 10rpx;
  164. margin-bottom: 20rpx;
  165. }
  166. .right-list {
  167. margin-left: 10rpx;
  168. margin-bottom: 20rpx;
  169. }
  170. }
  171. .tip-box {
  172. background: #fff0e7;
  173. padding: 20rpx;
  174. width: 100%;
  175. position: relative;
  176. box-sizing: border-box;
  177. .activity-left-image {
  178. position: absolute;
  179. bottom: 0;
  180. left: 0;
  181. width: 58rpx;
  182. height: 36rpx;
  183. }
  184. .activity-right-image {
  185. position: absolute;
  186. top: 0;
  187. right: 0;
  188. width: 72rpx;
  189. height: 50rpx;
  190. }
  191. .type-text {
  192. font-size: 26rpx;
  193. font-weight: 500;
  194. color: #ff6000;
  195. line-height: 42rpx;
  196. }
  197. .tip-content {
  198. font-size: 26rpx;
  199. font-weight: 500;
  200. color: #ff6000;
  201. line-height: 42rpx;
  202. }
  203. }
  204. </style>