Browse Source

修复变更位数调整问题

laiguoran 3 năm trước cách đây
mục cha
commit
219eb5d9d5

+ 16 - 6
app/controller/change_controller.js

@@ -2999,9 +2999,9 @@ module.exports = app => {
                             throw '修改失败';
                         }
                         break;
-                    case 'update_tp':
-                        await ctx.service.changeApply.saveInfo(ctx.change.id, { name: 'total_price', val: data.updateData });
-                        break;
+                    // case 'update_tp':
+                    //     await ctx.service.changeApply.saveInfo(ctx.change.id, { name: 'total_price', val: data.updateData });
+                    //     break;
                     default: throw '参数有误';
                 }
 
@@ -3585,6 +3585,16 @@ module.exports = app => {
                         await ctx.service.changePlanList.saveDatas(data.updateData);
                         // 取所有工料表
                         responseData.data = await ctx.service.changePlanList.getList(ctx.change.id);
+                        if (ctx.change.status === audit.changeApply.status.checking || ctx.change.status === audit.changeApply.status.checked) {
+                            const listAudits = await ctx.service.changePlanAudit.getAuditGroupByList(ctx.change.id, ctx.change.times);
+                            for (const cl of responseData.data) {
+                                const audit_amount = cl.audit_amount !== null && cl.audit_amount !== '' ? cl.audit_amount.split(',') : '';
+                                // 清单表页赋值
+                                for (const [index, au] of listAudits.entries()) {
+                                    cl['audit_amount_' + au.aid] = ctx.change.shenpiPower && au.aid === ctx.session.sessionUser.accountId ? cl.spamount : (audit_amount[index] ? parseFloat(audit_amount[index]) : null);
+                                }
+                            }
+                        }
                         break;
                     case 'list_rule':
                         const result = await ctx.service.tender.saveTenderData(ctx.tender.id, { c_plan_list_rule: data.postData });
@@ -3607,9 +3617,9 @@ module.exports = app => {
                         // 取所有工料表
                         responseData.data = changeList;
                         break;
-                    case 'update_tp':
-                        await ctx.service.changePlan.saveInfo(ctx.change.id, { name: 'total_price', val: data.updateData });
-                        break;
+                    // case 'update_tp':
+                    //     await ctx.service.changePlan.saveInfo(ctx.change.id, { name: 'total_price', val: data.updateData });
+                    //     break;
                     default: throw '参数有误';
                 }
 

+ 4 - 1
app/middleware/tender_check.js

@@ -69,6 +69,8 @@ module.exports = options => {
             const changeProjectXsAuditorsId = this.helper._.map(changeProjectXsAuditors, 'aid');
             const changeApplyAuditors = this.session.sessionProject.page_show.openChangeApply ? yield this.service.changeApplyAudit.getAllAuditors(tender.id) : [];
             const changeApplyAuditorsId = this.helper._.map(changeApplyAuditors, 'aid');
+            const changePlanAuditors = this.session.sessionProject.page_show.openChangePlan ? yield this.service.changePlanAudit.getAllAuditors(tender.id) : [];
+            const changePlanAuditorsId = this.helper._.map(changePlanAuditors, 'aid');
             const tenderPermission = this.session.sessionUser.permission ? this.session.sessionUser.permission.tender : null;
             const isTenderTourist = yield this.service.tenderTourist.getDataByCondition({ tid: tender.id, user_id: accountId });
             // 判断访问人是否具有游客身份
@@ -79,7 +81,8 @@ module.exports = options => {
                 (tenderPermission === null || tenderPermission === undefined || tenderPermission.indexOf('2') === -1) &&
                 stageAuditorsId.indexOf(accountId) === -1 && changeAuditorsId.indexOf(accountId) === -1 &&
                 reviseAuditorsId.indexOf(accountId) === -1 && materialAuditorsId.indexOf(accountId) === -1 &&
-                changeProjectAuditorsId.indexOf(accountId) === -1 && changeProjectXsAuditorsId.indexOf(accountId) === -1 && changeApplyAuditorsId.indexOf(accountId) === -1 &&
+                changeProjectAuditorsId.indexOf(accountId) === -1 && changeProjectXsAuditorsId.indexOf(accountId) === -1 &&
+                changeApplyAuditorsId.indexOf(accountId) === -1 && changePlanAuditorsId.indexOf(accountId) === -1 &&
                 advanceAuditorsId.indexOf(accountId) === -1 && !this.session.sessionUser.is_admin && !isTenderTourist) {
                 throw '您无权查看该项目';
             }

+ 24 - 4
app/public/js/change_apply_information.js

@@ -644,13 +644,33 @@ $(document).ready(() => {
 
         // 计算最新的变更总额和change的total_price是否一致,不一致则更新
         if (change.status !== auditConst.status.checked) {
-            let new_tp = 0;
+            // let new_tp = 0;
+            const updateArray = [];
             for (const c of changeList) {
-                new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.camount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
+                const oneUpdate = {};
+                console.log(ZhCalc.round(c.camount, findDecimal(c.unit)), c.camount);
+                if (ZhCalc.round(c.oamount, findDecimal(c.unit)) !== c.oamount) oneUpdate.oamount = ZhCalc.round(c.oamount, findDecimal(c.unit));
+                if (ZhCalc.round(c.camount, findDecimal(c.unit)) !== c.camount) oneUpdate.camount = ZhCalc.round(c.camount, findDecimal(c.unit));
+                if (ZhCalc.round(c.unit_price, unitPriceUnit) !== c.unit_price) oneUpdate.unit_price = ZhCalc.round(c.unit_price, unitPriceUnit);
+                if (!_.isEmpty(oneUpdate)) {
+                    oneUpdate.id = c.id;
+                    updateArray.push(oneUpdate);
+                }
+                // new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
             }
-            if (change.total_price && change.total_price !== new_tp) {
-                postData(preUrl + '/list/save', { type:'update_tp', updateData: new_tp }, function (result) {});
+            console.log(updateArray);
+            if (updateArray.length > 0) {
+                // 更新至服务器
+                postData(preUrl + '/list/save', { type:'paste', updateData: updateArray }, function (result) {
+                    changeList = result;
+                    SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
+                    changeSpreadObj.makeSjsFooter();
+                });
             }
+            // if (change.total_price && change.total_price !== new_tp) {
+            //     postData(preUrl + '/list/save', {type: 'update_tp', updateData: new_tp}, function (result) {
+            //     });
+            // }
         }
     });
 });

+ 39 - 20
app/public/js/change_plan_information.js

@@ -268,6 +268,7 @@ $(document).ready(() => {
         setAuditValue: function () {
             for (const c of changeList) {
                 for (const audit of change.listAudits) {
+                    c['audit_amount_' + audit.aid] = ZhCalc.round(c['audit_amount_' + audit.aid], findDecimal(c.unit));
                     c['sa_tp_' + audit.aid] = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c['audit_amount_' + audit.aid], findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
                 }
             }
@@ -816,40 +817,58 @@ $(document).ready(() => {
         });
         // 数组去重
         dealBillList = result.dealBills;
-        // for (const db of gclGatherData) {
-        //     const exist_index = dealBillList.findIndex(function (item) {
-        //         return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
-        //     });
-        //     if (exist_index !== -1) {
-        //         dealBillList.splice(exist_index, 1);
-        //     }
-        // }
-        // changeListData = gclGatherData.concat(dealBillList);
         changeListData = gclGatherData;
         console.log(changeListData, dealBillList);
-
         SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
         SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
         if (change.status === auditConst.status.checking || change.status === auditConst.status.checked) changeSpreadObj.setAuditValue();
         SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
         changeSpreadObj.makeSjsFooter();
-        if (change.status === auditConst.status.checked) {
-            changeSpreadObj.showHideAudit(false);
-        } else {
-            changeSpreadObj.showHideAudit(true);
-        }
-
         // 计算最新的变更总额和change的total_price是否一致,不一致则更新
         if (change.status !== auditConst.status.checked) {
-            let new_tp = 0;
+            // let new_tp = 0;
+            const updateArray = [];
             for (const c of changeList) {
-                new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
+                const oneUpdate = {};
+                if (ZhCalc.round(c.spamount, findDecimal(c.unit)) !== c.spamount) oneUpdate.spamount = ZhCalc.round(c.spamount, findDecimal(c.unit));
+                if (ZhCalc.round(c.oamount, findDecimal(c.unit)) !== c.oamount) oneUpdate.oamount = ZhCalc.round(c.oamount, findDecimal(c.unit));
+                if (ZhCalc.round(c.camount, findDecimal(c.unit)) !== c.camount) oneUpdate.camount = ZhCalc.round(c.camount, findDecimal(c.unit));
+                if (ZhCalc.round(c.unit_price, unitPriceUnit) !== c.unit_price) oneUpdate.unit_price = ZhCalc.round(c.unit_price, unitPriceUnit);
+                const audit_amount = c.audit_amount ? c.audit_amount.split(',') : null;
+                if (audit_amount) {
+                    for (const i in audit_amount) {
+                        if (ZhCalc.round(parseFloat(audit_amount[i]), findDecimal(c.unit)) !== parseFloat(audit_amount[i])) audit_amount[i] = ZhCalc.round(parseFloat(audit_amount[i]), findDecimal(c.unit));
+                    }
+                    if (c.audit_amount !== audit_amount.join(',')) oneUpdate.audit_amount = audit_amount.join(',');
+                }
+                if (!_.isEmpty(oneUpdate)) {
+                    oneUpdate.id = c.id;
+                    updateArray.push(oneUpdate);
+                }
+                // new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
             }
-            if (change.total_price && change.total_price !== new_tp) {
-                postData(preUrl + '/list/save', {type: 'update_tp', updateData: new_tp}, function (result) {
+            console.log(updateArray);
+            if (updateArray.length > 0) {
+                // 更新至服务器
+                postData(preUrl + '/list/save', { type:'paste', updateData: updateArray }, function (result) {
+                    changeList = result;
+                    if (change.status === auditConst.status.checking) changeSpreadObj.setAuditValue();
+                    SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
+                    changeSpreadObj.makeSjsFooter();
                 });
             }
+            // if (change.total_price && change.total_price !== new_tp) {
+            //     postData(preUrl + '/list/save', {type: 'update_tp', updateData: new_tp}, function (result) {
+            //     });
+            // }
+            if (change.status === auditConst.status.checked) {
+                changeSpreadObj.showHideAudit(false);
+            } else {
+                changeSpreadObj.showHideAudit(true);
+            }
         }
+
+
     });
 
     // 审批流程展示与隐藏