【秒杀商品详情】

1. 完整接入 SKU 选择
pull/1/MERGE
YunaiV 2023-06-11 18:37:40 +08:00
parent 07b9521a63
commit 7bc30ba3eb
3 changed files with 160 additions and 161 deletions

View File

@ -48,7 +48,10 @@
+ +
</view> </view>
<view v-else class='item plus' <view v-else class='item plus'
:class='(attr.productSelect.cart_num >= attr.productSelect.quota) || (attr.productSelect.cart_num >= attr.productSelect.stock) || (attr.productSelect.cart_num >= attr.productSelect.num)? "on":""' :class='(attr.productSelect.cart_num >= attr.productSelect.quota) //
|| (attr.productSelect.cart_num >= attr.productSelect.stock) //
|| (attr.productSelect.cart_num >= attr.productSelect.limitCount) //
? "on":""'
@click='CartNumAdd'>+</view> @click='CartNumAdd'>+</view>
</view> </view>
</view> </view>

View File

@ -47,7 +47,7 @@
</view> </view>
</view> </view>
<!-- SKU 选择 --> <!-- SKU 选择 -->
<view class='attribute acea-row row-between-wrapper mb30 borRadius14' @tap='selecAttr'> <view class='attribute acea-row row-between-wrapper mb30 borRadius14' @tap='openAttr'>
<view class="line1">{{ attrValue.length > 0 ? "已选择" : "请选择" }} <view class="line1">{{ attrValue.length > 0 ? "已选择" : "请选择" }}
<text class='atterTxt'>{{attrValue}}</text> <text class='atterTxt'>{{attrValue}}</text>
</view> </view>
@ -129,11 +129,10 @@
<product-window <product-window
:attr='attribute' :attr='attribute'
:limitNum='1' :limitNum='1'
@myevent="onMyEvent"
@ChangeAttr="ChangeAttr" @ChangeAttr="ChangeAttr"
@ChangeCartNum="ChangeCartNum" @ChangeCartNum="ChangeCartNum"
@attrVal="attrVal"
@iptCartNum="iptCartNum" @iptCartNum="iptCartNum"
@close="closeAttr"
/> />
<home></home> <home></home>
<!-- 分享按钮 TODO--> <!-- 分享按钮 TODO-->
@ -466,8 +465,21 @@
this.$set(this, 'spu', spu); this.$set(this, 'spu', spu);
this.$set(this.attribute, 'properties', ProductUtil.convertProductPropertyList(skus)); this.$set(this.attribute, 'properties', ProductUtil.convertProductPropertyList(skus));
this.$set(this, 'skuMap', ProductUtil.convertProductSkuMap(skus)); this.$set(this, 'skuMap', ProductUtil.convertProductSkuMap(skus));
// TODO minPrice // SKU
this.activity.products.forEach(product => {
this.spu.price = Math.min(this.spu.price, product.seckillPrice); // SPU
});
skus.forEach(sku => {
const product = this.activity.products.find(product => product.skuId === sku.id);
if (product) {
sku.price = product.seckillPrice;
sku.quota = product.quota;
sku.limitCount = product.limitCount;
} else { //
sku.quota = 0;
sku.limitCount = 0;
}
});
// //
setTimeout(() => { setTimeout(() => {
@ -491,10 +503,6 @@
// sku // sku
this.selectDefaultSku(); this.selectDefaultSku();
}).catch(err => { }).catch(err => {
// TODO
if (true) {
return
}
return this.$util.Tips({ return this.$util.Tips({
title: err.toString() title: err.toString()
}, { }, {
@ -503,68 +511,9 @@
}); });
}) })
}, },
/**
// TODO * 默认选中属性
*/
kefuClick(){
location.href = this.chatUrl;
},
closePosters:function(){
this.posters = false;
},
getProductReplyList: function() {
getReplyList(this.storeInfo.productId, {
page: 1,
limit: 3,
type: 0,
}).then(res => {
this.reply = res.data.list;
})
},
getProductReplyCount: function() {
let that = this;
getReplyConfig(that.storeInfo.productId).then(res => {
that.$set(that, 'replyChance', res.data.replyChance * 100);
that.$set(that, 'replyCount', res.data.sumCount);
});
},
/**
* 购物车手动填写
*
*/
iptCartNum: function (e) {
this.$set(this.attribute.productSelect, 'cart_num', e?e:1);
this.$set(this, "cart_num", e);
if (e > 1) {
return this.$util.Tips({
title: `该商品每次限购1${this.storeInfo.unitName}`
});
}
},
// 退
returns: function() {
uni.navigateBack()
},
setShare: function() {
this.$wechat.isWeixin() &&
this.$wechat.wechatEvevt([
"updateAppMessageShareData",
"updateTimelineShareData",
"onMenuShareAppMessage",
"onMenuShareTimeline"
], {
desc: this.storeInfo.info,
title: this.storeInfo.title,
link: location.href,
imgUrl: this.storeInfo.image
}).then(res => {
}).catch(err => {
console.log(err);
});
},
/**
* 默认选中属性
*/
selectDefaultSku: function() { selectDefaultSku: function() {
const properties = this.attribute.properties; const properties = this.attribute.properties;
// "," skuKey = ["", ""] // "," skuKey = ["", ""]
@ -593,99 +542,145 @@
this.$set(this.attribute.productSelect, "price", sku.price); this.$set(this.attribute.productSelect, "price", sku.price);
this.$set(this.attribute.productSelect, "stock", sku.stock); this.$set(this.attribute.productSelect, "stock", sku.stock);
this.$set(this.attribute.productSelect, "cart_num", 1); this.$set(this.attribute.productSelect, "cart_num", 1);
//
this.$set(this.attribute.productSelect, "quota", sku.quota); this.$set(this.attribute.productSelect, "quota", sku.quota);
this.$set(this.attribute.productSelect, "limitCount", sku.limitCount);
this.$set(this, "attrValue", skuKey.join(",")); this.$set(this, "attrValue", skuKey.join(","));
}, },
selecAttr: function() { /**
this.attribute.cartAttr = true * 打开 SKU 属性的选择
}, */
onMyEvent: function() { openAttr: function() {
this.$set(this.attribute, 'cartAttr', false); this.$set(this.attribute, 'cartAttr', true);
this.$set(this, 'isOpen', false); },
}, /**
/** * 关闭 productWindow 弹窗
* 购物车数量加和数量减 */
* closeAttr: function() {
*/ this.$set(this.attribute, 'cartAttr', false);
ChangeCartNum: function(changeValue) { },
//changeValue: | /**
// * 属性变动赋值
let productSelect = this.productValue[this.attrValue]; *
if (this.cart_num) { * @param newSkuKey 新的 skuKey
productSelect.cart_num = this.cart_num; * @param propertyIndex properties 的下标
this.attribute.productSelect.cart_num = this.cart_num; * @param valueIndex values 的下标
} */
//, ChangeAttr: function(newSkuKey, propertyIndex, valueIndex) {
if (productSelect === undefined && !this.attribute.productAttr.length) // SKU
productSelect = this.attribute.productSelect; let sku = this.skuMap[newSkuKey];
//0 if (!sku) {
if (productSelect === undefined) return; return;
let stock = productSelect.stock || 0; }
let quota = productSelect.quota || 0; this.$set(this.attribute.productSelect, "id", sku.id);
let num = this.attribute.productSelect; this.$set(this.attribute.productSelect, "picUrl", sku.picUrl);
// this.$set(this.attribute.productSelect, "price", sku.price);
if (productSelect.cart_num == undefined) productSelect.cart_num = 1; this.$set(this.attribute.productSelect, "stock", sku.stock);
if (changeValue) { this.$set(this.attribute.productSelect, "quota", sku.quota);
if (num.cart_num === 1) { this.$set(this.attribute.productSelect, "limitCount", sku.limitCount);
return this.$util.Tips({ this.$set(this.attribute.productSelect, "cart_num", 1);
title: `该商品每次限购 1 ${this.storeInfo.unitName}` // SKU
}); this.$set(this.attribute.properties[propertyIndex], 'index',
} this.attribute.properties[propertyIndex].values[valueIndex].name);
num.cart_num++; this.$set(this, "attrValue", newSkuKey);
let arrMin = []; },
arrMin.push(quota); /**
arrMin.push(stock); * 购物车数量加和数量减
let minN = Math.min.apply(null, arrMin); *
if (num.cart_num >= minN) { * @param changeValue true 增加false 减少
this.$set(this.attribute.productSelect, "cart_num", minN ? minN : 1); */
this.$set(this, "cart_num", minN ? minN : 1); ChangeCartNum: function(changeValue) {
} // sku
this.$set(this, "cart_num", num.cart_num); let sku = this.attribute.productSelect;
this.$set(this.attribute.productSelect, "cart_num", num.cart_num); if (!sku) {
return;
}
} else { //
num.cart_num--; let stock = sku.stock || 0;
if (num.cart_num < 1) { let quota = sku.quota || 0;
this.$set(this.attribute.productSelect, "cart_num", 1); let limitCount = sku.limitCount;
this.$set(this, "cart_num", 1); if (changeValue) {
} sku.cart_num++;
this.$set(this, "cart_num", num.cart_num); if (limitCount !== undefined && sku.cart_num > limitCount) {
this.$set(this.attribute.productSelect, "cart_num", num.cart_num); this.$set(this.attribute.productSelect, "cart_num", limitCount);
} this.$util.Tips({
}, title: `该商品每次限购 ${sku.limitCount} ${this.spu.unitName}`
attrVal(val) { });
this.attribute.productAttr[val.indexw].index = this.attribute.productAttr[val.indexw].attrValues[val.indexn]; } else if (sku.cart_num > stock || sku.cart_num > quota) {
}, this.$set(this.attribute.productSelect, "cart_num", Math.min(stock, quota));
/** }
* 属性变动赋值 } else {
* sku.cart_num--;
*/ if (sku.cart_num < 1) {
ChangeAttr: function(res) { this.$set(this.attribute.productSelect, "cart_num", 1);
this.$set(this,'cart_num',1); }
let productSelect = this.productValue[res]; }
if (productSelect) { },
this.$set(this.attribute.productSelect, "image", productSelect.image); /**
this.$set(this.attribute.productSelect, "price", productSelect.price); * 购物车手动填写
this.$set(this.attribute.productSelect, "stock", productSelect.stock); *
this.$set(this.attribute.productSelect, "unique", productSelect.id); * @param number 数量
this.$set(this.attribute.productSelect, "cart_num", 1); */
this.$set(this.attribute.productSelect, "quota", productSelect.quota); iptCartNum: function (number) {
this.$set(this.attribute.productSelect, "quotaShow", productSelect.quotaShow); this.$set(this.attribute.productSelect, 'cart_num', number ? number : 1);
this.$set(this, "attrValue", res); //
this.attrTxt = "已选择" let sku = this.attribute.productSelect;
} else { let limitCount = sku.limitCount;
this.$set(this.attribute.productSelect, "image", this.storeInfo.image); if (limitCount !== undefined && number > limitCount) {
this.$set(this.attribute.productSelect, "price", this.storeInfo.price); this.$set(this.attribute.productSelect, "cart_num", limitCount);
this.$set(this.attribute.productSelect, "stock", 0); this.$util.Tips({
this.$set(this.attribute.productSelect, "unique", ""); title: `该商品每次限购 ${sku.limitCount} ${this.spu.unitName}`
this.$set(this.attribute.productSelect, "cart_num", 0); });
this.$set(this.attribute.productSelect, "quota", 0); }
this.$set(this.attribute.productSelect, "quotaShow", 0); },
this.$set(this, "attrValue", "");
this.attrTxt = "已选择"
} // TODO
kefuClick(){
location.href = this.chatUrl;
}, },
closePosters:function(){
this.posters = false;
},
getProductReplyList: function() {
getReplyList(this.storeInfo.productId, {
page: 1,
limit: 3,
type: 0,
}).then(res => {
this.reply = res.data.list;
})
},
getProductReplyCount: function() {
let that = this;
getReplyConfig(that.storeInfo.productId).then(res => {
that.$set(that, 'replyChance', res.data.replyChance * 100);
that.$set(that, 'replyCount', res.data.sumCount);
});
},
// 退
returns: function() {
uni.navigateBack()
},
setShare: function() {
this.$wechat.isWeixin() &&
this.$wechat.wechatEvevt([
"updateAppMessageShareData",
"updateTimelineShareData",
"onMenuShareAppMessage",
"onMenuShareTimeline"
], {
desc: this.storeInfo.info,
title: this.storeInfo.title,
link: location.href,
imgUrl: this.storeInfo.image
}).then(res => {
}).catch(err => {
console.log(err);
});
},
scroll: function(e) { scroll: function(e) {
var that = this, var that = this,
scrollY = e.detail.scrollTop; scrollY = e.detail.scrollTop;

View File

@ -632,7 +632,8 @@
this.$set(this.attr.productSelect, "stock", sku.stock); this.$set(this.attr.productSelect, "stock", sku.stock);
this.$set(this.attr.productSelect, "cart_num", 1); this.$set(this.attr.productSelect, "cart_num", 1);
// SKU // SKU
this.$set(this.attr.properties[propertyIndex], 'index', this.attr.properties[propertyIndex].values[valueIndex].name); this.$set(this.attr.properties[propertyIndex], 'index',
this.attr.properties[propertyIndex].values[valueIndex].name);
this.$set(this, "attrValue", newSkuKey); this.$set(this, "attrValue", newSkuKey);
}, },
/** /**