laiguoran před 4 roky
rodič
revize
83a3cd9e4c

+ 19 - 0
app/controller/schedule_controller.js

@@ -43,9 +43,25 @@ module.exports = app => {
             try {
                 const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
                 const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
+                const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
+                // 汇总并统计前几个计划月总计划额
+                for (const i in scheduleStage) {
+                    let nowIndex = 0;
+                    let lastIndex = 0;
+                    if (i > 0) {
+                        nowIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i].yearmonth }) + 1;
+                        lastIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i - 1].yearmonth }) + 1;
+                    } else {
+                        nowIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i].yearmonth }) + 1;
+                    }
+                    // 获取新计划月数组
+                    const newSm = scheduleMonth.slice(lastIndex, nowIndex);
+                    scheduleStage[i].plan_tp = _.sumBy(newSm, 'plan_tp');
+                }
                 const renderData = {
                     schedule,
                     scheduleMonth,
+                    scheduleStage,
                     tender: ctx.tender.data,
                     tenderMenu: this.menu.tenderMenu,
                     planMonth: await this._getLastPlanMonth(ctx),
@@ -358,6 +374,9 @@ module.exports = app => {
                     case 'reload_stage':
                         responseData.data = await ctx.service.scheduleStage.changeOrder(data.postData);
                         break;
+                    case 'update_tp':
+                        responseData.data = await ctx.service.scheduleStage.updateOneTp(data.postData);
+                        break;
                     default: throw '参数有误';
                 }
                 ctx.body = responseData;

+ 3 - 2
app/public/js/schedule_stage_tp.js

@@ -219,9 +219,10 @@ function calcGatherTpAndUpdate(tree) {
         console.log(curScheduleStage.tp, total_tp);
         if (curScheduleStage.tp !== total_tp) {
             // 更新计量总金额并更新金额模式总金额
-
+            postData('/tender/' + getTenderId() + '/schedule/stage/save', { type: 'update_tp', postData: { tp: total_tp, order: curScheduleStage.order } }, function (data) {
+                console.log('总金额已更新');
+            })
         }
-
     }
 
 }

+ 38 - 0
app/service/schedule_stage.js

@@ -80,6 +80,44 @@ module.exports = app => {
                 throw err;
             }
         }
+
+        async updateOneTp(data) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const updateData = {
+                    tp: data.tp,
+                };
+                const option = {
+                    where: {
+                        tid: this.ctx.tender.id,
+                        order: data.order,
+                    },
+                };
+                await transaction.update(this.tableName, updateData, option);
+                // 重算计量总金额
+                await this.calcStageSjTp(transaction, this.ctx.tender.id);
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
+        async calcStageSjTp(transaction, tid) {
+            const sql = 'SELECT SUM(`tp`) as stage_sj_tp FROM ?? WHERE tid = ?';
+            const sqlParam = [this.tableName, tid];
+            const result = await transaction.queryOne(sql, sqlParam);
+            const updateData = {
+                stage_sj_tp: result.stage_sj_tp,
+            };
+            const option = {
+                where: {
+                    tid,
+                },
+            };
+            return await transaction.update(this.ctx.service.schedule.tableName, updateData, option);
+        }
     }
     return ScheduleStage;
 };

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 171 - 42
app/view/schedule/index.ejs