list.vue 13 KB

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