Files
kangyuan-mobile/pages/increment/info.vue
T
2026-05-26 15:52:30 +08:00

539 lines
13 KiB
Vue

<template>
<view>
<s-layout title="商品详情">
<!-- 标题栏 -->
<!-- 骨架屏 -->
<detailSkeleton v-if="state.skeletonLoading" />
<!-- 下架/售罄提醒 -->
<s-empty
v-else-if="state.goodsInfo === null"
text="商品不存在或已下架"
icon="/static/soldout-empty.png"
showAction
actionText="再逛逛"
actionUrl="/pages/goods/list"
/>
<block v-else>
<view class="detail-swiper-selector">
<!-- 商品轮播图 -->
<su-swiper
v-if="state.goodsInfo.sliderPicUrls"
class=""
isPreview
:list="formatGoodsSwiper(state.goodsInfo.sliderPicUrls)"
otStyle="tag"
imageMode="widthFix"
dotCur="bg-mask-40"
:seizeHeight="750"
/>
<!-- 价格+标题 -->
<view class="title-card detail-card ss-p-y-32 ss-p-x-32">
<view class="title-text ss-line-2 ss-m-b-6 c0"> {{ state.goodsInfo.name }}</view>
<view class="subtitle-text ss-line-1 c0">{{ state.goodsInfo.introduction }}</view>
<view class="c35 size32 m-t-10"
>{{ state.goodsInfo.price }}<span class="size24">积分</span></view
>
</view>
</view>
<view class="m-t-30 m-b-40 bg24 p-l-40 p-r-32 p-y-8">
<view v-if="mesArr.length">
<maoScroll
:data="mesArr"
:lineHeight="72"
:animation="1000"
:animationScroll="5000"
:showNum="2"
>
<template #default="{ line }">
<view class="flex-center ju-between">
<view class="flex-row al-flex-end">
<view v-for="(item, index) in line.participantAvatars" :key="index">
<view
class="userImg bg0 flex-center"
v-if="index < 3"
:style="{ 'margin-left': index ? '-28rpx' : 0, 'z-index': index + 10 }"
>
<image
class="w_56 h_56"
:src="item"
mode="scaleToFill"
v-if="item"
style="border-radius: 50%"
/>
<image
v-else
class="w_56 h_56"
:src="`${$url}home/head.png`"
mode="scaleToFill"
style="border-radius: 50%"
/>
</view>
</view>
<view
class="w_28 h_26"
v-if="line.participantAvatars.length > 3"
style="margin-left: -14rpx; margin-bottom: 5rpx"
>
<image
class="w100 h100"
src="/static/increment/more.png"
mode="scaleToFill"
/>
</view>
</view>
<view class="flex-center ju-flex-end">
<view style="text-align: right">
<view class="c13 size28">还剩{{ line.remainingCount }}</view>
<view class="c19 size24">倒计时{{ getTime(line.expireTime) }}</view>
</view>
<view
class="w_170 line56 bg35 radius12 center size28 m-l-10"
@click.stop="sub(line)"
style="color: #fff"
>{{
statusObj(parseInt(line.joinStatus) || 0, parseInt(line.status) || 0)
}}</view
>
</view>
</view>
</template>
</maoScroll>
</view>
</view>
<!-- 详情 -->
<detail-content-card
class="detail-content-selector"
:content="state.goodsInfo.description"
/>
</block>
</s-layout>
</view>
</template>
<script setup>
import { reactive, computed, ref, onMounted, onUnmounted } from 'vue';
import { onLoad, onPageScroll } from '@dcloudio/uni-app';
import maoScroll from '@/components/mao-scroll/mao-scroll.vue';
import sheep from '@/sheep';
import {
formatSales,
formatGoodsSwiper,
fen2yuan,
fen2yuanSimple,
formatDiscountPercent,
getRewardActivityRuleItemDescriptions,
} from '@/sheep/hooks/useGoods';
import detailSkeleton from './components/detail/detail-skeleton.vue';
import detailContentCard from './components/detail/detail-content-card.vue';
import * as SpuApi from '@/sheep/api/increment';
onPageScroll(() => {});
import OrderApi from '@/sheep/api/trade/order';
import { SharePageEnum } from '@/sheep/helper/const';
import { emojiList } from '../chat/util/emoji';
const statusObj = (joinStatus, status) => {
let text = '未开团';
switch (status) {
case 0:
text = '未开团';
if (joinStatus === 1) {
text = '已参团';
} else {
text = '立即参团';
}
break;
case 1:
text = '已开团';
if (joinStatus === 1) {
text = '已参团';
} else {
text = '立即参团';
}
break;
case 2:
text = '开团成功';
break;
case 3:
text = '开团失败';
break;
}
return text;
};
const bgColor = {
bgColor: '#E93323',
Color: '#fff',
width: '44rpx',
timeTxtwidth: '16rpx',
isDay: true,
};
const isLogin = computed(() => sheep.$store('user').isLogin);
const state = reactive({
goodsId: 0,
info: {},
skeletonLoading: true, // SPU 加载中
goodsInfo: {}, // SPU 信息
showSelectSku: false, // 是否展示 SKU 选择弹窗
selectedSku: {}, // 选中的 SKU
settlementSku: {}, // 结算的 SKU:由于 selectedSku 不进行默认选中,所以初始使用结算价格最低的 SKU 作为基础展示
showModel: false, // 是否展示 Coupon 优惠劵的弹窗
updateKey: Date.now(), // 用于更新倒计时的触发键
couponInfo: [], // 可领取的 Coupon 优惠劵的列表
showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
rewardActivity: {}, // 【满减送】活动
activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
});
let mesArr = ref([]);
const getDetail = () => {
SpuApi.getGroupDetail({
id: state.goodsId,
}).then((res) => {
if (res.code !== 0 || !res.data) {
state.goodsInfo = null;
state.skeletonLoading = false;
return;
}
state.skeletonLoading = false;
state.goodsInfo = res.data;
});
};
const getList = () => {
SpuApi.getGroupBuys({
productId: state.goodsId,
}).then((res) => {
if (res.code === 0) {
mesArr.value = res.data;
console.log(mesArr.value);
}
});
};
onLoad((options) => {
// 滚到顶部
uni.pageScrollTo({
scrollTop: 0,
});
// 非法参数
if (!options.id) {
state.goodsInfo = null;
state.skeletonLoading = false;
return;
}
state.goodsId = options.id;
getDetail();
getList();
});
const sub = (e) => {
SpuApi.joinGroup({
groupBuyId: e.groupBuyId,
}).then((res) => {
getList();
});
};
// 时间戳倒计时
const getTime = (t) => {
// 计算剩余时间(毫秒)
let time = t - Date.now();
// 确保时间不为负数
if (time <= 0) {
return '00:00:00';
}
// 转换为时分秒
let hour = Math.floor(time / (60 * 60 * 1000));
let minute = Math.floor((time % (60 * 60 * 1000)) / (60 * 1000));
let second = Math.floor((time % (60 * 1000)) / 1000);
// 格式化为两位数显示
hour = hour.toString().padStart(2, '0');
minute = minute.toString().padStart(2, '0');
second = second.toString().padStart(2, '0');
return `${hour}:${minute}:${second}`;
};
// 如果需要让倒计时动态更新,可以添加定时器
onMounted(() => {
// 每秒更新一次倒计时
const timer = setInterval(() => {
// 触发页面重新渲染
state.updateKey = Date.now();
}, 1000);
// 组件卸载时清除定时器
onUnmounted(() => {
clearInterval(timer);
});
});
</script>
<style lang="scss" scoped>
.userImg {
border-radius: 50%;
overflow: hidden;
}
.detail-card {
background-color: var(--color24);
border-radius: 10rpx;
overflow: hidden;
margin-bottom: 40rpx;
// color: #fff;
}
// 价格标题卡片
.title-card {
.price-box {
.price-text {
font-size: 42rpx;
font-weight: 500;
color: #ff3000;
line-height: 30rpx;
font-family: OPPOSANS;
&::before {
content: '¥';
font-size: 30rpx;
}
}
.origin-price-text {
font-size: 26rpx;
font-weight: 400;
text-decoration: line-through;
color: $gray-c;
font-family: OPPOSANS;
&::before {
content: '¥';
}
}
}
.sales-text {
font-size: 26rpx;
font-weight: 500;
color: $gray-c;
}
.discounts-box {
.tag-content {
flex: 1;
min-width: 0;
white-space: nowrap;
}
.tag-box {
overflow: hidden;
text-overflow: ellipsis;
}
.tag {
flex-shrink: 0;
padding: 4rpx 10rpx;
font-size: 24rpx;
font-weight: 500;
border-radius: 4rpx;
color: var(--ui-BG-Main);
background: var(--ui-BG-Main-tag);
}
.discounts-title {
font-size: 24rpx;
font-weight: 500;
color: var(--ui-BG-Main);
line-height: normal;
}
.cicon-forward {
color: var(--ui-BG-Main);
font-size: 24rpx;
line-height: normal;
margin-top: 4rpx;
}
}
.title-text {
color: #333333;
font-size: 32rpx;
line-height: 42rpx;
}
.subtitle-text {
font-size: 26rpx;
font-weight: 400;
color: $dark-9;
line-height: 42rpx;
}
}
// 购买
.buy-box {
.add-btn {
width: 240rpx;
height: 72rpx;
font-weight: 500;
font-size: 30rpx;
border-radius: 12rpx 0 0 12rpx;
background-color: #74aef6;
color: #ffffff;
}
.buy-btn {
width: 240rpx;
height: 72rpx;
font-weight: 500;
font-size: 30rpx;
border-radius: 0 12rpx 12rpx 0;
background: #366eee;
color: #ffffff;
}
.disabled-btn {
width: 428rpx;
height: 72rpx;
border-radius: 40rpx;
background: #999999;
color: $white;
}
}
.model-box {
height: 60vh;
.model-content {
height: 56vh;
}
.title {
font-size: 36rpx;
font-weight: bold;
color: #333333;
}
.subtitle {
font-size: 26rpx;
font-weight: 500;
color: #333333;
}
}
// 限时折扣
.discount {
width: 750rpx;
height: 100rpx;
// background-color: red;
overflow: hidden;
position: relative;
}
.disImg {
width: 750rpx;
height: 100rpx;
position: absolute;
top: 0;
z-index: -1;
}
.discountCont {
width: 680rpx;
height: 90rpx;
margin: 10rpx auto 0 auto;
// background-color: gold;
}
.disContT {
width: 680rpx;
height: 50rpx;
display: flex;
justify-content: space-between;
}
.disContT1 {
// width: 400rpx;
// height: 50rpx;
// background-color: green;
display: flex;
justify-content: flex-start;
align-items: center;
}
.disContT2 {
width: 200rpx;
height: 50rpx;
line-height: 50rpx;
// background-color: gold;
font-size: 30rpx;
text-align: end;
color: #ff393a;
font-weight: bolder;
font-style: oblique 20deg;
letter-spacing: 0.1rem;
}
.disContT1P {
color: white;
font-size: 44rpx;
}
.disContT1End {
// width: 180rpx;
padding: 0 20rpx;
height: 36rpx;
line-height: 36rpx;
text-align: center;
background-color: #fee2be;
color: #f71b1b;
font-size: 23rpx;
border-radius: 20rpx;
margin-left: 26rpx;
}
.disContB {
width: 680rpx;
height: 40rpx;
display: flex;
justify-content: space-between;
font-size: 20rpx;
color: white;
align-items: center;
}
.disContB1 {
width: 300rpx;
height: 40rpx;
line-height: 40rpx;
color: #ffcccc;
font-size: 24rpx;
// 删除线
text-decoration: line-through;
padding-left: 6rpx;
}
.disContB2 {
width: 300rpx;
height: 40rpx;
line-height: 40rpx;
display: flex;
justify-content: flex-end;
}
.label {
display: inline-block;
font-size: 20rpx;
color: #ff5040;
border: 1px solid #ff5040;
border-radius: 8rpx;
height: 34rpx;
line-height: 34rpx;
padding: 0 8rpx;
box-sizing: border-box;
margin-top: 10rpx;
margin-bottom: 12rpx;
}
</style>