| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | 
							- 'use strict';
 
- /**
 
-  * 变更方案
 
-  *
 
-  * @author Mai
 
-  * @date
 
-  * @version
 
-  */
 
- const RptMemBase = require('./base');
 
- const bindData = {};
 
- class rptMemChange extends RptMemBase {
 
-     constructor(ctx) {
 
-         super(ctx, bindData);
 
-     }
 
-     async doCheckChangePlan(id) {
 
-         if (this.ctx.change_plan) return;
 
-         this.ctx.change_plan = await this.ctx.service.changePlan.getDataById(id);
 
-     }
 
-     async doCheckTender(tenderId) {
 
-         if (this.ctx.tender) return;
 
-         this.ctx.tender = { id: tenderId };
 
-         this.ctx.tender.data = await this.ctx.service.tender.getTender(tenderId);
 
-         this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
 
-     }
 
-     async doBeforeLoadReport(params) {
 
-         await this.doCheckChangePlan(params.change_plan_id);
 
-         await this.doCheckTender(this.ctx.change_plan.tid);
 
-     }
 
-     async _getChangePlanBills() {
 
-         const helper = this.ctx.helper;
 
-         const decimal = this.ctx.tender.info.decimal;
 
-         const plan = this.ctx.change_plan;
 
-         const bills = await this.ctx.service.changePlanList.getAllDataByCondition({ where: { cpid: this.ctx.change_plan.id} });
 
-         bills.forEach(x => {
 
-             const p_decimal = plan.decimal ? JSON.stringify(plan.decimal) : { tp: decimal.tp, up: decimal.up };
 
-             x.o_tp = helper.mul(x.oamount, x.unit_price, p_decimal.tp);
 
-             x.c_tp = helper.mul(x.camount, x.unit_price, p_decimal.tp);
 
-             x.s_tp = helper.mul(x.samount, x.unit_price, p_decimal.tp);
 
-             x.sp_tp = helper.mul(x.spamount, x.unit_price, p_decimal.tp);
 
-             const auditAmount = x.audit_amount ? x.audit_amount.split(',') : [];
 
-             for (const [i, aa] of auditAmount.entries()) {
 
-                 const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
 
-                 x[amountField] = aa ? parseFloat(aa) : 0;
 
-                 x[tpField] = helper.mul(x[amountField], x.unit_price, p_decimal.tp);
 
-                 if (plan) {
 
-                     plan[tpField] = helper.add(plan[tpField], x[tpField]);
 
-                 }
 
-             }
 
-         });
 
-         bills.sort(function(a, b) {
 
-             return helper.compareCode(a.code, b.code);
 
-         });
 
-         return bills;
 
-     }
 
-     async _getChangePlanAudit() {
 
-         const changeAudit = await this.ctx.service.changePlanAudit.getAllDataByCondition({ where: { cpid: this.ctx.change_plan.id, times: this.ctx.change_plan.times }});
 
-         return this.ctx.helper.filterLastestData(changeAudit, ['aid']);
 
-     }
 
-     getCommonData(params, tableName, fields, customDefine, customSelect) {
 
-         switch (tableName) {
 
-             case 'mem_change_plan':
 
-                 return [this.ctx.change_plan];
 
-             case 'mem_change_plan_bills':
 
-                 return this._getChangePlanBills();
 
-             case 'mem_change_plan_audit':
 
-                 return this._getChangePlanAudit();
 
-             case 'mem_change_plan_att':
 
-                 return this.ctx.service.changePlanAtt.getAllChangePlanAtt(this.ctx.change_plan.tid, this.ctx.change_plan.id);
 
-             case 'mem_project':
 
-                 return this.ctx.service.project.getDataByCondition({ id: this.ctx.session.sessionProject.id });
 
-             case 'mem_tender':
 
-                 return [this.ctx.tender.data];
 
-             case 'mem_tender_info':
 
-                 return [this.ctx.tender.info];
 
-             default:
 
-                 return [];
 
-         }
 
-     }
 
- }
 
- module.exports = rptMemChange;
 
 
  |