【订单详情】

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

View File

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