学习很差啦 2022-08-30 09:06:29 +08:00
commit 248c4031c0
2 changed files with 74 additions and 25 deletions

View File

@ -444,7 +444,7 @@ export default {
addSettlementBtn: true, //
day: 1, //
tabName: "base", // tabname
tabNameList: ["base", "entry", "category", "send", "settlement"], // tabname
tabNameList: ["base", "entry", "category", "settlement"], // tabname
shopValidate: {
//
memberName: [{ required: true, message: "会员不能为空" }],

View File

@ -274,7 +274,10 @@
placeholder="请输入规格名称"
:filter-method="filterMethod"
:data="skuData"
@on-change="editSkuItem"
@on-focus="changeSkuItem(item.name)"
@on-change="
editSkuItem(item.name, $index, item)
"
>
</AutoComplete>
</FormItem>
@ -297,10 +300,8 @@
placeholder="请输入规格项"
:filter-method="filterMethod"
:data="skuVal"
@on-focus="changeSkuVals(item.name)"
@on-change="
skuValueChange(val.value, index, item)
"
@on-focus="changeSkuVals(val, item.name)"
@on-change="skuValueChange(val, index, item)"
>
</AutoComplete>
<Button
@ -1298,24 +1299,55 @@ export default {
this.$Message.error("规格项不能大于5个");
return;
}
if (this.skuInfo.find((i) => i.name === "")) {
this.$Message.error("规格项不能为空!");
return;
}
//
let num = this.global++;
this.$set(this.skuInfo, this.skuInfo.length, {
spec_values: [{ name: "规格名" + num, value: "" }],
name: "规格名" + num,
spec_values: [{ name: "" + num, value: "" }],
name: "",
});
this.renderTableData(this.skuTableData);
},
changeSkuItem(val) {
this.currentSkuItem = val;
},
//
editSkuItem() {
editSkuItem(val, index, item) {
if (this.skuTableData.find((i) => i[val])) {
this.$Message.error("已存在相同规格项!");
return;
}
this.skuTableData = this.skuTableData.map((e) => {
e[val] = e[this.currentSkuItem];
delete e[this.currentSkuItem];
return e;
});
this.currentSkuItem = val;
this.renderTableData(this.skuTableData);
},
//
async skuValueChange(val, index, item) {
skuValueChange(val, index, item) {
console.log("currentSkuVal: " + this.currentSkuVal);
if (this.skuTableData.find((i) => i[val.name] === val.value)) {
this.$Message.error("已存在相同规格值!");
return;
}
this.skuTableData = this.skuTableData.map((e) => {
if (e[val.name] === this.currentSkuVal) {
e[val.name] = val.value;
}
return e;
});
this.currentSkuVal = val.value;
this.renderTableData(this.skuTableData);
},
//
changeSkuVals(name) {
changeSkuVals(val, name) {
this.currentSkuVal = val.value;
if (name) {
this.skuData.forEach((e, index) => {
if (e === name) {
@ -1328,10 +1360,15 @@ export default {
},
/** 移除当前规格项 进行数据变化*/
handleCloseSkuItem($index, item) {
if ($index === 0 && this.skuInfo.length === 1) {
this.skuInfo = [];
this.skuTableData = [];
} else {
this.skuInfo.splice($index, 1);
this.skuTableData.forEach((e, index) => {
delete e[item.name];
});
}
/**
* 渲染规格详细表格
*/
@ -1359,7 +1396,6 @@ export default {
this.$Message.error("规格值不能大于10个");
return;
}
this.$set(item.spec_values, item.spec_values.length, {
name: item.name,
value: "",
@ -1493,6 +1529,11 @@ export default {
});
}
});
// console.log("=====result=====");
// console.log(JSON.parse(JSON.stringify(result)));
// console.log("=====cloneTemp=====");
// console.log(JSON.parse(JSON.stringify(cloneTemp)));
cloneTemp.splice(0, 1);
result = this.specIterator(result, cloneTemp, skus);
this.skuTableData = result;
@ -1510,25 +1551,33 @@ export default {
// console.log(JSON.parse(JSON.stringify(result)));
// console.log("-----cloneTemp-----");
// console.log(JSON.parse(JSON.stringify(cloneTemp)));
let empotyKey1 = "";
//
if (cloneTemp.length > 0) {
let table = [];
//
let findIndex = 0;
result.forEach((resItem, index) => {
empotyKey1 = Object.keys(resItem).find(ke => resItem[ke] === "");
cloneTemp[0].spec_values.forEach((valItem, _index) => {
let obj = cloneObj(resItem);
let containsEmptyValue =
valItem.value === "" || (!!empotyKey1 && obj[empotyKey1] === "");
// let containsEmptyValue = !!Object.values(obj).find(l => l === "");
// console.log(obj);
// console.log("-=-=-=-=-=-=-=-=-=-=-=-");
//
if (
skus.length > result.length &&
valItem.value !== "" &&
!containsEmptyValue &&
skus[findIndex]
) {
obj = cloneObj(skus[findIndex]);
}
let emptyFlag = false;
//
if (cloneTemp[0].spec_values.length > 1 && valItem.value === "") {
if (cloneTemp[0].spec_values.length > 1 && containsEmptyValue) {
delete obj.id;
delete obj.sn;
delete obj.quantity;
@ -1550,7 +1599,7 @@ export default {
skus &&
skus[findIndex] &&
(!skus[findIndex].id || obj.id === skus[findIndex].id) &&
valItem.value !== "" &&
!containsEmptyValue &&
!emptyFlag
) {
//
@ -1563,6 +1612,7 @@ export default {
weight: obj.weight || originSku.weight,
...obj,
};
if (
originSku[valItem.name] === valItem.value ||
(obj.id && originSku.id === obj.id)
@ -1580,25 +1630,24 @@ export default {
if (
skus.length > result.length &&
skus[findIndex] &&
valItem.value !== ""
!containsEmptyValue
) {
findIndex++;
}
obj[cloneTemp[0].name] = valItem.value;
// console.log(resItem);
// console.log(obj);
table.push(obj);
});
});
result = [];
table.forEach((t) => {
result.push(t);
});
result = table;
//
cloneTemp.splice(0, 1);
} else {
return result;
}
return this.specIterator(result, cloneTemp, skus);
return this.specIterator(result, cloneTemp, skus, empotyKey1);
},
/** 根据分类id获取系统设置规格信息*/
Get_SkuInfoByCategory(categoryId) {