list.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <s-layout navbar="inner" :bgStyle="{ color: '#FE832A' }">
  3. <view
  4. class="page-bg"
  5. :style="[{ marginTop: '-' + Number(statusBarHeight + 88) + 'rpx' }]"
  6. ></view>
  7. <view class="list-content">
  8. <view class="content-header ss-flex-col ss-col-center ss-row-center">
  9. <view class="content-header-title ss-m-b-22 ss-flex ss-row-center">
  10. <view>{{ state.activityInfo.title }}</view>
  11. <!-- <view class="more">更多</view> -->
  12. </view>
  13. <view class="content-header-box ss-flex ss-row-center">
  14. <view class="countdown-box ss-flex" v-if="endTime?.ms > 0 && state.activityInfo">
  15. <view class="countdown-title ss-m-r-12">距结束</view>
  16. <view class="ss-flex countdown-time">
  17. <view class="ss-flex countdown-h">{{ endTime.h }}</view>
  18. <view class="ss-m-x-4">:</view>
  19. <view class="countdown-num ss-flex ss-row-center">{{ endTime.m }}</view>
  20. <view class="ss-m-x-4">:</view>
  21. <view class="countdown-num ss-flex ss-row-center">{{ endTime.s }}</view>
  22. </view>
  23. </view>
  24. <view class="" v-if="endTime?.ms < 0 && state.activityInfo"> 活动已结束 </view>
  25. </view>
  26. </view>
  27. <scroll-view
  28. class="scroll-box"
  29. :style="{ height: pageHeight + 'rpx' }"
  30. scroll-y="true"
  31. :scroll-with-animation="false"
  32. :enable-back-to-top="true"
  33. >
  34. <view class="goods-box ss-m-b-20" v-for="item in state.pagination.data" :key="item.id">
  35. <s-goods-column
  36. class=""
  37. size="lg"
  38. :data="item"
  39. :grouponTag="true"
  40. @click="
  41. sheep.$router.go('/pages/goods/groupon', {
  42. id: item.id,
  43. activity_id: state.activityId,
  44. })
  45. "
  46. >
  47. <template v-slot:cart>
  48. <button class="ss-reset-button cart-btn">去拼团</button>
  49. </template>
  50. </s-goods-column>
  51. </view>
  52. <uni-load-more
  53. v-if="state.pagination.total > 0"
  54. :status="state.loadStatus"
  55. :content-text="{
  56. contentdown: '上拉加载更多',
  57. }"
  58. @tap="loadmore"
  59. />
  60. </scroll-view>
  61. </view>
  62. </s-layout>
  63. </template>
  64. <script setup>
  65. import { reactive, computed } from 'vue';
  66. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  67. import sheep from '@/sheep';
  68. import _ from 'lodash';
  69. import { useDurationTime } from '@/sheep/hooks/useGoods';
  70. const { screenHeight, safeAreaInsets, screenWidth, safeArea } = sheep.$platform.device;
  71. const sys_navBar = sheep.$platform.navbar;
  72. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  73. const pageHeight =
  74. (safeArea.height + safeAreaInsets.bottom) * 2 + statusBarHeight - sys_navBar - 350;
  75. const headerBg = sheep.$url.css('/static/img/shop/goods/groupon-header.png');
  76. const state = reactive({
  77. activityId: 0,
  78. pagination: {
  79. data: [],
  80. current_page: 1,
  81. total: 1,
  82. last_page: 1,
  83. },
  84. loadStatus: '',
  85. activityInfo: {},
  86. });
  87. // 倒计时
  88. const endTime = computed(() => {
  89. if (state.activityInfo.end_time) {
  90. return useDurationTime(state.activityInfo.end_time);
  91. }
  92. });
  93. async function getList(activityId, page = 1, list_rows = 4) {
  94. state.loadStatus = 'loading';
  95. const res = await sheep.$api.goods.activityList({
  96. list_rows,
  97. activity_id: activityId,
  98. page,
  99. });
  100. if (res.error === 0) {
  101. if (page >= 2) {
  102. let couponList = _.concat(state.pagination.data, res.data.data);
  103. state.pagination = {
  104. ...res.data,
  105. data: couponList,
  106. };
  107. } else {
  108. state.pagination = res.data;
  109. }
  110. if (state.pagination.current_page < state.pagination.last_page) {
  111. state.loadStatus = 'more';
  112. } else {
  113. state.loadStatus = 'noMore';
  114. }
  115. }
  116. }
  117. async function getActivity(id) {}
  118. // 加载更多
  119. function loadmore() {
  120. if (state.loadStatus !== 'noMore') {
  121. getList(state.activityId, state.pagination.current_page + 1);
  122. }
  123. }
  124. // 上拉加载更多
  125. onReachBottom(() => {
  126. loadmore();
  127. });
  128. onLoad(async (options) => {
  129. if (!options.id) {
  130. state.activityInfo = null;
  131. return;
  132. }
  133. state.activityId = options.id;
  134. getList(state.activityId);
  135. const { error, data } = await sheep.$api.activity.activity(options.id);
  136. if (error === 0) {
  137. state.activityInfo = data;
  138. } else {
  139. state.activityInfo = null;
  140. }
  141. });
  142. </script>
  143. <style lang="scss" scoped>
  144. .page-bg {
  145. width: 100%;
  146. height: 458rpx;
  147. margin-top: -88rpx;
  148. background: v-bind(headerBg) no-repeat;
  149. background-size: 100% 100%;
  150. }
  151. .list-content {
  152. position: relative;
  153. z-index: 3;
  154. margin: -190rpx 20rpx 0 20rpx;
  155. background: #fff;
  156. border-radius: 20rpx 20rpx 0 0;
  157. .content-header {
  158. width: 100%;
  159. border-radius: 20rpx 20rpx 0 0;
  160. height: 150rpx;
  161. background: linear-gradient(180deg, #fff4f7, #ffe4d1);
  162. .content-header-title {
  163. width: 100%;
  164. font-size: 30rpx;
  165. font-weight: 500;
  166. color: #ff2923;
  167. line-height: 30rpx;
  168. position: relative;
  169. .more {
  170. position: absolute;
  171. right: 30rpx;
  172. top: 0;
  173. font-size: 24rpx;
  174. font-weight: 400;
  175. color: #999999;
  176. line-height: 30rpx;
  177. }
  178. }
  179. .content-header-box {
  180. width: 678rpx;
  181. height: 64rpx;
  182. background: rgba($color: #fff, $alpha: 0.66);
  183. border-radius: 32px;
  184. .num {
  185. font-size: 24rpx;
  186. font-family: OPPOSANS;
  187. font-weight: 500;
  188. color: #f51c11;
  189. line-height: 30rpx;
  190. }
  191. .title {
  192. font-size: 24rpx;
  193. font-weight: 400;
  194. font-family: OPPOSANS;
  195. color: #333;
  196. line-height: 30rpx;
  197. }
  198. .countdown-title {
  199. font-size: 28rpx;
  200. font-weight: 500;
  201. color: #333333;
  202. line-height: 28rpx;
  203. }
  204. .countdown-time {
  205. font-size: 28rpx;
  206. color: rgba(#ed3c30, 0.23);
  207. .countdown-h {
  208. font-size: 24rpx;
  209. font-family: OPPOSANS;
  210. font-weight: 500;
  211. color: #ffffff;
  212. padding: 0 4rpx;
  213. height: 40rpx;
  214. background: rgba(#ed3c30, 0.23);
  215. border-radius: 6rpx;
  216. }
  217. .countdown-num {
  218. font-size: 24rpx;
  219. font-family: OPPOSANS;
  220. font-weight: 500;
  221. color: #ffffff;
  222. width: 40rpx;
  223. height: 40rpx;
  224. background: rgba(#ed3c30, 0.23);
  225. border-radius: 6rpx;
  226. }
  227. }
  228. }
  229. }
  230. .scroll-box {
  231. height: 900rpx;
  232. .goods-box {
  233. position: relative;
  234. .cart-btn {
  235. position: absolute;
  236. bottom: 10rpx;
  237. right: 20rpx;
  238. z-index: 11;
  239. height: 50rpx;
  240. line-height: 50rpx;
  241. padding: 0 20rpx;
  242. border-radius: 25rpx;
  243. font-size: 24rpx;
  244. color: #fff;
  245. background: linear-gradient(90deg, #ff6600 0%, #fe832a 100%);
  246. }
  247. }
  248. }
  249. }
  250. </style>