|  | @@ -37,31 +37,33 @@ module.exports = app => {
 | 
	
		
			
				|  |  |           * 添加月信息价 并更新 工料平均单价、本期单价,调差金额等
 | 
	
		
			
				|  |  |           * @return {void}
 | 
	
		
			
				|  |  |           */
 | 
	
		
			
				|  |  | -        async add(data, monthList, mbList) {
 | 
	
		
			
				|  |  | +        async adds(data, monthList, mbList) {
 | 
	
		
			
				|  |  |              if (!this.ctx.tender || !this.ctx.material) {
 | 
	
		
			
				|  |  |                  throw '数据错误';
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              const transaction = await this.db.beginTransaction();
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  |                  const material_month = this.ctx.material.months ? this.ctx.material.months.split(',') : [];
 | 
	
		
			
				|  |  | -                material_month.push(data.yearmonth);
 | 
	
		
			
				|  |  | +                material_month.push(...data.yearmonths);
 | 
	
		
			
				|  |  |                  material_month.sort();
 | 
	
		
			
				|  |  |                  if (mbList.length !== 0) {
 | 
	
		
			
				|  |  |                      const insertArray = [];
 | 
	
		
			
				|  |  |                      const updateArray = [];
 | 
	
		
			
				|  |  |                      for (const mb of mbList) {
 | 
	
		
			
				|  |  | -                        const one_month = {
 | 
	
		
			
				|  |  | -                            tid: this.ctx.tender.id,
 | 
	
		
			
				|  |  | -                            mid: this.ctx.material.id,
 | 
	
		
			
				|  |  | -                            mb_id: mb.id,
 | 
	
		
			
				|  |  | -                            msg_tp: monthList.length !== 0 ? null : mb.msg_tp,
 | 
	
		
			
				|  |  | -                            yearmonth: data.yearmonth,
 | 
	
		
			
				|  |  | -                        };
 | 
	
		
			
				|  |  | -                        insertArray.push(one_month);
 | 
	
		
			
				|  |  | +                        for (const ym of data.yearmonths) {
 | 
	
		
			
				|  |  | +                            const one_month = {
 | 
	
		
			
				|  |  | +                                tid: this.ctx.tender.id,
 | 
	
		
			
				|  |  | +                                mid: this.ctx.material.id,
 | 
	
		
			
				|  |  | +                                mb_id: mb.id,
 | 
	
		
			
				|  |  | +                                msg_tp: monthList.length !== 0 ? null : mb.msg_tp,
 | 
	
		
			
				|  |  | +                                yearmonth: ym,
 | 
	
		
			
				|  |  | +                            };
 | 
	
		
			
				|  |  | +                            insertArray.push(one_month);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  |                          if (monthList.length !== 0) {
 | 
	
		
			
				|  |  |                              const mb_msg_tp_sum = this._.sumBy(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp');
 | 
	
		
			
				|  |  | -                            const month_num = material_month.length - this.ctx.helper.arrayCount(this._.concat(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), one_month.msg_tp), [null, '', 0]);
 | 
	
		
			
				|  |  | -                            const new_msg_tp = this.ctx.helper.round(this.ctx.helper.div(this.ctx.helper.add(mb_msg_tp_sum, one_month.msg_tp), month_num), this.ctx.material.decimal.up);
 | 
	
		
			
				|  |  | +                            const month_num = material_month.length - this.ctx.helper.arrayCount(this._.concat(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), insertArray[0].msg_tp), [null, '', 0]);
 | 
	
		
			
				|  |  | +                            const new_msg_tp = this.ctx.helper.round(this.ctx.helper.div(this.ctx.helper.add(mb_msg_tp_sum, insertArray[0].msg_tp), month_num), this.ctx.material.decimal.up);
 | 
	
		
			
				|  |  |                              const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mb, new_msg_tp);
 | 
	
		
			
				|  |  |                              const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, newm_spread), this.ctx.material.decimal.tp);
 | 
	
		
			
				|  |  |                              updateArray.push({
 |