mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 02:16:12 +08:00
chore(Sku): prettier code
This commit is contained in:
parent
eee0ade7ea
commit
38c327d47a
@ -205,6 +205,7 @@ export default createComponent({
|
|||||||
stock_num: this.sku.stock_num,
|
stock_num: this.sku.stock_num,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skuComb) {
|
if (skuComb) {
|
||||||
skuComb.properties = getSelectedProperties(
|
skuComb.properties = getSelectedProperties(
|
||||||
this.propList,
|
this.propList,
|
||||||
@ -292,7 +293,9 @@ export default createComponent({
|
|||||||
|
|
||||||
stockText() {
|
stockText() {
|
||||||
const { stockFormatter } = this.customStepperConfig;
|
const { stockFormatter } = this.customStepperConfig;
|
||||||
if (stockFormatter) return stockFormatter(this.stock);
|
if (stockFormatter) {
|
||||||
|
return stockFormatter(this.stock);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
`${t('stock')} `,
|
`${t('stock')} `,
|
||||||
@ -318,6 +321,7 @@ export default createComponent({
|
|||||||
(item) => this.selectedSku[item.k_s] === UNSELECTED_SKU_VALUE_ID
|
(item) => this.selectedSku[item.k_s] === UNSELECTED_SKU_VALUE_ID
|
||||||
)
|
)
|
||||||
.map((item) => item.k);
|
.map((item) => item.k);
|
||||||
|
|
||||||
const unselectedProp = this.propList
|
const unselectedProp = this.propList
|
||||||
.filter((item) => (this.selectedProp[item.k_id] || []).length < 1)
|
.filter((item) => (this.selectedProp[item.k_id] || []).length < 1)
|
||||||
.map((item) => item.k);
|
.map((item) => item.k);
|
||||||
@ -479,6 +483,7 @@ export default createComponent({
|
|||||||
onPropSelect(propValue) {
|
onPropSelect(propValue) {
|
||||||
const arr = this.selectedProp[propValue.skuKeyStr] || [];
|
const arr = this.selectedProp[propValue.skuKeyStr] || [];
|
||||||
const pos = arr.indexOf(propValue.id);
|
const pos = arr.indexOf(propValue.id);
|
||||||
|
|
||||||
if (pos > -1) {
|
if (pos > -1) {
|
||||||
arr.splice(pos, 1);
|
arr.splice(pos, 1);
|
||||||
} else if (propValue.multiple) {
|
} else if (propValue.multiple) {
|
||||||
@ -486,10 +491,12 @@ export default createComponent({
|
|||||||
} else {
|
} else {
|
||||||
arr.splice(0, 1, propValue.id);
|
arr.splice(0, 1, propValue.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectedProp = {
|
this.selectedProp = {
|
||||||
...this.selectedProp,
|
...this.selectedProp,
|
||||||
[propValue.skuKeyStr]: arr,
|
[propValue.skuKeyStr]: arr,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$emit('sku-prop-selected', {
|
this.$emit('sku-prop-selected', {
|
||||||
propValue,
|
propValue,
|
||||||
selectedProp: this.selectedProp,
|
selectedProp: this.selectedProp,
|
||||||
@ -502,10 +509,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onPreviewImage(indexImage) {
|
onPreviewImage(indexImage) {
|
||||||
const { previewOnClickImage } = this;
|
|
||||||
|
|
||||||
const index = this.imageList.findIndex((image) => image === indexImage);
|
const index = this.imageList.findIndex((image) => image === indexImage);
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
index,
|
index,
|
||||||
imageList: this.imageList,
|
imageList: this.imageList,
|
||||||
@ -514,7 +518,7 @@ export default createComponent({
|
|||||||
|
|
||||||
this.$emit('open-preview', params);
|
this.$emit('open-preview', params);
|
||||||
|
|
||||||
if (!previewOnClickImage) {
|
if (!this.previewOnClickImage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,14 +561,12 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onStepperState(data) {
|
onStepperState(data) {
|
||||||
if (data.valid) {
|
this.stepperError = data.valid
|
||||||
this.stepperError = null;
|
? null
|
||||||
} else {
|
: {
|
||||||
this.stepperError = {
|
|
||||||
...data,
|
...data,
|
||||||
action: 'plus',
|
action: 'plus',
|
||||||
};
|
};
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onAddCart() {
|
onAddCart() {
|
||||||
@ -576,11 +578,13 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onBuyOrAddCart(type) {
|
onBuyOrAddCart(type) {
|
||||||
// 有信息表示该sku根本不符合购买条件
|
// sku 不符合购买条件
|
||||||
if (this.stepperError) {
|
if (this.stepperError) {
|
||||||
return this.onOverLimit(this.stepperError);
|
return this.onOverLimit(this.stepperError);
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = this.validateSku();
|
const error = this.validateSku();
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
Toast(error);
|
Toast(error);
|
||||||
} else {
|
} else {
|
||||||
@ -592,10 +596,10 @@ export default createComponent({
|
|||||||
getSkuData() {
|
getSkuData() {
|
||||||
return {
|
return {
|
||||||
goodsId: this.goodsId,
|
goodsId: this.goodsId,
|
||||||
selectedNum: this.selectedNum,
|
|
||||||
selectedSkuComb: this.selectedSkuComb,
|
|
||||||
messages: this.getSkuMessages(),
|
messages: this.getSkuMessages(),
|
||||||
|
selectedNum: this.selectedNum,
|
||||||
cartMessages: this.getSkuCartMessages(),
|
cartMessages: this.getSkuCartMessages(),
|
||||||
|
selectedSkuComb: this.selectedSkuComb,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user