list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <!-- 秒杀活动列表 -->
  2. <template>
  3. <s-layout :bgStyle="{ color: 'rgb(245,28,19)' }" navbar="inner">
  4. <!--顶部背景图-->
  5. <view
  6. class="page-bg"
  7. :style="[{ marginTop: '-' + Number(statusBarHeight + 88) + 'rpx' }]"
  8. ></view>
  9. <!-- 时间段轮播图 -->
  10. <view class="header" v-if="activeTimeConfig?.sliderPicUrls?.length > 0">
  11. <swiper
  12. indicator-dots="true"
  13. autoplay="true"
  14. :circular="true"
  15. interval="3000"
  16. duration="1500"
  17. indicator-color="rgba(255,255,255,0.6)"
  18. indicator-active-color="#fff"
  19. >
  20. <block v-for="(picUrl, index) in activeTimeConfig.sliderPicUrls" :key="index">
  21. <swiper-item class="borRadius14">
  22. <image :src="picUrl" class="slide-image borRadius14" lazy-load />
  23. </swiper-item>
  24. </block>
  25. </swiper>
  26. </view>
  27. <!-- 时间段列表 -->
  28. <view class="flex align-center justify-between ss-p-25">
  29. <!-- 左侧图标 -->
  30. <view class="time-icon">
  31. <image
  32. class="ss-w-100 ss-h-100"
  33. :src="sheep.$url.static('/static/img/shop/priceTag.png')"
  34. />
  35. </view>
  36. <scroll-view
  37. class="time-list"
  38. :scroll-into-view="activeTimeElId"
  39. scroll-x
  40. scroll-with-animation
  41. >
  42. <view
  43. v-for="(config, index) in timeConfigList"
  44. :key="index"
  45. :class="['item', { active: activeTimeIndex === index }]"
  46. :id="`timeItem${index}`"
  47. @tap="handleChangeTimeConfig(index, config.id)"
  48. >
  49. <!-- 活动起始时间 -->
  50. <view class="time">{{ config.startTime }}</view>
  51. <!-- 活动状态 -->
  52. <view class="status">{{ config?.status }}</view>
  53. </view>
  54. </scroll-view>
  55. </view>
  56. <!-- 内容区 -->
  57. <view class="list-content">
  58. <!-- 活动倒计时 -->
  59. <view class="content-header ss-flex-col ss-col-center ss-row-center">
  60. <view class="content-header-box ss-flex ss-row-center">
  61. <view
  62. class="countdown-box ss-flex"
  63. v-if="activeTimeConfig?.status === TimeStatusEnum.STARTED"
  64. >
  65. <view class="countdown-title ss-m-r-12">距结束</view>
  66. <view class="ss-flex countdown-time">
  67. <view class="ss-flex countdown-h">{{ countDown.h }}</view>
  68. <view class="ss-m-x-4">:</view>
  69. <view class="countdown-num ss-flex ss-row-center">{{ countDown.m }}</view>
  70. <view class="ss-m-x-4">:</view>
  71. <view class="countdown-num ss-flex ss-row-center">{{ countDown.s }}</view>
  72. </view>
  73. </view>
  74. <view v-else> {{ activeTimeConfig?.status }} </view>
  75. </view>
  76. </view>
  77. <!-- 活动列表 -->
  78. <scroll-view
  79. class="scroll-box"
  80. :style="{ height: pageHeight + 'rpx' }"
  81. scroll-y="true"
  82. :scroll-with-animation="false"
  83. :enable-back-to-top="true"
  84. >
  85. <view class="goods-box ss-m-b-20" v-for="activity in activityList" :key="activity.id">
  86. <s-goods-column
  87. size="lg"
  88. :data="{ ...activity, price: activity.seckillPrice }"
  89. :goodsFields="goodsFields"
  90. :seckillTag="true"
  91. >
  92. <!-- 抢购进度 -->
  93. <template #activity>
  94. <view class="limit">
  95. 限量
  96. <text class="ss-m-l-5">{{ activity.stock }} {{ activity.unitName }}</text>
  97. </view>
  98. <su-progress :percentage="activity.percent" strokeWidth="10" textInside isAnimate />
  99. </template>
  100. <!-- 抢购按钮 -->
  101. <template #cart>
  102. <button
  103. :class="[
  104. 'ss-reset-button cart-btn',
  105. { disabled: activeTimeConfig?.status === TimeStatusEnum.END },
  106. ]"
  107. v-if="activeTimeConfig?.status === TimeStatusEnum.WAIT_START"
  108. >
  109. <span>未开始</span>
  110. </button>
  111. <button
  112. :class="[
  113. 'ss-reset-button cart-btn',
  114. { disabled: activeTimeConfig?.status === TimeStatusEnum.END },
  115. ]"
  116. @click="sheep.$router.go('/pages/goods/seckill', { id: activity.id })"
  117. v-else-if="activeTimeConfig?.status === TimeStatusEnum.STARTED"
  118. >
  119. <span>马上抢</span>
  120. </button>
  121. <button
  122. :class="[
  123. 'ss-reset-button cart-btn',
  124. { disabled: activeTimeConfig?.status === TimeStatusEnum.END },
  125. ]"
  126. v-else
  127. >
  128. <span>已结束</span>
  129. </button>
  130. </template>
  131. </s-goods-column>
  132. </view>
  133. <uni-load-more
  134. v-if="activityTotal > 0"
  135. :status="loadStatus"
  136. :content-text="{
  137. contentdown: '上拉加载更多',
  138. }"
  139. @tap="loadMore"
  140. />
  141. </scroll-view>
  142. </view>
  143. </s-layout>
  144. </template>
  145. <script setup>
  146. import { computed, nextTick, reactive, ref } from 'vue';
  147. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  148. import sheep from '@/sheep';
  149. import { useDurationTime } from '@/sheep/hooks/useGoods';
  150. import SeckillApi from '@/sheep/api/promotion/seckill';
  151. import dayjs from 'dayjs';
  152. import { TimeStatusEnum } from '@/sheep/helper/const';
  153. // 计算页面高度
  154. const { safeAreaInsets, safeArea } = sheep.$platform.device;
  155. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  156. const pageHeight =
  157. (safeArea.height + safeAreaInsets.bottom) * 2 + statusBarHeight - sheep.$platform.navbar - 350;
  158. const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-header.png');
  159. // 商品控件显示的字段(不显示库存、销量。改为显示自定义的进度条)
  160. const goodsFields = {
  161. name: {
  162. show: true,
  163. },
  164. introduction: {
  165. show: true,
  166. },
  167. price: {
  168. show: true,
  169. },
  170. marketPrice: {
  171. show: true,
  172. },
  173. };
  174. //#region 时间段
  175. // 时间段列表
  176. const timeConfigList = ref([]);
  177. // 查询时间段
  178. const getSeckillConfigList = async () => {
  179. const { data } = await SeckillApi.getSeckillConfigList();
  180. const now = dayjs();
  181. const today = now.format('YYYY-MM-DD');
  182. const select = ref([]);
  183. // 判断时间段的状态
  184. data.forEach((config, index) => {
  185. const startTime = dayjs(`${today} ${config.startTime}`);
  186. const endTime = dayjs(`${today} ${config.endTime}`);
  187. select.value[index] = config.id;
  188. if (now.isBefore(startTime)) {
  189. config.status = TimeStatusEnum.WAIT_START;
  190. } else if (now.isAfter(endTime)) {
  191. config.status = TimeStatusEnum.END;
  192. } else {
  193. config.status = TimeStatusEnum.STARTED;
  194. activeTimeIndex.value = index;
  195. }
  196. });
  197. timeConfigList.value = data;
  198. // 默认选中进行中的活动
  199. handleChangeTimeConfig(activeTimeIndex.value, select.value[activeTimeIndex.value]);
  200. // 滚动到进行中的时间段
  201. scrollToTimeConfig(activeTimeIndex.value);
  202. };
  203. // 滚动到指定时间段
  204. const activeTimeElId = ref(''); // 当前选中的时间段的元素ID
  205. const scrollToTimeConfig = (index) => {
  206. nextTick(() => (activeTimeElId.value = `timeItem${index}`));
  207. };
  208. // 切换时间段
  209. const activeTimeIndex = ref(0); // 当前选中的时间段的索引
  210. const activeTimeConfig = computed(() => timeConfigList.value[activeTimeIndex.value]); // 当前选中的时间段
  211. const handleChangeTimeConfig = (index, id) => {
  212. activeTimeIndex.value = index;
  213. // 查询活动列表
  214. activityPageParams.pageNo = 1;
  215. activityPageParams.configId = id;
  216. activityList.value = [];
  217. getActivityList();
  218. };
  219. // 倒计时
  220. const countDown = computed(() => {
  221. const endTime = activeTimeConfig.value?.endTime;
  222. if (endTime) {
  223. return useDurationTime(`${dayjs().format('YYYY-MM-DD')} ${endTime}`);
  224. }
  225. });
  226. //#endregion
  227. //#region 分页查询活动列表
  228. // 查询活动列表
  229. const activityPageParams = reactive({
  230. configId: 0, // 时间段 ID
  231. pageNo: 1, // 页码
  232. pageSize: 5, // 每页数量
  233. });
  234. const activityTotal = ref(0); // 活动总数
  235. const activityList = ref([]); // 活动列表
  236. const loadStatus = ref(''); // 页面加载状态
  237. async function getActivityList() {
  238. loadStatus.value = 'loading';
  239. const { data } = await SeckillApi.getSeckillActivityPage(activityPageParams);
  240. data.list.forEach((activity) => {
  241. // 计算抢购进度
  242. activity.percent = parseInt(
  243. (100 * (activity.totalStock - activity.stock)) / activity.totalStock,
  244. );
  245. });
  246. activityList.value = activityList.value.concat(...data.list);
  247. activityTotal.value = data.total;
  248. loadStatus.value = activityList.value.length < activityTotal.value ? 'more' : 'noMore';
  249. }
  250. // 加载更多
  251. function loadMore() {
  252. if (loadStatus.value !== 'noMore') {
  253. activityPageParams.pageNo += 1;
  254. getActivityList();
  255. }
  256. }
  257. // 上拉加载更多
  258. onReachBottom(() => loadMore());
  259. //#endregion
  260. // 页面初始化
  261. onLoad(async () => {
  262. await getSeckillConfigList();
  263. });
  264. </script>
  265. <style lang="scss" scoped>
  266. // 顶部背景图
  267. .page-bg {
  268. width: 100%;
  269. height: 458rpx;
  270. background: v-bind(headerBg) no-repeat;
  271. background-size: 100% 100%;
  272. }
  273. // 时间段轮播图
  274. .header {
  275. width: 710rpx;
  276. height: 330rpx;
  277. margin: -276rpx auto 0 auto;
  278. border-radius: 14rpx;
  279. overflow: hidden;
  280. swiper {
  281. height: 330rpx !important;
  282. border-radius: 14rpx;
  283. overflow: hidden;
  284. }
  285. image {
  286. width: 100%;
  287. height: 100%;
  288. border-radius: 14rpx;
  289. overflow: hidden;
  290. img {
  291. border-radius: 14rpx;
  292. }
  293. }
  294. }
  295. // 时间段列表:左侧图标
  296. .time-icon {
  297. width: 75rpx;
  298. height: 70rpx;
  299. }
  300. // 时间段列表
  301. .time-list {
  302. width: 596rpx;
  303. white-space: nowrap;
  304. // 时间段
  305. .item {
  306. display: inline-block;
  307. font-size: 20rpx;
  308. color: #666;
  309. text-align: center;
  310. box-sizing: border-box;
  311. margin-right: 30rpx;
  312. width: 130rpx;
  313. // 开始时间
  314. .time {
  315. font-size: 36rpx;
  316. font-weight: 600;
  317. color: #333;
  318. }
  319. // 选中的时间段
  320. &.active {
  321. .time {
  322. color: var(--ui-BG-Main);
  323. }
  324. // 状态
  325. .status {
  326. height: 30rpx;
  327. line-height: 30rpx;
  328. border-radius: 15rpx;
  329. width: 128rpx;
  330. background: linear-gradient(90deg, var(--ui-BG-Main) 0%, var(--ui-BG-Main-gradient) 100%);
  331. color: #fff;
  332. }
  333. }
  334. }
  335. }
  336. // 内容区
  337. .list-content {
  338. position: relative;
  339. z-index: 3;
  340. margin: 0 20rpx 0 20rpx;
  341. background: #fff;
  342. border-radius: 20rpx 20rpx 0 0;
  343. .content-header {
  344. width: 100%;
  345. border-radius: 20rpx 20rpx 0 0;
  346. height: 150rpx;
  347. background: linear-gradient(180deg, #fff4f7, #ffe6ec);
  348. .content-header-box {
  349. width: 678rpx;
  350. height: 64rpx;
  351. background: rgba($color: #fff, $alpha: 0.66);
  352. border-radius: 32px;
  353. // 场次倒计时内容
  354. .countdown-title {
  355. font-size: 28rpx;
  356. font-weight: 500;
  357. color: #333333;
  358. line-height: 28rpx;
  359. }
  360. // 场次倒计时
  361. .countdown-time {
  362. font-size: 28rpx;
  363. color: rgba(#ed3c30, 0.23);
  364. // 场次倒计时:小时部分
  365. .countdown-h {
  366. font-size: 24rpx;
  367. font-family: OPPOSANS;
  368. font-weight: 500;
  369. color: #ffffff;
  370. padding: 0 4rpx;
  371. height: 40rpx;
  372. background: rgba(#ed3c30, 0.23);
  373. border-radius: 6rpx;
  374. }
  375. // 场次倒计时:分钟、秒
  376. .countdown-num {
  377. font-size: 24rpx;
  378. font-family: OPPOSANS;
  379. font-weight: 500;
  380. color: #ffffff;
  381. width: 40rpx;
  382. height: 40rpx;
  383. background: rgba(#ed3c30, 0.23);
  384. border-radius: 6rpx;
  385. }
  386. }
  387. }
  388. }
  389. // 活动列表
  390. .scroll-box {
  391. height: 900rpx;
  392. // 活动
  393. .goods-box {
  394. position: relative;
  395. // 抢购按钮
  396. .cart-btn {
  397. position: absolute;
  398. bottom: 10rpx;
  399. right: 20rpx;
  400. z-index: 11;
  401. height: 44rpx;
  402. line-height: 50rpx;
  403. padding: 0 20rpx;
  404. border-radius: 25rpx;
  405. font-size: 24rpx;
  406. color: #fff;
  407. background: linear-gradient(90deg, #ff6600 0%, #fe832a 100%);
  408. &.disabled {
  409. background: $gray-b;
  410. color: #fff;
  411. }
  412. }
  413. // 秒杀限量商品数
  414. .limit {
  415. font-size: 22rpx;
  416. color: $dark-9;
  417. margin-bottom: 5rpx;
  418. }
  419. }
  420. }
  421. }
  422. </style>