|  | @@ -749,12 +749,6 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                      case 'set-pay-tender':
 | 
	
		
			
				|  |  |                          responseData.data = await ctx.service.financialPayTender.savePayTender(ctx.subProject.id, data.updateData);
 | 
	
		
			
				|  |  |                          break;
 | 
	
		
			
				|  |  | -                    case 'get-auditors':
 | 
	
		
			
				|  |  | -                        const fpInfo = await ctx.service.financialPay.getDataById(data.id);
 | 
	
		
			
				|  |  | -                        await ctx.service.financialPay.loadPayUser(fpInfo);
 | 
	
		
			
				|  |  | -                        await ctx.service.financialPay.loadFinancialPayAuditViewData(fpInfo);
 | 
	
		
			
				|  |  | -                        responseData.data = fpInfo;
 | 
	
		
			
				|  |  | -                        break;
 | 
	
		
			
				|  |  |                      default: throw '参数有误';
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  ctx.body = responseData;
 | 
	
	
		
			
				|  | @@ -775,14 +769,15 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  const status = parseInt(ctx.query.status) || 0;
 | 
	
		
			
				|  |  |                  const tid = parseInt(ctx.query.tid) || null;
 | 
	
		
			
				|  |  |                  const used = ctx.query.used || null;
 | 
	
		
			
				|  |  | -                await this._filterPay(ctx, status, tid, used);
 | 
	
		
			
				|  |  | +                const from = ctx.query.from || null;
 | 
	
		
			
				|  |  | +                await this._filterPay(ctx, status, tid, used, from);
 | 
	
		
			
				|  |  |              } catch (err) {
 | 
	
		
			
				|  |  |                  this.log(err);
 | 
	
		
			
				|  |  |                  ctx.redirect(`/sp/${ctx.subProject.id}/dashboard`);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        async _filterPay(ctx, status = 0, tid = null, used = null) {
 | 
	
		
			
				|  |  | +        async _filterPay(ctx, status = 0, tid = null, used = null, from) {
 | 
	
		
			
				|  |  |              const financialPermission = await ctx.service.subProjPermission.getFinancailPermission(ctx.subProject.permission.fund_trans_permission, ctx.subProject.permission.fund_pay_permission);
 | 
	
		
			
				|  |  |              if (!financialPermission.pay_show) {
 | 
	
		
			
				|  |  |                  throw '没有查看权限';
 | 
	
	
		
			
				|  | @@ -895,6 +890,7 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  tid,
 | 
	
		
			
				|  |  |                  status,
 | 
	
		
			
				|  |  |                  used,
 | 
	
		
			
				|  |  | +                from,
 | 
	
		
			
				|  |  |                  payList,
 | 
	
		
			
				|  |  |                  payStage,
 | 
	
		
			
				|  |  |                  notStagePays,
 | 
	
	
		
			
				|  | @@ -903,7 +899,7 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  unitList,
 | 
	
		
			
				|  |  |                  moment,
 | 
	
		
			
				|  |  |                  auditType: auditConst.auditType,
 | 
	
		
			
				|  |  | -                // preUrl: '/financial',
 | 
	
		
			
				|  |  | +                preUrl: '/sp/' + ctx.subProject.id + '/financial/pay' + (from ? '/list' : '/stage'),
 | 
	
		
			
				|  |  |                  jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.pay),
 | 
	
		
			
				|  |  |                  pageInfo,
 | 
	
		
			
				|  |  |              };
 | 
	
	
		
			
				|  | @@ -929,6 +925,168 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                      throw '提交数据错误';
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  const payStage = await ctx.service.financialPayStage.getDataById(ctx.params.fpsid);
 | 
	
		
			
				|  |  | +                const fileds = ['batch-old-pays', 'add-pay'];
 | 
	
		
			
				|  |  | +                if (!payStage && fileds.indexOf(data.type) !== -1) {
 | 
	
		
			
				|  |  | +                    throw '资金支付单位期不存在';
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                switch (data.type) {
 | 
	
		
			
				|  |  | +                    case 'batch-old-pays':
 | 
	
		
			
				|  |  | +                        await ctx.service.financialPay.batchOldPays(ctx.subProject.id, payStage, data.postData.payIds);
 | 
	
		
			
				|  |  | +                        break;
 | 
	
		
			
				|  |  | +                    case 'add-pay':
 | 
	
		
			
				|  |  | +                        responseData.data = await ctx.service.financialPay.addPay(ctx.subProject.id, payStage, data.updateData);
 | 
	
		
			
				|  |  | +                        break;
 | 
	
		
			
				|  |  | +                    case 'del-pay':
 | 
	
		
			
				|  |  | +                        responseData.data = await ctx.service.financialPay.delPay(data.postData.node);
 | 
	
		
			
				|  |  | +                        break;
 | 
	
		
			
				|  |  | +                    case 'get-auditors':
 | 
	
		
			
				|  |  | +                        const fpInfo = await ctx.service.financialPay.getDataById(data.id);
 | 
	
		
			
				|  |  | +                        await ctx.service.financialPay.loadPayUser(fpInfo);
 | 
	
		
			
				|  |  | +                        await ctx.service.financialPay.loadFinancialPayAuditViewData(fpInfo);
 | 
	
		
			
				|  |  | +                        responseData.data = fpInfo;
 | 
	
		
			
				|  |  | +                        break;
 | 
	
		
			
				|  |  | +                    default: throw '参数有误';
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                ctx.body = responseData;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                this.log(err);
 | 
	
		
			
				|  |  | +                ctx.body = { err: 1, msg: err.toString(), data: {} };
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /**
 | 
	
		
			
				|  |  | +         * 变更管理 页面 (Get)
 | 
	
		
			
				|  |  | +         *
 | 
	
		
			
				|  |  | +         * @param {Object} ctx - egg全局变量
 | 
	
		
			
				|  |  | +         * @return {void}
 | 
	
		
			
				|  |  | +         */
 | 
	
		
			
				|  |  | +        async payList(ctx) {
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                const company = ctx.query.company || null;
 | 
	
		
			
				|  |  | +                const qi = parseInt(ctx.query.qi) || null;
 | 
	
		
			
				|  |  | +                const status = parseInt(ctx.query.status) || 0;
 | 
	
		
			
				|  |  | +                const tid = parseInt(ctx.query.tid) || null;
 | 
	
		
			
				|  |  | +                const used = ctx.query.used || null;
 | 
	
		
			
				|  |  | +                await this._filterPayList(ctx, company, qi, status, tid, used);
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                this.log(err);
 | 
	
		
			
				|  |  | +                ctx.redirect(`/sp/${ctx.subProject.id}/dashboard`);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        async _filterPayList(ctx, company = null, qi = null, status = 0, tid = null, used = null) {
 | 
	
		
			
				|  |  | +            const financialPermission = await ctx.service.subProjPermission.getFinancailPermission(ctx.subProject.permission.fund_trans_permission, ctx.subProject.permission.fund_pay_permission);
 | 
	
		
			
				|  |  | +            if (!financialPermission.pay_show) {
 | 
	
		
			
				|  |  | +                throw '没有查看权限';
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            const fptAudits = await ctx.service.financialPayTenderAudit.getAllDataByCondition({ where: { spid: ctx.subProject.id, uid: ctx.session.sessionUser.accountId } });
 | 
	
		
			
				|  |  | +            const fptAuditTids = ctx.helper._.map(fptAudits, 'tid');
 | 
	
		
			
				|  |  | +            const fptReportTids = ctx.helper._.map(ctx.helper._.filter(fptAudits, { is_report: 1 }), 'tid');
 | 
	
		
			
				|  |  | +            const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
 | 
	
		
			
				|  |  | +            const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : fptAuditTids) : [tid];
 | 
	
		
			
				|  |  | +            const tenderCondition = { spid: ctx.subProject.id, filter_fund: 0 };
 | 
	
		
			
				|  |  | +            let hadTender = false;
 | 
	
		
			
				|  |  | +            if (ctx.session.sessionUser.is_admin) {
 | 
	
		
			
				|  |  | +                hadTender = true;
 | 
	
		
			
				|  |  | +            } else if (fptAuditTids.length !== 0) {
 | 
	
		
			
				|  |  | +                hadTender = true;
 | 
	
		
			
				|  |  | +                tenderCondition.id = fptAuditTids;
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                hadTender = false;
 | 
	
		
			
				|  |  | +                tenderCondition.id = -1;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            const categoryData = await this.ctx.service.category.getAllCategory(ctx.subProject);
 | 
	
		
			
				|  |  | +            const tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name', 'category'] }) : [];
 | 
	
		
			
				|  |  | +            const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'company_id', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
 | 
	
		
			
				|  |  | +            const user = accountList.find(item => item.id === ctx.session.sessionUser.accountId) || null;
 | 
	
		
			
				|  |  | +            const userCompany = user ? ctx.helper._.find(unitList, { name: user.company }) : null;
 | 
	
		
			
				|  |  | +            if (!userCompany) {
 | 
	
		
			
				|  |  | +                throw '请联系管理员添加用户所在单位信息';
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            const userOrderList = await ctx.service.financialPayStage.getUserOrderList(ctx.subProject.id, userCompany ? userCompany.id : 0);
 | 
	
		
			
				|  |  | +            const userCompanyList = await ctx.service.financialPayStage.getUserCompanyList(ctx.subProject.id, userCompany ? userCompany.id : 0, unitList);
 | 
	
		
			
				|  |  | +            let fpsidList = [];
 | 
	
		
			
				|  |  | +            if (company || qi) {
 | 
	
		
			
				|  |  | +                const companyInfo = company ? ctx.helper._.find(unitList, { name: company }) : null;
 | 
	
		
			
				|  |  | +                const fpstageList = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, companyInfo ? companyInfo.id : null, userCompany ? userCompany.id : 0, qi, 0);
 | 
	
		
			
				|  |  | +                fpsidList = ctx.helper._.map(fpstageList, 'id');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            // const payList = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, companyInfo ? companyInfo.id : null, userCompany ? userCompany.id : 0, qi);
 | 
	
		
			
				|  |  | +            const filter = JSON.parse(JSON.stringify(auditConst.financial.filter));
 | 
	
		
			
				|  |  | +            filter.count = [];
 | 
	
		
			
				|  |  | +            filter.count[filter.status.pending] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, filter.status.pending, filterTids, used);
 | 
	
		
			
				|  |  | +            filter.count[filter.status.uncheck] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, filter.status.uncheck, filterTids, used);
 | 
	
		
			
				|  |  | +            filter.count[filter.status.checking] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, filter.status.checking, filterTids, used);
 | 
	
		
			
				|  |  | +            filter.count[filter.status.checked] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, filter.status.checked, filterTids, used);
 | 
	
		
			
				|  |  | +            const payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, status, filterTids, used, 1);
 | 
	
		
			
				|  |  | +            const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, status, filterTids, used);
 | 
	
		
			
				|  |  | +            // 分页相关
 | 
	
		
			
				|  |  | +            const page = ctx.page;
 | 
	
		
			
				|  |  | +            const pageSize = ctx.pageSize;
 | 
	
		
			
				|  |  | +            const pageInfo = {
 | 
	
		
			
				|  |  | +                page,
 | 
	
		
			
				|  |  | +                pageSizeSelect: 1,
 | 
	
		
			
				|  |  | +                pageSize,
 | 
	
		
			
				|  |  | +                total_num: total,
 | 
	
		
			
				|  |  | +                total: Math.ceil(total / pageSize),
 | 
	
		
			
				|  |  | +                queryData: JSON.stringify(ctx.urlInfo.query),
 | 
	
		
			
				|  |  | +            };
 | 
	
		
			
				|  |  | +            for (const pay of payList) {
 | 
	
		
			
				|  |  | +                const t = ctx.helper._.find(tenders, { id: pay.tid });
 | 
	
		
			
				|  |  | +                pay.tenderName = t ? t.name : '';
 | 
	
		
			
				|  |  | +                const userInfo = ctx.helper._.find(accountList, { id: pay.uid });
 | 
	
		
			
				|  |  | +                pay.username = userInfo ? userInfo.name : '';
 | 
	
		
			
				|  |  | +                if (pay.status !== auditConst.financial.status.checked || !pay.final_auditor_str) {
 | 
	
		
			
				|  |  | +                    pay.curAuditors = await ctx.service.financialPayAudit.getAuditorsByStatus(pay.id, pay.status, pay.times);
 | 
	
		
			
				|  |  | +                    if (pay.status === auditConst.financial.status.checked && pay.curAuditors.length > 0) {
 | 
	
		
			
				|  |  | +                        const final_auditor_str = pay.curAuditors[0].audit_type === auditConst.auditType.key.common
 | 
	
		
			
				|  |  | +                            ? pay.curAuditors[0].name + (pay.curAuditors[0].role ? '-' + pay.curAuditors[0].role : '')
 | 
	
		
			
				|  |  | +                            : ctx.helper.transFormToChinese(pay.curAuditors[0].audit_order) + '审';
 | 
	
		
			
				|  |  | +                        await ctx.service.financialPay.defaultUpdate({ final_auditor_str }, { where: { id: pay.id } });
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (pay.status !== auditConst.financial.status.checked) {
 | 
	
		
			
				|  |  | +                    pay.entities = await ctx.service.financialPayContract.getEntities(pay.id);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                pay.stage = pay.fpsid ? await ctx.service.financialPayStage.getOnePayStage(pay.fpsid) : null;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            const renderData = {
 | 
	
		
			
				|  |  | +                categoryData,
 | 
	
		
			
				|  |  | +                tenders,
 | 
	
		
			
				|  |  | +                financialPermission,
 | 
	
		
			
				|  |  | +                usedList: financialConst.used,
 | 
	
		
			
				|  |  | +                auditConst: auditConst.financial,
 | 
	
		
			
				|  |  | +                filter,
 | 
	
		
			
				|  |  | +                tid,
 | 
	
		
			
				|  |  | +                status,
 | 
	
		
			
				|  |  | +                used,
 | 
	
		
			
				|  |  | +                company,
 | 
	
		
			
				|  |  | +                qi,
 | 
	
		
			
				|  |  | +                userCompanyList,
 | 
	
		
			
				|  |  | +                userOrderList,
 | 
	
		
			
				|  |  | +                payList,
 | 
	
		
			
				|  |  | +                fptAuditTids,
 | 
	
		
			
				|  |  | +                fptReportTids,
 | 
	
		
			
				|  |  | +                unitList,
 | 
	
		
			
				|  |  | +                moment,
 | 
	
		
			
				|  |  | +                auditType: auditConst.auditType,
 | 
	
		
			
				|  |  | +                // preUrl: '/sp/' + ctx.subProject.id + '/financial/pay' + (from === 'list' ? '/list/?from=' + from : '/stage'),
 | 
	
		
			
				|  |  | +                jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.payList),
 | 
	
		
			
				|  |  | +                pageInfo,
 | 
	
		
			
				|  |  | +            };
 | 
	
		
			
				|  |  | +            await this.layout('financial/pay_list.ejs', renderData, 'financial/pay_list_modal.ejs');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        async payListSave(ctx) {
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                const responseData = {
 | 
	
		
			
				|  |  | +                    err: 0, msg: '', data: {},
 | 
	
		
			
				|  |  | +                };
 | 
	
		
			
				|  |  | +                const data = JSON.parse(ctx.request.body.data);
 | 
	
		
			
				|  |  | +                if (!data.type) {
 | 
	
		
			
				|  |  | +                    throw '提交数据错误';
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                const payStage = await ctx.service.financialPayStage.getDataById(ctx.params.fpsid);
 | 
	
		
			
				|  |  |                  if (!payStage) {
 | 
	
		
			
				|  |  |                      throw '资金支付单位期不存在';
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -968,6 +1126,7 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  await this._getFinancialAuditViewData(ctx);
 | 
	
		
			
				|  |  |                  // 获取附件列表
 | 
	
		
			
				|  |  | +                const from = ctx.query.from || null;
 | 
	
		
			
				|  |  |                  const fileList = await ctx.service.financialPayAtt.getAtt(ctx.financialPay.id);
 | 
	
		
			
				|  |  |                  const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
 | 
	
		
			
				|  |  |                  const auth_mobile = pa.auth_mobile;
 | 
	
	
		
			
				|  | @@ -980,8 +1139,10 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                      auditType: auditConst.auditType,
 | 
	
		
			
				|  |  |                      whiteList: ctx.app.config.multipart.whitelist,
 | 
	
		
			
				|  |  |                      moment,
 | 
	
		
			
				|  |  | +                    from,
 | 
	
		
			
				|  |  |                      fileList,
 | 
	
		
			
				|  |  |                      authMobile: auth_mobile,
 | 
	
		
			
				|  |  | +                    returnUrl: `/sp/${ctx.subProject.id}/financial/pay/${from === 'list' ? 'list' : 'stage/' + ctx.financialPay.fpsid}`,
 | 
	
		
			
				|  |  |                      preUrl: `/sp/${ctx.subProject.id}/financial/pay`,
 | 
	
		
			
				|  |  |                      preUrl2: `/sp/${ctx.subProject.id}/financial/pay/` + ctx.financialPay.id,
 | 
	
		
			
				|  |  |                      jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.payDetail),
 |