index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. {{ formatRewardActivityRule(state.activityInfo, item) }}
  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';
  65. import RewardActivityApi from '@/sheep/api/promotion/rewardActivity';
  66. import { formatRewardActivityRule } from '@/sheep/hooks/useGoods';
  67. import SpuApi from '@/sheep/api/product/spu';
  68. const state = reactive({
  69. activityId: 0, // 获得编号
  70. activityInfo: {}, // 获得信息
  71. pagination: {
  72. list: [],
  73. total: 1,
  74. pageNo: 1,
  75. pageSize: 8,
  76. },
  77. loadStatus: '',
  78. leftGoodsList: [],
  79. rightGoodsList: [],
  80. });
  81. // 加载瀑布流
  82. let count = 0;
  83. let leftHeight = 0;
  84. let rightHeight = 0;
  85. function mountMasonry(height = 0, where = 'left') {
  86. if (!state.pagination.list[count]) return;
  87. if (where === 'left') {
  88. leftHeight += height;
  89. } else {
  90. rightHeight += height;
  91. }
  92. if (leftHeight <= rightHeight) {
  93. state.leftGoodsList.push(state.pagination.list[count]);
  94. } else {
  95. state.rightGoodsList.push(state.pagination.list[count]);
  96. }
  97. count++;
  98. }
  99. // 加载商品信息
  100. async function getList() {
  101. // 处理拓展参数
  102. const params = {};
  103. if (state.activityInfo.productScope === 2) {
  104. params.ids = state.activityInfo.productSpuIds.join(',');
  105. } else if (state.activityInfo.productScope === 3) {
  106. params.categoryIds = state.activityInfo.productSpuIds.join(',');
  107. }
  108. // 请求数据
  109. state.loadStatus = 'loading';
  110. const { code, data } = await SpuApi.getSpuPage({
  111. pageNo: state.pagination.pageNo,
  112. pageSize: state.pagination.pageSize,
  113. ...params
  114. });
  115. if (code !== 0) {
  116. return;
  117. }
  118. state.pagination.list = _.concat(state.pagination.list, data.list);
  119. state.pagination.total = data.total;
  120. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  121. mountMasonry();
  122. }
  123. // 加载活动信息
  124. async function getActivity(id) {
  125. const { code, data } = await RewardActivityApi.getRewardActivity(id);
  126. if (code === 0) {
  127. state.activityInfo = data;
  128. }
  129. }
  130. // 加载更多
  131. function loadMore() {
  132. if (state.loadStatus === 'noMore') {
  133. return;
  134. }
  135. state.pagination.pageNo++;
  136. getList();
  137. }
  138. // 上拉加载更多
  139. onReachBottom(() => {
  140. loadMore();
  141. });
  142. onLoad(async (options) => {
  143. state.activityId = options.activityId;
  144. await getActivity(state.activityId);
  145. await getList(state.activityId);
  146. });
  147. </script>
  148. <style lang="scss" scoped>
  149. .goods-list-box {
  150. width: 50%;
  151. box-sizing: border-box;
  152. .left-list {
  153. margin-right: 10rpx;
  154. margin-bottom: 20rpx;
  155. }
  156. .right-list {
  157. margin-left: 10rpx;
  158. margin-bottom: 20rpx;
  159. }
  160. }
  161. .tip-box {
  162. background: #fff0e7;
  163. padding: 20rpx;
  164. width: 100%;
  165. position: relative;
  166. box-sizing: border-box;
  167. .activity-left-image {
  168. position: absolute;
  169. bottom: 0;
  170. left: 0;
  171. width: 58rpx;
  172. height: 36rpx;
  173. }
  174. .activity-right-image {
  175. position: absolute;
  176. top: 0;
  177. right: 0;
  178. width: 72rpx;
  179. height: 50rpx;
  180. }
  181. .type-text {
  182. font-size: 26rpx;
  183. font-weight: 500;
  184. color: #ff6000;
  185. line-height: 42rpx;
  186. }
  187. .tip-content {
  188. font-size: 26rpx;
  189. font-weight: 500;
  190. color: #ff6000;
  191. line-height: 42rpx;
  192. }
  193. }
  194. </style>