mall-uniapp/pages/activity/seckill/list.vue

427 lines
12 KiB
Vue
Raw Normal View History

2023-12-27 11:22:55 +00:00
<!-- 秒杀活动列表 -->
2022-11-22 07:45:36 +00:00
<template>
<s-layout navbar="inner" :bgStyle="{ color: 'rgb(245,28,19)' }">
2023-12-19 13:39:52 +00:00
<!--顶部背景图-->
2024-09-15 09:32:29 +00:00
<view class="page-bg" :style="[{ marginTop: '-' + Number(statusBarHeight + 88) + 'rpx' }]"></view>
2023-12-19 13:39:52 +00:00
<!-- 时间段轮播图 -->
<view class="header" v-if="activeTimeConfig?.sliderPicUrls?.length > 0">
<swiper indicator-dots="true" autoplay="true" :circular="true" interval="3000" duration="1500"
indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
<block v-for="(picUrl, index) in activeTimeConfig.sliderPicUrls" :key="index">
<swiper-item class="borRadius14">
<image :src="picUrl" class="slide-image borRadius14" lazy-load />
</swiper-item>
</block>
</swiper>
</view>
<!-- 时间段列表 -->
<view class="flex align-center justify-between ss-p-25">
<!-- 左侧图标 -->
<view class="time-icon">
2023-12-27 11:22:55 +00:00
<!-- TODO 芋艿图片统一维护 -->
<image class="ss-w-100 ss-h-100" src="http://mall.yudao.iocoder.cn/static/images/priceTag.png" />
2023-12-19 13:39:52 +00:00
</view>
<scroll-view class="time-list" :scroll-into-view="activeTimeElId" scroll-x scroll-with-animation>
<view v-for="(config, index) in timeConfigList" :key="index"
2024-09-15 09:32:29 +00:00
:class="['item', { active: activeTimeIndex === index}]" :id="`timeItem${index}`"
@tap="handleChangeTimeConfig(index,config.id)">
2023-12-19 13:39:52 +00:00
<!-- 活动起始时间 -->
<view class="time">{{ config.startTime }}</view>
<!-- 活动状态 -->
2024-09-15 09:32:29 +00:00
<view class="status">{{ config?.status }}</view>
2023-12-19 13:39:52 +00:00
</view>
</scroll-view>
</view>
2023-12-27 11:22:55 +00:00
2023-12-19 13:39:52 +00:00
<!-- 内容区 -->
2022-11-22 07:45:36 +00:00
<view class="list-content">
2023-12-19 13:39:52 +00:00
<!-- 活动倒计时 -->
2022-11-22 07:45:36 +00:00
<view class="content-header ss-flex-col ss-col-center ss-row-center">
<view class="content-header-box ss-flex ss-row-center">
2023-12-19 13:39:52 +00:00
<view class="countdown-box ss-flex" v-if="activeTimeConfig?.status === TimeStatusEnum.STARTED">
2022-11-22 07:45:36 +00:00
<view class="countdown-title ss-m-r-12">距结束</view>
<view class="ss-flex countdown-time">
2023-12-19 13:39:52 +00:00
<view class="ss-flex countdown-h">{{ countDown.h }}</view>
2022-11-22 07:45:36 +00:00
<view class="ss-m-x-4">:</view>
2023-12-19 13:39:52 +00:00
<view class="countdown-num ss-flex ss-row-center">{{ countDown.m }}</view>
2022-11-22 07:45:36 +00:00
<view class="ss-m-x-4">:</view>
2023-12-19 13:39:52 +00:00
<view class="countdown-num ss-flex ss-row-center">{{ countDown.s }}</view>
2022-11-22 07:45:36 +00:00
</view>
</view>
2023-12-19 13:39:52 +00:00
<view v-else> {{ activeTimeConfig?.status }} </view>
2022-11-22 07:45:36 +00:00
</view>
</view>
2023-12-27 11:22:55 +00:00
2023-12-19 13:39:52 +00:00
<!-- 活动列表 -->
2024-09-15 09:32:29 +00:00
<scroll-view class="scroll-box" :style="{ height: pageHeight + 'rpx' }" scroll-y="true"
:scroll-with-animation="false" :enable-back-to-top="true">
2023-12-19 13:39:52 +00:00
<view class="goods-box ss-m-b-20" v-for="activity in activityList" :key="activity.id">
2024-09-15 09:32:29 +00:00
<s-goods-column size="lg" :data="{ ...activity, price: activity.seckillPrice }"
:goodsFields="goodsFields" :seckillTag="true">
2023-12-19 13:39:52 +00:00
<!-- 抢购进度 -->
<template #activity>
2024-09-15 09:32:29 +00:00
<view class="limit">限量 <text class="ss-m-l-5">{{ activity.stock}}
{{activity.unitName}}</text></view>
2023-12-19 13:39:52 +00:00
<su-progress :percentage="activity.percent" strokeWidth="10" textInside isAnimate />
</template>
<!-- 抢购按钮 -->
<template #cart>
2024-09-15 09:32:29 +00:00
<button
:class="['ss-reset-button cart-btn', { disabled: activeTimeConfig?.status === TimeStatusEnum.END}]"
v-if="activeTimeConfig?.status === TimeStatusEnum.WAIT_START">
<span>未开始</span>
</button>
<button
:class="['ss-reset-button cart-btn', { disabled: activeTimeConfig?.status === TimeStatusEnum.END}]"
@click="sheep.$router.go('/pages/goods/seckill', { id: activity.id })"
v-else-if='activeTimeConfig?.status === TimeStatusEnum.STARTED'>
<span>马上抢</span>
</button>
<button
:class="['ss-reset-button cart-btn', { disabled: activeTimeConfig?.status === TimeStatusEnum.END}]"
v-else>
<span>已结束</span>
2023-12-19 13:39:52 +00:00
</button>
2022-11-22 07:45:36 +00:00
</template>
</s-goods-column>
</view>
2024-09-15 09:32:29 +00:00
<uni-load-more v-if="activityTotal > 0" :status="loadStatus" :content-text="{
2022-11-22 07:45:36 +00:00
contentdown: '上拉加载更多',
2024-09-15 09:32:29 +00:00
}" @tap="loadMore" />
2022-11-22 07:45:36 +00:00
</scroll-view>
</view>
</s-layout>
</template>
<script setup>
2024-09-15 09:32:29 +00:00
import {
reactive,
computed,
ref,
nextTick
} from 'vue';
import {
onLoad,
onReachBottom
} from '@dcloudio/uni-app';
2022-11-22 07:45:36 +00:00
import sheep from '@/sheep';
2024-09-15 09:32:29 +00:00
import {
useDurationTime
} from '@/sheep/hooks/useGoods';
2023-12-19 13:39:52 +00:00
import SeckillApi from "@/sheep/api/promotion/seckill";
import dayjs from "dayjs";
2024-09-15 09:32:29 +00:00
import {
TimeStatusEnum
} from "@/sheep/util/const";
2022-11-22 07:45:36 +00:00
2023-12-19 13:39:52 +00:00
// 计算页面高度
2024-09-15 09:32:29 +00:00
const {
safeAreaInsets,
safeArea
} = sheep.$platform.device;
2022-11-22 07:45:36 +00:00
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
2023-12-19 13:39:52 +00:00
const pageHeight = (safeArea.height + safeAreaInsets.bottom) * 2 + statusBarHeight - sheep.$platform.navbar - 350;
2023-01-29 07:26:45 +00:00
const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-header.png');
2022-11-22 07:45:36 +00:00
2023-12-19 13:39:52 +00:00
// 商品控件显示的字段(不显示库存、销量。改为显示自定义的进度条)
const goodsFields = {
2024-09-15 09:32:29 +00:00
name: {
show: true
},
introduction: {
show: true
},
price: {
show: true
},
marketPrice: {
show: true
},
2023-12-19 13:39:52 +00:00
};
2022-11-22 07:45:36 +00:00
2023-12-19 13:39:52 +00:00
//#region 时间段
// 时间段列表
const timeConfigList = ref([])
// 查询时间段
const getSeckillConfigList = async () => {
2024-09-15 09:32:29 +00:00
const {
data
} = await SeckillApi.getSeckillConfigList()
2023-12-19 13:39:52 +00:00
const now = dayjs();
const today = now.format('YYYY-MM-DD')
2024-09-15 09:32:29 +00:00
const select = ref([])
2023-12-19 13:39:52 +00:00
// 判断时间段的状态
data.forEach((config, index) => {
const startTime = dayjs(`${today} ${config.startTime}`)
const endTime = dayjs(`${today} ${config.endTime}`)
2024-09-15 09:32:29 +00:00
select.value[index] = config.id;
2023-12-19 13:39:52 +00:00
if (now.isBefore(startTime)) {
config.status = TimeStatusEnum.WAIT_START;
2024-09-15 09:32:29 +00:00
// select.value[index] = config.id;
2023-12-19 13:39:52 +00:00
} else if (now.isAfter(endTime)) {
config.status = TimeStatusEnum.END;
2024-09-15 09:32:29 +00:00
// select.value[index] = config.id;
2022-11-22 07:45:36 +00:00
} else {
2023-12-19 13:39:52 +00:00
config.status = TimeStatusEnum.STARTED;
2024-09-15 09:32:29 +00:00
// select.value[index] = config.id;
activeTimeIndex.value = index
2022-11-22 07:45:36 +00:00
}
2023-12-19 13:39:52 +00:00
})
timeConfigList.value = data
// 默认选中进行中的活动
2024-09-15 09:32:29 +00:00
handleChangeTimeConfig(activeTimeIndex.value, select.value[activeTimeIndex.value]);
2023-12-19 13:39:52 +00:00
// 滚动到进行中的时间段
scrollToTimeConfig(activeTimeIndex.value)
}
// 滚动到指定时间段
2023-12-27 11:22:55 +00:00
const activeTimeElId = ref('') // 当前选中的时间段的元素ID
2023-12-19 13:39:52 +00:00
const scrollToTimeConfig = (index) => {
nextTick(() => activeTimeElId.value = `timeItem${index}`)
}
// 切换时间段
2023-12-27 11:22:55 +00:00
const activeTimeIndex = ref(0) // 当前选中的时间段的索引
const activeTimeConfig = computed(() => timeConfigList.value[activeTimeIndex.value]) // 当前选中的时间段
2024-09-15 09:32:29 +00:00
const handleChangeTimeConfig = (index, id) => {
2023-12-19 13:39:52 +00:00
activeTimeIndex.value = index
// 查询活动列表
activityPageParams.pageNo = 1
2024-09-15 09:32:29 +00:00
activityPageParams.configId = id;
2023-12-19 13:39:52 +00:00
activityList.value = []
getActivityList();
}
// 倒计时
const countDown = computed(() => {
const endTime = activeTimeConfig.value?.endTime
if (endTime) {
return useDurationTime(`${dayjs().format('YYYY-MM-DD')} ${endTime}`);
2022-11-22 07:45:36 +00:00
}
2023-12-19 13:39:52 +00:00
});
//#endregion
//#region 分页查询活动列表
2023-12-27 11:22:55 +00:00
// 查询活动列表
2023-12-19 13:39:52 +00:00
const activityPageParams = reactive({
2024-09-15 09:32:29 +00:00
configId: 0, // 时间段 ID
2023-12-27 11:22:55 +00:00
pageNo: 1, // 页码
pageSize: 5, // 每页数量
2023-12-19 13:39:52 +00:00
})
2023-12-27 11:22:55 +00:00
const activityTotal = ref(0) // 活动总数
const activityList = ref([]) // 活动列表
const loadStatus = ref('') // 页面加载状态
2023-12-19 13:39:52 +00:00
async function getActivityList() {
loadStatus.value = 'loading';
2024-09-15 09:32:29 +00:00
const {
data
} = await SeckillApi.getSeckillActivityPage(activityPageParams)
2023-12-19 13:39:52 +00:00
data.list.forEach(activity => {
// 计算抢购进度
activity.percent = parseInt(100 * (activity.totalStock - activity.stock) / activity.totalStock);
})
activityList.value = activityList.value.concat(...data.list);
activityTotal.value = data.total;
loadStatus.value = activityList.value.length < activityTotal.value ? 'more' : 'noMore';
2022-11-22 07:45:36 +00:00
}
2023-12-19 13:39:52 +00:00
2022-11-22 07:45:36 +00:00
// 加载更多
2023-12-19 13:39:52 +00:00
function loadMore() {
if (loadStatus.value !== 'noMore') {
activityPageParams.pageNo += 1
getActivityList();
2022-11-22 07:45:36 +00:00
}
}
// 上拉加载更多
2023-12-19 13:39:52 +00:00
onReachBottom(() => loadMore());
2023-12-27 11:22:55 +00:00
2023-12-19 13:39:52 +00:00
//#endregion
// 页面初始化
onLoad(async () => {
await getSeckillConfigList()
2022-11-22 07:45:36 +00:00
});
</script>
<style lang="scss" scoped>
2023-12-19 13:39:52 +00:00
// 顶部背景图
2022-11-22 07:45:36 +00:00
.page-bg {
width: 100%;
height: 458rpx;
background: v-bind(headerBg) no-repeat;
2022-11-22 07:45:36 +00:00
background-size: 100% 100%;
}
2023-12-19 13:39:52 +00:00
// 时间段轮播图
.header {
width: 710rpx;
height: 330rpx;
margin: -276rpx auto 0 auto;
border-radius: 14rpx;
overflow: hidden;
2024-09-15 09:32:29 +00:00
swiper {
2023-12-19 13:39:52 +00:00
height: 330rpx !important;
border-radius: 14rpx;
overflow: hidden;
}
image {
width: 100%;
height: 100%;
border-radius: 14rpx;
overflow: hidden;
2024-09-15 09:32:29 +00:00
img {
2023-12-19 13:39:52 +00:00
border-radius: 14rpx;
}
}
}
// 时间段列表:左侧图标
.time-icon {
width: 75rpx;
height: 70rpx;
}
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 时间段列表
.time-list {
width: 596rpx;
white-space: nowrap;
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 时间段
.item {
display: inline-block;
font-size: 20rpx;
color: #666;
text-align: center;
box-sizing: border-box;
margin-right: 30rpx;
width: 130rpx;
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 开始时间
.time {
font-size: 36rpx;
font-weight: 600;
color: #333;
}
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 选中的时间段
&.active {
.time {
color: var(--ui-BG-Main);
}
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 状态
.status {
height: 30rpx;
line-height: 30rpx;
border-radius: 15rpx;
width: 128rpx;
background: linear-gradient(90deg, var(--ui-BG-Main) 0%, var(--ui-BG-Main-gradient) 100%);
color: #fff;
}
}
}
}
// 内容区
2022-11-22 07:45:36 +00:00
.list-content {
position: relative;
z-index: 3;
2023-12-19 13:39:52 +00:00
margin: 0 20rpx 0 20rpx;
2022-11-22 07:45:36 +00:00
background: #fff;
border-radius: 20rpx 20rpx 0 0;
2024-09-15 09:32:29 +00:00
2022-11-22 07:45:36 +00:00
.content-header {
width: 100%;
border-radius: 20rpx 20rpx 0 0;
height: 150rpx;
background: linear-gradient(180deg, #fff4f7, #ffe6ec);
2023-12-19 13:39:52 +00:00
2022-11-22 07:45:36 +00:00
.content-header-box {
width: 678rpx;
height: 64rpx;
background: rgba($color: #fff, $alpha: 0.66);
border-radius: 32px;
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 场次倒计时内容
2022-11-22 07:45:36 +00:00
.countdown-title {
font-size: 28rpx;
font-weight: 500;
color: #333333;
line-height: 28rpx;
}
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 场次倒计时
2022-11-22 07:45:36 +00:00
.countdown-time {
font-size: 28rpx;
color: rgba(#ed3c30, 0.23);
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 场次倒计时:小时部分
2022-11-22 07:45:36 +00:00
.countdown-h {
font-size: 24rpx;
font-family: OPPOSANS;
font-weight: 500;
color: #ffffff;
padding: 0 4rpx;
height: 40rpx;
background: rgba(#ed3c30, 0.23);
border-radius: 6rpx;
}
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 场次倒计时:分钟、秒
2022-11-22 07:45:36 +00:00
.countdown-num {
font-size: 24rpx;
font-family: OPPOSANS;
font-weight: 500;
color: #ffffff;
width: 40rpx;
height: 40rpx;
background: rgba(#ed3c30, 0.23);
border-radius: 6rpx;
}
}
}
}
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 活动列表
2022-11-22 07:45:36 +00:00
.scroll-box {
height: 900rpx;
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 活动
2022-11-22 07:45:36 +00:00
.goods-box {
position: relative;
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 抢购按钮
2022-11-22 07:45:36 +00:00
.cart-btn {
position: absolute;
bottom: 10rpx;
right: 20rpx;
z-index: 11;
2023-12-19 13:39:52 +00:00
height: 44rpx;
2022-11-22 07:45:36 +00:00
line-height: 50rpx;
padding: 0 20rpx;
border-radius: 25rpx;
font-size: 24rpx;
color: #fff;
background: linear-gradient(90deg, #ff6600 0%, #fe832a 100%);
2023-12-19 13:39:52 +00:00
&.disabled {
background: $gray-b;
color: #fff;
}
}
2024-09-15 09:32:29 +00:00
2023-12-19 13:39:52 +00:00
// 秒杀限量商品数
.limit {
font-size: 22rpx;
color: $dark-9;
margin-bottom: 5rpx;
2022-11-22 07:45:36 +00:00
}
}
}
}
2024-09-15 09:32:29 +00:00
</style>