【订单详情】

1. 简化 sku 选择的逻辑,默认选择有库存,否则第一个 sku
pull/1/MERGE
YunaiV 2023-06-06 23:18:13 +08:00
parent c8fdda0bb0
commit 9fca18b350
2 changed files with 41 additions and 77 deletions

View File

@ -42,13 +42,9 @@
<view class='item num'>
<input type="number" v-model="attr.productSelect.cart_num"
data-name="productSelect.cart_num"
@input="bindCode(attr.productSelect.cart_num)"></input>
@input="bindCode(attr.productSelect.cart_num)" />
</view>
<view v-if="iSplus" class="item plus" :class="
attr.productSelect.cart_num >= attr.productSelect.stock
? 'on'
: ''
" @click="CartNumAdd">
<view v-if="iSplus" class="item plus" :class="attr.productSelect.cart_num >= attr.productSelect.stock ? 'on' : ''" @click="CartNumAdd">
+
</view>
<view v-else class='item plus'
@ -57,7 +53,7 @@
</view>
</view>
</view>
<view class="joinBnt bg-color" v-if="iSbnt && attr.productSelect.stock>0 &&attr.productSelect.quota>0"
<view class="joinBnt bg-color" v-if="iSbnt && attr.productSelect.stock > 0 && attr.productSelect.quota > 0"
@click="goCat">我要参团</view>
<view class="joinBnt on"
v-else-if="(iSbnt && attr.productSelect.quota<=0)||(iSbnt &&attr.productSelect.stock<=0)">已售罄</view>

View File

@ -85,8 +85,8 @@
</view>
</view>
</view>
<view class='attribute acea-row row-between-wrapper mb30 borRadius14' @click="selecAttr">
<view class="line1">{{attrTxt}}
<view class='attribute acea-row row-between-wrapper mb30 borRadius14' @click="openAttr">
<view class="line1">{{ attrValue.length > 0 ? "已选择" : "请选择" }}
<text class='atterTxt'>{{attrValue}}</text>
</view>
<view class='iconfont icon-jiantou'></view>
@ -333,8 +333,6 @@
list: [],
count: []
},
attrTxt: '请选择', //
attrValue: '', //
animated: false, //
id: 0, //id
replyCount: 0, //
@ -367,8 +365,9 @@
isDown: true,
posters: false,
weixinStatus: false,
attrValue: '', // ,
attr: { // productWindow 使
cartAttr: false, // TODO
cartAttr: false, //
// id = name = values[].id = values[].name = index =
properties: [],
productSelect: {} // SKU
@ -671,23 +670,16 @@
* @param newSkuKey 新的 skuKey
*/
ChangeAttr: function(newSkuKey) {
let productSelect = this.skuMap[newSkuKey];
if (productSelect) {
this.$set(this.attr.productSelect, "id", productSelect.id);
this.$set(this.attr.productSelect, "picUrl", productSelect.picUrl);
this.$set(this.attr.productSelect, "price", productSelect.price);
this.$set(this.attr.productSelect, "stock", productSelect.stock);
let sku = this.skuMap[newSkuKey];
if (!sku) {
return;
}
this.$set(this.attr.productSelect, "id", sku.id);
this.$set(this.attr.productSelect, "picUrl", sku.picUrl);
this.$set(this.attr.productSelect, "price", sku.price);
this.$set(this.attr.productSelect, "stock", sku.stock);
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", newSkuKey);
this.$set(this, "attrTxt", "已选择");
} else {
this.$set(this.attr.productSelect, "image", this.spu.image);
this.$set(this.attr.productSelect, "price", this.spu.price);
this.$set(this.attr.productSelect, "stock", 0);
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", "");
this.$set(this, "attrTxt", "请选择");
}
},
/**
* 领取完毕移除当前页面领取过的优惠券展示
@ -778,12 +770,8 @@
// #ifndef H5
that.downloadFilestoreImage();
// #endif
that.DefaultSelect();
that.selectDefaultSku();
}).catch(err => {
console.error(err)
if (true) {
return;
}
//
return that.$util.Tips({
title: err.toString()
@ -855,59 +843,39 @@
/**
* 查找默认选中的 sku设置到 attr.productSelect
*
* 先找有库存的 SKU否则找第一个 SKU
*/
DefaultSelect: function() {
selectDefaultSku: function() {
let properties = this.attr.properties;
// "," skuKey = ["", ""]
let skuKey = [];
let skuKey = undefined;
for (let key in this.skuMap) {
if (this.skuMap[key].stock > 0) {
skuKey = this.attr.properties.length ? key.split(",") : [];
skuKey = key.split(",");
break;
}
}
if (!skuKey) { //
skuKey = Object.keys(this.skuMap)[0].split(",");
}
// 使 index
for (let i = 0; i < properties.length; i++) {
this.$set(properties[i], "index", skuKey[i]);
}
// sort();:--
let productSelect = this.skuMap[skuKey.join(",")];
// SKU
if (productSelect && properties.length) {
let sku = this.skuMap[skuKey.join(",")];
if (!sku) {
return
}
this.$set(this.attr.productSelect, "spuName", this.spu.name);
this.$set(this.attr.productSelect, "id", productSelect.id);
this.$set(this.attr.productSelect, "picUrl", productSelect.picUrl);
this.$set(this.attr.productSelect, "price", productSelect.price);
this.$set(this.attr.productSelect, "stock", productSelect.stock);
this.$set(this.attr.productSelect, "id", sku.id);
this.$set(this.attr.productSelect, "picUrl", sku.picUrl);
this.$set(this.attr.productSelect, "price", sku.price);
this.$set(this.attr.productSelect, "stock", sku.stock);
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", skuKey.join(","));
this.$set(this, "attrTxt", "已选择");
// SKU
} else if (!productSelect && properties.length) {
this.$set(this.attr.productSelect, "spuName", this.spu.name);
this.$set(this.attr.productSelect, "id", productSelect.id);
this.$set(this.attr.productSelect, "picUrl", productSelect.picUrl);
this.$set(this.attr.productSelect, "price", productSelect.price);
this.$set(this.attr.productSelect, "stock", 0);
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", "");
this.$set(this, "attrTxt", "请选择");
// TODO
} else if (!productSelect && !properties.length) {
this.$set(this.attr.productSelect, "storeName", this.productInfo.storeName);
this.$set(this.attr.productSelect, "image", this.productInfo.image);
this.$set(this.attr.productSelect, "price", this.productInfo.price);
this.$set(this.attr.productSelect, "stock", this.productInfo.stock);
this.$set(
this.attr.productSelect,
"unique",
this.productInfo.id || ""
);
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", "");
this.$set(this, "attrTxt", "请选择");
}
},
/**
* 获取优惠券
@ -962,9 +930,9 @@
}
},
/**
* 打开属性插件
* 打开 SKU 属性的选择
*/
selecAttr: function() {
openAttr: function() {
this.$set(this.attr, 'cartAttr', true);
this.$set(this, 'isOpen', true);
},