学习很差啦 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, // addSettlementBtn: true, //
day: 1, // day: 1, //
tabName: "base", // tabname tabName: "base", // tabname
tabNameList: ["base", "entry", "category", "send", "settlement"], // tabname tabNameList: ["base", "entry", "category", "settlement"], // tabname
shopValidate: { shopValidate: {
// //
memberName: [{ required: true, message: "会员不能为空" }], memberName: [{ required: true, message: "会员不能为空" }],

View File

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