|
@@ -5,7 +5,15 @@
|
|
|
<view class="tui-popup-box">
|
|
<view class="tui-popup-box">
|
|
|
<scroll-view scroll-y class="tui-popup-scroll">
|
|
<scroll-view scroll-y class="tui-popup-scroll">
|
|
|
<view class="tui-scrolldiv-box">
|
|
<view class="tui-scrolldiv-box">
|
|
|
- <view v-if="info.specEnabled == 1" class="spec-list"><view class="tui-attr-title">规格</view><button v-for="(spec,index) in info.specList" :key="spec.id" class="spec-button" :class="{active:selIndex===index}" @click="selectSpec(index)">{{spec.specName}}</button></view>
|
|
|
|
|
|
|
+ <view v-if="info.specEnabled == 1" class="spec-list">
|
|
|
|
|
+ <view class="tui-attr-title">规格</view>
|
|
|
|
|
+ <button v-for="(spec,index) in info.specList" :key="spec.id" class="spec-button" :class="{active:selIndex===index}" @click="selectSpec(index)">{{spec.specName}}</button>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <!-- 当前详情本身是主商品下的规格 SKU:只展示规格名,不可切换 -->
|
|
|
|
|
+ <view v-if="isMasterSpecSku" class="spec-list">
|
|
|
|
|
+ <view class="tui-attr-title">规格</view>
|
|
|
|
|
+ <button class="spec-button active">{{ info.specName }}</button>
|
|
|
|
|
+ </view>
|
|
|
<view class="tui-number-box tui-bold tui-attr-title">
|
|
<view class="tui-number-box tui-bold tui-attr-title">
|
|
|
<view class="tui-attr-title">数量</view>
|
|
<view class="tui-attr-title">数量</view>
|
|
|
<view class="number-box-wrapper">
|
|
<view class="number-box-wrapper">
|
|
@@ -82,6 +90,20 @@ export default {
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
computed: {
|
|
computed: {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 是否为挂在主商品下的规格 SKU(masterId/master 不为 0)
|
|
|
|
|
+ * 与主商品开启 specEnabled 选规格不同:此时详情页就是某一个规格本身
|
|
|
|
|
+ */
|
|
|
|
|
+ isMasterSpecSku() {
|
|
|
|
|
+ const master = this.info.masterId != null ? this.info.masterId : this.info.master;
|
|
|
|
|
+ return master != null && String(master) !== '0' && Number(master) > 0;
|
|
|
|
|
+ },
|
|
|
|
|
+ /** 主商品 id:规格 SKU 场景下用于购物车 goodsId */
|
|
|
|
|
+ masterGoodsId() {
|
|
|
|
|
+ if (!this.isMasterSpecSku) return 0;
|
|
|
|
|
+ const master = this.info.masterId != null ? this.info.masterId : this.info.master;
|
|
|
|
|
+ return Number(master) || 0;
|
|
|
|
|
+ },
|
|
|
maxStock() {
|
|
maxStock() {
|
|
|
const spec = this.info.specEnabled == 1 && this.info.specList ? this.info.specList[this.selIndex] : this.info;
|
|
const spec = this.info.specEnabled == 1 && this.info.specList ? this.info.specList[this.selIndex] : this.info;
|
|
|
return Number(spec && spec.stockSet == 1 ? spec.stock : 9999) || 9999;
|
|
return Number(spec && spec.stockSet == 1 ? spec.stock : 9999) || 9999;
|
|
@@ -94,8 +116,27 @@ export default {
|
|
|
close() {
|
|
close() {
|
|
|
this.$emit("close");
|
|
this.$emit("close");
|
|
|
},
|
|
},
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 组装当前规格 SKU 数据(详情本身即规格时用)
|
|
|
|
|
+ * 供加购写入 specGoodsId / specName,下单时 goodsId 用主商品 id
|
|
|
|
|
+ */
|
|
|
|
|
+ buildMasterSpecPayload() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: this.info.id,
|
|
|
|
|
+ specName: this.info.specName || '',
|
|
|
|
|
+ price: this.info.price,
|
|
|
|
|
+ priceType: this.info.priceType,
|
|
|
|
|
+ stock: this.info.stock,
|
|
|
|
|
+ stockSet: this.info.stockSet,
|
|
|
|
|
+ weight: this.info.weight,
|
|
|
|
|
+ };
|
|
|
|
|
+ },
|
|
|
getSelectedSpec() {
|
|
getSelectedSpec() {
|
|
|
- const spec = this.info.specEnabled == 1 ? this.info.specList[this.selIndex] : null;
|
|
|
|
|
|
|
+ let spec = this.info.specEnabled == 1 ? this.info.specList[this.selIndex] : null;
|
|
|
|
|
+ // 详情本身是规格 SKU:没有 specList 可选,直接把当前商品当作规格带上
|
|
|
|
|
+ if (!spec && this.isMasterSpecSku) {
|
|
|
|
|
+ spec = this.buildMasterSpecPayload();
|
|
|
|
|
+ }
|
|
|
if (this.info.specEnabled == 1 && !spec) {
|
|
if (this.info.specEnabled == 1 && !spec) {
|
|
|
this.$msg('请选择规格');
|
|
this.$msg('请选择规格');
|
|
|
return null;
|
|
return null;
|
|
@@ -120,7 +161,10 @@ export default {
|
|
|
goods.activityLimit = this.info.activityLimit;
|
|
goods.activityLimit = this.info.activityLimit;
|
|
|
}
|
|
}
|
|
|
uni.setStorageSync("buyGoodsDetil", goods);
|
|
uni.setStorageSync("buyGoodsDetil", goods);
|
|
|
- let url = "/pages/order/buy?hdId="+this.hdId+'&goodsId='+this.info.id+'&specGoodsId='+(spec ? spec.id : '')+'&goodsNum='+this.buyNum+'&selIndex='+this.selIndex+'&account='+this.account+'&freightType='+this.info.freightType
|
|
|
|
|
|
|
+ // 规格 SKU:goodsId 传主商品,specGoodsId 传当前规格商品
|
|
|
|
|
+ const goodsId = this.isMasterSpecSku ? this.masterGoodsId : this.info.id;
|
|
|
|
|
+ const specGoodsId = spec ? spec.id : '';
|
|
|
|
|
+ let url = "/pages/order/buy?hdId="+this.hdId+'&goodsId='+goodsId+'&specGoodsId='+specGoodsId+'&goodsNum='+this.buyNum+'&selIndex='+this.selIndex+'&account='+this.account+'&freightType='+this.info.freightType
|
|
|
if (this.info.activityType === 'seckill') {
|
|
if (this.info.activityType === 'seckill') {
|
|
|
url += '&activityType=seckill'
|
|
url += '&activityType=seckill'
|
|
|
}
|
|
}
|
|
@@ -129,13 +173,19 @@ export default {
|
|
|
addCartFn() {
|
|
addCartFn() {
|
|
|
const selected = this.getSelectedSpec();
|
|
const selected = this.getSelectedSpec();
|
|
|
if (!selected) return false;
|
|
if (!selected) return false;
|
|
|
|
|
+ // master !== 0 时把规格数据带上,并回传主商品 id 供购物车 goodsId 使用
|
|
|
this.$emit('addCart', {
|
|
this.$emit('addCart', {
|
|
|
spec: selected.spec,
|
|
spec: selected.spec,
|
|
|
buyNum: this.buyNum,
|
|
buyNum: this.buyNum,
|
|
|
- selIndex: this.selIndex
|
|
|
|
|
|
|
+ selIndex: this.selIndex,
|
|
|
|
|
+ masterId: this.masterGoodsId || 0,
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
- selectSpec(index) { this.selIndex=index; const spec=this.info.specList[index]; this.$emit('changeSpec', spec); },
|
|
|
|
|
|
|
+ selectSpec(index) {
|
|
|
|
|
+ this.selIndex=index;
|
|
|
|
|
+ const spec=this.info.specList[index];
|
|
|
|
|
+ this.$emit('changeSpec', spec);
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
</script>
|
|
</script>
|