Bläddra i källkod

修复新建期值传问题

laiguoran 3 år sedan
förälder
incheckning
456ac4c4b9
2 ändrade filer med 23 tillägg och 3 borttagningar
  1. 22 2
      app/public/js/measure_material.js
  2. 1 1
      app/service/material.js

+ 22 - 2
app/public/js/measure_material.js

@@ -310,13 +310,16 @@ $(function () {
             }
             const insertList = [];
             const insertGclList = [];
+            const hadQtySelfList = [];
             for (const one of insertGcl) {
                 if (one.leafXmjs && one.leafXmjs.length > 0) {
                     for (const xmj of one.leafXmjs) {
                         const is_self = _.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : null }) !== -1;// 区分单独计量的明细工料含量
                         if (is_self) {
                             const billsList = _.filter(materialListForSelf, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : null });
+                            console.log(billsList);
                             for (const bill of billsList) {
+                                hadQtySelfList.push(bill);
                                 insertSelfList.push({
                                     gcl_id: xmj.gcl_id,
                                     mx_id: xmj.mx_id ? xmj.mx_id : null,
@@ -326,7 +329,7 @@ $(function () {
                                     expr: bill.expr,
                                     mb_id: bill.mb_id,
                                     order: bill.order,
-                                })
+                                });
                             }
                         } else {
                             const newgcl = _.find(gclList, { gcl_id: xmj.gcl_id });
@@ -357,12 +360,29 @@ $(function () {
                     }
                 }
             }
+            // 通过比较materialListForSelf和hadQtySelfList不重合部分,得出本期为null的gather_qty列表,插入到insertSelfList中
+            const pushSelfList = _.xorWith(materialListForSelf, hadQtySelfList, _.isEqual);
+            if (pushSelfList.length > 0) {
+                for (const ps of pushSelfList) {
+                    insertSelfList.push({
+                        gcl_id: ps.gcl_id,
+                        mx_id: ps.mx_id,
+                        xmj_id: ps.xmj_id,
+                        gather_qty: null,
+                        quantity: ps.quantity,
+                        expr: ps.expr,
+                        mb_id: ps.mb_id,
+                        order: ps.order,
+                    });
+                }
+            }
             // 可能需要新增list_gcl表
             newMaterialData.material_list = insertList;
             newMaterialData.material_self_list = insertSelfList;
             newMaterialData.insertGclList = insertGclList;
             newMaterialData.removeGclList = removeGclList;
             console.log(newMaterialData);
+            console.log(insertSelfList);
             postData(preUrl + '/measure/material/add', newMaterialData, function (result) {
                 window.location.href = preUrl + '/measure/material/' + result.order;
             }, function () {
@@ -374,7 +394,7 @@ $(function () {
                 // _self.parents('div[id="add-qi"]').modal('show');
                 _self.attr('disabled', false).text('确认添加');
             });
-            // return;
+            return;
         });
         // $(this).parents('form').submit();
     });

+ 1 - 1
app/service/material.js

@@ -198,7 +198,7 @@ module.exports = app => {
                     };
                     await transaction.update(this.tableName, updateMaterialData);
                     // 删除material_list表冗余数据,减少表数据量
-                    await transaction.delete(this.ctx.service.materialList.tableName, { tid: this.ctx.tender.id, gather_qty: null });
+                    await transaction.delete(this.ctx.service.materialList.tableName, { tid: this.ctx.tender.id, gather_qty: null, is_self: 0 });
                 }
 
                 await transaction.commit();