index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. await OrderApi.getSettlementProduct(data.list.map((item) => item.id).join(',')).then((res) => {
  121. if (res.code !== 0) {
  122. return;
  123. }
  124. appendSettlementProduct(data.list, res.data);
  125. });
  126. state.pagination.list = _.concat(state.pagination.list, data.list);
  127. state.pagination.total = data.total;
  128. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  129. mountMasonry();
  130. }
  131. // 加载活动信息
  132. async function getActivity(id) {
  133. const { code, data } = await RewardActivityApi.getRewardActivity(id);
  134. if (code === 0) {
  135. state.activityInfo = data;
  136. }
  137. }
  138. // 加载更多
  139. function loadMore() {
  140. if (state.loadStatus === 'noMore') {
  141. return;
  142. }
  143. state.pagination.pageNo++;
  144. getList();
  145. }
  146. // 上拉加载更多
  147. onReachBottom(() => {
  148. loadMore();
  149. });
  150. onLoad(async (options) => {
  151. state.activityId = options.activityId;
  152. await getActivity(state.activityId);
  153. await getList(state.activityId);
  154. });
  155. </script>
  156. <style lang="scss" scoped>
  157. .goods-list-box {
  158. width: 50%;
  159. box-sizing: border-box;
  160. .left-list {
  161. margin-right: 10rpx;
  162. margin-bottom: 20rpx;
  163. }
  164. .right-list {
  165. margin-left: 10rpx;
  166. margin-bottom: 20rpx;
  167. }
  168. }
  169. .tip-box {
  170. background: #fff0e7;
  171. padding: 20rpx;
  172. width: 100%;
  173. position: relative;
  174. box-sizing: border-box;
  175. .activity-left-image {
  176. position: absolute;
  177. bottom: 0;
  178. left: 0;
  179. width: 58rpx;
  180. height: 36rpx;
  181. }
  182. .activity-right-image {
  183. position: absolute;
  184. top: 0;
  185. right: 0;
  186. width: 72rpx;
  187. height: 50rpx;
  188. }
  189. .type-text {
  190. font-size: 26rpx;
  191. font-weight: 500;
  192. color: #ff6000;
  193. line-height: 42rpx;
  194. }
  195. .tip-content {
  196. font-size: 26rpx;
  197. font-weight: 500;
  198. color: #ff6000;
  199. line-height: 42rpx;
  200. }
  201. }
  202. </style>