浏览代码

计划方式更改重算计划月数据

laiguoran 4 年之前
父节点
当前提交
9325065182
共有 3 个文件被更改,包括 71 次插入4 次删除
  1. 0 1
      app/controller/schedule_controller.js
  2. 42 2
      app/public/js/schedule_plan.js
  3. 29 1
      app/service/schedule.js

+ 0 - 1
app/controller/schedule_controller.js

@@ -63,7 +63,6 @@ module.exports = app => {
                     hadDataLidList.push(info.lid);
                 }
             }
-            console.log(hadDataLidList);
             const renderData = {
                 tender: tender.data,
                 tenderInfo: tender.info,

+ 42 - 2
app/public/js/schedule_plan.js

@@ -351,13 +351,53 @@ $(function () {
     // 进度计算方式选择
     $('.mode-select').on('click', function () {
         const _self = $(this);
-        postData(window.location.pathname + '/save', {type: 'mode', postData: $(this).data('mode')}, function (result) {
+        const this_mode = _self.data('mode');
+        // 重新计算所有月份数据
+        const under_ledger = _.filter(ledgerTree.nodes, { is_leaf: true});
+        const update_nodes = [];
+        for (const ul of under_ledger) {
+            for (const m of monthList) {
+                if (ul[m+'_tp'] || ul[m+'_gcl']) {
+                    update_nodes.push(ul);
+                    break;
+                }
+            }
+        }
+        const update_under_ledger = [];
+        if(update_nodes.length > 0) {
+            for (const un of update_nodes) {
+                if (this_mode === mode.gcl) {
+                    for (const m of monthList) {
+                        if(un[m+'_tp']) {
+                            un[m+'_tp'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(un[m+'_gcl'], un.dgn_price), 0) : 0;
+                            update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
+                        }
+                    }
+                } else {
+                    for (const m of monthList) {
+                        if(un[m+'_gcl']) {
+                            un[m+'_gcl'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(un[m+'_tp'], un.dgn_price), 3) : 0;
+                            update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
+                        }
+                    }
+                }
+            }
+        }
+        console.log(update_under_ledger);
+        postData(window.location.pathname + '/save', {type: 'mode', postData: {mode: this_mode, update_under_ledger}}, function (result) {
             _self.addClass('disabled').attr('disabled', true);
             _self.parents('.col-6').siblings('.col-6').find('button').removeClass('disabled').removeAttr('disabled');
             $('#mode-tips').show();
             $('#mode-cancel').show();
             $('#mode').modal('hide');
-            schedule.mode = _self.data('mode');
+            schedule.mode = this_mode;
+            if (update_nodes.length > 0) {
+                for (const uul of update_nodes) {
+                    const nodes = treeCalc.calculateParent(ledgerSpread.getActiveSheet().zh_tree, uul);
+                    const refreshNode = ledgerTree.loadPostData({update: nodes});
+                    ledgerSpreadObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
+                }
+            }
             SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());
         })
     });

+ 29 - 1
app/service/schedule.js

@@ -16,9 +16,37 @@ module.exports = app => {
                     },
                 };
                 const updateData = {
-                    mode: data,
+                    mode: data.mode,
                 };
                 await transaction.update(this.tableName, updateData, options);
+                if (data.update_under_ledger.length > 0) {
+                    const month_list = [];
+                    const update_options = [];
+                    for (const un of data.update_under_ledger) {
+                        const option = {
+                            row: {
+                                plan_tp: un.plan_tp,
+                                plan_gcl: un.plan_gcl,
+                            },
+                            where: {
+                                tid: this.ctx.tender.id,
+                                lid: un.lid,
+                                yearmonth: un.yearmonth,
+                            },
+                        };
+                        update_options.push(option);
+                        if (!this._.find(month_list, un.yearmonth)) {
+                            month_list.push(un.yearmonth);
+                        }
+                    }
+                    if (update_options.length > 0) {
+                        await transaction.updateRows(this.ctx.service.scheduleLedgerMonth.tableName, update_options);
+                        for (const m of month_list) {
+                            await this.ctx.service.scheduleLedgerMonth.calcMonthPlan(transaction, this.ctx.tender.id, m);
+                        }
+                        await this.ctx.service.scheduleMonth.calcPlan(transaction, this.ctx.tender.id);
+                    }
+                }
                 await transaction.commit();
                 return true;
             } catch (err) {