Explorar o código

更新json字段名及新增规格

laiguoran %!s(int64=2) %!d(string=hai) anos
pai
achega
9a0c0e2374
Modificáronse 1 ficheiros con 25 adicións e 18 borrados
  1. 25 18
      app/public/js/material_checklist.js

+ 25 - 18
app/public/js/material_checklist.js

@@ -1110,18 +1110,18 @@ $(document).ready(() => {
                 if (/(xls|xlsx|XLS|XLSX)$/.test(ext)) {
                     const workbook = XLSX.read(data, {type: 'binary'}); // 以二进制流方式读取得到整份excel表格对象
                     const jsonData = transExcel(XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { defval: null }));
-                    if (!(jsonData[0] && jsonData[0].code !== undefined && jsonData[0].code !== null &&
-                        jsonData[0].b_code !== undefined && jsonData[0].name !== undefined &&
+                    if (!(jsonData[0] && jsonData[0].b_code !== undefined && jsonData[0].b_code !== null &&
+                        jsonData[0].GLJcode !== undefined && jsonData[0].name !== undefined && jsonData[0].name !== undefined &&
                         jsonData[0].unit !== undefined && jsonData[0].unit_price !== undefined)) {
                         throw 'excel必须按指定格式内容上传';
                     }
                     tree = _.filter(jsonData, function (item) {
-                        return item.code !== null;
+                        return item.b_code !== null;
                     });
                     for (const [i,t] of tree.entries()) {
-                        const jIndex1 = _.findIndex(jsonData, { code: t.code, name: t.name, unit: t.unit, unit_price: t.unit_price });
+                        const jIndex1 = _.findIndex(jsonData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price });
                         if (i + 1 < tree.length) {
-                            const jIndex2 = _.findIndex(jsonData, { code: tree[i+1].code, name: tree[i+1].name, unit: tree[i+1].unit, unit_price: tree[i+1].unit_price });
+                            const jIndex2 = _.findIndex(jsonData, { b_code: tree[i+1].b_code, name: tree[i+1].name, unit: tree[i+1].unit, unit_price: tree[i+1].unit_price });
                             t.children = jsonData.slice(jIndex1 + 1, jIndex2);
                         } else {
                             t.children = jsonData.slice(jIndex1 + 1);
@@ -1131,6 +1131,11 @@ $(document).ready(() => {
                     const ascii = jschardet.detect(data.substring(0, 10000));
                     iconv.skipDecodeWarning = true
                     tree = JSON.parse(iconv.decode(data, ascii.encoding));// 需要转码,否则前端处理中文会出现乱码
+                    if (!(tree[0] && tree[0].b_code !== undefined && tree[0].b_code !== null &&
+                        tree[0].GLJcode !== undefined && tree[0].name !== undefined && tree[0].name !== undefined &&
+                        tree[0].unit !== undefined && tree[0].unit_price !== undefined)) {
+                        throw 'json必须按指定格式内容上传';
+                    }
                 }
                 stopProgress($('#export-progress'));
                 $('#bill-detail').show();
@@ -1142,9 +1147,9 @@ $(document).ready(() => {
                 const needPushTree = [];
                 // 分析materialCheckList和tree,找出相同的清单并插入对应不存在的工料
                 for (const t of tree) {
-                    const order = _.findIndex(gclGatherData, { b_code: t.code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
-                    const mlOrder = _.findIndex(materialChecklistData, { b_code: t.code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
-                    if (mlOrder === -1 && order !== -1 && _.findIndex(pushChecklist, { b_code: t.code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null}) === -1) {
+                    const order = _.findIndex(gclGatherData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
+                    const mlOrder = _.findIndex(materialChecklistData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
+                    if (mlOrder === -1 && order !== -1 && _.findIndex(pushChecklist, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null}) === -1) {
                         pushChecklist.push({
                             b_code: gclGatherData[order].b_code,
                             name: gclGatherData[order].name,
@@ -1159,12 +1164,13 @@ $(document).ready(() => {
                     }
                     needPushTree.push(t);
                     for (const c of t.children) {
-                        const mbOrder = _.findIndex(materialBillsData, { code: c.b_code, name: c.name, unit: c.unit });
-                        if (c.b_code !== null && mbOrder === -1 && _.findIndex(pushBillsData, { code: c.b_code, name: c.name, unit: c.unit }) === -1) {
+                        const mbOrder = _.findIndex(materialBillsData, { code: c.GLJcode, name: c.name, unit: c.unit });
+                        if (c.b_code !== null && mbOrder === -1 && _.findIndex(pushBillsData, { code: c.GLJcode, name: c.name, unit: c.unit }) === -1) {
                             pushBillsData.push({
-                                code: c.b_code,
+                                code: c.GLJcode,
                                 name: c.name,
-                                unit: c.unit
+                                unit: c.unit,
+                                spec: c.specs,
                             })
                         }
                     }
@@ -1272,7 +1278,7 @@ $(document).ready(() => {
         console.log(tree);
         if (tree.length > 0) {
             for (const [i,t] of tree.entries()) {
-                $('#list-detail').find('b').text(t.code);
+                $('#list-detail').find('b').text(t.b_code);
                 resetProgress($('#list-progress'));
                 if (!interval) {
                     $('#list-detail').show();
@@ -1280,7 +1286,7 @@ $(document).ready(() => {
                 }
                 const mbList = [];
                 for (const mb of t.children) {
-                    const mbInfo = _.find(materialBillsData, { code: mb.b_code, name: mb.name, unit: mb.unit });
+                    const mbInfo = _.find(materialBillsData, { code: mb.GLJcode, name: mb.name, unit: mb.unit });
                     if (mbInfo) {
                         const num = parseFloat(mb.quantity);
                         if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
@@ -1291,7 +1297,7 @@ $(document).ready(() => {
                     }
                 }
 
-                const gclIndex = _.findIndex(gclGatherData, { b_code: t.code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
+                const gclIndex = _.findIndex(gclGatherData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
                 const gcl = gclGatherData[gclIndex].leafXmjs;
                 const ms_id = isStageSelf ? materialStageData[0].id : null;
                 // const index = materialChecklistData.indexOf(select);
@@ -1334,7 +1340,7 @@ $(document).ready(() => {
                 }
 
                 // 上传到数据库
-                const select = _.find(materialChecklistData, { b_code: t.code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
+                const select = _.find(materialChecklistData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
                 console.log(select, datas, mbList);
                 if (select) {
                     await postData(window.location.pathname + '/save', {type: 'adds', checklist: { id: select.id, had_bills: 1 }, postData: {xmjs: datas, mbIds: mbList, export: true}}, function (result) {
@@ -1362,10 +1368,11 @@ $(document).ready(() => {
 
     function transExcel(results) {
         const mapInfo = {
-            '清单编号': 'code',
-            '工料编号': 'b_code',
+            '清单编号': 'b_code',
+            '工料编号': 'GLJcode',
             '名称': 'name',
             '单位': 'unit',
+            '规格': 'specs',
             '单价': 'unit_price',
             '单位耗量': 'quantity',
         };