commit
2dcba5bbea
|
@ -1,29 +1,58 @@
|
||||||
<template>
|
<template>
|
||||||
<s-layout navbar="inner" :bgStyle="{ color: 'rgb(245,28,19)' }">
|
<s-layout navbar="inner" :bgStyle="{ color: 'rgb(245,28,19)' }">
|
||||||
|
<!--顶部背景图-->
|
||||||
<view
|
<view
|
||||||
class="page-bg"
|
class="page-bg"
|
||||||
:style="[{ marginTop: '-' + Number(statusBarHeight + 88) + 'rpx' }]"
|
:style="[{ marginTop: '-' + Number(statusBarHeight + 88) + 'rpx' }]"
|
||||||
></view>
|
></view>
|
||||||
<view class="list-content">
|
<!-- 时间段轮播图 -->
|
||||||
<view class="content-header ss-flex-col ss-col-center ss-row-center">
|
<view class="header" v-if="activeTimeConfig?.sliderPicUrls?.length > 0">
|
||||||
<view class="content-header-title ss-m-b-22 ss-flex ss-row-center">
|
<swiper indicator-dots="true" autoplay="true" :circular="true" interval="3000" duration="1500"
|
||||||
<view>{{ state.activityInfo.title }}</view>
|
indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
|
||||||
<!-- <view class="more">更多</view> -->
|
<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">
|
||||||
|
<image class="ss-w-100 ss-h-100" src="http://mall.yudao.iocoder.cn/static/images/priceTag.png"></image>
|
||||||
|
</view>
|
||||||
|
<scroll-view class="time-list" :scroll-into-view="activeTimeElId" scroll-x scroll-with-animation>
|
||||||
|
<view v-for="(config, index) in timeConfigList" :key="index"
|
||||||
|
:class="['item', { active: activeTimeIndex === index}]"
|
||||||
|
:id="`timeItem${index}`"
|
||||||
|
@tap="handleChangeTimeConfig(index)">
|
||||||
|
<!-- 活动起始时间 -->
|
||||||
|
<view class="time">{{ config.startTime }}</view>
|
||||||
|
<!-- 活动状态 -->
|
||||||
|
<view class="status">{{ config.status }}</view>
|
||||||
</view>
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</view>
|
||||||
|
<!-- 内容区 -->
|
||||||
|
<view class="list-content">
|
||||||
|
<!-- 活动倒计时 -->
|
||||||
|
<view class="content-header ss-flex-col ss-col-center ss-row-center">
|
||||||
<view class="content-header-box ss-flex ss-row-center">
|
<view class="content-header-box ss-flex ss-row-center">
|
||||||
<view class="countdown-box ss-flex" v-if="endTime?.ms > 0 && state.activityInfo">
|
<view class="countdown-box ss-flex" v-if="activeTimeConfig?.status === TimeStatusEnum.STARTED">
|
||||||
<view class="countdown-title ss-m-r-12">距结束</view>
|
<view class="countdown-title ss-m-r-12">距结束</view>
|
||||||
<view class="ss-flex countdown-time">
|
<view class="ss-flex countdown-time">
|
||||||
<view class="ss-flex countdown-h">{{ endTime.h }}</view>
|
<view class="ss-flex countdown-h">{{ countDown.h }}</view>
|
||||||
<view class="ss-m-x-4">:</view>
|
<view class="ss-m-x-4">:</view>
|
||||||
<view class="countdown-num ss-flex ss-row-center">{{ endTime.m }}</view>
|
<view class="countdown-num ss-flex ss-row-center">{{ countDown.m }}</view>
|
||||||
<view class="ss-m-x-4">:</view>
|
<view class="ss-m-x-4">:</view>
|
||||||
<view class="countdown-num ss-flex ss-row-center">{{ endTime.s }}</view>
|
<view class="countdown-num ss-flex ss-row-center">{{ countDown.s }}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="" v-if="endTime?.ms < 0 && state.activityInfo"> 活动已结束 </view>
|
<view v-else> {{ activeTimeConfig?.status }} </view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<!-- 活动列表 -->
|
||||||
<scroll-view
|
<scroll-view
|
||||||
class="scroll-box"
|
class="scroll-box"
|
||||||
:style="{ height: pageHeight + 'rpx' }"
|
:style="{ height: pageHeight + 'rpx' }"
|
||||||
|
@ -31,125 +60,260 @@
|
||||||
:scroll-with-animation="false"
|
:scroll-with-animation="false"
|
||||||
:enable-back-to-top="true"
|
:enable-back-to-top="true"
|
||||||
>
|
>
|
||||||
<view class="goods-box ss-m-b-20" v-for="item in state.pagination.data" :key="item.id">
|
<view class="goods-box ss-m-b-20" v-for="activity in activityList" :key="activity.id">
|
||||||
<s-goods-column
|
<s-goods-column
|
||||||
class=""
|
|
||||||
size="lg"
|
size="lg"
|
||||||
:data="item"
|
:data="{ ...activity, price: activity.seckillPrice }"
|
||||||
|
:goodsFields="goodsFields"
|
||||||
:seckillTag="true"
|
:seckillTag="true"
|
||||||
@click="
|
@click="sheep.$router.go('/pages/goods/seckill', { id: activity.id })"
|
||||||
sheep.$router.go('/pages/goods/seckill', {
|
|
||||||
id: item.id,
|
|
||||||
activity_id: state.activityId,
|
|
||||||
})
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<template v-slot:cart>
|
<!-- 抢购进度 -->
|
||||||
<button class="ss-reset-button cart-btn">去抢购</button>
|
<template #activity>
|
||||||
|
<view class="limit">限量 <text class="ss-m-l-5">{{ activity.stock}} {{activity.unitName}}</text></view>
|
||||||
|
<su-progress :percentage="activity.percent" strokeWidth="10" textInside isAnimate />
|
||||||
|
</template>
|
||||||
|
<!-- 抢购按钮 -->
|
||||||
|
<template #cart>
|
||||||
|
<button :class="['ss-reset-button cart-btn', { disabled: activeTimeConfig.status === TimeStatusEnum.END }]">
|
||||||
|
<span v-if="activeTimeConfig?.status === TimeStatusEnum.WAIT_START">未开始</span>
|
||||||
|
<span v-else-if="activeTimeConfig?.status === TimeStatusEnum.STARTED">马上抢</span>
|
||||||
|
<span v-else>已结束</span>
|
||||||
|
</button>
|
||||||
</template>
|
</template>
|
||||||
</s-goods-column>
|
</s-goods-column>
|
||||||
</view>
|
</view>
|
||||||
<uni-load-more
|
<uni-load-more
|
||||||
v-if="state.pagination.total > 0"
|
v-if="activityTotal > 0"
|
||||||
:status="state.loadStatus"
|
:status="loadStatus"
|
||||||
:content-text="{
|
:content-text="{
|
||||||
contentdown: '上拉加载更多',
|
contentdown: '上拉加载更多',
|
||||||
}"
|
}"
|
||||||
@tap="loadmore"
|
@tap="loadMore"
|
||||||
/>
|
/>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
</s-layout>
|
</s-layout>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, computed } from 'vue';
|
import {reactive, computed, ref, nextTick} from 'vue';
|
||||||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import _ from 'lodash';
|
|
||||||
import { useDurationTime } from '@/sheep/hooks/useGoods';
|
import { useDurationTime } from '@/sheep/hooks/useGoods';
|
||||||
|
import SeckillApi from "@/sheep/api/promotion/seckill";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
const { screenHeight, safeAreaInsets, screenWidth, safeArea } = sheep.$platform.device;
|
// 时间段的状态枚举
|
||||||
const sys_navBar = sheep.$platform.navbar;
|
const TimeStatusEnum = {
|
||||||
|
WAIT_START: '即将开始',
|
||||||
|
STARTED: '进行中',
|
||||||
|
END: '已结束',
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算页面高度
|
||||||
|
const { safeAreaInsets, safeArea } = sheep.$platform.device;
|
||||||
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
|
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
|
||||||
const pageHeight =
|
const pageHeight = (safeArea.height + safeAreaInsets.bottom) * 2 + statusBarHeight - sheep.$platform.navbar - 350;
|
||||||
(safeArea.height + safeAreaInsets.bottom) * 2 + statusBarHeight - sys_navBar - 350;
|
|
||||||
const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-header.png');
|
const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-header.png');
|
||||||
|
|
||||||
const state = reactive({
|
// 商品控件显示的字段(不显示库存、销量。改为显示自定义的进度条)
|
||||||
activityId: 0,
|
const goodsFields = {
|
||||||
pagination: {
|
// 商品名称
|
||||||
data: [],
|
name: { show: true },
|
||||||
current_page: 1,
|
// 商品介绍
|
||||||
total: 1,
|
introduction: { show: true },
|
||||||
last_page: 1,
|
// 商品价格
|
||||||
},
|
price: { show: true },
|
||||||
loadStatus: '',
|
// 市场价
|
||||||
activityInfo: {},
|
marketPrice: { show: true },
|
||||||
});
|
};
|
||||||
|
|
||||||
|
//#region 时间段
|
||||||
|
// 时间段列表
|
||||||
|
const timeConfigList = ref([])
|
||||||
|
// 查询时间段
|
||||||
|
const getSeckillConfigList = async () => {
|
||||||
|
const { data } = await SeckillApi.getSeckillConfigList()
|
||||||
|
const now = dayjs();
|
||||||
|
const today = now.format('YYYY-MM-DD')
|
||||||
|
// 判断时间段的状态
|
||||||
|
data.forEach((config, index) => {
|
||||||
|
const startTime = dayjs(`${today} ${config.startTime}`)
|
||||||
|
const endTime = dayjs(`${today} ${config.endTime}`)
|
||||||
|
if (now.isBefore(startTime)) {
|
||||||
|
config.status = TimeStatusEnum.WAIT_START;
|
||||||
|
} else if (now.isAfter(endTime)) {
|
||||||
|
config.status = TimeStatusEnum.END;
|
||||||
|
} else {
|
||||||
|
config.status = TimeStatusEnum.STARTED;
|
||||||
|
activeTimeIndex.value = index;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
timeConfigList.value = data
|
||||||
|
// 默认选中进行中的活动
|
||||||
|
handleChangeTimeConfig(activeTimeIndex.value);
|
||||||
|
// 滚动到进行中的时间段
|
||||||
|
scrollToTimeConfig(activeTimeIndex.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当前选中的时间段的元素ID
|
||||||
|
const activeTimeElId = ref('')
|
||||||
|
// 滚动到指定时间段
|
||||||
|
const scrollToTimeConfig = (index) => {
|
||||||
|
nextTick(() => activeTimeElId.value = `timeItem${index}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当前选中的时间段的索引
|
||||||
|
const activeTimeIndex = ref(0)
|
||||||
|
// 当前选中的时间段
|
||||||
|
const activeTimeConfig = computed(() => timeConfigList.value[activeTimeIndex.value])
|
||||||
|
// 切换时间段
|
||||||
|
const handleChangeTimeConfig = (index) => {
|
||||||
|
activeTimeIndex.value = index
|
||||||
|
|
||||||
|
// 查询活动列表
|
||||||
|
activityPageParams.pageNo = 1
|
||||||
|
activityList.value = []
|
||||||
|
getActivityList();
|
||||||
|
}
|
||||||
|
|
||||||
// 倒计时
|
// 倒计时
|
||||||
const endTime = computed(() => {
|
const countDown = computed(() => {
|
||||||
if (state.activityInfo.end_time) {
|
const endTime = activeTimeConfig.value?.endTime
|
||||||
return useDurationTime(state.activityInfo.end_time);
|
if (endTime) {
|
||||||
|
return useDurationTime(`${dayjs().format('YYYY-MM-DD')} ${endTime}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function getList(activityId, page = 1, list_rows = 4) {
|
//#endregion
|
||||||
state.loadStatus = 'loading';
|
|
||||||
const res = await sheep.$api.goods.activityList({
|
//#region 分页查询活动列表
|
||||||
list_rows,
|
|
||||||
activity_id: activityId,
|
// 活动分页查询参数
|
||||||
page,
|
const activityPageParams = reactive({
|
||||||
});
|
// 时间段ID
|
||||||
if (res.error === 0) {
|
id: 0,
|
||||||
let couponList = _.concat(state.pagination.data, res.data.data);
|
// 页码
|
||||||
state.pagination = {
|
pageNo: 1,
|
||||||
...res.data,
|
// 每页数量
|
||||||
data: couponList,
|
pageSize: 5,
|
||||||
};
|
})
|
||||||
if (state.pagination.current_page < state.pagination.last_page) {
|
// 活动总数
|
||||||
state.loadStatus = 'more';
|
const activityTotal = ref(0)
|
||||||
} else {
|
// 活动列表
|
||||||
state.loadStatus = 'noMore';
|
const activityList = ref([])
|
||||||
}
|
// 页面加载状态
|
||||||
}
|
const loadStatus = ref('')
|
||||||
|
// 查询活动列表
|
||||||
|
async function getActivityList() {
|
||||||
|
loadStatus.value = 'loading';
|
||||||
|
const { data } = await SeckillApi.getSeckillActivityPage(activityPageParams)
|
||||||
|
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';
|
||||||
}
|
}
|
||||||
async function getActivity(id) {}
|
|
||||||
// 加载更多
|
// 加载更多
|
||||||
function loadmore() {
|
function loadMore() {
|
||||||
if (state.loadStatus !== 'noMore') {
|
if (loadStatus.value !== 'noMore') {
|
||||||
getList(state.activityId, state.pagination.current_page + 1);
|
activityPageParams.pageNo += 1
|
||||||
|
getActivityList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 上拉加载更多
|
// 上拉加载更多
|
||||||
onReachBottom(() => {
|
onReachBottom(() => loadMore());
|
||||||
loadmore();
|
//#endregion
|
||||||
});
|
|
||||||
onLoad(async (options) => {
|
// 页面初始化
|
||||||
if (!options.id) {
|
onLoad(async () => {
|
||||||
state.activityInfo = null;
|
await getSeckillConfigList()
|
||||||
return;
|
|
||||||
}
|
|
||||||
state.activityId = options.id;
|
|
||||||
getList(state.activityId);
|
|
||||||
const { error, data } = await sheep.$api.activity.activity(options.id);
|
|
||||||
if (error === 0) {
|
|
||||||
state.activityInfo = data;
|
|
||||||
} else {
|
|
||||||
state.activityInfo = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
// 顶部背景图
|
||||||
.page-bg {
|
.page-bg {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 458rpx;
|
height: 458rpx;
|
||||||
background: v-bind(headerBg) no-repeat;
|
background: v-bind(headerBg) no-repeat;
|
||||||
background-size: 100% 100%;
|
background-size: 100% 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 时间段轮播图
|
||||||
|
.header {
|
||||||
|
width: 710rpx;
|
||||||
|
height: 330rpx;
|
||||||
|
margin: -276rpx auto 0 auto;
|
||||||
|
border-radius: 14rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
swiper{
|
||||||
|
height: 330rpx !important;
|
||||||
|
border-radius: 14rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 14rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
img{
|
||||||
|
border-radius: 14rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 时间段列表:左侧图标
|
||||||
|
.time-icon {
|
||||||
|
width: 75rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
}
|
||||||
|
// 时间段列表
|
||||||
|
.time-list {
|
||||||
|
width: 596rpx;
|
||||||
|
white-space: nowrap;
|
||||||
|
// 时间段
|
||||||
|
.item {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 20rpx;
|
||||||
|
color: #666;
|
||||||
|
text-align: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-right: 30rpx;
|
||||||
|
width: 130rpx;
|
||||||
|
// 开始时间
|
||||||
|
.time {
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
// 选中的时间段
|
||||||
|
&.active {
|
||||||
|
.time {
|
||||||
|
color: var(--ui-BG-Main);
|
||||||
|
}
|
||||||
|
// 状态
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 内容区
|
||||||
.list-content {
|
.list-content {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
margin: -190rpx 20rpx 0 20rpx;
|
margin: 0 20rpx 0 20rpx;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-radius: 20rpx 20rpx 0 0;
|
border-radius: 20rpx 20rpx 0 0;
|
||||||
.content-header {
|
.content-header {
|
||||||
|
@ -157,52 +321,24 @@
|
||||||
border-radius: 20rpx 20rpx 0 0;
|
border-radius: 20rpx 20rpx 0 0;
|
||||||
height: 150rpx;
|
height: 150rpx;
|
||||||
background: linear-gradient(180deg, #fff4f7, #ffe6ec);
|
background: linear-gradient(180deg, #fff4f7, #ffe6ec);
|
||||||
.content-header-title {
|
|
||||||
width: 100%;
|
|
||||||
font-size: 30rpx;
|
|
||||||
font-weight: 500;
|
|
||||||
color: #ff2923;
|
|
||||||
line-height: 30rpx;
|
|
||||||
position: relative;
|
|
||||||
.more {
|
|
||||||
position: absolute;
|
|
||||||
right: 30rpx;
|
|
||||||
top: 0;
|
|
||||||
font-size: 24rpx;
|
|
||||||
font-weight: 400;
|
|
||||||
color: #999999;
|
|
||||||
line-height: 30rpx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.content-header-box {
|
.content-header-box {
|
||||||
width: 678rpx;
|
width: 678rpx;
|
||||||
height: 64rpx;
|
height: 64rpx;
|
||||||
background: rgba($color: #fff, $alpha: 0.66);
|
background: rgba($color: #fff, $alpha: 0.66);
|
||||||
border-radius: 32px;
|
border-radius: 32px;
|
||||||
.num {
|
// 场次倒计时内容
|
||||||
font-size: 24rpx;
|
|
||||||
font-family: OPPOSANS;
|
|
||||||
font-weight: 500;
|
|
||||||
color: #f51c11;
|
|
||||||
line-height: 30rpx;
|
|
||||||
}
|
|
||||||
.title {
|
|
||||||
font-size: 24rpx;
|
|
||||||
font-weight: 400;
|
|
||||||
font-family: OPPOSANS;
|
|
||||||
color: #333;
|
|
||||||
line-height: 30rpx;
|
|
||||||
}
|
|
||||||
.countdown-title {
|
.countdown-title {
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: #333333;
|
color: #333333;
|
||||||
line-height: 28rpx;
|
line-height: 28rpx;
|
||||||
}
|
}
|
||||||
|
// 场次倒计时
|
||||||
.countdown-time {
|
.countdown-time {
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: rgba(#ed3c30, 0.23);
|
color: rgba(#ed3c30, 0.23);
|
||||||
|
// 场次倒计时:小时部分
|
||||||
.countdown-h {
|
.countdown-h {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
font-family: OPPOSANS;
|
font-family: OPPOSANS;
|
||||||
|
@ -213,6 +349,7 @@
|
||||||
background: rgba(#ed3c30, 0.23);
|
background: rgba(#ed3c30, 0.23);
|
||||||
border-radius: 6rpx;
|
border-radius: 6rpx;
|
||||||
}
|
}
|
||||||
|
// 场次倒计时:分钟、秒
|
||||||
.countdown-num {
|
.countdown-num {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
font-family: OPPOSANS;
|
font-family: OPPOSANS;
|
||||||
|
@ -226,22 +363,36 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 活动列表
|
||||||
.scroll-box {
|
.scroll-box {
|
||||||
height: 900rpx;
|
height: 900rpx;
|
||||||
|
// 活动
|
||||||
.goods-box {
|
.goods-box {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
// 抢购按钮
|
||||||
.cart-btn {
|
.cart-btn {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 10rpx;
|
bottom: 10rpx;
|
||||||
right: 20rpx;
|
right: 20rpx;
|
||||||
z-index: 11;
|
z-index: 11;
|
||||||
height: 50rpx;
|
height: 44rpx;
|
||||||
line-height: 50rpx;
|
line-height: 50rpx;
|
||||||
padding: 0 20rpx;
|
padding: 0 20rpx;
|
||||||
border-radius: 25rpx;
|
border-radius: 25rpx;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: linear-gradient(90deg, #ff6600 0%, #fe832a 100%);
|
background: linear-gradient(90deg, #ff6600 0%, #fe832a 100%);
|
||||||
|
|
||||||
|
&.disabled {
|
||||||
|
background: $gray-b;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 秒杀限量商品数
|
||||||
|
.limit {
|
||||||
|
font-size: 22rpx;
|
||||||
|
color: $dark-9;
|
||||||
|
margin-bottom: 5rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<view class="price-box ss-flex ss-row-between ss-m-b-18">
|
<view class="price-box ss-flex ss-row-between ss-m-b-18">
|
||||||
<view class="ss-flex">
|
<view class="ss-flex">
|
||||||
<view class="price-text ss-m-r-16">
|
<view class="price-text ss-m-r-16">
|
||||||
{{ state.selectedSkuPrice.price || formatPrice(state.goodsInfo.price) }}
|
{{ fen2yuan(state.selectedSku.price || state.goodsInfo.price) }}
|
||||||
</view>
|
</view>
|
||||||
<view class="tig ss-flex ss-col-center">
|
<view class="tig ss-flex ss-col-center">
|
||||||
<view class="tig-icon ss-flex ss-col-center ss-row-center">
|
<view class="tig-icon ss-flex ss-col-center ss-row-center">
|
||||||
|
@ -53,24 +53,24 @@
|
||||||
<view class="countdown-title" v-else> 活动已结束 </view>
|
<view class="countdown-title" v-else> 活动已结束 </view>
|
||||||
</view>
|
</view>
|
||||||
<view class="ss-flex ss-row-between ss-m-b-60">
|
<view class="ss-flex ss-row-between ss-m-b-60">
|
||||||
<view class="origin-price ss-flex ss-col-center" v-if="state.goodsInfo.original_price">
|
<view class="origin-price ss-flex ss-col-center" v-if="state.goodsInfo.marketPrice">
|
||||||
原价
|
原价
|
||||||
<view class="origin-price-text">
|
<view class="origin-price-text">
|
||||||
{{ state.selectedSkuPrice.original_price || state.goodsInfo.original_price }}
|
{{ fen2yuan(state.selectedSku.marketPrice || state.goodsInfo.marketPrice) }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<detail-progress :percent="state.percent" />
|
<detail-progress :percent="state.percent" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="title-text ss-line-2 ss-m-b-6">{{ state.goodsInfo.title }}</view>
|
<view class="title-text ss-line-2 ss-m-b-6">{{ state.goodsInfo.name }}</view>
|
||||||
<view class="subtitle-text ss-line-1">{{ state.goodsInfo.subtitle }}</view>
|
<view class="subtitle-text ss-line-1">{{ state.goodsInfo.introduction }}</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 功能卡片 -->
|
<!-- 功能卡片 -->
|
||||||
<view class="detail-cell-card detail-card ss-flex-col">
|
<view class="detail-cell-card detail-card ss-flex-col">
|
||||||
<detail-cell-sku
|
<detail-cell-sku
|
||||||
v-model="state.selectedSkuPrice.goods_sku_text"
|
v-model="state.selectedSku.goods_sku_text"
|
||||||
:skus="state.goodsInfo.skus"
|
:sku="state.selectedSku"
|
||||||
@tap="state.showSelectSku = true"
|
@tap="state.showSelectSku = true"
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
@ -78,6 +78,7 @@
|
||||||
<s-select-seckill-sku
|
<s-select-seckill-sku
|
||||||
v-model="state.goodsInfo"
|
v-model="state.goodsInfo"
|
||||||
:show="state.showSelectSku"
|
:show="state.showSelectSku"
|
||||||
|
:single-limit-count="activity.singleLimitCount"
|
||||||
@buy="onBuy"
|
@buy="onBuy"
|
||||||
@change="onSkuChange"
|
@change="onSkuChange"
|
||||||
@close="state.showSelectSku = false"
|
@close="state.showSelectSku = false"
|
||||||
|
@ -85,9 +86,9 @@
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 评价 -->
|
<!-- 评价 -->
|
||||||
<detail-comment-card class="detail-comment-selector" :goodsId="state.goodsId" />
|
<detail-comment-card class="detail-comment-selector" :goodsId="state.goodsInfo.id" />
|
||||||
<!-- 详情 -->
|
<!-- 详情 -->
|
||||||
<detail-content-card class="detail-content-selector" :content="state.goodsInfo.content" />
|
<detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
|
||||||
|
|
||||||
<!-- 详情tabbar -->
|
<!-- 详情tabbar -->
|
||||||
<detail-tabbar v-model="state.goodsInfo">
|
<detail-tabbar v-model="state.goodsInfo">
|
||||||
|
@ -95,11 +96,11 @@
|
||||||
<view class="buy-box ss-flex ss-col-center ss-p-r-20">
|
<view class="buy-box ss-flex ss-col-center ss-p-r-20">
|
||||||
<button
|
<button
|
||||||
class="ss-reset-button origin-price-btn ss-flex-col"
|
class="ss-reset-button origin-price-btn ss-flex-col"
|
||||||
v-if="state.goodsInfo.original_price"
|
v-if="state.goodsInfo.marketPrice"
|
||||||
@tap="sheep.$router.go('/pages/goods/index', { id: state.goodsInfo.id })"
|
@tap="sheep.$router.go('/pages/goods/index', { id: state.goodsInfo.id })"
|
||||||
>
|
>
|
||||||
<view>
|
<view>
|
||||||
<view class="btn-price">{{ state.goodsInfo.original_price }}</view>
|
<view class="btn-price">{{ fen2yuan(state.goodsInfo.marketPrice) }}</view>
|
||||||
<view>原价购买</view>
|
<view>原价购买</view>
|
||||||
</view>
|
</view>
|
||||||
</button>
|
</button>
|
||||||
|
@ -107,7 +108,7 @@
|
||||||
<view
|
<view
|
||||||
class="no-original"
|
class="no-original"
|
||||||
:class="
|
:class="
|
||||||
state.goodsInfo.stock === 0 || state.goodsInfo.activity.status != 'ing' ? '' : ''
|
state.goodsInfo.stock === 0 || activity.status != 'ing' ? '' : ''
|
||||||
"
|
"
|
||||||
>秒杀价</view
|
>秒杀价</view
|
||||||
>
|
>
|
||||||
|
@ -116,18 +117,18 @@
|
||||||
class="ss-reset-button btn-box ss-flex-col"
|
class="ss-reset-button btn-box ss-flex-col"
|
||||||
@tap="state.showSelectSku = true"
|
@tap="state.showSelectSku = true"
|
||||||
:class="
|
:class="
|
||||||
state.goodsInfo.activity.status === 'ing' && state.goodsInfo.stock != 0
|
activity.status === 'ing' && state.goodsInfo.stock != 0
|
||||||
? 'check-btn-box'
|
? 'check-btn-box'
|
||||||
: 'disabled-btn-box'
|
: 'disabled-btn-box'
|
||||||
"
|
"
|
||||||
:disabled="state.goodsInfo.stock === 0 || state.goodsInfo.activity.status != 'ing'"
|
:disabled="state.goodsInfo.stock === 0 || activity.status != 'ing'"
|
||||||
>
|
>
|
||||||
<view class="btn-price">{{ state.goodsInfo.price[0] }}</view>
|
<view class="btn-price">{{ fen2yuan(state.goodsInfo.price) }}</view>
|
||||||
<view v-if="state.goodsInfo.activity.status === 'ing'">
|
<view v-if="activity.status === 'ing'">
|
||||||
<view v-if="state.goodsInfo.stock === 0">已售罄</view>
|
<view v-if="state.goodsInfo.stock === 0">已售罄</view>
|
||||||
<view v-else>立即秒杀</view>
|
<view v-else>立即秒杀</view>
|
||||||
</view>
|
</view>
|
||||||
<view v-else>{{ state.goodsInfo.activity.status_text }}</view>
|
<view v-else>{{ activity.status_text }}</view>
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
</detail-tabbar>
|
</detail-tabbar>
|
||||||
|
@ -136,11 +137,11 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, computed } from 'vue';
|
import {reactive, computed, ref} from 'vue';
|
||||||
import { onLoad, onPageScroll } from '@dcloudio/uni-app';
|
import { onLoad, onPageScroll } from '@dcloudio/uni-app';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import { isEmpty } from 'lodash';
|
import {isEmpty, min} from 'lodash';
|
||||||
import { useDurationTime, formatGoodsSwiper, formatPrice } from '@/sheep/hooks/useGoods';
|
import {useDurationTime, formatGoodsSwiper, fen2yuan} from '@/sheep/hooks/useGoods';
|
||||||
import detailNavbar from './components/detail/detail-navbar.vue';
|
import detailNavbar from './components/detail/detail-navbar.vue';
|
||||||
import detailCellSku from './components/detail/detail-cell-sku.vue';
|
import detailCellSku from './components/detail/detail-cell-sku.vue';
|
||||||
import detailTabbar from './components/detail/detail-tabbar.vue';
|
import detailTabbar from './components/detail/detail-tabbar.vue';
|
||||||
|
@ -148,6 +149,8 @@
|
||||||
import detailCommentCard from './components/detail/detail-comment-card.vue';
|
import detailCommentCard from './components/detail/detail-comment-card.vue';
|
||||||
import detailContentCard from './components/detail/detail-content-card.vue';
|
import detailContentCard from './components/detail/detail-content-card.vue';
|
||||||
import detailProgress from './components/detail/detail-progress.vue';
|
import detailProgress from './components/detail/detail-progress.vue';
|
||||||
|
import SeckillApi from "@/sheep/api/promotion/seckill";
|
||||||
|
import SpuApi from "@/sheep/api/product/spu";
|
||||||
|
|
||||||
const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-bg.png');
|
const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-bg.png');
|
||||||
const btnBg = sheep.$url.css('/static/img/shop/goods/seckill-btn.png');
|
const btnBg = sheep.$url.css('/static/img/shop/goods/seckill-btn.png');
|
||||||
|
@ -159,26 +162,24 @@
|
||||||
|
|
||||||
onPageScroll(() => {});
|
onPageScroll(() => {});
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
goodsId: 0,
|
|
||||||
skeletonLoading: true,
|
skeletonLoading: true,
|
||||||
goodsInfo: {},
|
goodsInfo: {},
|
||||||
showSelectSku: false,
|
showSelectSku: false,
|
||||||
goodsSwiper: [],
|
goodsSwiper: [],
|
||||||
selectedSkuPrice: {},
|
selectedSku: {},
|
||||||
showModel: false,
|
showModel: false,
|
||||||
total: 0,
|
total: 0,
|
||||||
percent: 0,
|
percent: 0,
|
||||||
price: '',
|
price: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
// 倒计时
|
|
||||||
const endTime = computed(() => {
|
const endTime = computed(() => {
|
||||||
return useDurationTime(state.goodsInfo.activity.end_time);
|
return useDurationTime(activity.value.endTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 规格变更
|
// 规格变更
|
||||||
function onSkuChange(e) {
|
function onSkuChange(e) {
|
||||||
state.selectedSkuPrice = e;
|
state.selectedSku = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 立即购买
|
// 立即购买
|
||||||
|
@ -187,7 +188,7 @@
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
order_type: 'goods',
|
order_type: 'goods',
|
||||||
buy_type: 'seckill',
|
buy_type: 'seckill',
|
||||||
activity_id: state.goodsInfo.activity.id,
|
activityId: activity.value.id,
|
||||||
goods_list: [
|
goods_list: [
|
||||||
{
|
{
|
||||||
goods_id: e.goods_id,
|
goods_id: e.goods_id,
|
||||||
|
@ -203,53 +204,76 @@
|
||||||
if (isEmpty(state.goodsInfo?.activity)) return {};
|
if (isEmpty(state.goodsInfo?.activity)) return {};
|
||||||
return sheep.$platform.share.getShareInfo(
|
return sheep.$platform.share.getShareInfo(
|
||||||
{
|
{
|
||||||
title: state.goodsInfo.title,
|
title: state.goodsInfo.name,
|
||||||
image: sheep.$url.cdn(state.goodsInfo.image),
|
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
||||||
params: {
|
params: {
|
||||||
page: '4',
|
page: '4',
|
||||||
query: state.goodsInfo.id + ',' + state.goodsInfo.activity.id,
|
query: state.goodsInfo.id + ',' + activity.value.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'goods', // 商品海报
|
type: 'goods', // 商品海报
|
||||||
title: state.goodsInfo.title, // 商品标题
|
title: state.goodsInfo.name, // 商品标题
|
||||||
image: sheep.$url.cdn(state.goodsInfo.image), // 商品主图
|
image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
|
||||||
price: state.goodsInfo.price[0], // 商品价格
|
price: state.goodsInfo.price[0], // 商品价格
|
||||||
original_price: state.goodsInfo.original_price, // 商品原价
|
marketPrice: state.goodsInfo.marketPrice, // 商品原价
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const activity = ref()
|
||||||
|
// 查询活动
|
||||||
|
const getActivity = async (id) => {
|
||||||
|
const { data } = await SeckillApi.getSeckillActivity(id)
|
||||||
|
activity.value = data
|
||||||
|
|
||||||
|
// 查询商品
|
||||||
|
await getSpu(data.spuId)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getSpu = async (id) => {
|
||||||
|
const { data } = await SpuApi.getSpuDetail(id)
|
||||||
|
// 模拟
|
||||||
|
data.activity_type = 'seckill'
|
||||||
|
state.goodsInfo = data
|
||||||
|
// 处理轮播图
|
||||||
|
state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.sliderPicUrls);
|
||||||
|
|
||||||
|
// 默认显示最低价
|
||||||
|
state.goodsInfo.price = min([state.goodsInfo.price, ...activity.value.products.map(spu => spu.seckillPrice)])
|
||||||
|
|
||||||
|
// 价格、库存使用活动的
|
||||||
|
data.skus.forEach(sku => {
|
||||||
|
debugger
|
||||||
|
const product = activity.value.products.find(product => product.skuId === sku.id);
|
||||||
|
if (product) {
|
||||||
|
sku.price = product.seckillPrice;
|
||||||
|
sku.stock = Math.min(sku.stock, product.stock);
|
||||||
|
} else { // 找不到可能是没配置,则不能发起秒杀
|
||||||
|
sku.stock = 0;
|
||||||
|
}
|
||||||
|
// 设置限购数量
|
||||||
|
if (activity.value.totalLimitCount > 0 && activity.value.singleLimitCount > 0) {
|
||||||
|
sku.limitCount = Math.min(activity.value.totalLimitCount, activity.value.singleLimitCount);
|
||||||
|
} else if (activity.value.totalLimitCount > 0) {
|
||||||
|
sku.limitCount = activity.value.totalLimitCount;
|
||||||
|
} else if (activity.value.singleLimitCount > 0) {
|
||||||
|
sku.limitCount = activity.value.singleLimitCount;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
state.skeletonLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
// 非法参数
|
// 非法参数
|
||||||
if (!options.id) {
|
if (!options.id) {
|
||||||
state.goodsInfo = null;
|
state.goodsInfo = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state.goodsId = options.id;
|
|
||||||
// 加载商品信息
|
// 查询活动
|
||||||
sheep.$api.goods
|
getActivity(options.id)
|
||||||
.detail(options.id, {
|
|
||||||
activity_id: options.activity_id,
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
state.skeletonLoading = false;
|
|
||||||
if (res.error === 0) {
|
|
||||||
state.goodsInfo = res.data;
|
|
||||||
state.percent =
|
|
||||||
state.goodsInfo.stock + state.goodsInfo.sales > 0
|
|
||||||
? (
|
|
||||||
(state.goodsInfo.sales / (state.goodsInfo.sales + state.goodsInfo.stock)) *
|
|
||||||
100
|
|
||||||
).toFixed(2)
|
|
||||||
: 0;
|
|
||||||
state.percent = Number(state.percent);
|
|
||||||
state.goodsSwiper = formatGoodsSwiper(state.goodsInfo.images);
|
|
||||||
} else {
|
|
||||||
// 未找到商品
|
|
||||||
state.goodsInfo = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ const SeckillApi = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获得秒杀活动分页
|
// 获得秒杀活动分页
|
||||||
getSeckillActivityPage: () => {
|
getSeckillActivityPage: (params) => {
|
||||||
return request2({ url: 'promotion/seckill-activity/page', method: 'GET' });
|
return request2({ url: 'promotion/seckill-activity/page', method: 'GET', params });
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,8 +28,7 @@
|
||||||
:bottomRadius="data.borderRadiusBottom"
|
:bottomRadius="data.borderRadiusBottom"
|
||||||
@click="
|
@click="
|
||||||
sheep.$router.go('/pages/goods/seckill', {
|
sheep.$router.go('/pages/goods/seckill', {
|
||||||
id: product.id,
|
id: props.data.activityId,
|
||||||
activity_id: props.data.activityId,
|
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
></s-goods-column>
|
></s-goods-column>
|
||||||
|
@ -55,8 +54,7 @@
|
||||||
:bottomRadius="data.borderRadiusBottom"
|
:bottomRadius="data.borderRadiusBottom"
|
||||||
@click="
|
@click="
|
||||||
sheep.$router.go('/pages/goods/seckill', {
|
sheep.$router.go('/pages/goods/seckill', {
|
||||||
id: product.id,
|
id: props.data.activityId,
|
||||||
activity_id: props.data.activityId,
|
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
|
|
|
@ -1,55 +1,61 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- 规格弹窗 -->
|
<!-- 规格弹窗 -->
|
||||||
<su-popup :show="show" round="10" @close="emits('close')">
|
<su-popup :show="show" round="10" @close="emits('close')">
|
||||||
<view class="ss-modal-box bg-white ss-flex-col">
|
<!-- SKU 信息 -->
|
||||||
<view class="modal-header ss-flex ss-col-center">
|
<view class="ss-modal-box bg-white ss-flex-col">
|
||||||
<view class="header-left ss-m-r-30">
|
<view class="modal-header ss-flex ss-col-center">
|
||||||
<image
|
<!-- 规格图 -->
|
||||||
class="sku-image"
|
<view class="header-left ss-m-r-30">
|
||||||
:src="sheep.$url.cdn(state.selectedSkuPrice.image || state.goodsInfo.image)"
|
<image
|
||||||
mode="aspectFill"
|
class="sku-image"
|
||||||
>
|
:src="sheep.$url.cdn(state.selectedSku.picUrl || state.goodsInfo.picUrl)"
|
||||||
</image>
|
mode="aspectFill"
|
||||||
</view>
|
>
|
||||||
<view class="header-right ss-flex-col ss-row-between ss-flex-1">
|
</image>
|
||||||
<view class="goods-title ss-line-2">{{ state.goodsInfo.title }}</view>
|
</view>
|
||||||
<view class="header-right-bottom ss-flex ss-col-center ss-row-between">
|
<view class="header-right ss-flex-col ss-row-between ss-flex-1">
|
||||||
<view class="price-text">
|
<!-- 名称 -->
|
||||||
{{ state.selectedSkuPrice.groupon_price || formatPrice(state.goodsInfo.price) }}
|
<view class="goods-title ss-line-2">{{ state.goodsInfo.name }}</view>
|
||||||
</view>
|
<view class="header-right-bottom ss-flex ss-col-center ss-row-between">
|
||||||
<view class="tig ss-flex ss-col-center">
|
<!-- 价格 -->
|
||||||
<view class="tig-icon ss-flex ss-col-center ss-row-center">
|
<view class="price-text">
|
||||||
<text class="cicon-alarm"></text>
|
{{ fen2yuan(state.selectedSku.price || state.goodsInfo.price) }}
|
||||||
|
</view>
|
||||||
|
<!-- 秒杀价格标签 -->
|
||||||
|
<view class="tig ss-flex ss-col-center">
|
||||||
|
<view class="tig-icon ss-flex ss-col-center ss-row-center">
|
||||||
|
<text class="cicon-alarm"></text>
|
||||||
</view>
|
</view>
|
||||||
<view class="tig-title">秒杀价</view>
|
<view class="tig-title">秒杀价</view>
|
||||||
</view>
|
</view>
|
||||||
|
<!-- 库存 -->
|
||||||
<view class="stock-text ss-m-l-20">
|
<view class="stock-text ss-m-l-20">
|
||||||
库存{{ state.selectedSkuPrice.stock || state.goodsInfo.stock }}件
|
库存{{ state.selectedSku.stock || state.goodsInfo.stock }}件
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="modal-content ss-flex-1">
|
<view class="modal-content ss-flex-1">
|
||||||
<scroll-view scroll-y="true" class="modal-content-scroll">
|
<scroll-view scroll-y="true" class="modal-content-scroll">
|
||||||
<view class="sku-item ss-m-b-20" v-for="sku1 in state.goodsInfo.skus" :key="sku1.id">
|
<view class="sku-item ss-m-b-20" v-for="property in propertyList" :key="property.id">
|
||||||
<view class="label-text ss-m-b-20">{{ sku1.name }}</view>
|
<view class="label-text ss-m-b-20">{{ property.name }}</view>
|
||||||
<view class="ss-flex ss-col-center ss-flex-wrap">
|
<view class="ss-flex ss-col-center ss-flex-wrap">
|
||||||
<button
|
<button
|
||||||
class="ss-reset-button spec-btn"
|
class="ss-reset-button spec-btn"
|
||||||
v-for="sku2 in sku1.children"
|
v-for="value in property.values"
|
||||||
:class="[
|
:class="[
|
||||||
{
|
{
|
||||||
'checked-btn': state.currentSkuArray[sku2.parent_id] == sku2.id,
|
'checked-btn': state.currentPropertyArray[property.id] === value.id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'disabled-btn': sku2.disabled == true,
|
'disabled-btn': value.disabled === true,
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
:key="sku2.id"
|
:key="value.id"
|
||||||
:disabled="sku2.disabled == true"
|
:disabled="value.disabled === true"
|
||||||
@tap="onSelectSku(sku2.parent_id, sku2.id)"
|
@tap="onSelectSku(property.id, value.id)"
|
||||||
>
|
>
|
||||||
{{ sku2.name }}
|
{{ value.name }}
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -57,10 +63,10 @@
|
||||||
<view class="label-text">购买数量</view>
|
<view class="label-text">购买数量</view>
|
||||||
<su-number-box
|
<su-number-box
|
||||||
:min="1"
|
:min="1"
|
||||||
:max="state.selectedSkuPrice.stock"
|
:max="min([singleLimitCount, state.selectedSku.stock])"
|
||||||
:step="1"
|
:step="1"
|
||||||
v-model="state.selectedSkuPrice.goods_num"
|
v-model="state.selectedSku.count"
|
||||||
@change="onNumberChange($event)"
|
@change="onBuyCountChange($event)"
|
||||||
activity="seckill"
|
activity="seckill"
|
||||||
></su-number-box>
|
></su-number-box>
|
||||||
</view>
|
</view>
|
||||||
|
@ -77,13 +83,15 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
/**
|
/**
|
||||||
* 1. 根据spus获得skus: 后台已算好
|
* 秒杀活动SKU选择,
|
||||||
* 2. 用路径字典,生成路径map
|
* 与s-select-sku的区别:多一个秒杀价的标签、没有加入购物车按钮、立即购买按钮叫确认、秒杀有最大购买数量限制
|
||||||
* 3. 计算用户选择后,其他路径是否可用
|
* 差别不大,可以考虑合并 todo @芋艿
|
||||||
*/
|
*/
|
||||||
// 按钮状态: active,nostock
|
// 按钮状态: active,nostock
|
||||||
import { computed, reactive, watch } from 'vue';
|
import { computed, reactive, watch } from 'vue';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
|
import {convertProductPropertyList, fen2yuan} from "@/sheep/hooks/useGoods";
|
||||||
|
import {min} from "lodash";
|
||||||
const emits = defineEmits(['change', 'addCart', 'buy', 'close']);
|
const emits = defineEmits(['change', 'addCart', 'buy', 'close']);
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
@ -94,28 +102,34 @@
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
// 单次限购数量
|
||||||
|
singleLimitCount: {
|
||||||
|
type: Number,
|
||||||
|
default: 1,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
goodsInfo: computed(() => props.modelValue),
|
goodsInfo: computed(() => props.modelValue),
|
||||||
skuPrices: computed(() => {
|
selectedSku: {},
|
||||||
let skuPrices = props.modelValue.sku_prices;
|
currentPropertyArray: [],
|
||||||
if (props.modelValue.is_sku) {
|
|
||||||
skuPrices.forEach((item) => {
|
|
||||||
item.goods_sku_id_arr = item.goods_sku_ids.split(',');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return skuPrices;
|
|
||||||
}),
|
|
||||||
skuList: props.modelValue.skus,
|
|
||||||
selectedSkuPrice: {},
|
|
||||||
currentSkuArray: [],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const propertyList = convertProductPropertyList(state.goodsInfo.skus);
|
||||||
|
// SKU 列表
|
||||||
|
const skuList = computed(() => {
|
||||||
|
let skuPrices = state.goodsInfo.skus;
|
||||||
|
for (let price of skuPrices) {
|
||||||
|
price.value_id_array = price.properties.map((item) => item.valueId)
|
||||||
|
}
|
||||||
|
return skuPrices;
|
||||||
|
});
|
||||||
|
|
||||||
if (!state.goodsInfo.is_sku) {
|
if (!state.goodsInfo.is_sku) {
|
||||||
state.selectedSkuPrice = state.goodsInfo.sku_prices[0];
|
state.selectedSku = state.goodsInfo.skus[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => state.selectedSkuPrice,
|
() => state.selectedSku,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
emits('change', newVal);
|
emits('change', newVal);
|
||||||
},
|
},
|
||||||
|
@ -125,178 +139,152 @@
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// 格式化价格
|
const onBuy = () => {
|
||||||
const formatPrice = (e) => {
|
if (state.selectedSku.id) {
|
||||||
return e.length === 1 ? e[0] : e.join('~');
|
if (state.selectedSku.stock <= 0) {
|
||||||
};
|
|
||||||
const onAddCart = () => {
|
|
||||||
if (state.selectedSkuPrice.goods_id) {
|
|
||||||
if (state.selectedSkuPrice.stock <= 0) {
|
|
||||||
sheep.$helper.toast('库存不足');
|
sheep.$helper.toast('库存不足');
|
||||||
} else {
|
} else {
|
||||||
emits('addCart', state.selectedSkuPrice);
|
emits('buy', state.selectedSku);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sheep.$helper.toast('请选择规格');
|
sheep.$helper.toast('请选择规格');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onBuy = () => {
|
// 购买数量改变
|
||||||
if (state.selectedSkuPrice.goods_id) {
|
function onBuyCountChange(buyCount) {
|
||||||
if (state.selectedSkuPrice.stock <= 0) {
|
if (buyCount > 0 && state.selectedSku.count !== buyCount) {
|
||||||
sheep.$helper.toast('库存不足');
|
state.selectedSku.count = buyCount;
|
||||||
} else {
|
|
||||||
emits('buy', state.selectedSkuPrice);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sheep.$helper.toast('请选择规格');
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
//输入框改变数量
|
|
||||||
function onNumberChange(e) {
|
|
||||||
if (e === 0) return;
|
|
||||||
if (state.selectedSkuPrice.goods_num === e) return;
|
|
||||||
state.selectedSkuPrice.goods_num = e;
|
|
||||||
}
|
}
|
||||||
// 改变禁用状态
|
// 改变禁用状态
|
||||||
const changeDisabled = (isChecked = false, pid = 0, skuId = 0) => {
|
const changeDisabled = (isChecked = false, propertyId = 0, valueId = 0) => {
|
||||||
let newPrice = []; // 所有可以选择的 skuPrice
|
let newSkus = []; // 所有可以选择的 sku 数组
|
||||||
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
// 选中规格
|
// 情况一:选中 property
|
||||||
// 当前点击选中规格下的 所有可用 skuPrice
|
// 获得当前点击选中 property 的、所有可用 SKU
|
||||||
for (let price of state.skuPrices) {
|
for (let price of skuList.value) {
|
||||||
if (price.stock <= 0) {
|
if (price.stock <= 0) {
|
||||||
// this.goodsNum 不判断是否大于当前选择数量,在 uni-number-box 判断,并且 取 stock 和 goods_num 的小值
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (price.goods_sku_id_arr.indexOf(skuId.toString()) >= 0) {
|
if (price.value_id_array.indexOf(valueId) >= 0) {
|
||||||
newPrice.push(price);
|
newSkus.push(price);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 取消选中
|
// 情况二:取消选中 property
|
||||||
// 当前所选规格下,所有可以选择的 skuPrice
|
// 当前所选 property 下,所有可以选择的 SKU
|
||||||
newPrice = getCanUseSkuPrice();
|
newSkus = getCanUseSkuList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 所有存在并且有库存未选择的规格项 的 子项 id
|
// 所有存在并且有库存未选择的 SKU 的 value 属性值 id
|
||||||
let noChooseSkuIds = [];
|
let noChooseValueIds = [];
|
||||||
for (let price of newPrice) {
|
for (let price of newSkus) {
|
||||||
noChooseSkuIds = noChooseSkuIds.concat(price.goods_sku_id_arr);
|
noChooseValueIds = noChooseValueIds.concat(price.value_id_array);
|
||||||
}
|
}
|
||||||
|
noChooseValueIds = Array.from(new Set(noChooseValueIds)); // 去重
|
||||||
// 去重
|
|
||||||
noChooseSkuIds = Array.from(new Set(noChooseSkuIds));
|
|
||||||
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
// 去除当前选中的规格项
|
// 去除当前选中的 value 属性值 id
|
||||||
let index = noChooseSkuIds.indexOf(skuId.toString());
|
let index = noChooseValueIds.indexOf(valueId);
|
||||||
noChooseSkuIds.splice(index, 1);
|
noChooseValueIds.splice(index, 1);
|
||||||
} else {
|
} else {
|
||||||
// 循环去除当前已选择的规格项
|
// 循环去除当前已选择的 value 属性值 id
|
||||||
state.currentSkuArray.forEach((sku) => {
|
state.currentPropertyArray.forEach((currentPropertyId) => {
|
||||||
if (sku.toString() != '') {
|
if (currentPropertyId.toString() !== '') {
|
||||||
// sku 为空是反选 填充的
|
return;
|
||||||
let index = noChooseSkuIds.indexOf(sku.toString());
|
}
|
||||||
if (index >= 0) {
|
// currentPropertyId 为空是反选 填充的
|
||||||
// sku 存在于 noChooseSkuIds
|
let index = noChooseValueIds.indexOf(currentPropertyId);
|
||||||
noChooseSkuIds.splice(index, 1);
|
if (index >= 0) {
|
||||||
}
|
// currentPropertyId 存在于 noChooseValueIds
|
||||||
|
noChooseValueIds.splice(index, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当前已选择的规格大类
|
// 当前已选择的 property 数组
|
||||||
let chooseSkuKey = [];
|
let choosePropertyIds = [];
|
||||||
if (!isChecked) {
|
if (!isChecked) {
|
||||||
// 当前已选择的规格大类
|
// 当前已选择的 property
|
||||||
state.currentSkuArray.forEach((sku, key) => {
|
state.currentPropertyArray.forEach((currentPropertyId, currentValueId) => {
|
||||||
if (sku != '') {
|
if (currentPropertyId !== '') {
|
||||||
// sku 为空是反选 填充的
|
// currentPropertyId 为空是反选 填充的
|
||||||
chooseSkuKey.push(key);
|
choosePropertyIds.push(currentValueId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 当前点击选择的规格大类
|
// 当前点击选择的 property
|
||||||
chooseSkuKey = [pid];
|
choosePropertyIds = [propertyId];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i in state.skuList) {
|
for (let propertyIndex in propertyList) {
|
||||||
// 当前点击的规格,或者取消选择时候 已选中的规格 不进行处理
|
// 当前点击的 property、或者取消选择时候,已选中的 property 不进行处理
|
||||||
if (chooseSkuKey.indexOf(state.skuList[i]['id']) >= 0) {
|
if (choosePropertyIds.indexOf(propertyList[propertyIndex]['id']) >= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// 如果当前 property id 不存在于有库存的 SKU 中,则禁用
|
||||||
for (let j in state.skuList[i]['children']) {
|
for (let valueIndex in propertyList[propertyIndex]['values']) {
|
||||||
// 如果当前规格项 id 不存在于有库存的规格项中,则禁用
|
propertyList[propertyIndex]['values'][valueIndex]['disabled'] =
|
||||||
if (noChooseSkuIds.indexOf(state.skuList[i]['children'][j]['id'].toString()) >= 0) {
|
noChooseValueIds.indexOf(propertyList[propertyIndex]['values'][valueIndex]['id']) < 0; // true 禁用 or false 不禁用
|
||||||
state.skuList[i]['children'][j]['disabled'] = false;
|
|
||||||
} else {
|
|
||||||
state.skuList[i]['children'][j]['disabled'] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 当前所选规格下,获取所有有库存的 skuPrice
|
// 获取可用的(有库存的)SKU 列表
|
||||||
const getCanUseSkuPrice = () => {
|
const getCanUseSkuList = () => {
|
||||||
let newPrice = [];
|
let newSkus = [];
|
||||||
|
for (let sku of skuList.value) {
|
||||||
for (let price of state.skuPrices) {
|
if (sku.stock <= 0) {
|
||||||
if (price.stock <= 0) {
|
|
||||||
// || price.stock < this.goodsNum 不判断是否大于当前选择数量,在 uni-number-box 判断,并且 取 stock 和 goods_num 的小值
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var isOk = true;
|
let isOk = true;
|
||||||
|
state.currentPropertyArray.forEach((propertyId) => {
|
||||||
state.currentSkuArray.forEach((sku) => {
|
// propertyId 不为空,并且,这个 条 sku 没有被选中,则排除
|
||||||
// sku 不为空,并且,这个 条 skuPrice 没有被选中,则排除
|
if (propertyId.toString() !== '' && sku.value_id_array.indexOf(propertyId) < 0) {
|
||||||
if (sku.toString() != '' && price.goods_sku_id_arr.indexOf(sku.toString()) < 0) {
|
|
||||||
isOk = false;
|
isOk = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isOk) {
|
if (isOk) {
|
||||||
newPrice.push(price);
|
newSkus.push(sku);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return newSkus;
|
||||||
return newPrice;
|
|
||||||
};
|
};
|
||||||
// 选择规格
|
// 选择规格
|
||||||
const onSelectSku = (pid, skuId) => {
|
const onSelectSku = (propertyId, valueId) => {
|
||||||
// 清空已选择
|
// 清空已选择
|
||||||
let isChecked = true; // 选中 or 取消选中
|
let isChecked = true; // 选中 or 取消选中
|
||||||
if (state.currentSkuArray[pid] != undefined && state.currentSkuArray[pid] == skuId) {
|
if (state.currentPropertyArray[propertyId] !== undefined && state.currentPropertyArray[propertyId] === valueId) {
|
||||||
// 点击已被选中的,删除并填充 ''
|
// 点击已被选中的,删除并填充 ''
|
||||||
isChecked = false;
|
isChecked = false;
|
||||||
state.currentSkuArray.splice(pid, 1, '');
|
state.currentPropertyArray.splice(propertyId, 1, '');
|
||||||
} else {
|
} else {
|
||||||
// 选中
|
// 选中
|
||||||
state.currentSkuArray[pid] = skuId;
|
state.currentPropertyArray[propertyId] = valueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
let chooseSkuId = []; // 选中的规格大类
|
// 选中的 property 大类
|
||||||
state.currentSkuArray.forEach((sku) => {
|
let choosePropertyId = [];
|
||||||
if (sku != '') {
|
state.currentPropertyArray.forEach((currentPropertyId) => {
|
||||||
// sku 为空是反选 填充的
|
if (currentPropertyId !== '') {
|
||||||
chooseSkuId.push(sku);
|
// currentPropertyId 为空是反选 填充的
|
||||||
|
choosePropertyId.push(currentPropertyId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 当前所选规格下,所有可以选择的 skuPric
|
// 当前所选 property 下,所有可以选择的 SKU 们
|
||||||
let newPrice = getCanUseSkuPrice();
|
let newSkuList = getCanUseSkuList();
|
||||||
|
|
||||||
// 判断所有规格大类是否选择完成
|
// 判断所有 property 大类是否选择完成
|
||||||
if (chooseSkuId.length == state.skuList.length && newPrice.length) {
|
if (choosePropertyId.length === propertyList.length && newSkuList.length) {
|
||||||
newPrice[0].goods_num = state.selectedSkuPrice.goods_num || 1;
|
newSkuList[0].goods_num = state.selectedSku.goods_num || 1;
|
||||||
state.selectedSkuPrice = newPrice[0];
|
state.selectedSku = newSkuList[0];
|
||||||
} else {
|
} else {
|
||||||
state.selectedSkuPrice = {};
|
state.selectedSku = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 改变规格项禁用状态
|
// 改变 property 禁用状态
|
||||||
changeDisabled(isChecked, pid, skuId);
|
changeDisabled(isChecked, propertyId, valueId);
|
||||||
};
|
};
|
||||||
|
|
||||||
changeDisabled(false);
|
changeDisabled(false);
|
||||||
|
|
|
@ -74,7 +74,7 @@ const VIDEO_SUFFIX_LIST = ['.avi', '.mp4']
|
||||||
* @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表
|
* @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表
|
||||||
*/
|
*/
|
||||||
export function formatGoodsSwiper(urlList) {
|
export function formatGoodsSwiper(urlList) {
|
||||||
return urlList.map((url, key) => {
|
return urlList.filter(url => url).map((url, key) => {
|
||||||
const isVideo = VIDEO_SUFFIX_LIST.some(suffix => url.includes(suffix));
|
const isVideo = VIDEO_SUFFIX_LIST.some(suffix => url.includes(suffix));
|
||||||
const type = isVideo ? 'video' : 'image'
|
const type = isVideo ? 'video' : 'image'
|
||||||
const src = $url.cdn(url);
|
const src = $url.cdn(url);
|
||||||
|
|
|
@ -136,8 +136,7 @@ const decryptSpm = (spm) => {
|
||||||
shareParams.page = '/pages/goods/seckill';
|
shareParams.page = '/pages/goods/seckill';
|
||||||
query = shareParamsArray[2].split(',');
|
query = shareParamsArray[2].split(',');
|
||||||
shareParams.query = {
|
shareParams.query = {
|
||||||
id: query[0],
|
id: query[1],
|
||||||
activity_id: query[1],
|
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case '5':
|
case '5':
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
v-if="isAnimate"
|
v-if="isAnimate"
|
||||||
>
|
>
|
||||||
<view class="textInside flex a-center j-center" v-if="textInside && !noData">
|
<view class="textInside flex a-center j-center" v-if="textInside && !noData">
|
||||||
<view>{{ percentage }}%</view>
|
<view class="text">{{ percentage }}%</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
// 背景颜色
|
// 背景颜色
|
||||||
bgColor: {
|
bgColor: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '#409eff',
|
default: 'linear-gradient(90deg, var(--ui-BG-Main) 0%, var(--ui-BG-Main-gradient) 100%)',
|
||||||
},
|
},
|
||||||
// 是否不显示数据
|
// 是否不显示数据
|
||||||
noData: {
|
noData: {
|
||||||
|
@ -168,6 +168,9 @@
|
||||||
|
|
||||||
.text {
|
.text {
|
||||||
margin-left: 10rpx;
|
margin-left: 10rpx;
|
||||||
|
font-size: 16rpx;
|
||||||
|
width: 100rpx;
|
||||||
|
color: #FFB9B9;
|
||||||
}
|
}
|
||||||
|
|
||||||
.percentage {
|
.percentage {
|
||||||
|
|
Loading…
Reference in New Issue