list.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <s-layout navbar="inner" :bgStyle="{ color: 'rgb(245,28,19)' }">
  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. :seckillTag="true"
  40. @click="
  41. sheep.$router.go('/pages/goods/seckill', {
  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/seckill-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. let couponList = _.concat(state.pagination.data, res.data.data);
  102. state.pagination = {
  103. ...res.data,
  104. data: couponList,
  105. };
  106. if (state.pagination.current_page < state.pagination.last_page) {
  107. state.loadStatus = 'more';
  108. } else {
  109. state.loadStatus = 'noMore';
  110. }
  111. }
  112. }
  113. async function getActivity(id) {}
  114. // 加载更多
  115. function loadmore() {
  116. if (state.loadStatus !== 'noMore') {
  117. getList(state.activityId, state.pagination.current_page + 1);
  118. }
  119. }
  120. // 上拉加载更多
  121. onReachBottom(() => {
  122. loadmore();
  123. });
  124. onLoad(async (options) => {
  125. if (!options.id) {
  126. state.activityInfo = null;
  127. return;
  128. }
  129. state.activityId = options.id;
  130. getList(state.activityId);
  131. const { error, data } = await sheep.$api.activity.activity(options.id);
  132. if (error === 0) {
  133. state.activityInfo = data;
  134. } else {
  135. state.activityInfo = null;
  136. }
  137. });
  138. </script>
  139. <style lang="scss" scoped>
  140. .page-bg {
  141. width: 100%;
  142. height: 458rpx;
  143. background: v-bind(headerBg) no-repeat;
  144. background-size: 100% 100%;
  145. }
  146. .list-content {
  147. position: relative;
  148. z-index: 3;
  149. margin: -190rpx 20rpx 0 20rpx;
  150. background: #fff;
  151. border-radius: 20rpx 20rpx 0 0;
  152. .content-header {
  153. width: 100%;
  154. border-radius: 20rpx 20rpx 0 0;
  155. height: 150rpx;
  156. background: linear-gradient(180deg, #fff4f7, #ffe6ec);
  157. .content-header-title {
  158. width: 100%;
  159. font-size: 30rpx;
  160. font-weight: 500;
  161. color: #ff2923;
  162. line-height: 30rpx;
  163. position: relative;
  164. .more {
  165. position: absolute;
  166. right: 30rpx;
  167. top: 0;
  168. font-size: 24rpx;
  169. font-weight: 400;
  170. color: #999999;
  171. line-height: 30rpx;
  172. }
  173. }
  174. .content-header-box {
  175. width: 678rpx;
  176. height: 64rpx;
  177. background: rgba($color: #fff, $alpha: 0.66);
  178. border-radius: 32px;
  179. .num {
  180. font-size: 24rpx;
  181. font-family: OPPOSANS;
  182. font-weight: 500;
  183. color: #f51c11;
  184. line-height: 30rpx;
  185. }
  186. .title {
  187. font-size: 24rpx;
  188. font-weight: 400;
  189. font-family: OPPOSANS;
  190. color: #333;
  191. line-height: 30rpx;
  192. }
  193. .countdown-title {
  194. font-size: 28rpx;
  195. font-weight: 500;
  196. color: #333333;
  197. line-height: 28rpx;
  198. }
  199. .countdown-time {
  200. font-size: 28rpx;
  201. color: rgba(#ed3c30, 0.23);
  202. .countdown-h {
  203. font-size: 24rpx;
  204. font-family: OPPOSANS;
  205. font-weight: 500;
  206. color: #ffffff;
  207. padding: 0 4rpx;
  208. height: 40rpx;
  209. background: rgba(#ed3c30, 0.23);
  210. border-radius: 6rpx;
  211. }
  212. .countdown-num {
  213. font-size: 24rpx;
  214. font-family: OPPOSANS;
  215. font-weight: 500;
  216. color: #ffffff;
  217. width: 40rpx;
  218. height: 40rpx;
  219. background: rgba(#ed3c30, 0.23);
  220. border-radius: 6rpx;
  221. }
  222. }
  223. }
  224. }
  225. .scroll-box {
  226. height: 900rpx;
  227. .goods-box {
  228. position: relative;
  229. .cart-btn {
  230. position: absolute;
  231. bottom: 10rpx;
  232. right: 20rpx;
  233. z-index: 11;
  234. height: 50rpx;
  235. line-height: 50rpx;
  236. padding: 0 20rpx;
  237. border-radius: 25rpx;
  238. font-size: 24rpx;
  239. color: #fff;
  240. background: linear-gradient(90deg, #ff6600 0%, #fe832a 100%);
  241. }
  242. }
  243. }
  244. }
  245. </style>