list.vue 12 KB

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