list.vue 12 KB

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