Преглед изворни кода

Merge branch 'dev' of maixinrong/Calculation into uat

maixinrong пре 3 година
родитељ
комит
68efea06e4

+ 1 - 1
app/public/js/material.js

@@ -106,7 +106,7 @@ $(document).ready(() => {
     const materialSpreadSetting = {
         emptyRows: 0,
         headRows: 2,
-        headRowHeight: [25, 25],
+        headRowHeight: [25, 32],
         defaultRowHeight: 21,
         headerFont: '12px 微软雅黑',
         font: '12px 微软雅黑',

+ 10 - 5
app/public/js/material_checklist.js

@@ -140,7 +140,7 @@ $(document).ready(() => {
         gclGatherData = gclGatherModel.gatherGclData();
         console.log(gclGatherData);
         const hadBillsidList = _.uniq(_.map(gclList, 'gcl_id'));
-        console.log(hadBillsidList);
+        console.log(hadBillsidList, materialChecklistData);
         // 对比清单设置和调差清单,还要和台账对比,显示已选清单列表 不同则更新到清单设置页中
         const pushData = [];
         const updateData = [];
@@ -160,20 +160,24 @@ $(document).ready(() => {
         const removeData = [];
         for (const mc of materialChecklistData) {
             const gcl = _.find(gclGatherData, { b_code: mc.b_code, name: mc.name, unit: mc.unit, unit_price: mc.unit_price });
+            console.log(gcl);
             // 判断是否已不存在工料清单,台账修改过后删除之
             if (!gcl) {
                 removeData.push(mc.id);
             } else {
+                const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
+                const jiaoji = _.intersection(gcl_ids, hadBillsidList);
+                // const leafXmjs = gcl.leafXmjs ? gcl.leafXmjs.filter(item => item.gather_qty) : [];
                 // 更新had_bills值
                 const updateObj = { id: mc.id };
                 if (mc.had_bills === 1) {
-                    if (_.indexOf(hadBillsidList, gcl.leafXmjs ? gcl.leafXmjs[0].gcl_id : null) === -1) {
+                    if (jiaoji.length === 0) {
                         updateObj.mid = materialID;
                         updateObj.had_bills = 0;
                         // updateData.push({ id: mc.id, mid: materialID, had_bills: 0 });
                     }
                 } else if (mc.had_bills === 0) {
-                    if (_.indexOf(hadBillsidList, gcl.leafXmjs ? gcl.leafXmjs[0].gcl_id: null) !== -1) {
+                    if (jiaoji.length !== 0) {
                         updateObj.had_bills = 1;
                     }
                 }
@@ -259,10 +263,11 @@ $(document).ready(() => {
         //     return item.qc_qty || item.contract_qty
         // }) : null;
         if (gcl && gcl.leafXmjs) {
-            const xmj2 = gcl.leafXmjs[iLXmjRow];
+            const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
+            // const xmj2 = gcl.leafXmjs[iLXmjRow];
             materialList = [];
             const newMaterialList = _.uniqBy(_.filter(gclList, function (m) {
-                return xmj2 && m.gcl_id === xmj2.gcl_id;
+                return _.indexOf(gcl_ids, m.gcl_id) !== -1;
             }), 'mb_id');
             for(const m of newMaterialList) {
                 const bills = _.find(materialBillsData, { id: m.mb_id });

+ 7 - 1
app/public/js/material_list.js

@@ -245,12 +245,18 @@ $(document).ready(() => {
                 } else {
                     // 更新had_bills值
                     const updateObj = { id: mc.id };
+                    const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
+                    const jiaoji = _.intersection(gcl_ids, hadBillsidList);
                     if (mc.had_bills === 1) {
-                        if (_.indexOf(hadBillsidList, gcl.leafXmjs ? gcl.leafXmjs[0].gcl_id : null) === -1) {
+                        if (jiaoji.length === 0) {
                             updateObj.mid = materialID;
                             updateObj.had_bills = 0;
                             // updateData.push({ id: mc.id, mid: materialID, had_bills: 0 });
                         }
+                    } else if (mc.had_bills === 0) {
+                        if (jiaoji.length !== 0) {
+                            updateObj.had_bills = 1;
+                        }
                     }
                     // 更新工程量及台账金额
                     if (mc.quantity !== (gcl.quantity ? gcl.quantity : null)) {

+ 21 - 19
app/service/material_list.js

@@ -300,26 +300,28 @@ module.exports = app => {
          * @return {Promise<void>}
          */
         async copyPreMaterialList2(transaction, materialListData, notJoinList, newMaterial) {
-            const copyMLArray = [];
-            for (const ml of materialListData) {
-                const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id });
-                const newMaterialList = {
-                    tid: newMaterial.tid,
-                    order: ml.order,
-                    mid: newMaterial.id,
-                    mb_id: ml.mb_id,
-                    gcl_id: ml.gcl_id,
-                    xmj_id: ml.xmj_id,
-                    mx_id: ml.mx_id,
-                    gather_qty: ml.gather_qty,
-                    quantity: ml.quantity ? ml.quantity : 0,
-                    expr: ml.expr ? ml.expr : '',
-                    is_join: is_join ? 0 : 1,
-                    in_time: new Date(),
-                };
-                copyMLArray.push(newMaterialList);
+            if (materialListData && materialListData.length > 0) {
+                const copyMLArray = [];
+                for (const ml of materialListData) {
+                    const is_join = this._.find(notJoinList, { gcl_id: ml.gcl_id, xmj_id: ml.xmj_id, mx_id: ml.mx_id });
+                    const newMaterialList = {
+                        tid: newMaterial.tid,
+                        order: ml.order,
+                        mid: newMaterial.id,
+                        mb_id: ml.mb_id,
+                        gcl_id: ml.gcl_id,
+                        xmj_id: ml.xmj_id,
+                        mx_id: ml.mx_id,
+                        gather_qty: ml.gather_qty,
+                        quantity: ml.quantity ? ml.quantity : 0,
+                        expr: ml.expr ? ml.expr : '',
+                        is_join: is_join ? 0 : 1,
+                        in_time: new Date(),
+                    };
+                    copyMLArray.push(newMaterialList);
+                }
+                return copyMLArray.length !== 0 ? await transaction.insert(this.tableName, copyMLArray) : true;
             }
-            return copyMLArray.length !== 0 ? await transaction.insert(this.tableName, copyMLArray) : true;
         }
 
 

+ 2 - 2
app/service/material_list_gcl.js

@@ -49,14 +49,14 @@ module.exports = app => {
         }
 
         async insertOrDelGcl(transaction, insertGclList, removeGclList, mid) {
-            if (insertGclList.length > 0) {
+            if (insertGclList && insertGclList.length > 0) {
                 for (const gcl of insertGclList) {
                     gcl.tid = this.ctx.tender.id;
                     gcl.mid = mid;
                 }
                 await transaction.insert(this.tableName, insertGclList);
             }
-            if (removeGclList.length > 0) {
+            if (removeGclList && removeGclList.length > 0) {
                 for (const gcl of removeGclList) {
                     await transaction.delete(this.tableName, { id: gcl.id });
                 }