list.vue 12 KB

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