|
|
@@ -33,10 +33,13 @@
|
|
|
|
|
|
<!-- 商品基础信息 -->
|
|
|
<view class="base-info">
|
|
|
- <view class="title">{{ detailData.productName }}</view>
|
|
|
+ <view class="title">
|
|
|
+ <text class="group-tag" v-if="activityType === 'group' && detailData.groupNum">{{ detailData.groupNum }}人团</text>
|
|
|
+ {{ detailData.productName }}
|
|
|
+ </view>
|
|
|
<view class="sub-info">
|
|
|
<text class="sales">销量: {{ detailData.sales || 0 }}</text>
|
|
|
- <text class="stock">剩余库存: {{ detailData.remainStock || 0 }}</text>
|
|
|
+ <text class="stock">剩余库存: {{ detailData.productStock || 0 }}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
@@ -81,7 +84,7 @@
|
|
|
</view>
|
|
|
<view class="desc-box">
|
|
|
<text class="text">已选:{{ currentSpec.specName || '默认规格' }}</text>
|
|
|
- <text class="text">库存:{{ currentSpec.remainStock !== undefined ? currentSpec.remainStock : detailData.remainStock }}</text>
|
|
|
+ <text class="text">库存:{{ currentSpec.stock !== undefined ? currentSpec.stock : detailData.productStock }}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -95,7 +98,7 @@
|
|
|
:key="index"
|
|
|
:class="['item', specIndex === index ? 'active' : '']"
|
|
|
@click="choseSpec(index)">
|
|
|
- {{ item.specName }}
|
|
|
+ {{ item.specName || '默认规格' }}
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -122,6 +125,7 @@
|
|
|
<script>
|
|
|
import { getFlashSaleDetail, getFlashSaleServerTime } from '@/api/flashSale.js';
|
|
|
import { getDiscountDetail, getDiscountServerTime } from '@/api/discount.js';
|
|
|
+import { getGroupBuyDetail, getGroupBuyServerTime } from '@/api/groupBuy.js';
|
|
|
import { addCart } from '@/api/product.js';
|
|
|
import popupBottom from '@/components/px-popup-bottom/px-popup-bottom.vue';
|
|
|
|
|
|
@@ -131,7 +135,7 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- activityType: 'flash', // 'flash' 或 'discount'
|
|
|
+ activityType: 'flash', // 'flash', 'discount' 或 'group'
|
|
|
activityId: '',
|
|
|
detailData: {},
|
|
|
timer: null,
|
|
|
@@ -145,8 +149,10 @@ export default {
|
|
|
currentPrice() {
|
|
|
if (this.activityType === 'flash') {
|
|
|
return this.detailData.flashPrice || 0;
|
|
|
+ } else if (this.activityType === 'discount') {
|
|
|
+ return this.detailData.discountPrice || this.detailData.groupPrice || 0;
|
|
|
} else {
|
|
|
- return this.detailData.discountPrice || 0;
|
|
|
+ return this.detailData.groupPrice || 0;
|
|
|
}
|
|
|
},
|
|
|
btnText() {
|
|
|
@@ -154,8 +160,8 @@ export default {
|
|
|
switch (status) {
|
|
|
case 'not_started':
|
|
|
let time = this.formatTime(this.detailData.countdown);
|
|
|
- return `即将开抢 ${time.h}:${time.m}:${time.s}`;
|
|
|
- case 'ongoing': return '立即抢购';
|
|
|
+ return `即将开始 ${time.h}:${time.m}:${time.s}`;
|
|
|
+ case 'ongoing': return this.activityType === 'group' ? '立即参团' : '立即抢购';
|
|
|
case 'sold_out': return '已售罄';
|
|
|
case 'ended': return '已结束';
|
|
|
default: return '抢购';
|
|
|
@@ -177,7 +183,13 @@ export default {
|
|
|
if (this.detailData.specs && this.detailData.specs.length > 0) {
|
|
|
let spec = this.detailData.specs[this.specIndex];
|
|
|
if (spec) {
|
|
|
- spec.price = this.activityType === 'flash' ? spec.flashPrice : spec.discountPrice;
|
|
|
+ if (this.activityType === 'flash') {
|
|
|
+ spec.price = spec.flashPrice;
|
|
|
+ } else if (this.activityType === 'discount') {
|
|
|
+ spec.price = spec.discountPrice || spec.groupPrice;
|
|
|
+ } else {
|
|
|
+ spec.price = spec.groupPrice;
|
|
|
+ }
|
|
|
return spec;
|
|
|
}
|
|
|
}
|
|
|
@@ -187,9 +199,11 @@ export default {
|
|
|
onLoad(options) {
|
|
|
if (options.type) {
|
|
|
this.activityType = options.type;
|
|
|
- uni.setNavigationBarTitle({
|
|
|
- title: this.activityType === 'flash' ? '秒杀商品详情' : '折扣商品详情'
|
|
|
- });
|
|
|
+ let title = '商品详情';
|
|
|
+ if (this.activityType === 'flash') title = '秒杀商品详情';
|
|
|
+ else if (this.activityType === 'discount') title = '折扣商品详情';
|
|
|
+ else if (this.activityType === 'group') title = '团购商品详情';
|
|
|
+ uni.setNavigationBarTitle({ title });
|
|
|
}
|
|
|
if (options.id) {
|
|
|
this.activityId = options.id;
|
|
|
@@ -227,11 +241,16 @@ export default {
|
|
|
getFlashSaleDetail(this.activityId),
|
|
|
getFlashSaleServerTime()
|
|
|
]);
|
|
|
- } else {
|
|
|
+ } else if (this.activityType === 'discount') {
|
|
|
[detailRes, timeRes] = await Promise.all([
|
|
|
getDiscountDetail(this.activityId),
|
|
|
getDiscountServerTime()
|
|
|
]);
|
|
|
+ } else {
|
|
|
+ [detailRes, timeRes] = await Promise.all([
|
|
|
+ getGroupBuyDetail(this.activityId),
|
|
|
+ getGroupBuyServerTime()
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
if (detailRes.code === 0 || detailRes.code === 200) {
|
|
|
@@ -301,14 +320,16 @@ export default {
|
|
|
let res;
|
|
|
if (this.activityType === 'flash') {
|
|
|
res = await getFlashSaleDetail(this.activityId);
|
|
|
- } else {
|
|
|
+ } else if (this.activityType === 'discount') {
|
|
|
res = await getDiscountDetail(this.activityId);
|
|
|
+ } else {
|
|
|
+ res = await getGroupBuyDetail(this.activityId);
|
|
|
}
|
|
|
|
|
|
if (res.code === 0 || res.code === 200) {
|
|
|
- let remainStock = res.data?.remainStock || 0;
|
|
|
- this.detailData.remainStock = remainStock;
|
|
|
- if (remainStock <= 0) {
|
|
|
+ let productStock = res.data?.productStock || 0;
|
|
|
+ this.detailData.productStock = productStock;
|
|
|
+ if (productStock <= 0) {
|
|
|
this.detailData.activityStatus = 'sold_out';
|
|
|
this.clearStockPolling();
|
|
|
}
|
|
|
@@ -346,7 +367,7 @@ export default {
|
|
|
uni.showToast({ title: '抱歉,活动已结束', icon: 'none' });
|
|
|
return;
|
|
|
}
|
|
|
- if (status === 'sold_out' || this.detailData.remainStock <= 0) {
|
|
|
+ if (status === 'sold_out' || this.detailData.productStock <= 0) {
|
|
|
uni.showToast({ title: '活动商品已售罄', icon: 'none' });
|
|
|
return;
|
|
|
}
|
|
|
@@ -362,7 +383,7 @@ export default {
|
|
|
this.specIndex = index;
|
|
|
},
|
|
|
submitSpec() {
|
|
|
- let stock = this.currentSpec.remainStock !== undefined ? this.currentSpec.remainStock : this.detailData.remainStock;
|
|
|
+ let stock = this.currentSpec.stock !== undefined ? this.currentSpec.stock : this.detailData.productStock;
|
|
|
if (stock <= 0) {
|
|
|
uni.showToast({ title: '该规格库存不足', icon: 'none' });
|
|
|
return;
|
|
|
@@ -387,7 +408,11 @@ export default {
|
|
|
if (res.code === 200) {
|
|
|
this.specVisible = false; // 关闭弹窗
|
|
|
let cartIds = res.id;
|
|
|
- let orderType = this.activityType === 'flash' ? 6 : 7;
|
|
|
+ let orderType = 6;
|
|
|
+ if (this.activityType === 'flash') orderType = 6;
|
|
|
+ else if (this.activityType === 'discount') orderType = 7;
|
|
|
+ else if (this.activityType === 'group') orderType = 8;
|
|
|
+
|
|
|
// associatedId 为中间表 ID,即 specs 数组里的 id
|
|
|
let associatedId = this.detailData.specs && this.detailData.specs.length > 0 ? (this.detailData.specs[this.specIndex].id || this.activityId) : this.activityId;
|
|
|
|
|
|
@@ -441,6 +466,10 @@ export default {
|
|
|
&.discount {
|
|
|
background: linear-gradient(90deg, #b835c9, #9c26b0);
|
|
|
}
|
|
|
+
|
|
|
+ &.group {
|
|
|
+ background: linear-gradient(90deg, #66b2ef, #4C49E9);
|
|
|
+ }
|
|
|
|
|
|
.price-info {
|
|
|
display: flex;
|
|
|
@@ -504,6 +533,20 @@ export default {
|
|
|
font-weight: bold;
|
|
|
line-height: 44rpx;
|
|
|
margin-bottom: 20rpx;
|
|
|
+
|
|
|
+ .group-tag {
|
|
|
+ display: inline-block;
|
|
|
+ padding: 0 12rpx;
|
|
|
+ height: 34rpx;
|
|
|
+ line-height: 34rpx;
|
|
|
+ background: #4C49E9;
|
|
|
+ color: #fff;
|
|
|
+ font-size: 20rpx;
|
|
|
+ border-radius: 4rpx;
|
|
|
+ margin-right: 12rpx;
|
|
|
+ vertical-align: middle;
|
|
|
+ font-weight: normal;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
.sub-info {
|
|
|
@@ -574,6 +617,10 @@ export default {
|
|
|
&.discount {
|
|
|
background: linear-gradient(90deg, #b835c9, #9c26b0);
|
|
|
}
|
|
|
+
|
|
|
+ &.group {
|
|
|
+ background: linear-gradient(90deg, #66b2ef, #4C49E9);
|
|
|
+ }
|
|
|
|
|
|
&.disabled {
|
|
|
background: #cccccc;
|