diff --git a/src/renderer/src/views/shujuguanli.vue b/src/renderer/src/views/shujuguanli.vue index 7f2de7c..8849ddf 100644 --- a/src/renderer/src/views/shujuguanli.vue +++ b/src/renderer/src/views/shujuguanli.vue @@ -192,124 +192,108 @@ export default { }, dealData2(sheetData) { let groupObj = _.groupBy(this.fileData1, 'g') - if (this.fileData1.length === 0) { ElMessage({ message: `请先导入A表数据`, type: 'error', }) } else { - try { - for (let i = 0; i < sheetData.length; i++) { - let element = sheetData[i]; - let itemList = groupObj[element.Store] || [] - if (itemList.length === 1) { - // a: "STYLE NO." b: "STYLE NO." c: "箱号" d: "箱号" e: "箱号" f: "箱数" g: "商店名称" h: "条码贴" - // i: "颜色" j: "CH" k: "M" l: "G" m: "EG" n: "每箱总件数" o: "总件数" p: "每箱毛重\n(KGS)" q: "每箱净重\n(KGS)" - // r: "总毛重\n(KGS)" s: "总净重\n(KGS)" t: "长" u: "宽" v: "高" w: "立方米CBM" x: "" - // 条贴码 - element["Barcode"] = itemList[0].h - // 箱数 - element["Quantity of containers"] = itemList[0].f - // CH尺码的数量 - if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`)) { - element["Quantity per container"] = itemList[0].j - } - // M尺码的数量 - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, M, AZUL MARINO WKM`)) { - element["Quantity per container"] = itemList[0].k - } - // G尺码的数量 - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, G, AZUL MARINO WKM`)) { - element["Quantity per container"] = itemList[0].l - } - // EG尺码的数量 - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, EG, AZUL MARINO WKM`)) { - element["Quantity per container"] = itemList[0].m - } - } else if (itemList.length > 1) { - // j: "CH" k: "M" l: "G" m: "EG" - // CH - if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`)) { - let allCHData = _.filter(itemList, v => Number(v.j)) - let containerList = _.filter(sheetData, v => v.Store === element.Store && Number(v["Quantity per container"]) && _.startsWith(`${v.Description}`, `VESTIDO DISNEY DTR, CH, AZUL MARINO WKM`)) - let isHas = !!(containerList.length) - if (!isHas) { - element["Barcode"] = allCHData[0].h - // 箱数为所有的箱数之和 - element["Quantity of containers"] = _.sumBy(allCHData, o => Number(o.f)) - // CH尺码的数量 - element["Quantity per container"] = allCHData[0].j - // todo 需要判断是否已经存在 - } - else { - let iteml = allCHData[containerList.length] - element["Barcode"] = iteml.h - // CH尺码的数量 - element["Quantity per container"] = iteml.j - } - } - // M - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, M, AZUL MARINO WKM`)) { - let allCHData = _.filter(itemList, v => Number(v.k)) - let containerList = _.filter(sheetData, v => v.Store === element.Store && Number(v["Quantity per container"]) && _.startsWith(`${v.Description}`, `VESTIDO DISNEY DTR, M, AZUL MARINO WKM`)) - let isHas = !!(containerList.length) - if (!isHas) { - element["Barcode"] = allCHData[0].h - // 箱数为所有的箱数之和 - element["Quantity of containers"] = _.sumBy(allCHData, o => Number(o.f)) - // M尺码的数量 - element["Quantity per container"] = allCHData[0].k - } - else { - let iteml = allCHData[containerList.length] - element["Barcode"] = iteml.h - // M尺码的数量 - element["Quantity per container"] = iteml.k - } - } - // G - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, G, AZUL MARINO WKM`)) { - let allCHData = _.filter(itemList, v => Number(v.l)) - let containerList = _.filter(sheetData, v => v.Store === element.Store && Number(v["Quantity per container"]) && _.startsWith(`${v.Description}`, `VESTIDO DISNEY DTR, G, AZUL MARINO WKM`)) - let isHas = !!(containerList.length) - if (!isHas) { - element["Barcode"] = allCHData[0].h - // 箱数为所有的箱数之和 - element["Quantity of containers"] = _.sumBy(allCHData, o => Number(o.f)) - // G尺码的数量 - element["Quantity per container"] = allCHData[0].l + let itemTemp = [] + let newData = [] + for (let key in groupObj) { + if (key && _.isNumber(Number(key))) { + let itemList = groupObj[key] || [] + for (let j = 0; j < itemList.length; j++) { + let storeItem = itemList[j]; + if (Number(storeItem.j)) { + itemTemp.push({ + g: storeItem.g,//Store + h: storeItem.h,//Barcode + f: Number(storeItem.f),//Quantity of containers + type: "CH",//类型 + j: Number(storeItem.j),//Quantity per container(CH) + k: 0,//Quantity per container(M) + l: 0,//Quantity per container(G) + m: 0//Quantity per container(EG) + }) } - else { - let iteml = allCHData[containerList.length] - element["Barcode"] = iteml.h - // G尺码的数量 - element["Quantity per container"] = iteml.l + if (Number(storeItem.k)) { + itemTemp.push({ + g: storeItem.g,//Store + h: storeItem.h,//Barcode + f: Number(storeItem.f),//Quantity of containers + type: "M",//类型 + j: 0,//Quantity per container(CH) + k: Number(storeItem.k),//Quantity per container(M) + l: 0,//Quantity per container(G) + m: 0//Quantity per container(EG) + }) } - } - // EG - else if (_.startsWith(`${element.Description}`, `VESTIDO DISNEY DTR, EG, AZUL MARINO WKM`)) { - let allCHData = _.filter(itemList, v => Number(v.m)) - let containerList = _.filter(sheetData, v => v.Store === element.Store && Number(v["Quantity per container"]) && _.startsWith(`${v.Description}`, `VESTIDO DISNEY DTR, EG, AZUL MARINO WKM`)) - let isHas = !!(containerList.length) - if (!isHas) { - element["Barcode"] = allCHData[0].h - // 箱数为所有的箱数之和 - element["Quantity of containers"] = _.sumBy(allCHData, o => Number(o.f)) - // EG尺码的数量 - element["Quantity per container"] = allCHData[0].m + if (Number(storeItem.l)) { + itemTemp.push({ + g: storeItem.g,//Store + h: storeItem.h,//Barcode + f: Number(storeItem.f),//Quantity of containers + type: "G",//类型 + j: 0,//Quantity per container(CH) + k: 0,//Quantity per container(M) + l: Number(storeItem.l),//Quantity per container(G) + m: 0//Quantity per container(EG) + }) } - else { - let iteml = allCHData[containerList.length] - element["Barcode"] = iteml.h - // EG尺码的数量 - element["Quantity per container"] = iteml.m + if (Number(storeItem.m)) { + itemTemp.push({ + g: storeItem.g,//Store + h: storeItem.h,//Barcode + f: Number(storeItem.f),//Quantity of containers + type: "EG",//类型 + j: 0,//Quantity per container(CH) + k: 0,//Quantity per container(M) + l: 0,//Quantity per container(G) + m: Number(storeItem.m)//Quantity per container(EG) + }) } } } } - this.fileData2 = sheetData + for (let i = 0; i < itemTemp.length; i++) { + let firstItem = itemTemp[i]; + let hasBarcodeIndex = _.findIndex(sheetData, o => _.startsWith(`${o.Description}`, `VESTIDO DISNEY DTR, ${firstItem.type}, AZUL MARINO WKM`) && o.Store === firstItem.g && _.trim(o.Barcode)) + let noBarcodeIndex = _.findIndex(sheetData, o => _.startsWith(`${o.Description}`, `VESTIDO DISNEY DTR, ${firstItem.type}, AZUL MARINO WKM`) && o.Store === firstItem.g && !_.trim(o.Barcode)) + if (hasBarcodeIndex !== -1) { + let hasBarcode = sheetData[hasBarcodeIndex] + // 修改原来的值 + hasBarcode["Barcode"] = firstItem.h + hasBarcode["Quantity of containers"] += firstItem.f + hasBarcode["Quantity to deliver"] += firstItem.j || firstItem.k || firstItem.l || firstItem.m || 0 + hasBarcode["Quantity per container"] = firstItem.j || firstItem.k || firstItem.l || firstItem.m || 0 + let newItem = _.find(newData, o => _.startsWith(`${o.Description}`, `VESTIDO DISNEY DTR, ${firstItem.type}, AZUL MARINO WKM`) && o.Store === firstItem.g && _.trim(o.Barcode)) + // 修改新添加的值 + newItem["Quantity of containers"] += firstItem.f + newItem["Quantity to deliver"] += firstItem.j || firstItem.k || firstItem.l || firstItem.m || 0 + // 再新增一条数据 + newData.push({ + ...hasBarcode, + "Barcode": firstItem.h, + "Quantity of containers": "", + "Quantity to deliver": "", + "Quantity per container": firstItem.j || firstItem.k || firstItem.l || firstItem.m || 0 + }) + } + if (noBarcodeIndex !== -1) { + let noBarcode = sheetData[noBarcodeIndex] + // 修改原有的值 + noBarcode["Barcode"] = firstItem.h + noBarcode["Quantity of containers"] = firstItem.f + noBarcode["Quantity to deliver"] = firstItem.j || firstItem.k || firstItem.l || firstItem.m || 0 + noBarcode["Quantity per container"] = firstItem.j || firstItem.k || firstItem.l || firstItem.m || 0 + newData.push({ + ...noBarcode, + }) + } + } + this.fileData2 = _.cloneDeep(newData) } catch (error) { ElMessage({ message: `表格处理出错:, ${error}`, @@ -351,7 +335,7 @@ export default { let lilstLocal = [] for (let i = 0; i < listCopy.length; i++) { let item = listCopy[i]; - lilstLocal.push({ ...item, 'Quantity to deliver': item["Quantity to deliver"].toFixed(3) }) + lilstLocal.push({ ...item, 'Quantity to deliver': item["Quantity to deliver"] ? item["Quantity to deliver"].toFixed(3) : "" }) } let jsonWorkSheet = XLSX.utils.json_to_sheet(lilstLocal); for (let index = 0; index < newHeaders.length; index++) {