优化商品发布规格丢失问题 新增修改删除规格值不丢失

master
lemon橪 2022-05-12 15:36:59 +08:00
parent b197cda548
commit 9ccf51dd5c
1 changed files with 63 additions and 25 deletions

View File

@ -691,7 +691,7 @@ export default {
}, },
params: { params: {
pageNumber: 1, pageNumber: 1,
pageSize:10 pageSize: 10,
}, },
skuInfoRules: {}, skuInfoRules: {},
/** 品牌列表 */ /** 品牌列表 */
@ -700,6 +700,7 @@ export default {
shopCategory: [], shopCategory: [],
/** 商品单位列表 */ /** 商品单位列表 */
goodsUnitList: [], goodsUnitList: [],
initSkuTableData: [],
ignoreColumn: [ ignoreColumn: [
// //
"_index", "_index",
@ -884,7 +885,7 @@ export default {
GET_GoodsUnit() { GET_GoodsUnit() {
API_GOODS.getGoodsUnitList(this.params).then((res) => { API_GOODS.getGoodsUnitList(this.params).then((res) => {
if (res.success) { if (res.success) {
console.log(res) console.log(res);
this.goodsUnitList.push(...res.result.records.map((i) => i.name)); this.goodsUnitList.push(...res.result.records.map((i) => i.name));
this.total = res.result.total; this.total = res.result.total;
} }
@ -957,7 +958,7 @@ export default {
renderGoodsDetailSku(skuList) { renderGoodsDetailSku(skuList) {
let skus = []; let skus = [];
let skusInfo = []; let skusInfo = [];
skuList.map((e) => { skuList.map((e, skuListIndex) => {
let sku = { let sku = {
id: e.id, id: e.id,
sn: e.sn, sn: e.sn,
@ -965,6 +966,7 @@ export default {
cost: e.cost, cost: e.cost,
quantity: e.quantity, quantity: e.quantity,
weight: e.weight, weight: e.weight,
_id: new Date().getTime() + skuListIndex, //
}; };
e.specList.forEach((u) => { e.specList.forEach((u) => {
if (u.specName === "images") { if (u.specName === "images") {
@ -978,8 +980,10 @@ export default {
skusInfo.push({ skusInfo.push({
name: u.specName, name: u.specName,
spec_id: u.specNameId, spec_id: u.specNameId,
_id: new Date().getTime(),
spec_values: [ spec_values: [
{ {
_id: new Date().getTime(),
id: u.specValueId, id: u.specValueId,
name: u.specName, name: u.specName,
value: u.specValue || "", value: u.specValue || "",
@ -994,6 +998,7 @@ export default {
) { ) {
sk.spec_values.push({ sk.spec_values.push({
id: u.specValueId, id: u.specValueId,
_id: new Date().getTime(),
name: u.specName, name: u.specName,
value: u.specValue || "", value: u.specValue || "",
}); });
@ -1059,8 +1064,15 @@ export default {
} }
// //
this.$set(this.skuInfo, this.skuInfo.length, { this.$set(this.skuInfo, this.skuInfo.length, {
spec_values: [], spec_values: [
{
name: "规格项",
value: "规格项值" + this.skuInfo.length,
_id: new Date().getTime() + Math.random(0.1),
},
],
name: "规格名", name: "规格名",
_id: new Date().getTime(),
}); });
this.renderTableData(); this.renderTableData();
}, },
@ -1117,6 +1129,7 @@ export default {
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: "",
_id: new Date().getTime(),
}); });
this.baseInfoForm.regeneratorSkuFlag = true; this.baseInfoForm.regeneratorSkuFlag = true;
/** /**
@ -1142,8 +1155,9 @@ export default {
*/ */
renderTableData() { renderTableData() {
this.skuTableColumn = []; this.skuTableColumn = [];
this.skuTableData = [];
let pushData = []; let pushData = [];
this.initSkuTableData = this.skuTableData;
this.skuTableData = [];
// //
this.skuInfo.forEach((sku) => { this.skuInfo.forEach((sku) => {
// !sku.name ? (sku.name = "") : ""; // !sku.name ? (sku.name = "") : "";
@ -1188,8 +1202,6 @@ export default {
// //
let cloneTemp = cloneObj(this.skuInfo); let cloneTemp = cloneObj(this.skuInfo);
//
this.$set(this, "skuTableData", []);
// //
if (cloneTemp[0]) { if (cloneTemp[0]) {
// //
@ -1199,12 +1211,31 @@ export default {
result.push({ result.push({
[cloneTemp[0].name]: specItem.value, [cloneTemp[0].name]: specItem.value,
images: this.baseInfoForm.goodsGalleryFiles || [], images: this.baseInfoForm.goodsGalleryFiles || [],
_name: cloneTemp[0].name,
...specItem,
}); });
}); });
cloneTemp.splice(0, 1); cloneTemp.splice(0, 1);
result = this.specIterator(result, cloneTemp); result = this.specIterator(result, cloneTemp);
this.skuTableData = result; this.skuTableData = result;
console.log(this.skuTableData); this.skuTableData.forEach((item, index) => {
this.initSkuTableData.forEach((sku) => {
// id
if (sku._id.length && this.scalarArrayEquals(item._id, sku._id)) {
this.skuTableData[index] = {
...item,
...sku,
};
} else if (item.value == sku[item._name] || item._id == sku._id) {
// // id
this.skuTableData[index] = {
...sku,
...item,
};
// }
}
});
});
} }
}, },
/** /**
@ -1217,10 +1248,13 @@ export default {
if (cloneTemp.length > 0) { if (cloneTemp.length > 0) {
let table = []; let table = [];
result.forEach((resItem) => { result.forEach((resItem) => {
cloneTemp[0].spec_values.forEach((valItem) => { cloneTemp[0].spec_values.forEach((valItem,i) => {
let obj = cloneObj(resItem); let obj = cloneObj(resItem);
obj[cloneTemp[0].name] = valItem.value; obj[cloneTemp[0].name] = valItem.value;
obj._name = obj[cloneTemp[0].name];
if (obj._id) {
obj._id = `${obj._id},${obj._id + i}`.split(",");
}
table.push(obj); table.push(obj);
}); });
}); });
@ -1355,6 +1389,10 @@ export default {
delete sku._rowKey; delete sku._rowKey;
delete sku.specNameId; delete sku.specNameId;
delete sku.specValueId; delete sku.specValueId;
delete sku._id;
delete sku.name;
delete sku.value;
delete sku._name
return sku; return sku;
}); });