|  | @@ -61,6 +61,33 @@ module.exports = app => {
 | 
	
		
			
				|  |  |              // throw
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        async _getCustFolder(ctx, acc_id, tender_id) {
 | 
	
		
			
				|  |  | +            const rst = [];
 | 
	
		
			
				|  |  | +            // 因新需求,将增加tender_id作为定制化显示,但考虑到无缝链接,还是保留acc_id的判断:
 | 
	
		
			
				|  |  | +            const custFolders1 = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(acc_id);
 | 
	
		
			
				|  |  | +            const custFolders2 = await ctx.service.rptTreeNodeCust.getCustFolderByTenderId(tender_id);
 | 
	
		
			
				|  |  | +            // 1. 两种条件都要查询结果,然后:
 | 
	
		
			
				|  |  | +            //  1.1. 两种条件都没有,返回空数组
 | 
	
		
			
				|  |  | +            //  1.2. 两种条件都有,返回tender_id的,删除acc_id的
 | 
	
		
			
				|  |  | +            //  1.3. 只有acc_id的,那么:
 | 
	
		
			
				|  |  | +            //   1.3.1 增加新记录,用tender_id作为索引保存(acc_id = -1);
 | 
	
		
			
				|  |  | +            //   1.3.2 删除acc_id的这条记录,返回tender_id的这条记录
 | 
	
		
			
				|  |  | +            //  1.4. 只有tender_id的,返回这条记录
 | 
	
		
			
				|  |  | +            if (custFolders1.length > 0) {
 | 
	
		
			
				|  |  | +                if (custFolders2.length > 0) {
 | 
	
		
			
				|  |  | +                    rst.push(custFolders2[0]);
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    await ctx.service.rptTreeNodeCust.createCustNodeByTenderId(tender_id, custFolders1[0].rpt_tpl_items);
 | 
	
		
			
				|  |  | +                    rst.push(custFolders1[0]); // 直接拿原先的用了
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                // 考虑不同的用户会有同一个标段,需要不断地删除用户的自定义设置
 | 
	
		
			
				|  |  | +                await ctx.service.rptTreeNodeCust.removeCustFolder(custFolders1[0].id);
 | 
	
		
			
				|  |  | +            } else if (custFolders2.length > 0) {
 | 
	
		
			
				|  |  | +                rst.push(custFolders2[0]);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return rst;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          async _createNodes(ctx, source_type, pid) {
 | 
	
		
			
				|  |  |              const treeNodes = await ctx.service.rptTreeNode.getNodesBySourceType([pid], source_type); // 这个查定制的
 | 
	
		
			
				|  |  |              const commonTreeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1]); // 这个查通用的
 | 
	
	
		
			
				|  | @@ -141,7 +168,8 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  let stage_status = -1;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  const { treeNodes, custCfg, allTreeItems, allIndivTreeItems } = await this._createNodes(ctx, sourceTypeConst.sourceType.tender, tender.data.project_id);
 | 
	
		
			
				|  |  | -                const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
 | 
	
		
			
				|  |  | +                // const custTreeFolders = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
 | 
	
		
			
				|  |  | +                const custTreeFolders = await this._getCustFolder(ctx, this.ctx.session.sessionUser.accountId, tender.id);
 | 
	
		
			
				|  |  |                  const stageList = await ctx.service.stage.getValidStagesShort(tender.id);
 | 
	
		
			
				|  |  |                  const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: tender.data.project_id } }); // 找公司章用的
 | 
	
		
			
				|  |  |                  // 以后还有预付款、材差
 | 
	
	
		
			
				|  | @@ -285,8 +313,8 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  const cust_select_keys = JSON.stringify(['common', 'customize']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
 | 
	
		
			
				|  |  |                  const rpt_tpl_items = { customize: [], common: [] };
 | 
	
		
			
				|  |  | -                if (custTreeNodes.length > 0) {
 | 
	
		
			
				|  |  | -                    const cust_select_item = JSON.parse(custTreeNodes[0].rpt_tpl_items);
 | 
	
		
			
				|  |  | +                if (custTreeFolders.length > 0) {
 | 
	
		
			
				|  |  | +                    const cust_select_item = JSON.parse(custTreeFolders[0].rpt_tpl_items);
 | 
	
		
			
				|  |  |                      if (cust_select_item.common) rpt_tpl_items.common = cust_select_item.common;
 | 
	
		
			
				|  |  |                      if (cust_select_item.customize) rpt_tpl_items.customize = cust_select_item.customize;
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -590,9 +618,9 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  const cust_select_keys = JSON.stringify(['common_dynamic', 'customize_dynamic']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
 | 
	
		
			
				|  |  |                  const rpt_tpl_items = { customize: [], common: [] };
 | 
	
		
			
				|  |  | -                const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
 | 
	
		
			
				|  |  | -                if (custTreeNodes.length > 0) {
 | 
	
		
			
				|  |  | -                    const cust_select_item = JSON.parse(custTreeNodes[0].rpt_tpl_items);
 | 
	
		
			
				|  |  | +                const custTreeFolders = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
 | 
	
		
			
				|  |  | +                if (custTreeFolders.length > 0) {
 | 
	
		
			
				|  |  | +                    const cust_select_item = JSON.parse(custTreeFolders[0].rpt_tpl_items);
 | 
	
		
			
				|  |  |                      if (cust_select_item.common_dynamic) rpt_tpl_items.common = cust_select_item.common_dynamic;
 | 
	
		
			
				|  |  |                      if (cust_select_item.customize_dynamic) rpt_tpl_items.customize = cust_select_item.customize_dynamic;
 | 
	
		
			
				|  |  |                      if (!cust_select_item.hasOwnProperty('common_dynamic') && !cust_select_item.hasOwnProperty('customize_dynamic')) {
 |