Browse Source

修复取消单独工料时为空无法重置为清单工料对应关系问题

laiguoran 2 years ago
parent
commit
161c93b9e8

+ 1 - 1
app/controller/material_controller.js

@@ -819,7 +819,7 @@ module.exports = app => {
                         responseData.data = await ctx.service.materialListSelf.add(data.select);
                         break;
                     case 'noself':
-                        responseData.data = await ctx.service.materialListSelf.del(data.select.id, data.ms_id);
+                        responseData.data = await ctx.service.materialListSelf.del(data.select.id, data.ms_id, data.select.gather_qty);
                         break;
                     case 'paste':
                         await ctx.service.materialList.saveDatas(data.updateData, data.ms_id);

+ 20 - 0
app/public/js/material_list.js

@@ -851,6 +851,26 @@ $(document).ready(() => {
                 select: type === 'noself' ? findSelfLeafXmj(select) : select,
                 ms_id: $('#myTab').find('.active').data('msid') || null,
             };
+            if (type === 'noself') {
+                if (isStageSelf) {
+                    // 取所有的gclGatherData才行,然后获取下的值
+                    const gclData = gclGatherData[index];
+                    for (const [index, ms] of materialStageData.entries()) {
+                        const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
+                        let gather_qty = null;
+                        if (gclOther) {
+                            const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
+                            const oneXmj = _.find(leafXmjs, function (item) {
+                                return item.gcl_id === select.gcl_id && item.id === select.id && (select.mx_id === undefined || item.mx_id === select.mx_id);
+                            });
+                            if (oneXmj) gather_qty = oneXmj.gather_qty;
+                        }
+                        data.select.gather_qty[ms.id] = gather_qty;
+                    }
+                } else {
+                    data.select.gather_qty = select.gather_qty ? select.gather_qty : null;
+                }
+            }
             // 添加到
             postData(window.location.pathname + '/save', data, function (result) {
                 if (type === 'noself') {

+ 15 - 0
app/service/material_list_notjoin.js

@@ -146,6 +146,21 @@ module.exports = app => {
             // 复制上一期不参与调差的清单
             return notJoinlist.length > 0 ? await transaction.insert(this.tableName, notJoinlist) : true;
         }
+
+        async getJoinMsg(transaction, mid, datas) {
+            const searchData = {
+                tid: this.ctx.tender.id,
+                mid,
+                gcl_id: datas.gcl_id,
+                xmj_id: datas.xmj_id,
+                mx_id: datas.mx_id,
+            };
+            const info = await transaction.get(this.tableName, searchData);
+            if (info) {
+                return 0;
+            }
+            return 1;
+        }
     }
     return MaterialListNotJoin;
 };

+ 41 - 39
app/service/material_list_self.js

@@ -71,13 +71,14 @@ module.exports = app => {
          * @param {int} id 工料id
          * @return {void}
          */
-        async del(id, ms_id = null,) {
+        async del(id, ms_id = null, gather_qty = null) {
             if (!this.ctx.tender || !this.ctx.material) {
                 throw '数据错误';
             }
             const transaction = await this.db.beginTransaction();
             try {
                 const selfInfo = await this.getDataById(id);
+                selfInfo.gather_qty = gather_qty;
                 await this.updateAllMaterials(transaction, selfInfo, ms_id);
                 // 判断是否可删
                 const result = await transaction.delete(this.tableName, { id });
@@ -108,8 +109,8 @@ module.exports = app => {
             const materialListData = await this.ctx.service.materialList.getAllDataByCondition({
                 where: searchSql,
             });
+            const mbIdList = [];
             if (materialListData && materialListData.length > 0) {
-                const mbIdList = [];
                 for (const ml of materialListData) {
                     if (mbIdList.indexOf(ml.mb_id) === -1) {
                         mbIdList.push(ml.mb_id);
@@ -122,38 +123,18 @@ module.exports = app => {
                     xmj_id: data.xmj_id,
                     mx_id: data.mx_id ? data.mx_id : '',
                 });
-                const materialListGclData = await this.ctx.service.materialListGcl.getAllDataByCondition({
-                    where: { tid: this.ctx.tender.id, gcl_id: data.gcl_id },
-                });
-                const insertList = [];
-                if (this.ctx.material.is_stage_self) {
-                    const materialStageList = await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } });
-                    for (const ms of materialStageList) {
-                        const oneML = this._.filter(materialListData, { ms_id: ms.id });
-                        const gather_qty = oneML[0].gather_qty;
-                        const is_join = oneML[0].is_join;
-                        for (const m of materialListGclData) {
-                            insertList.push({
-                                tid: this.ctx.tender.id,
-                                order: m.order,
-                                mid: this.ctx.material.id,
-                                mb_id: m.mb_id,
-                                gcl_id: data.gcl_id,
-                                xmj_id: data.xmj_id,
-                                mx_id: data.mx_id,
-                                ms_id: ms.id,
-                                gather_qty,
-                                quantity: m.quantity,
-                                expr: m.expr,
-                                is_join,
-                                is_self: 0,
-                                in_time: new Date(),
-                            });
-                        }
-                    }
-                } else {
-                    const gather_qty = materialListData[0].gather_qty;
-                    const is_join = materialListData[0].is_join;
+            }
+            const materialListGclData = await this.ctx.service.materialListGcl.getAllDataByCondition({
+                where: { tid: this.ctx.tender.id, gcl_id: data.gcl_id },
+            });
+            const insertList = [];
+            const is_join = await this.ctx.service.materialListNotjoin.getJoinMsg(transaction, this.ctx.material.id, data);
+            if (this.ctx.material.is_stage_self) {
+                const materialStageList = await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } });
+                for (const ms of materialStageList) {
+                    // const oneML = this._.filter(materialListData, { ms_id: ms.id });
+                    // const gather_qty = oneML[0].gather_qty;
+                    // const is_join = oneML[0].is_join;
                     for (const m of materialListGclData) {
                         insertList.push({
                             tid: this.ctx.tender.id,
@@ -163,7 +144,8 @@ module.exports = app => {
                             gcl_id: data.gcl_id,
                             xmj_id: data.xmj_id,
                             mx_id: data.mx_id,
-                            gather_qty,
+                            ms_id: ms.id,
+                            gather_qty: data.gather_qty[ms.id],
                             quantity: m.quantity,
                             expr: m.expr,
                             is_join,
@@ -172,12 +154,32 @@ module.exports = app => {
                         });
                     }
                 }
-                if (insertList.length > 0) await transaction.insert(this.ctx.service.materialList.tableName, insertList);
-                // 重新计算金额
-                for (const mb_id of mbIdList) {
-                    await this.service.materialList.calcQuantityByML(transaction, mb_id, ms_id, 'all');
+            } else {
+                // const gather_qty = materialListData[0].gather_qty;
+                // const is_join = materialListData[0].is_join;
+                for (const m of materialListGclData) {
+                    insertList.push({
+                        tid: this.ctx.tender.id,
+                        order: m.order,
+                        mid: this.ctx.material.id,
+                        mb_id: m.mb_id,
+                        gcl_id: data.gcl_id,
+                        xmj_id: data.xmj_id,
+                        mx_id: data.mx_id,
+                        gather_qty: data.gather_qty,
+                        quantity: m.quantity,
+                        expr: m.expr,
+                        is_join,
+                        is_self: 0,
+                        in_time: new Date(),
+                    });
                 }
             }
+            if (insertList.length > 0) await transaction.insert(this.ctx.service.materialList.tableName, insertList);
+            // 重新计算金额
+            for (const mb_id of mbIdList) {
+                await this.service.materialList.calcQuantityByML(transaction, mb_id, ms_id, 'all');
+            }
         }
 
         /**