소스 검색

变更立项书功能

laiguoran 3 년 전
부모
커밋
eab610c62f

+ 1 - 0
app/const/account_permission.js

@@ -29,6 +29,7 @@ const permission = {
             { title: '创建标段', value: 1 },
             { title: '查阅所有标段', value: 2 },
             { title: '维护签约清单', value: 3, hint: '开启该选项,台账审批通过后,可上传签约清单', hintIcon: 'fa-question-circle' },
+            { title: '变更意向', value: 5, hint: '开启该选项,变更立项可新建变更意向书', hintIcon: 'fa-question-circle' },
             { title: '材差清单设置', value: 4, hint: '开启该选项,当前账号可设置允许调差的清单', hintIcon: 'fa-question-circle' },
         ],
     },

+ 90 - 0
app/const/audit.js

@@ -421,6 +421,94 @@ const advance = (function() {
     auditStringClass[status.checkNo] = 'text-warning';
     return { type, status, statusString, statusClass, auditString, auditStringClass };
 })();
+
+// 变更立项 审批流程
+const changeProject = (function() {
+    const status = {
+        uncheck: 1, // 待上报
+        checking: 2, // 待审批|审批中
+        checked: 3, // 审批通过
+        checkNo: 4, // 审批终止
+        back: 5, // 退回到原报人重新上报
+    };
+    const statusString = [];
+    statusString[status.uncheck] = '待上报';
+    statusString[status.checking] = '审批中';
+    statusString[status.checked] = '审批通过';
+    statusString[status.checkNo] = '终止';
+    statusString[status.back] = '审批退回';
+
+    const statusClass = [];
+    statusClass[status.uncheck] = '';
+    statusClass[status.checking] = 'text-warning';
+    statusClass[status.checked] = 'text-success';
+    statusClass[status.checkNo] = 'text-danger';
+    statusClass[status.back] = 'text-warning';
+
+    // 标段概况页
+    // 描述文本
+    const auditString = [];
+    auditString[status.uncheck] = '';
+    auditString[status.checking] = '审批中';
+    auditString[status.checked] = '审批通过';
+    auditString[status.checkNo] = '终止';
+    auditString[status.back] = '审批退回';
+    // 文字样式
+    const auditStringClass = [];
+    auditStringClass[status.uncheck] = '';
+    auditStringClass[status.checking] = 'text-warning';
+    auditStringClass[status.checked] = 'text-success';
+    auditStringClass[status.checkNo] = 'text-danger';
+    auditStringClass[status.back] = 'text-warning';
+    // 描述文本
+    const auditProgress = [];
+    auditProgress[status.uncheck] = '草稿';
+    auditProgress[status.checking] = '审批中';
+    auditProgress[status.checked] = '审批通过';
+    auditProgress[status.checkNo] = '终止';
+    auditProgress[status.back] = '审批退回';
+    // 样式
+    const auditProgressClass = [];
+    auditProgressClass[status.uncheck] = '';
+    auditProgressClass[status.checking] = 'text-warning';
+    auditProgressClass[status.checked] = 'text-success';
+    auditProgressClass[status.checkNo] = 'text-danger';
+    auditProgressClass[status.back] = 'text-warning';
+
+    const filter = {
+        status: {
+            pending: 1,
+            uncheck: 5,
+            checking: 2,
+            checked: 3,
+            checkNo: 4,
+        },
+        statusString: [],
+    };
+    filter.statusString[filter.status.pending] = '待处理';
+    filter.statusString[filter.status.uncheck] = '待上报';
+    filter.statusString[filter.status.checking] = '进行中';
+    filter.statusString[filter.status.checked] = '已通过';
+    filter.statusString[filter.status.checkNo] = '终止';
+
+    // 按钮
+    const statusButton = [];
+    statusButton[status.uncheck] = '待上报';
+    statusButton[status.checking] = '审批';
+    statusButton[status.checked] = '';
+    statusButton[status.checkNo] = '';
+    statusButton[status.back] = '重新上报';
+
+    // 按钮样式
+    const statusButtonClass = [];
+    statusButtonClass[status.uncheck] = 'btn-primary';
+    statusButtonClass[status.checking] = 'btn-success';
+    statusButtonClass[status.checked] = '';
+    statusButtonClass[status.checkNo] = '';
+    statusButtonClass[status.back] = 'btn-warning';
+    return { status, statusString, statusClass, auditString, auditStringClass, auditProgress, auditProgressClass, filter, statusButton, statusButtonClass };
+})();
+
 // 推送类型
 const pushType = {
     material: 1,
@@ -429,6 +517,7 @@ const pushType = {
     revise: 4,
     ledger: 5,
     advance: 6,
+    changeProject: 7,
 };
 
 module.exports = {
@@ -449,4 +538,5 @@ module.exports = {
     filter,
     pushType,
     advance,
+    changeProject,
 };

+ 5 - 0
app/const/change.js

@@ -106,4 +106,9 @@ module.exports = {
         souban: { unit: '艘班' },
         mu: { unit: '亩' },
     },
+    // 立项类型
+    project_type: {
+        3: '变更建议',
+        4: '变更意向',
+    },
 };

+ 7 - 0
app/const/code_rule.js

@@ -11,13 +11,20 @@
 const ruleType = {
     measure: 1,
     change: 2,
+    suggestion: 3,
+    will: 4,
 };
 const ruleField = [];
 ruleField[ruleType.measure] = 'm_rule';
 ruleField[ruleType.change] = 'c_rule';
+ruleField[ruleType.suggestion] = 'suggestion';
+ruleField[ruleType.will] = 'will';
 const ruleString = [];
 ruleString[ruleType.measure] = 'measure';
 ruleString[ruleType.change] = 'change';
+ruleString[ruleType.suggestion] = 'suggestion';
+ruleString[ruleType.will] = 'will';
+
 
 // 中间计量编号规则
 const measure = {

+ 2 - 0
app/const/page_show.js

@@ -40,6 +40,8 @@ const defaultSetting = {
     openManagement: 0,
     openMaterialChecklist: 0,
     close1stStageCheckDealParam: 0,
+    openChangeProject: 0,
+    openChangeApply: 0,
 };
 
 

+ 548 - 3
app/controller/change_controller.js

@@ -194,7 +194,20 @@ module.exports = app => {
                     throw '当前未打开标段';
                 }
                 const tenderData = await ctx.service.tender.getDataById(tenderId);
-                const cCodeRule = tenderData.c_rule !== null ? JSON.parse(tenderData.c_rule) : [];
+                const data = JSON.parse(ctx.request.body.data);
+                let cCodeRule;
+                let cConnector;
+                let changeCount = 0;
+                if (data && data.type) {
+                    const c_code_rules = tenderData.c_code_rules !== null ? JSON.parse(tenderData.c_code_rules) : null;
+                    cCodeRule = c_code_rules && c_code_rules[data.type + '_rule'] ? c_code_rules[data.type + '_rule'] : [];
+                    cConnector = c_code_rules && c_code_rules[data.type + '_connector'] ? c_code_rules[data.type + '_connector'] : null;
+                    changeCount = await ctx.service.changeProject.count({ tid: tenderId, type: codeRuleConst.ruleType[data.type] });
+                } else {
+                    cCodeRule = tenderData.c_rule !== null ? JSON.parse(tenderData.c_rule) : [];
+                    cConnector = tenderData.c_connector;
+                    changeCount = await ctx.service.change.count({ tid: tenderId });
+                }
 
                 const code = [];
                 for (const rule of cCodeRule) {
@@ -213,14 +226,14 @@ module.exports = app => {
                             break;
                         case codeRuleConst.measure.ruleType.addNo:
                             let s = '0000000000';
-                            const count = rule.start + await ctx.service.change.count({ tid: tenderId });
+                            const count = rule.start + changeCount;
                             s = s + count;
                             code.push(s.substr(s.length - rule.format));
                             break;
                         default: break;
                     }
                 }
-                responseData.data = code.join(tenderData.c_connector !== null && tenderData.c_connector !== 3 ? codeRuleConst.measure.connectorString[tenderData.c_connector] : '');
+                responseData.data = code.join(cConnector !== null && cConnector !== 3 ? codeRuleConst.measure.connectorString[cConnector] : '');
             } catch (err) {
                 responseData.err = 1;
                 responseData.msg = err;
@@ -1805,6 +1818,538 @@ module.exports = app => {
                     throw '未知操作';
             }
         }
+
+        async _filterChangesProject(ctx, status = 0) {
+            const tenderId = ctx.params.id;
+            ctx.session.sessionUser.tenderId = tenderId;
+            const tender = await this.service.tender.getDataById(ctx.tender.id);
+            // const tender = ctx.tender;
+            // const tenderList = await this.service.tender.getList();
+
+            const page = ctx.page;
+            const sorts = ctx.query.sort ? ctx.query.sort : 0;
+            const orders = ctx.query.order ? ctx.query.order : 0;
+            const changes = await ctx.service.changeProject.getListByStatus(tender.id, status, 1, sorts, orders);
+            const total = await ctx.service.changeProject.getCountByStatus(tender.id, status);
+            for (const c of changes) {
+                c.curAuditor = await ctx.service.changeProjectAudit.getAuditorByStatus(c.id, c.status, c.times);
+            }
+            const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
+            const userPermission = accountInfo !== undefined && accountInfo.permission !== ''
+                ? JSON.parse(accountInfo.permission) : null;
+            // let page_total = 0;
+            // if (changes !== null) {
+            //     let i = 0;
+            //     for (const c of changes) {
+            //         page_total = ctx.helper.add(page_total, c.total_price);
+            //         const status = c.status === audit.uncheck ? 0 : 1;
+            //         // 根据审批人对当前变更令的状态取不同的展示方式。
+            //         let changeAudit = '';
+            //         let auditStatus = 0;
+            //         switch (c.status) {
+            //             case 1:
+            //                 auditStatus = 1;
+            //                 break;
+            //             case 2:
+            //                 changeAudit = await ctx.service.changeAudit.getLastUser(c.cid, c.times, status);
+            //                 auditStatus = changeAudit.uid === ctx.session.sessionUser.accountId ? 1 : 0;
+            //                 break;
+            //             case 3:
+            //             case 4:
+            //                 auditStatus = 0;
+            //                 changeAudit = await ctx.service.changeAudit.getLastUser(c.cid, c.times, status);
+            //                 break;
+            //             case 5:
+            //                 changeAudit = await ctx.service.changeAudit.getLastUser(c.cid, c.times - 1, status);
+            //                 auditStatus = c.uid === ctx.session.sessionUser.accountId ? 1 : 0;
+            //                 const back_changeUsedData = await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, c.cid);
+            //                 c.stageChangeNum = this.ctx.helper.sum(back_changeUsedData.map(x => { return Math.abs(x.used_qty); }));
+            //                 break;
+            //             case 6:
+            //                 changeAudit = await ctx.service.changeAudit.getLastBackUser(c.cid, c.times);
+            //                 const checkingAudit = await ctx.service.changeAudit.getLastUser(c.cid, c.times, status);
+            //                 auditStatus = checkingAudit.uid === ctx.session.sessionUser.accountId ? 1 : 0;
+            //                 break;
+            //             case 9:
+            //                 auditStatus = 9;
+            //                 const changeUsedData = await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, c.cid);
+            //                 c.stageChangeNum = this.ctx.helper.sum(changeUsedData.map(x => { return Math.abs(x.used_qty); }));
+            //                 break;
+            //             default:
+            //                 break;
+            //         }
+            //         changes[i].changeAudit = changeAudit;
+            //         changes[i].auditStatus = auditStatus;
+            //         i++;
+            //     }
+            // }
+
+            // 分页相关
+            const pageInfo = {
+                page,
+                total: Math.ceil(total / app.config.pageSize),
+                queryData: JSON.stringify(ctx.urlInfo.query),
+            };
+
+            const filter = JSON.parse(JSON.stringify(audit.changeProject.filter));
+            filter.count = [];
+            filter.count[filter.status.pending] = await ctx.service.changeProject.getCountByStatus(tender.id, filter.status.pending);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
+            filter.count[filter.status.uncheck] = await ctx.service.changeProject.getCountByStatus(tender.id, filter.status.uncheck);// await ctx.service.change.checkingDatas(tender.id, ctx.session.sessionUser.accountId);
+            filter.count[filter.status.checking] = await ctx.service.changeProject.getCountByStatus(tender.id, filter.status.checking);// await ctx.service.change.checkedDatas(tender.id, ctx.session.sessionUser.accountId);
+            filter.count[filter.status.checked] = await ctx.service.changeProject.getCountByStatus(tender.id, filter.status.checked);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
+            filter.count[filter.status.checkNo] = await ctx.service.changeProject.getCountByStatus(tender.id, filter.status.checkNo);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
+            let codeRule = [];
+            let c_connector = '1';
+            let c_rule_first = 1;
+            const rule_type = tender.user_id === ctx.session.sessionUser.accountId ? 'suggestion' : 'will';
+            if (tender.c_code_rules) {
+                const c_code_rules = JSON.parse(tender.c_code_rules);
+                codeRule = c_code_rules[rule_type + '_rule'] !== undefined ? c_code_rules[rule_type + '_rule'] : [];
+                c_connector = c_code_rules[rule_type + '_connector'] !== undefined ? c_code_rules[rule_type + '_connector'] : '1';
+                c_rule_first = c_code_rules[rule_type + '_rule_first'] !== undefined ? c_code_rules[rule_type + '_rule_first'] : 1;
+            }
+            for (const rule of codeRule) {
+                switch (rule.rule_type) {
+                    case codeRuleConst.measure.ruleType.dealCode:
+                        rule.preview = ctx.tender.info.deal_info.dealCode;
+                        break;
+                    case codeRuleConst.measure.ruleType.tenderName:
+                        rule.preview = tender.name;
+                        break;
+                    case codeRuleConst.measure.ruleType.inDate:
+                        rule.preview = moment().format('YYYY');
+                        break;
+                    case codeRuleConst.measure.ruleType.text:
+                        rule.preview = rule.text;
+                        break;
+                    case codeRuleConst.measure.ruleType.addNo:
+                        const s = '0000000000';
+                        rule.preview = s.substr(s.length - rule.format);
+                        break;
+                    default: break;
+                }
+            }
+            const renderData = {
+                uid: ctx.session.sessionUser.accountId,
+                userPermission,
+                tender,
+                pageInfo,
+                changes,
+                status,
+                rule_type,
+                codeRule,
+                c_connector,
+                c_rule_first,
+                filter,
+                ruleType: codeRuleConst.ruleType[rule_type],
+                dealCode: ctx.tender.info.deal_info.dealCode,
+                auditConst: audit.changeProject,
+                ruleConst: codeRuleConst.measure,
+                changeConst,
+                tenderMenu: this.menu.tenderMenu,
+                preUrl: '/tender/' + tender.id,
+                jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.change.project),
+            };
+            await this.layout('change/project.ejs', renderData, 'change/project_modal.ejs');
+        }
+
+        /**
+         * 变更立项列表 页面 (Get)
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        async project(ctx) {
+            try {
+                await this._filterChangesProject(ctx);
+            } catch (err) {
+                this.log(err);
+                ctx.redirect('/dashboard');
+            }
+        }
+
+        /**
+         * 新增变更立项 (Post)
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        async projectAdd(ctx) {
+            try {
+                const tenderId = ctx.params.id;
+                if (!tenderId) {
+                    throw '当前未打开标段';
+                }
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data.code || data.code === '' || !data.name || data.name === '') {
+                    throw '变更立项书编号不能为空';
+                }
+
+                const change = await ctx.service.changeProject.add(tenderId, ctx.session.sessionUser.accountId, data.code, data.name);
+
+                ctx.body = { err: 0, msg: '', data: change };
+            } catch (err) {
+                this.log(err);
+                ctx.body = { err: 1, msg: err.toString() };
+            }
+        }
+
+        /**
+         * 变更管理 状态筛选 页面 (Get)
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        async projectStatus(ctx) {
+            try {
+                const status = parseInt(ctx.params.status);
+                await this._filterChangesProject(ctx, status);
+            } catch (err) {
+                this.logger.error(err);
+                ctx.redirect('/tender/' + ctx.params.id + '/change/project');
+            }
+        }
+
+        /**
+         * 获取审批界面所需的 原报、审批人数据等
+         * @param ctx
+         * @return {Promise<void>}
+         * @private
+         */
+        async _getChangeProjectAuditViewData(ctx) {
+            const auditConst = audit.changeProject;
+            const times = ctx.change.status === auditConst.status.back ? ctx.change.times - 1 : ctx.change.times;
+            ctx.change.user = await ctx.service.projectAccount.getAccountInfoById(ctx.change.uid);
+            ctx.change.auditHistory = [];
+            if (times >= 1) {
+                for (let i = 1; i <= times; i++) {
+                    ctx.change.auditHistory.push(await ctx.service.changeProjectAudit.getAuditors(ctx.change.id, i));
+                }
+            }
+            // 获取审批流程中左边列表
+            ctx.change.auditors2 = ctx.change.status === auditConst.status.back && ctx.change.user_id !== ctx.session.sessionUser.accountId ?
+                await ctx.service.changeProjectAudit.getAuditorsWithOwner(ctx.change.id, times) :
+                await ctx.service.changeProjectAudit.getAuditorsWithOwner(ctx.change.id, ctx.change.times);
+            if (ctx.change.status === auditConst.status.uncheck || ctx.change.status === auditConst.status.back) {
+                ctx.change.auditorList = await ctx.service.changeProjectAudit.getAuditors(ctx.change.id, ctx.change.times);
+            }
+        }
+
+        async projectInformation(ctx) {
+            try {
+                const whiteList = this.ctx.app.config.multipart.whitelist;
+                const tender = await ctx.service.tender.getDataById(ctx.tender.id);
+                // 获取附件列表
+                const fileList = await ctx.service.changeProjectAtt.getAllChangeProjectAtt(ctx.tender.id, ctx.change.id);
+                await this._getChangeProjectAuditViewData(ctx);
+                const renderData = {
+                    tender,
+                    change: ctx.change,
+                    changeConst,
+                    auditConst: audit.changeProject,
+                    fileList,
+                    whiteList,
+                    jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.change.project_information),
+                    preUrl: '/tender/' + ctx.tender.id + '/change/project/' + ctx.change.id + '/information',
+                };
+                if ((ctx.change.status === audit.changeProject.status.uncheck || ctx.change.status === audit.changeProject.status.back) && (ctx.session.sessionUser.accountId === ctx.change.uid || ctx.tender.isTourist)) {
+                    // data.accountGroup = accountGroup;
+                    // 获取所有项目参与者
+                    const accountList = await ctx.service.projectAccount.getAllDataByCondition({
+                        where: { project_id: ctx.session.sessionProject.id, enable: 1 },
+                        columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
+                    });
+                    renderData.accountList = accountList;
+                    renderData.accountGroup = accountGroup.map((item, idx) => {
+                        const groupList = accountList.filter(item => item.account_group === idx);
+                        return { groupName: item, groupList };
+                    });
+                }
+                await this.layout('change/project_information.ejs', renderData, 'change/project_information_modal.ejs');
+            } catch (err) {
+                this.log(err);
+                ctx.redirect('/tender/' + ctx.params.id + '/change');
+            }
+        }
+
+        // 审批相关
+        /**
+         * 添加审批人
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async addProjectAudit(ctx) {
+            try {
+                const auditConst = audit.changeProject;
+                const data = JSON.parse(ctx.request.body.data);
+                const id = this.app._.toInteger(data.auditorId);
+                if (isNaN(id) || id <= 0) {
+                    throw '参数错误';
+                }
+                // 检查权限等
+                if (ctx.change.uid !== ctx.session.sessionUser.accountId) {
+                    throw '您无权添加审核人';
+                }
+                if (ctx.change.status === auditConst.status.checking || ctx.change.status === auditConst.status.checked) {
+                    throw '当前不允许添加审核人';
+                }
+
+                ctx.change.auditorList = await ctx.service.changeProjectAudit.getAuditors(ctx.change.id, ctx.change.times);
+                // 检查审核人是否已存在
+                const exist = this.app._.find(ctx.change.auditorList, { aid: id });
+                if (exist) {
+                    throw '该审核人已存在,请勿重复添加';
+                }
+                // const shenpiInfo = await ctx.service.shenpiAudit.getDataByCondition({ tid: ctx.tender.id, sp_type: shenpiConst.sp_type.material, sp_status: shenpiConst.sp_status.gdzs });
+                // const is_gdzs = shenpiInfo && ctx.tender.info.shenpi.material === shenpiConst.sp_status.gdzs ? 1 : 0;
+                const result = await ctx.service.changeProjectAudit.addAuditor(ctx.change.id, id, ctx.change.times);
+                if (!result) {
+                    throw '添加审核人失败';
+                }
+
+                const auditors = await ctx.service.changeProjectAudit.getAuditorsWithOwner(ctx.change.id, ctx.change.times);
+                ctx.body = { err: 0, msg: '', data: auditors };
+            } catch (err) {
+                this.log(err);
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
+
+        /**
+         * 移除审批人
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async deleteProjectAudit(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                const id = data.auditorId instanceof Number ? data.auditorId : this.app._.toNumber(data.auditorId);
+                if (isNaN(id) || id <= 0) {
+                    throw '参数错误';
+                }
+
+                const result = await ctx.service.changeProjectAudit.deleteAuditor(ctx.change.id, id, ctx.change.times);
+                if (!result) {
+                    throw '移除审核人失败';
+                }
+
+                const auditors = await ctx.service.changeProjectAudit.getAuditors(ctx.change.id, ctx.change.times);
+                ctx.body = { err: 0, msg: '', data: auditors };
+            } catch (err) {
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
+
+        /**
+         * 上传附件
+         * @param {*} ctx 上下文
+         */
+        async uploadProjectFile(ctx) {
+            let stream;
+            try {
+                const auditConst = audit.changeProject;
+                // this._checkAdvanceFileCanModify(ctx);
+                const parts = this.ctx.multipart({
+                    autoFields: true,
+                });
+                const files = [];
+                const create_time = Date.parse(new Date()) / 1000;
+                let idx = 0;
+                const extra_upload = ctx.change.status === auditConst.status.checked;
+                while ((stream = await parts()) !== undefined) {
+                    if (!stream.filename) {
+                        // 如果没有传入直接返回
+                        return;
+                    }
+                    const fileInfo = path.parse(stream.filename);
+                    const filepath = `app/public/upload/${this.ctx.tender.id.toString()}/change_project/fujian_${create_time + idx.toString() + fileInfo.ext}`;
+                    // await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
+                    await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
+                    files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
+                    ++idx;
+                    stream && (await sendToWormhole(stream));
+                }
+                const in_time = new Date();
+                const payload = files.map(file => {
+                    let idx;
+                    if (Array.isArray(parts.field.name)) {
+                        idx = parts.field.name.findIndex(name => name === file.name);
+                    } else {
+                        idx = 'isString';
+                    }
+                    const newFile = {
+                        tid: ctx.tender.id,
+                        cpid: ctx.change.id,
+                        uid: ctx.session.sessionUser.accountId,
+                        filename: file.name,
+                        fileext: file.ext,
+                        filesize: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
+                        filepath: file.filepath,
+                        upload_time: in_time,
+                        extra_upload,
+                    };
+                    return newFile;
+                });
+                // 执行文件信息写入数据库
+                await ctx.service.changeProjectAtt.saveFileMsgToDb(payload);
+                // 将最新的当前标段的所有文件信息返回
+                const data = await ctx.service.changeProjectAtt.getAllChangeProjectAtt(ctx.tender.id, ctx.change.id);
+                ctx.body = { err: 0, msg: '', data };
+            } catch (err) {
+                stream && (await sendToWormhole(stream));
+                this.log(err);
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
+
+        /**
+         * 删除附件
+         * @param {Ojbect} ctx 上下文
+         */
+        async deleteProjectFile(ctx) {
+            try {
+                const { id } = JSON.parse(ctx.request.body.data);
+                const fileInfo = await ctx.service.changeProjectAtt.getDataById(id);
+                if (fileInfo || Object.keys(fileInfo).length) {
+                    // 先删除文件
+                    // await fs.unlinkSync(path.resolve(this.app.baseDir, './app', fileInfo.filepath));
+                    await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + fileInfo.filepath);
+                    // 再删除数据库
+                    await ctx.service.changeProjectAtt.delete(id);
+                } else {
+                    throw '不存在该文件';
+                }
+                const data = await ctx.service.changeProjectAtt.getAllChangeProjectAtt(ctx.tender.id, ctx.change.id);
+                ctx.body = { err: 0, msg: '请求成功', data };
+            } catch (err) {
+                this.log(err);
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
+
+        /**
+         * 下载附件
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        async downloadProjectFile(ctx) {
+            const id = ctx.params.fid;
+            if (id) {
+                try {
+                    const fileInfo = await ctx.service.changeProjectAtt.getDataById(id);
+                    if (fileInfo !== undefined && fileInfo !== '') {
+                        // const fileName = path.join(__dirname, '../', fileInfo.filepath);
+                        // 解决中文无法下载问题
+                        const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
+                        let disposition = '';
+                        if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
+                            disposition = 'attachment; filename=' + encodeURIComponent(fileInfo.file_name);
+                        } else if (userAgent.indexOf('firefox') >= 0) {
+                            disposition = 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileInfo.file_name) + '"';
+                        } else {
+                            /* safari等其他非主流浏览器只能自求多福了 */
+                            disposition = 'attachment; filename=' + new Buffer(fileInfo.file_name).toString('binary');
+                        }
+                        ctx.response.set({
+                            'Content-Type': 'application/octet-stream',
+                            'Content-Disposition': disposition,
+                            'Content-Length': fileInfo.file_size,
+                        });
+                        // ctx.body = await fs.createReadStream(fileName);
+                        ctx.body = await ctx.helper.ossFileGet(fileInfo.filepath);
+                    } else {
+                        throw '不存在该文件';
+                    }
+                } catch (err) {
+                    this.log(err);
+                    this.setMessage(err.toString(), this.messageType.ERROR);
+                }
+            }
+        }
+
+        async projectInformationSave(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (data.name === 'code') {
+                    const info = await ctx.service.changeProject.isRepeat(ctx.change.id, data.val, ctx.tender.id, ctx.change.type);
+                    if (info) {
+                        throw '该编号已存在';
+                    }
+                }
+                const result = await ctx.service.changeProject.saveInfo(ctx.change.id, data);
+                if (!result) {
+                    throw '修改失败';
+                }
+                ctx.body = { err: 0, msg: '请求成功', data: null };
+            } catch (err) {
+                this.log(err);
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
+
+        /**
+         * 上报和重新上报
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async startProjectAudit(ctx) {
+            try {
+                const auditConst = audit.changeProject;
+                // 检查权限等
+                if (!ctx.change) {
+                    throw '数据错误';
+                }
+                if (ctx.change.uid !== ctx.session.sessionUser.accountId) {
+                    throw '您无权上报该期数据';
+                }
+                if (ctx.change.status === auditConst.status.checking || ctx.change.status === auditConst.status.checked) {
+                    throw '该材料调差期数据当前无法上报';
+                }
+
+                await ctx.service.changeProjectAudit.start(ctx.change.id, ctx.change.times);
+
+                ctx.redirect(ctx.request.header.referer);
+            } catch (err) {
+                this.log(err);
+                ctx.session.postError = err.toString();
+                ctx.redirect(ctx.request.header.referer);
+            }
+        }
+
+        /**
+         * 审批
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async checkProjectAudit(ctx) {
+            try {
+                const auditConst = audit.changeProject;
+                if (!ctx.change || ctx.change.status !== auditConst.status.checking) {
+                    throw '当前材料调差期数据有误';
+                }
+                if (!ctx.change.curAuditor || ctx.change.curAuditor.aid !== ctx.session.sessionUser.accountId) {
+                    throw '您无权进行该操作';
+                }
+                const data = {
+                    checkType: parseInt(ctx.request.body.checkType),
+                    opinion: ctx.request.body.opinion,
+                };
+                if (!data.checkType || isNaN(data.checkType)) {
+                    throw '提交数据错误';
+                }
+                // if (data.checkType === auditConst.status.checkNo) {
+                //     if (!data.checkType || isNaN(data.checkType)) {
+                //         throw '提交数据错误';
+                //     }
+                // }
+                await ctx.service.changeProjectAudit.check(ctx.change.id, data, ctx.change.times);
+
+                ctx.redirect(ctx.request.header.referer);
+            } catch (err) {
+                this.log(err);
+                ctx.session.postError = err.toString();
+                ctx.redirect(ctx.request.header.referer);
+            }
+        }
     }
 
     return ChangeController;

+ 3 - 0
app/controller/dashboard_controller.js

@@ -29,6 +29,7 @@ module.exports = app => {
             const auditRevise = await ctx.service.reviseAudit.getAuditRevise(ctx.session.sessionUser.accountId);
             const auditMaterial = await ctx.service.materialAudit.getAuditMaterial(ctx.session.sessionUser.accountId);
             const auditAdvance = await ctx.service.advanceAudit.getAuditAdvance(ctx.session.sessionUser.accountId);
+            const auditChangeProject = ctx.session.sessionProject.page_show.openChangeProject ? await ctx.service.changeProjectAudit.getAuditChangeProject(ctx.session.sessionUser.accountId) : [];
             const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
             const noticeList = await ctx.service.noticePush.getNotice(ctx.session.sessionProject.id, pa.id);
             const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
@@ -52,6 +53,7 @@ module.exports = app => {
                 auditRevise,
                 auditMaterial,
                 auditAdvance,
+                auditChangeProject,
                 role: pa.role,
                 authMobile: pa.auth_mobile,
                 acLedger: auditConst.ledger,
@@ -60,6 +62,7 @@ module.exports = app => {
                 acRevise: auditConst.revise,
                 acMaterial: auditConst.material,
                 acAdvance: auditConst.advance,
+                acChangeProject: auditConst.changeProject,
                 noticeList,
                 pushType: auditConst.pushType,
                 projectData,

+ 2 - 1
app/controller/setting_controller.js

@@ -763,7 +763,8 @@ module.exports = app => {
 
                 const result = await ctx.service.project.updateFunRela(projectId, ctx.request.body);
                 if (!result) throw '保存数据失败';
-                // this.ctx.session.sessionProject.page_show.openChangeRevise = data.openChangeRevise ? 1 : 0;
+                this.ctx.session.sessionProject.page_show.openChangeProject = data.openChangeProject ? 1 : 0;
+                this.ctx.session.sessionProject.page_show.openChangeApply = data.openChangeApply ? 1 : 0;
                 this.ctx.session.sessionProject.page_show.openMaterialTax = data.openMaterialTax ? 1 : 0;
                 this.ctx.session.sessionProject.page_show.openMaterialChecklist = data.openMaterialChecklist ? 1 : 0;
                 const result2 = await ctx.service.project.updatePageshow(projectId);

+ 21 - 4
app/controller/tender_controller.js

@@ -846,9 +846,18 @@ module.exports = app => {
                 const updateData = {
                     id: tenderId,
                 };
-                updateData[codeRuleConst.ruleField[data.rule]] = data.data;
-                updateData.c_connector = data.connector;
-                updateData.c_rule_first = 0;
+                if (data.type) {
+                    const tenderData = await ctx.service.tender.getDataById(tenderId);
+                    const c_code_rules = tenderData.c_code_rules ? JSON.parse(tenderData.c_code_rules) : {};
+                    c_code_rules[data.type + '_rule'] = JSON.parse(data.data);
+                    c_code_rules[data.type + '_rule_first'] = 0;
+                    c_code_rules[data.type + '_connector'] = data.connector;
+                    updateData.c_code_rules = JSON.stringify(c_code_rules);
+                } else {
+                    updateData[codeRuleConst.ruleField[data.rule]] = data.data;
+                    updateData.c_connector = data.connector;
+                    updateData.c_rule_first = 0;
+                }
 
                 const result = await ctx.service.tender.db.update(ctx.service.tender.tableName, updateData);
                 if (result.affectedRows !== 1) {
@@ -877,7 +886,15 @@ module.exports = app => {
                 const updateData = {
                     id: tenderId,
                 };
-                updateData.c_rule_first = 0;
+                const data = JSON.parse(ctx.request.body.data);
+                if (data && data.type) {
+                    const tenderData = await ctx.service.tender.getDataById(tenderId);
+                    const c_code_rules = tenderData.c_code_rules ? JSON.parse(tenderData.c_code_rules) : {};
+                    c_code_rules[data.type + '_rule_first'] = 0;
+                    updateData.c_code_rules = JSON.stringify(c_code_rules);
+                } else {
+                    updateData.c_rule_first = 0;
+                }
 
                 const result = await ctx.service.tender.db.update(ctx.service.tender.tableName, updateData);
                 if (result.affectedRows !== 1) {

+ 120 - 0
app/middleware/change_project_check.js

@@ -0,0 +1,120 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Ellisran
+ * @date 2020/10/15
+ * @version
+ */
+
+const status = require('../const/audit').changeProject.status;
+const _ = require('lodash');
+
+module.exports = options => {
+    /**
+     * 标段校验 中间件
+     * 1. 读取标段数据(包括属性)
+     * 2. 检验用户是否可见标段(不校验具体权限)
+     *
+     * @param {function} next - 中间件继续执行的方法
+     * @return {void}
+     */
+    return function* changeProjectCheck(next) {
+        try {
+            // 获取revise
+            if (!this.session.sessionProject.page_show.openChangeProject) {
+                throw '该功能已关闭';
+            }
+            const cpid = this.params.cpid || this.request.body.cpid;
+            if (!cpid) {
+                throw '您访问的变更立项不存在';
+            }
+            const change = yield this.service.changeProject.getDataById(cpid);
+            // 读取原报、审核人数据
+            change.auditors = yield this.service.changeProjectAudit.getAuditors(change.id, change.times);
+            change.curAuditor = yield this.service.changeProjectAudit.getCurAuditor(change.id, change.times);
+
+            if (!change) throw '变更令数据有误';
+            // 权限相关
+            // todo 校验权限 (标段参与人、分享)
+            const accountId = this.session.sessionUser.accountId,
+                auditorIds = _.map(change.auditors, 'aid'),
+                shareIds = [];
+            if (accountId === change.uid) { // 原报
+                // if (change.curAuditor) {
+                //     change.readOnly = change.status === status.checking && change.curAuditor.user_id === accountId;
+                // } else {
+                //     change.readOnly = change.status !== status.uncheck && change.status !== status.back;
+                // }
+                change.curTimes = change.times;
+                if (change.status === status.uncheck || change.status === status.back || change.status === status.checkNo) {
+                    change.curOrder = 0;
+                } else if (change.status === status.checked) {
+                    change.curOrder = _.max(_.map(change.auditors, 'order'));
+                } else {
+                    change.curOrder = change.curAuditor.aid === accountId ? change.curAuditor.order : change.curAuditor.order - 1;
+                }
+                change.filePermission = true;
+            } else if (this.tender.isTourist) {
+                change.curTimes = change.times;
+                if (change.status === status.uncheck || change.status === status.back || change.status === status.checkNo) {
+                    change.curOrder = 0;
+                } else if (change.status === status.checked) {
+                    change.curOrder = _.max(_.map(change.auditors, 'order'));
+                } else {
+                    change.curOrder = change.curAuditor.order;
+                }
+                change.filePermission = this.tender.touristPermission.file || auditorIds.indexOf(accountId) !== -1;
+            } else if (auditorIds.indexOf(accountId) !== -1) { // 审批人
+                if (change.status === status.uncheck) {
+                    throw '您无权查看该数据';
+                }
+                // change.readOnly = change.status !== status.checking || accountId !== change.curAuditor.aid;
+                change.curTimes = change.status === status.back ? change.times - 1 : change.times;
+                if (change.status === status.checked) {
+                    change.curOrder = _.max(_.map(change.auditors, 'order'));
+                } else if (change.status === status.back) {
+                    const audit = this.service.changeProjectAudit.getDataByCondition({
+                        cpid: change.id, times: change.times, status: status.back,
+                    });
+                    change.curOrder = audit.order;
+                } else if (change.status === status.checkNo) {
+                    change.curOrder = 0;
+                } else {
+                    change.curOrder = accountId === change.curAuditor.aid ? change.curAuditor.order : change.curAuditor.order - 1;
+                }
+                change.filePermission = true;
+            } else if (shareIds.indexOf(accountId) !== -1) { // 分享人
+                if (change.status === status.uncheck) {
+                    throw '您无权查看该数据';
+                }
+                // change.readOnly = true;
+                change.curTimes = change.status === status.back ? change.times - 1 : change.times;
+                change.curOrder = change.status === status.checked ? _.max(_.map(change.auditors, 'order')) : (change.status !== status.checkNo ? change.curAuditor.order - 1 : 0);
+                change.filePermission = false;
+            } else { // 其他不可见
+                throw '您无权查看该数据';
+            }
+            // 调差的readOnly 指表格和页面只能看不能改,和审批无关
+            change.readOnly = !((change.status === status.uncheck || change.status === status.back) && accountId === change.uid);
+            this.change = change;
+            yield next;
+        } catch (err) {
+            console.log(err);
+            // 输出错误到日志
+            if (err.stack) {
+                this.logger.error(err);
+            } else {
+                this.getLogger('fail').info(JSON.stringify({
+                    error: err,
+                    project: this.session.sessionProject,
+                    user: this.session.sessionUser,
+                    body: this.session.body,
+                }));
+            }
+            // 重定向值标段管理
+            this.redirect(this.request.headers.referer);
+        }
+    };
+};

+ 312 - 0
app/public/js/change_project.js

@@ -0,0 +1,312 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2018/8/21
+ * @version
+ */
+// 向后端请求中间计量号
+function getNewCode() {
+    postData('/tender/'+ tenderId +'/change/newCode', { type: rulesType }, function (code) {
+        if (code !== '') {
+            $('#bj-code').val(code);
+        }
+    });
+}
+
+class codeRuleSet {
+    constructor (obj) {
+        this.body = obj;
+        // 切换规则组件类型
+        $('.rule-change', obj).change(function () {
+            const codeType = this.selectedIndex-1;
+            if (codeType === ruleConst.ruleType.addNo) {
+                $('#format', obj).show();
+                $('#text', obj).show();
+                $('#text>label', obj).text('起始编号');
+                $('#text>input', obj).val('001');
+                const s = '0000000000' + 1;
+                $('#text>input', obj).val(s.substr(s.length - $('#format>input', obj).val()));
+            } else if (codeType === ruleConst.ruleType.text) {
+                $('#format', obj).hide();
+                $('#text', obj).show();
+                $('#text>label', obj).text('文本');
+                $('#text>input', obj).val('').attr('placeholder', '请在这里输入需要的文本');
+            } else {
+                $('#format', obj).hide();
+                $('#text', obj).hide();
+            }
+        });
+        // 修改编号位数
+        $('#format>input', obj).change(function () {
+            const s = '0000000000' + parseInt($('#text>input', obj).val());
+            $('#text>input', obj).val(s.substr(s.length - $(this).val()));
+        });
+
+        // 修改连接符
+        $('.connector-change', obj).change(function () {
+            const connectorType = this.options[this.selectedIndex].text;
+            const rules = $('span>span', obj), ruleText = [];
+            for (const r of rules) {
+                ruleText.push($.trim(r.innerText));
+            }
+            if (connectorType === '无') {
+                $('#preview', obj).text(ruleText.join(''));
+            } else {
+                $('#preview', obj).text(ruleText.join(connectorType));
+            }
+            connectorRule = this.options[this.selectedIndex].value;
+        });
+
+        // 新增规则组件
+        $('#addRule', obj).click(function () {
+            const codeType = $('select', obj)[1].selectedIndex-1;
+            const rule = {rule_type: codeType}, html = [];
+            let preview;
+            switch (codeType) {
+                case ruleConst.ruleType.dealCode: {
+                    if (dealCode === '') {
+                        toastr.error('当前标段合同编号为空,请选择其他组件。');
+                        return false;
+                    }
+                    preview = dealCode;
+                    break;
+                }
+                case ruleConst.ruleType.tenderName: {
+                    preview = tenderName;
+                    break;
+                }
+                case ruleConst.ruleType.text: {
+                    rule.text = $('#text>input', obj).val();
+                    if (rule.text === '') {
+                        toastr.error('文本内容不允许为空。');
+                        return false;
+                    }
+                    preview = rule.text;
+                    break;
+                }
+                case ruleConst.ruleType.inDate: {
+                    preview = moment().format('YYYY');
+                    break;
+                }
+                case ruleConst.ruleType.addNo: {
+                    rule.format = parseInt($('#format>input', obj).val());
+                    rule.start = parseInt($('#text>input', obj).val());
+                    if ($('#text>input', obj).val().length !== rule.format) {
+                        toastr.error('起始编号位数和自动编号位数不一致。');
+                        return false;
+                    }
+                    const s = '0000000000';
+                    preview = s.substr(s.length - rule.format);
+                    break;
+                }
+                default: {
+                    toastr.error('请选择组件再添加');
+                    return false;
+                }
+            }
+            // 更新规则
+            codeRule.push(rule);
+            // 更新规则显示
+            html.push('<span class="badge badge-light" title="' + ruleConst.ruleString[codeType] + '" rule="' + JSON.stringify(rule) + '">');
+            html.push('<span>' + preview + '</span>');
+            html.push('<a href="javascript: void(0);" class="text-danger" title="移除"><i class="fa fa-remove"></i></a>');
+            html.push('</span>');
+            const part = $('#ruleParts', obj).append(html.join(''));
+            // 更新规则预览
+            const connectorType = connectorRule !== '' && parseInt(connectorRule) !== ruleConst.connectorType.nothing ? ruleConst.connectorString[connectorRule] : '';
+            const previewtext = $.trim($('#preview', obj).text()) === '' ? preview : $.trim($('#preview', obj).text()) + connectorType + preview;
+            $('#preview', obj).text(previewtext);
+        });
+        // 删除规则组件
+        $($('#ruleParts', obj)).on('click', 'a', function () {
+            const index = $('a', obj).index(this);
+            codeRule.splice(index-1, 1);
+            $(this).parent().remove();
+            const rules = $('span>span', obj), ruleText = [];
+            for (const r of rules) {
+                ruleText.push($.trim(r.innerText));
+            }
+            const connectorType = connectorRule !== '' && parseInt(connectorRule) !== ruleConst.connectorType.nothing ? ruleConst.connectorString[connectorRule] : '';
+            $('#preview', obj).text(ruleText.join(connectorType));
+        });
+    }
+}
+
+$(document).ready(() => {
+    // 首次进入设置
+    let showNoNeed = false;
+    if (cRuleFirst) {
+        codeRule = [];
+        showNoNeed = true;
+        $('#setting').modal('show');
+    }
+    // else if ($('#changeList').children.length === 0) {
+    //     $('#add-bj').modal('show');
+    // }
+    // 设置
+    const ruleSet = new codeRuleSet($('div.modal-body', '#setting'));
+    $('#setRule', '#setting').bind('click', function () {
+        const data = {
+            rule: ruleType,
+            type: rulesType,
+            connector: connectorRule,
+            data: JSON.stringify(codeRule),
+        };
+        if (codeRule.length !== 0) {
+            $('#autoCodeShow').show();
+        }
+        postData('/tender/rule', data, function () {
+            if (cRuleFirst && showNoNeed) {
+                $('#changeFirst').click();
+                $('.ml-auto a[href="#add-bj"]').click();
+                // $('#add-bj-modal').modal('show');
+            } else {
+                $('#setting').modal('hide');
+            }
+        });
+    })
+    $('.ml-auto').on('click', 'a', function () {
+        const content = $(this).attr('href');
+        if (content === '#add-bj') {
+            $('#add-bj-modal').modal('show')
+                getNewCode();
+                if ($('#changeList').children.length === 0) {
+                    $('#addCancel').hide();
+                } else {
+                    $('#addCancel').show();
+                }
+                $('#bj-code').removeClass('is-invalid');
+        }
+    });
+
+    // 获取最新可用变更令号
+    $('#autoCode').click(getNewCode);
+    // 新增变更令 确认
+    $('#addOk').click(function () {
+        $(this).attr('disabled', true);
+        if ($('#bj-name').val().length === 0) {
+            $('#bj-name').addClass('is-invalid');
+            $('#name_error_msg').show();
+            $('#name_error_msg').text('工程名称不能为空。');
+            $(this).attr('disabled', false);
+            setTimeout(function () {
+                $('#bj-name').removeClass('is-invalid');
+                $('#name_error_msg').hide();
+            }, 2000);
+            return;
+        }
+        if ($('#bj-name').val().length > 100) {
+            $('#bj-name').addClass('is-invalid');
+            $('#name_error_msg').show();
+            $('#name_error_msg').text('名称超过100个字,请缩减名称。');
+            $(this).attr('disabled', false);
+            setTimeout(function () {
+                $('#bj-name').removeClass('is-invalid');
+                $('#name_error_msg').hide();
+            }, 2000);
+            return;
+        }
+        const data = {
+            code: $('#bj-code').val(),
+            name: $('#bj-name').val(),
+        };
+        if (data.code || data.code !== '' || data.name || data.name !== '') {
+            postData('/tender/'+ tenderId +'/change/project/add', data, function (rst) {
+                $('#bj-code').removeClass('is-invalid');
+                $('#mj-add').modal('hide');
+                $(this).attr('disabled', false);
+                window.location.href = '/tender/'+ tenderId +'/change/project/' + rst.id + '/information';
+            }, function () {
+                $('#mj-code').addClass('is-invalid');
+                $('#mj-Hint').show();
+                $(this).attr('disabled', false);
+            });
+        }
+    });
+
+    //状态切换
+    $('#status_select a').on('click', function () {
+       const status = $(this).data('val');
+       let url = '/tender/'+ tenderId +'/change/project';
+       if (status !== 0) {
+           url += '/status/'+ status;
+       }
+       let orderSetting = getLocalCache('change-project-'+ tenderId +'-list-order');
+       if (orderSetting) {
+           const orders = orderSetting.split('|');
+           url += '?sort=' + orders[0] + '&order=' + orders[1];
+       }
+       window.location.href = url;
+    });
+    // 不再显示首次使用
+    $('#changeFirst').click(function () {
+        showNoNeed = false;
+        $('#changeFirst').remove();
+        $('#hide_modal').show();
+        $('#setting').modal('hide');
+        postData('/tender/'+ tenderId +'/rule/first', { type: rulesType }, function () {
+        });
+    });
+
+    // 弹出删除变更框赋值
+    $('.delete-cid-modal').on('click', function () {
+        $('#delete-cid').val($(this).attr('cid'));
+    });
+
+    // 排序初始化
+    let orderSetting = getLocalCache('change-project-'+ tenderId +'-list-order');
+    if (!orderSetting) orderSetting = 'time|desc';
+    const orders = orderSetting.split('|');
+    $("#sort-radio input[value='"+ orders[0] +"']").prop('checked', true);
+    $("#order-radio input[value='"+ orders[1] +"']").prop('checked', true);
+    if (orders[0] === 'time') {
+        $('#bpaixu').text('排序:发起时间');
+    } else {
+        $('#bpaixu').text('排序:变更立项书编号');
+    }
+    // let sortSetting = getLocalCache('change-'+ $('#tenderId').val() +'-list-sort');
+    // if (sortSetting && parseInt(sortSetting) === 1) {
+    //     $('#bpaixu').click();
+    // }
+    // $('#sort-dropdown').on('shown.bs.dropdown', function () {
+    //     setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
+    // });
+    // $('#sort-dropdown').on('hidden.bs.dropdown', function () {
+    //     setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 0);
+    // });
+
+    $('#sort-radio input[name="paizhi"]').click(function () {
+        const orderStr = $(this).val() + '|' + $('#order-radio input[name="paixu"]:checked').val();
+        setLocalCache('change-project-'+ tenderId +'-list-order', orderStr);
+        // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
+        const link = window.location.origin + window.location.pathname + '?sort='+ $(this).val() + '&order=' + $('#order-radio input[name="paixu"]:checked').val();
+        window.location.href = link;
+    });
+    $('#order-radio input[name="paixu"]').click(function () {
+        const orderStr = $('#sort-radio input[name="paizhi"]:checked').val() + '|' + $(this).val();
+        setLocalCache('change-project-'+ tenderId +'-list-order', orderStr);
+        // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
+        const link = window.location.origin + window.location.pathname + '?sort='+ $('#sort-radio input[name="paizhi"]:checked').val() + '&order=' + $(this).val();
+        window.location.href = link;
+    })
+
+    $.subMenu({
+        menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
+        toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
+        key: 'menu.1.0.0',
+        miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
+        callback: function (info) {
+            if (info.mini) {
+                $('.panel-title').addClass('fluid');
+                $('#sub-menu').removeClass('panel-sidebar');
+            } else {
+                $('.panel-title').removeClass('fluid');
+                $('#sub-menu').addClass('panel-sidebar');
+            }
+            autoFlashHeight();
+        }
+    });
+});

+ 228 - 0
app/public/js/change_project_audit.js

@@ -0,0 +1,228 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2019/2/27
+ * @version
+ */
+
+$(document).ready(function () {
+    let timer = null
+    let oldSearchVal = null
+
+    $('#gr-search').bind('input propertychange', function(e) {
+        oldSearchVal = e.target.value
+        timer && clearTimeout(timer)
+        timer = setTimeout(() => {
+            const newVal = $('#gr-search').val()
+            let html = ''
+            if (newVal && newVal === oldSearchVal) {
+                accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
+                    html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
+                        <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
+                                class="ml-auto">${item.mobile || ''}</span></p>
+                        <span class="text-muted">${item.role || ''}</span>
+                    </dd>`
+                })
+                $('.book-list').empty()
+                $('.book-list').append(html)
+            } else {
+                if (!$('.acc-btn').length) {
+                    accountGroup.forEach((group, idx) => {
+                        if (!group) return
+                        html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
+                        </a> ${group.groupName}</dt>
+                        <div class="dd-content" data-toggleid="${idx}">`
+                        group.groupList.forEach(item => {
+                            if (item.id !== cur_uid) {
+                                html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
+                                    <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
+                                            class="ml-auto">${item.mobile || ''}</span></p>
+                                    <span class="text-muted">${item.role || ''}</span>
+                                </dd>`
+                            }
+                        });
+                        html += '</div>'
+                    })
+                    $('.book-list').empty()
+                    $('.book-list').append(html)
+                }
+            }
+        }, 400);
+    })
+
+    // 添加审批流程按钮逻辑
+    $('.book-list').on('click', 'dt', function () {
+        const idx = $(this).find('.acc-btn').attr('data-groupid')
+        const type = $(this).find('.acc-btn').attr('data-type')
+        if (type === 'hide') {
+            $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
+                $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
+                $(this).find('.acc-btn').attr('data-type', 'show')
+
+            })
+        } else {
+            $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
+                $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
+                $(this).find('.acc-btn').attr('data-type', 'hide')
+            })
+        }
+        return false
+    })
+
+    // 添加到审批流程中
+    $('dl').on('click', 'dd', function () {
+        const id = parseInt($(this).data('id'));
+        if (id) {
+            postData(preUrl + '/audit/add', { auditorId: id }, (datas) => {
+                const html = [];
+                // 如果是重新上报,添加到重新上报列表中
+                const auditorshtml = [];
+                for (const [index,data] of datas.entries()) {
+                    if (index !== 0) {
+                        html.push('<li class="list-group-item" auditorId="'+ data.aid +'">');
+                        html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
+                        html.push('<span>');
+                        html.push(data.order + ' ');
+                        html.push(data.name + ' ');
+                        html.push('</span>');
+                        html.push('<small class="text-muted">');
+                        html.push(data.role);
+                        html.push('</small></li>');
+                    }
+                    // 添加新审批人流程修改
+                    auditorshtml.push('<li class="list-group-item" data-auditorid="' + data.aid + '">');
+                    auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
+                    auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
+                    if (index === 0) {
+                        auditorshtml.push('<span class="pull-right">原报</span>');
+                    } else if (index+1 === datas.length) {
+                        auditorshtml.push('<span class="pull-right">终审</span>');
+                    } else {
+                        auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
+                    }
+                    auditorshtml.push('</li>');
+                }
+                $('#auditors').html(html.join(''));
+
+
+                // 重新上报时。令其它的审批人流程图标转换
+                // $('#auditors-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
+                // for (let i = 0; i < $('#auditors-list li').length; i++) {
+                //     $('#auditors-list li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
+                //     $('#auditors-list2 li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
+                // }
+
+                $('#auditors-list').html(auditorshtml.join(''));
+
+                // const auditorshtml2 = [];
+                // // 重新上报时。令其它的审批人流程图标转换
+                // $('#auditors-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
+                // // 添加新审批人
+                // auditorshtml2.push('<li class="list-group-item" data-auditid="' + data.aid + '">');
+                // auditorshtml2.push('<h5 class="card-title"><i class="fa fa-stop-circle"></i> ');
+                // auditorshtml2.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
+                // auditorshtml2.push('<span class="pull-right">终审</span>');
+                // auditorshtml2.push('</h5></li>');
+                // $('#auditors-list2').append(auditorshtml2.join(''));
+            });
+        }
+    });
+    // 删除审批人
+    $('body').on('click', '#auditors li>a', function () {
+        const li = $(this).parent();
+        const data = {
+            auditorId: parseInt(li.attr('auditorId')),
+        };
+        postData(preUrl +  '/audit/delete', data, (result) => {
+            li.remove();
+            for (const rst of result) {
+                const aLi = $('li[auditorId=' + rst.aid + ']');
+                $('span', aLi).text(rst.order + ' ' + rst.name + ' ');
+            }
+
+            // 如果是重新上报
+            // 令最后一个图标转换
+            $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove();
+            if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
+                $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
+                    .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
+            }
+            // $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
+            // if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
+            //     $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
+            //         .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
+            // }
+            for (let i = 0; i < $('#auditors-list li').length; i++) {
+                $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审');
+                // $('#auditors-list2').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2').length ? '终' : transFormToChinese(i+1)) + '审');
+            }
+        });
+    });
+    // 退回选择修改审批人流程
+    $('#hideSp').click(function () {
+        $('#sp-list').modal('hide');
+    });
+    $('a[f-target]').click(function () {
+        $($(this).attr('f-target')).modal('show');
+    });
+
+    // 多层modal关闭后的滚动bug修复
+    $('#sp-list').on('hidden.bs.modal', function (e) {
+        $(document.body).addClass('modal-open');
+    });
+});
+// 检查上报情况
+function checkAuditorFrom () {
+    if ($('#auditors li').length === 0) {
+        // if(shenpi_status === shenpiConst.sp_status.gdspl) {
+        //     toastr.error('请联系管理员添加审批人');
+        // } else {
+            toastr.error('请先选择审批人,再上报数据');
+        // }
+        return false;
+    }
+    let flag = false;
+    if (change.code === '') {
+        toastr.error('立项书编号不能为空');
+        flag = true;
+    }
+    if (change.name === '') {
+        toastr.error('工程名称不能为空');
+        flag = true;
+    }
+    if (!change.reason) {
+        toastr.error('变更原因不能为空');
+        flag = true;
+    }
+    if (flag) {
+        return false;
+    }
+    $('#hide-all').show();
+}
+// texterea换行
+function auditCheck(i) {
+    // const inlineRadio1 = $('#inlineRadio1:checked').val()
+    // const inlineRadio2 = $('#inlineRadio2:checked').val()
+    const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
+    $('textarea[name="opinion"]').eq(i).val(opinion);
+    if (i === 2) {
+        if ($('textarea[name="opinion"]').eq(i).val() === '') {
+            toastr.error('请输入终止原因');
+            return false;
+        }
+    }
+    // if (i === 1) {
+    //     if (!inlineRadio1 && !inlineRadio2) {
+    //         if (!$('#warning-text').length) {
+    //             $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
+    //         }
+    //         return false;
+    //     }
+    //     if ($('#warning-text').length) $('#warning-text').remove()
+    // }
+
+    return true;
+}

+ 195 - 0
app/public/js/change_project_information.js

@@ -0,0 +1,195 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author EllisRan
+ * @date 2022/01/21
+ * @version
+ */
+
+$(document).ready(() => {
+    $.subMenu({
+        menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
+        toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
+        key: 'menu.1.0.0',
+        miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
+        callback: function (info) {
+            if (info.mini) {
+                $('.panel-title').addClass('fluid');
+                $('#sub-menu').removeClass('panel-sidebar');
+            } else {
+                $('.panel-title').removeClass('fluid');
+                $('#sub-menu').addClass('panel-sidebar');
+            }
+            autoFlashHeight();
+        }
+    });
+
+    handleFileList(fileList);
+
+    $('#file-ok').click(function () {
+        const files = Array.from($('#file-modal')[0].files)
+        const valiData = files.map(v => {
+            const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
+            return {
+                size: v.size,
+                ext
+            }
+        })
+        if (validateFiles(valiData)) {
+            if (files.length) {
+                const formData = new FormData()
+                files.forEach(file => {
+                    formData.append('name', file.name)
+                    formData.append('size', file.size)
+                    formData.append('file', file)
+                })
+                postDataWithFile(preUrl + '/file/upload', formData, function (result) {
+                    handleFileList(result);
+                    $('#file-cancel').click()
+                });
+            }
+        }
+    })
+    function handleFileList(files = []) {
+        $('#file-content').empty();
+        // const { uncheck, checkNo } = auditConst.status
+        const newFiles = files.map(file => {
+            let showDel = false;
+            if (file.uid === cur_uid) {
+                // if (!curAuditor) {
+                //     advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
+                //     advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
+                // } else {
+                //     curAuditor.audit_id === cur_uid && (showDel = true)
+                // }
+                if (change.status === auditConst.status.checked) {
+                    showDel = Boolean(file.extra_upload )
+                } else {
+                    showDel = true
+                }
+            }
+            return {...file, showDel}
+        })
+        let html = change.filePermission ? `<tr><td colspan="5"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
+        newFiles.forEach((file, idx) => {
+            if (file.showDel) {
+                html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
+            } else {
+                html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td></td></tr>`
+            }
+        })
+        $('#file-content').append(html);
+    }
+
+    $('#file-content').on('click', 'a', function () {
+        if ($(this).hasClass('file-del')) {
+            const id = $(this).data('id');
+            postData(preUrl + '/file/delete', {id}, (result) => {
+                handleFileList(result);
+            })
+        }
+    });
+
+    // 回车提交
+    $('#project-table input').on('keypress', function () {
+        if(window.event.keyCode === 13) {
+            $(this).blur();
+        }
+    });
+
+    $('#project-table input').blur(function () {
+        const val_name = $(this).data('name');
+        let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
+        switch(val_name) {
+            case 'code':
+                if(!val) {
+                    toastr.error('立项书编号不能为空');
+                    $(this).val(change[val_name]);
+                    return false;
+                }
+                break;
+            case 'name':
+                if(!val) {
+                    toastr.error('工程名称不能为空');
+                    $(this).val(change[val_name]);
+                    return false;
+                } else if(val.length > 100) {
+                    toastr.error('名称超过100个字,请缩减名称');
+                    $(this).val(change[val_name]);
+                    return false;
+                }
+                break;
+            case 'org_price':
+            case 'change_price':
+            case 'crease_price':
+                val = val ? parseFloat(val) : null;
+                if(val && !_.isNumber(val)) {
+                    toastr.error('请输入数字');
+                    $(this).val(change[val_name]);
+                    return false;
+                }
+                break;
+            default:
+                if(val && val.length > 255) {
+                    toastr.error('超出字段范围,请缩减');
+                    $(this).val(change[val_name]);
+                    return false;
+                }
+                break;
+        }
+        if(change[val_name] !== val) {
+            const _self = $(this);
+            postData(preUrl + '/save', { name: val_name, val}, function (result) {
+                change[val_name] = val;
+                _self.val(change[val_name]);
+                if (val_name === 'code') {
+                    $('#change-project-code').text(change[val_name]);
+                }
+            }, function () {
+                _self.val(change[val_name]);
+            })
+        } else {
+            $(this).val(change[val_name]);
+        }
+    })
+
+    $('#project-table textarea').blur(function () {
+        const val_name = $(this).data('name');
+        let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
+        if(change[val_name] !== val) {
+            const _self = $(this);
+            postData(preUrl + '/save', { name: val_name, val}, function (result) {
+                change[val_name] = val;
+                _self.val(change[val_name]);
+            }, function () {
+                _self.val(change[val_name]);
+            })
+        } else {
+            $(this).val(change[val_name]);
+        }
+    })
+});
+
+/**
+ * 校验文件大小、格式
+ * @param {Array} files 文件数组
+ */
+function validateFiles(files) {
+    if (files.length > 10) {
+        toastr.error('至多同时上传10个文件');
+        return false
+    }
+    return files.every(file => {
+        if (file.size > 1024 * 1024 * 30) {
+            toastr.error('文件大小限制为30MB');
+            return false
+        }
+        if (whiteList.indexOf('.' + file.ext) === -1) {
+            toastr.error('请上传正确的格式文件');
+            return false
+        }
+        return true
+    })
+}

+ 17 - 1
app/public/js/global.js

@@ -116,6 +116,22 @@ $(function(){
             $(this).attr('href', $(this).attr('href') + '?sort=' + orders[0] + '&order=' + orders[1]);
         }
     });
+    $('.change_project_sort_link').each(function () {
+        const tender_id = $(this).attr('href').split('/')[2];
+        let orderSetting = getLocalCache('change-project-'+ tender_id +'-list-order');
+        if(orderSetting) {
+            const orders = orderSetting.split('|');
+            $(this).attr('href', $(this).attr('href') + '?sort=' + orders[0] + '&order=' + orders[1]);
+        }
+    });
+    $('.change_apply_sort_link').each(function () {
+        const tender_id = $(this).attr('href').split('/')[2];
+        let orderSetting = getLocalCache('change-apply-'+ tender_id +'-list-order');
+        if(orderSetting) {
+            const orders = orderSetting.split('|');
+            $(this).attr('href', $(this).attr('href') + '?sort=' + orders[0] + '&order=' + orders[1]);
+        }
+    });
 
     $('#nav_management').click(function(e) {
       e.preventDefault()
@@ -145,7 +161,7 @@ $(function(){
         })
       });
     $('#add-management .btn-primary').click(function() {
-      
+
       $('#add-management').modal('hide')
       $('#process-management').modal('show')
       $.ajax({

+ 23 - 0
app/router.js

@@ -27,6 +27,8 @@ module.exports = app => {
     const advanceCheck = app.middlewares.advanceCheck();
     // 变更令中间件
     const changeCheck = app.middlewares.changeCheck();
+    // 变更立项书中间件
+    const changeProjectCheck = app.middlewares.changeProjectCheck();
     // 投资进度中间件
     const scheduleCheck = app.middlewares.scheduleCheck();
     // 修订
@@ -448,6 +450,27 @@ module.exports = app => {
     // 变更新增部位页
     app.get('/tender/:id/change/:cid/information/revise', sessionAuth, tenderCheck, uncheckTenderCheck, changeCheck, 'changeController.reviseInfo');
     app.post('/tender/:id/change/:cid/information/revise/update', sessionAuth, tenderCheck, uncheckTenderCheck, changeCheck, 'changeController.updateRevise');
+    // 变更立项
+    app.get('/tender/:id/change/project', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.project');
+    app.get('/tender/:id/change/project/status/:status', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.projectStatus');
+    app.post('/tender/:id/change/project/add', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.projectAdd');
+    app.get('/tender/:id/change/project/:cpid/information', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.projectInformation');
+    app.post('/tender/:id/change/project/:cpid/information/save', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.projectInformationSave');
+    app.post('/tender/:id/change/project/:cpid/information/file/upload', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.uploadProjectFile');
+    app.post('/tender/:id/change/project/:cpid/information/file/delete', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.deleteProjectFile');
+    app.get('/tender/:id/change/project/:cpid/information/file/:fid/download', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.downloadProjectFile');
+    app.post('/tender/:id/change/project/:cpid/information/audit/add', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.addProjectAudit');
+    app.post('/tender/:id/change/project/:cpid/information/audit/delete', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.deleteProjectAudit');
+    app.post('/tender/:id/change/project/:cpid/information/audit/start', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.startProjectAudit');
+    app.post('/tender/:id/change/project/:cpid/information/audit/check', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.checkProjectAudit');
+    // // 变更申请
+    // app.get('/tender/:id/change/apply', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.apply');
+    // app.get('/tender/:id/change/apply/:cid/information', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.applyInformation');
+    // app.post('/tender/:id/change/apply/:cid/information/save', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.applyInformationSave');
+    // app.post('/tender/:id/change/apply/:cid/information/file/upload', sessionAuth, 'changeController.uploadFile');
+    // app.post('/tender/:id/change/apply/:cid/information/file/delete', sessionAuth, 'changeController.deleteFile');
+    // app.post('/tender/:id/change/apply/:cid/information/audit/add', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.addAudit');
+    // app.post('/tender/:id/change/apply/:cid/information/audit/delete', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.deleteAudit');
     // 材料调差
     app.get('/tender/:id/measure/material', sessionAuth, tenderCheck, uncheckTenderCheck, 'materialController.index');
     app.post('/tender/:id/measure/material/add', sessionAuth, tenderCheck, uncheckTenderCheck, 'materialController.add');

+ 363 - 0
app/service/change_project.js

@@ -0,0 +1,363 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2018/8/14
+ * @version
+ */
+
+const audit = require('../const/audit').changeProject;
+// const smsTypeConst = require('../const/sms_type');
+// const SMS = require('../lib/sms');
+// const SmsAliConst = require('../const/sms_alitemplate');
+const wxConst = require('../const/wechat_template');
+const pushType = require('../const/audit').pushType;
+const projectLogConst = require('../const/project_log');
+const codeRuleConst = require('../const/code_rule');
+
+module.exports = app => {
+    class ChangeProject extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'change_project';
+        }
+
+        async add(tenderId, userId, code, name) {
+            const type = userId === this.ctx.tender.data.user_id ? codeRuleConst.ruleType.suggestion : codeRuleConst.ruleType.will;
+            const sql = 'SELECT COUNT(*) as count FROM ?? WHERE `tid` = ? AND `code` = ? AND type = ?';
+            const sqlParam = [this.tableName, tenderId, code, audit.status.checked, code, audit.status.checked, type];
+            const codeCount = await this.db.queryOne(sql, sqlParam);
+            const count = codeCount.count;
+            if (count > 0) {
+                throw '立项书编号重复';
+            }
+
+            // 初始化事务
+            this.transaction = await this.db.beginTransaction();
+            let result = false;
+            try {
+                const change = {
+                    tid: tenderId,
+                    uid: userId,
+                    status: audit.status.uncheck,
+                    times: 1,
+                    type,
+                    in_time: new Date(),
+                    code,
+                    name,
+                };
+                const operate = await this.transaction.insert(this.tableName, change);
+
+                if (operate.affectedRows <= 0) {
+                    throw '新建变更令数据失败';
+                }
+                change.id = operate.insertId;
+                // 先找出标段最近存在的变更令审批人的变更令info
+                const preChangeInfo = await this.getHaveAuditLastInfo(tenderId, type);
+                if (preChangeInfo) {
+                    // 并把之前存在的变更令审批人添加到zh_change_audit
+                    const auditResult = await this.ctx.service.changeProjectAudit.copyPreChangeProjectAuditors(this.transaction, preChangeInfo, change);
+                    if (!auditResult) {
+                        throw '复制上一次审批流程失败';
+                    }
+                }
+                result = change;
+                this.transaction.commit();
+            } catch (error) {
+                console.log(error);
+                // 回滚
+                await this.transaction.rollback();
+            }
+
+            return result;
+        }
+
+        async getHaveAuditLastInfo(tenderId, type) {
+            const sql = 'SELECT a.* FROM ?? as a LEFT JOIN ?? as b ON a.`id` = b.`cpid` WHERE a.`tid` = ? AND a.type = ? ORDER BY a.`in_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.changeProjectAudit.tableName, tenderId, type];
+            return await this.db.queryOne(sql, sqlParam);
+        }
+
+        /**
+         * 获取变更立项列表
+         * @param {int} tenderId - 标段id
+         * @param {int} status - 状态
+         * @param {int} hadlimit - 分页
+         * @return {object} list - 列表
+         */
+        async getListByStatus(tenderId, status = 0, hadlimit = 1, sortBy = '', orderBy = '') {
+            let sql = '';
+            let sqlParam = '';
+            if (this.ctx.tender.isTourist && status === 0) {
+                sql = 'SELECT a.*, p.name as account_name FROM ?? As a LEFT JOIN ?? AS p On a.uid = p.id WHERE a.tid = ?';
+                sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId];
+            } else {
+                switch (status) {
+                    case 0: // 包含你的所有变更立项
+                        sql =
+                            'SELECT a.*, p.name as account_name FROM ?? AS a LEFT JOIN ?? AS p On a.uid = p.id WHERE a.tid = ? AND ' +
+                            '(a.uid = ? OR (a.status != ? AND a.id IN (SELECT b.cpid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.cpid)) OR a.status = ? )';
+                        sqlParam = [
+                            this.tableName,
+                            this.ctx.service.projectAccount.tableName,
+                            tenderId,
+                            this.ctx.session.sessionUser.accountId,
+                            audit.status.uncheck,
+                            this.ctx.service.changeProjectAudit.tableName,
+                            this.ctx.session.sessionUser.accountId,
+                            audit.status.checked,
+                        ];
+                        break;
+                    case 1: // 待处理(你的)
+                        sql = 'SELECT a.*, p.name as account_name FROM ?? as a LEFT JOIN ?? AS p On a.uid = p.id WHERE a.id in(SELECT b.cpid FROM ?? as b WHERE b.tid = ? AND b.aid = ? AND b.status = ?) OR (a.uid = ? AND (a.status = ? OR a.status = ?))';
+                        sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.service.changeProjectAudit.tableName, tenderId, this.ctx.session.sessionUser.accountId, audit.status.checking, this.ctx.session.sessionUser.accountId, audit.status.uncheck, audit.status.back];
+                        break;
+                    case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
+                        sql =
+                            'SELECT a.*, p.name as account_name FROM ?? AS a LEFT JOIN ?? AS p On a.uid = p.id WHERE ' +
+                            // 'a.id IN (SELECT b.cpid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.cpid) AND ' +
+                            'a.uid = ? AND a.tid = ? AND (a.status = ? OR a.status = ?)';
+                        sqlParam = [
+                            this.tableName,
+                            this.ctx.service.projectAccount.tableName,
+                            // this.ctx.service.changeProjectAudit.tableName,
+                            this.ctx.session.sessionUser.accountId,
+                            tenderId,
+                            audit.status.uncheck,
+                            audit.status.back,
+                        ];
+                        break;
+                    case 2: // 进行中(所有的)
+                    case 4: // 终止(所有的)
+                        sql =
+                            'SELECT a.*, p.name as account_name FROM ?? AS a LEFT JOIN ?? AS p On a.uid = p.id WHERE ' +
+                            'a.status = ? AND a.tid = ? AND (a.uid = ? OR a.id IN (SELECT b.cpid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.cpid))';
+                        sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, status, tenderId, this.ctx.session.sessionUser.accountId, this.ctx.service.changeProjectAudit.tableName, this.ctx.session.sessionUser.accountId];
+                        break;
+                    case 3: // 已完成(所有的)
+                        sql = 'SELECT a.*, p.name as account_name FROM ?? AS a LEFT JOIN ?? AS p On a.uid = p.id WHERE a.status = ? AND a.tid = ?';
+                        sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, status, tenderId];
+                        break;
+                    default:
+                        break;
+                }
+            }
+            if (sortBy && orderBy) {
+                if (sortBy === 'code') {
+                    sql += ' ORDER BY CHAR_LENGTH(a.code) ' + orderBy + ',convert(a.code using gbk) ' + orderBy;
+                } else {
+                    sql += ' ORDER BY a.in_time ' + orderBy;
+                }
+            } else {
+                sql += ' ORDER BY a.in_time DESC';
+            }
+            if (hadlimit) {
+                const limit = this.app.config.pageSize;
+                const offset = limit * (this.ctx.page - 1);
+                const limitString = offset >= 0 ? offset + ',' + limit : limit;
+                sql += ' LIMIT ' + limitString;
+            }
+            const list = await this.db.query(sql, sqlParam);
+            return list;
+        }
+
+        /**
+         * 获取变更令个数
+         * @param {int} tenderId - 标段id
+         * @param {int} status - 状态
+         * @return {void}
+         */
+        async getCountByStatus(tenderId, status) {
+            if (this.ctx.tender.isTourist && status === 0) {
+                const sql5 = 'SELECT count(*) AS count FROM ?? WHERE tid = ? ORDER BY in_time DESC';
+                const sqlParam5 = [this.tableName, tenderId];
+                const result5 = await this.db.query(sql5, sqlParam5);
+                return result5[0].count;
+            }
+            switch (status) {
+                case 0: // 包含你的所有变更令
+                    const sql =
+                        'SELECT count(*) AS count FROM ?? AS a WHERE a.tid = ? AND ' +
+                        '(a.uid = ? OR (a.status != ? AND a.id IN (SELECT b.cpid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.cpid)) OR a.status = ? )';
+                    const sqlParam = [
+                        this.tableName,
+                        tenderId,
+                        this.ctx.session.sessionUser.accountId,
+                        audit.status.uncheck,
+                        this.ctx.service.changeProjectAudit.tableName,
+                        this.ctx.session.sessionUser.accountId,
+                        audit.status.checked,
+                    ];
+                    const result = await this.db.query(sql, sqlParam);
+                    return result[0].count;
+                case 1: // 待处理(你的)
+                    // return await this.ctx.service.changeAudit.count({
+                    //     tid: tenderId,
+                    //     uid: this.ctx.session.sessionUser.accountId,
+                    //     status: 2,
+                    // });
+                    const sql6 = 'SELECT count(*) AS count FROM ?? as a WHERE a.id in(SELECT b.cpid FROM ?? as b WHERE b.tid = ? AND b.aid = ? AND b.status = ?) OR (a.uid = ? AND (a.status = ? OR a.status = ?))';
+                    const sqlParam6 = [this.tableName, this.ctx.service.changeProjectAudit.tableName, tenderId, this.ctx.session.sessionUser.accountId, audit.status.checking, this.ctx.session.sessionUser.accountId, audit.status.uncheck, audit.status.back];
+                    const result6 = await this.db.query(sql6, sqlParam6);
+                    return result6[0].count;
+                case 5: // 待上报(所有的)PS:取未上报,退回的变更立项
+                    const sql2 =
+                        'SELECT count(*) AS count FROM ?? AS a WHERE ' +
+                        // 'a.id IN (SELECT b.cpid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.cpid) ' +
+                        'a.uid = ? AND a.tid = ? AND (a.status = ? OR a.status = ?)';
+                    const sqlParam2 = [
+                        this.tableName,
+                        // this.ctx.service.changeProjectAudit.tableName,
+                        this.ctx.session.sessionUser.accountId,
+                        tenderId,
+                        audit.status.uncheck,
+                        audit.status.back,
+                    ];
+                    const result2 = await this.db.query(sql2, sqlParam2);
+                    return result2[0].count;
+                case 2: // 进行中(所有的)
+                case 4: // 终止(所有的)
+                    const sql3 =
+                        'SELECT count(*) AS count FROM ?? AS a WHERE ' +
+                        'a.status = ? AND a.tid = ? AND (a.uid = ? OR a.id IN (SELECT b.cpid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.cpid))';
+                    const sqlParam3 = [this.tableName, status, tenderId, this.ctx.session.sessionUser.accountId, this.ctx.service.changeProjectAudit.tableName, this.ctx.session.sessionUser.accountId];
+                    const result3 = await this.db.query(sql3, sqlParam3);
+                    return result3[0].count;
+                case 3: // 已完成(所有的)
+                    const sql4 = 'SELECT count(*) AS count FROM ?? WHERE status = ? AND tid = ?';
+                    const sqlParam4 = [this.tableName, status, tenderId];
+                    const result4 = await this.db.query(sql4, sqlParam4);
+                    return result4[0].count;
+                default:
+                    break;
+            }
+        }
+
+        /**
+         * 保存变更信息
+         * @param {int} postData - 表单提交的数据
+         * @param {int} tenderId - 标段id
+         * @return {void}
+         */
+        async saveInfo(cpId, postData) {
+            // 初始化事务
+            const transaction = await this.db.beginTransaction();
+            let result = false;
+            try {
+                const updateData = {
+                    id: cpId,
+                };
+                updateData[postData.name] = postData.val;
+                await transaction.update(this.tableName, updateData);
+                await transaction.commit();
+                result = true;
+            } catch (error) {
+                await transaction.rollback();
+                result = false;
+            }
+            return result;
+        }
+
+
+        /**
+         * 审批终止
+         * @param {int} postData - 表单提交的数据
+         * @return {void}
+         */
+        async approvalStop(postData) {
+            // 初始化事务
+            this.transaction = await this.db.beginTransaction();
+            let result = false;
+            try {
+                // 设置审批人终止
+                const audit_update = {
+                    id: postData.audit_id,
+                    sdesc: postData.sdesc,
+                    status: 4,
+                    sin_time: new Date(),
+                };
+                await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
+                // 设置变更令终止
+                const change_update = {
+                    w_code: postData.w_code,
+                    status: 4,
+                    cin_time: Date.parse(new Date()) / 1000,
+                };
+                const options = {
+                    where: {
+                        cid: postData.change_id,
+                    },
+                };
+                await this.transaction.update(this.tableName, change_update, options);
+                await this.transaction.commit();
+                result = true;
+            } catch (error) {
+                await this.transaction.rollback();
+                result = false;
+            }
+            return result;
+        }
+
+
+        /**
+         * 查询可用的变更令
+         * @param { string } cid - 查询的清单
+         * @return {Promise<*>} - 可用的变更令列表
+         */
+        async delete(cid) {
+            // 初始化事务
+            this.transaction = await this.db.beginTransaction();
+            let result = false;
+            try {
+                const changeInfo = await this.getDataByCondition({ cid });
+                // 先删除清单,审批人列表
+                await this.transaction.delete(this.ctx.service.changeAuditList.tableName, { cid });
+                await this.transaction.delete(this.ctx.service.changeAudit.tableName, { cid });
+                // 再删除附件和附件文件ni zuo
+                const attList = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { cid } });
+                await this.ctx.helper.delFiles(attList);
+                await this.transaction.delete(this.ctx.service.changeAtt.tableName, { cid });
+                // if (attList.length !== 0) {
+                //     for (const att of attList) {
+                //         await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
+                //     }
+                //     await this.transaction.delete(this.ctx.service.changeAtt.tableName, { cid });
+                // }
+                // 最后删除变更令
+                await this.transaction.delete(this.tableName, { cid });
+                // 记录删除日志
+                await this.ctx.service.projectLog.addProjectLog(this.transaction, projectLogConst.type.change, projectLogConst.status.delete, changeInfo.code);
+                await this.transaction.commit();
+                result = true;
+            } catch (e) {
+                await this.transaction.rollback();
+                result = false;
+            }
+            return result;
+        }
+
+        /**
+         * 判断是否有重名的变更立项
+         * @param cpid
+         * @param code
+         * @param tid
+         * @return {Promise<void>}
+         */
+        async isRepeat(cpId, code, tid, type) {
+            const sql = 'SELECT COUNT(*) as count FROM ?? WHERE `code` = ? AND `id` != ? AND `tid` = ? AND `type` = ?';
+            const sqlParam = [this.tableName, code, cpId, tid, type];
+            const result = await this.db.queryOne(sql, sqlParam);
+            return result.count !== 0;
+        }
+    }
+
+    return ChangeProject;
+};

+ 137 - 0
app/service/change_project_att.js

@@ -0,0 +1,137 @@
+'use strict';
+const archiver = require('archiver');
+const path = require('path');
+const fs = require('fs');
+/**
+ * 附件表 数据模型
+ * @author LanJianRong
+ * @date 2020/6/30
+ * @version
+ */
+
+module.exports = app => {
+    class ChangeProjectFile extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'change_project_attachment';
+        }
+
+        /**
+         * 获取当前标段(期)所有上传的附件
+         * @param {Number} tid 标段id
+         * @param {Number?} mid 期id
+         * @return {Promise<void>} 数据库查询实例
+         */
+        async getAllChangeProjectAtt(tid, cpid) {
+            const { ctx } = this;
+            // const where = { tid };
+            // if (cpid) where.cpid = cpid;
+            const sql = 'SELECT a.*,b.name as username FROM ?? as a LEFT JOIN ?? as b ON a.uid = b.id WHERE a.tid = ? AND a.cpid = ? ORDER BY upload_time DESC';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, cpid];
+            const result = await this.db.query(sql, sqlParam);
+            // const result = await this.db.select(this.tableName, {
+            //     where,
+            //     orders: [['upload_time', 'desc']],
+            // });
+            // for (const r of result) {
+            //     const userInfo = await this.ctx.service.projectAccount.getDataById(r.uid);
+            //     r.username = userInfo ? userInfo.name : '';
+            // }
+            return result.map(item => {
+                item.orginpath = this.ctx.app.config.fujianOssPath + item.filepath;
+                if (!ctx.helper.canPreview(item.fileext)) {
+                    item.filepath = `/tender/${ctx.tender.id}/change/project/${item.cpid}/information/file/${item.id}/download`;
+                } else {
+                    item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
+                }
+                return item;
+            });
+        }
+
+
+        /**
+         * 存储上传的文件信息至数据库
+         * @param {Array} payload 载荷
+         * @return {Promise<void>} 数据库插入执行实例
+         */
+        async saveFileMsgToDb(payload) {
+            return await this.db.insert(this.tableName, payload);
+        }
+
+        /**
+         * 获取单个文件信息
+         * @param {Number} id 文件id
+         * @return {Promise<void>} 数据库查询实例
+         */
+        async getMaterialFileById(id) {
+            return await this.getDataByCondition({ id });
+        }
+
+        /**
+         * 删除附件
+         * @param {Number} id - 附件id
+         * @return {void}
+         */
+        async delete(id) {
+            return await this.deleteById(id);
+        }
+
+        /**
+         * 将文件压缩成zip,并返回zip文件的路径
+         * @param {array} fileIds - 文件数组id
+         * @param {string} zipPath - 压缩文件存储路径
+         * @return {string} 压缩后的zip文件路径
+         */
+        async compressedFile(fileIds, zipPath) {
+            this.initSqlBuilder();
+            this.sqlBuilder.setAndWhere('id', {
+                value: fileIds,
+                operate: 'in',
+            });
+            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
+            const files = await this.db.query(sql, sqlParam);
+            // const paths = files.map(item => {
+            //     return { name: item.filename + item.fileext, path: item.filepath }
+            // })
+            return new Promise((resolve, reject) => {
+                // 每次开一个新的archiver
+                const ziparchiver = archiver('zip');
+                const outputPath = fs.createWriteStream(path.resolve(this.app.baseDir, zipPath));
+                outputPath.on('error', err => {
+                    return reject(err);
+                });
+
+                ziparchiver.pipe(outputPath);
+                files.forEach(item => {
+                    ziparchiver.file(path.resolve(this.app.baseDir, 'app', item.filepath), { name: item.file_name });
+                });
+
+                // 存档警告
+                ziparchiver.on('warning', function(err) {
+                    // if (err.code === 'ENOENT') {
+                    //     console.warn('stat故障和其他非阻塞错误');
+                    // }
+                    return reject(err);
+                });
+
+                // 存档出错
+                ziparchiver.on('error', function(err) {
+                    // console.log(err);
+                    return reject(err);
+                });
+                ziparchiver.finalize();
+                outputPath.on('close', () => {
+                    return resolve(ziparchiver.pointer());
+                });
+            });
+        }
+    }
+    return ChangeProjectFile;
+};
+

+ 571 - 0
app/service/change_project_audit.js

@@ -0,0 +1,571 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2018/8/14
+ * @version
+ */
+
+const auditConst = require('../const/audit').changeProject;
+const pushType = require('../const/audit').pushType;
+const shenpiConst = require('../const/shenpi');
+const smsTypeConst = require('../const/sms_type');
+const SMS = require('../lib/sms');
+const SmsAliConst = require('../const/sms_alitemplate');
+const wxConst = require('../const/wechat_template');
+
+module.exports = app => {
+    class ChangeProjectAudit extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'change_project_audit';
+        }
+
+        /**
+         * 获取 审核列表信息
+         *
+         * @param {Number} cpId - 变更立项id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<*>}
+         */
+        async getAuditors(cpId, times = 1) {
+            const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
+                'FROM ?? AS la, ?? AS pa, (SELECT `aid`,(@i:=@i+1) as `sort` FROM ??, (select @i:=0) as it WHERE `cpid` = ? AND `times` = ? GROUP BY `aid`) as g ' +
+                'WHERE la.`cpid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order`';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, cpId, times, cpId, times];
+            const result = await this.db.query(sql, sqlParam);
+            const sql2 = 'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `cpid` = ? AND `times` = ? GROUP BY `aid`) as a';
+            const sqlParam2 = [this.tableName, cpId, times];
+            const count = await this.db.queryOne(sql2, sqlParam2);
+            for (const i in result) {
+                result[i].max_sort = count.num;
+            }
+            return result;
+        }
+
+        /**
+         * 获取 当前审核人
+         *
+         * @param {Number} cpId - 变更立项id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<*>}
+         */
+        async getCurAuditor(cpId, times = 1) {
+            const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
+                '  WHERE la.`cpid` = ? and la.`status` = ? and la.`times` = ?';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, auditConst.status.checking, times];
+            return await this.db.queryOne(sql, sqlParam);
+        }
+
+        /**
+         * 获取审核人流程列表
+         *
+         * @param auditorId
+         * @return {Promise<*>}
+         */
+        async getAuditGroupByList(changeId, times) {
+            const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order` ' +
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                '  WHERE la.`cpid` = ? and la.`times` = ? GROUP BY la.`aid` ORDER BY la.`order`';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, changeId, times];
+            return await this.db.query(sql, sqlParam);
+        }
+
+        /**
+         * 移除审核人
+         *
+         * @param {Number} materialId - 材料调差期id
+         * @param {Number} status - 期状态
+         * @param {Number} status - 期次数
+         * @return {Promise<boolean>}
+         */
+        async getAuditorByStatus(cpId, status, times = 1) {
+            let auditor = null;
+            let sql = '';
+            let sqlParam = '';
+            switch (status) {
+                case auditConst.status.checking :
+                case auditConst.status.checked :
+                    sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order` ' +
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
+                        '  WHERE la.`cpid` = ? and la.`status` = ? ' +
+                        '  ORDER BY la.`times` desc, la.`order` desc';
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, status];
+                    auditor = await this.db.queryOne(sql, sqlParam);
+                    break;
+                case auditConst.status.checkNo :
+                    sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order` ' +
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                        '  WHERE la.`cpid` = ? and la.`status` = ? and la.`times` = ?' +
+                        '  ORDER BY la.`times` desc, la.`order` desc';
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, auditConst.status.checkNo, parseInt(times) - 1];
+                    auditor = await this.db.queryOne(sql, sqlParam);
+                    break;
+                case auditConst.status.uncheck :
+                    break;
+                case auditConst.status.back :
+                default:break;
+            }
+            return auditor;
+        }
+
+        /**
+         * 获取审核人流程列表(包括原报)
+         * @param {Number} materialId 调差id
+         * @param {Number} times 审核次数
+         * @return {Promise<Array>} 查询结果集(包括原报)
+         */
+        async getAuditorsWithOwner(cpId, times = 1) {
+            const result = await this.getAuditGroupByList(cpId, times);
+            const sql =
+                'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As cpid, 0 As `order`' +
+                '  FROM ' +
+                this.ctx.service.changeProject.tableName +
+                ' As s' +
+                '  LEFT JOIN ' +
+                this.ctx.service.projectAccount.tableName +
+                ' As pa' +
+                '  ON s.uid = pa.id' +
+                '  WHERE s.id = ?';
+            const sqlParam = [times, cpId, cpId];
+            const user = await this.db.queryOne(sql, sqlParam);
+            result.unshift(user);
+            return result;
+        }
+
+        /**
+         * 新增审核人
+         *
+         * @param {Number} cpId - 立项书id
+         * @param {Number} auditorId - 审核人id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<number>}
+         */
+        async addAuditor(cpId, auditorId, times = 1, is_gdzs = 0) {
+            const transaction = await this.db.beginTransaction();
+            let flag = false;
+            try {
+                let newOrder = await this.getNewOrder(cpId, times);
+                // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
+                newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
+                if (is_gdzs) await this._syncOrderByDelete(transaction, cpId, newOrder, times, '+');
+                const data = {
+                    tid: this.ctx.tender.id,
+                    cpid: cpId,
+                    aid: auditorId,
+                    times,
+                    order: newOrder,
+                    status: auditConst.status.uncheck,
+                };
+                const result = await transaction.insert(this.tableName, data);
+                await transaction.commit();
+                flag = result.effectRows = 1;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+            return flag;
+        }
+
+        /**
+         * 获取 最新审核顺序
+         *
+         * @param {Number} cpId - 立项书id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<number>}
+         */
+        async getNewOrder(cpId, times = 1) {
+            const sql = 'SELECT Max(??) As max_order FROM ?? Where `cpid` = ? and `times` = ?';
+            const sqlParam = ['order', this.tableName, cpId, times];
+            const result = await this.db.queryOne(sql, sqlParam);
+            return result && result.max_order ? result.max_order + 1 : 1;
+        }
+
+        /**
+         * 移除审核人
+         *
+         * @param {Number} cpId - 变更立项书id
+         * @param {Number} auditorId - 审核人id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<boolean>}
+         */
+        async deleteAuditor(cpId, auditorId, times = 1) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const condition = { cpid: cpId, aid: auditorId, times };
+                const auditor = await this.getDataByCondition(condition);
+                if (!auditor) {
+                    throw '该审核人不存在';
+                }
+                await this._syncOrderByDelete(transaction, cpId, auditor.order, times);
+                await transaction.delete(this.tableName, condition);
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+            return true;
+        }
+
+        /**
+         * 移除审核人时,同步其后审核人order
+         * @param transaction - 事务
+         * @param {Number} cpId - 变更立项书id
+         * @param {Number} auditorId - 审核人id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<*>}
+         * @private
+         */
+        async _syncOrderByDelete(transaction, cpId, order, times, selfOperate = '-') {
+            this.initSqlBuilder();
+            this.sqlBuilder.setAndWhere('cpid', {
+                value: cpId,
+                operate: '=',
+            });
+            this.sqlBuilder.setAndWhere('order', {
+                value: order,
+                operate: '>=',
+            });
+            this.sqlBuilder.setAndWhere('times', {
+                value: times,
+                operate: '=',
+            });
+            this.sqlBuilder.setUpdateData('order', {
+                value: 1,
+                selfOperate,
+            });
+            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
+            const data = await transaction.query(sql, sqlParam);
+
+            return data;
+        }
+
+        /**
+         * 开始审批
+         * @param {Number} cpId - 立项书id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<boolean>}
+         */
+        async start(cpId, times = 1) {
+            const audit = await this.getDataByCondition({ cpid: cpId, times, order: 1 });
+            if (!audit) {
+                // if (this.ctx.tender.info.shenpi.material === shenpiConst.sp_status.gdspl) {
+                //     throw '请联系管理员添加审批人';
+                // } else {
+                throw '请先选择审批人,再上报数据';
+                // }
+            }
+
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.update(this.tableName, { id: audit.id, status: auditConst.status.checking, begin_time: new Date() });
+                await transaction.update(this.ctx.service.changeProject.tableName, {
+                    id: cpId, status: auditConst.status.checking,
+                });
+                // 微信模板通知
+                // const materialInfo = await this.ctx.service.material.getDataById(materialId);
+                // const wechatData = {
+                //     qi: materialInfo.order,
+                //     status: wxConst.status.check,
+                //     tips: wxConst.tips.check,
+                //     begin_time: Date.parse(new Date()),
+                //     m_tp: this.ctx.helper.add(this.ctx.helper.round(materialInfo.m_tp, 2), this.ctx.helper.round(materialInfo.ex_tp, 2)),
+                //     hs_m_tp: this.ctx.helper.add(this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2), this.ctx.helper.round(this.ctx.helper.mul(materialInfo.ex_tp, 1+materialInfo.rate/100), 2)),
+                // };
+                // await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.TC, smsTypeConst.judge.approval.toString(), wxConst.template.material, wechatData);
+
+                // todo 更新标段tender状态 ?
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+            return true;
+        }
+
+        /**
+         * 获取审核人需要审核的期列表
+         *
+         * @param auditorId
+         * @return {Promise<*>}
+         */
+        async getAuditChangeProject(auditorId) {
+            const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`cpid`,' +
+                '    m.`status` As `mstatus`, m.`code` As `mcode`,' +
+                '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
+                '  FROM ?? AS ma, ?? AS m, ?? As t ' +
+                '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
+                '    and ma.`cpid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`begin_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.changeProject.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.back, auditConst.status.back];
+            return await this.db.query(sql, sqlParam);
+        }
+
+        /**
+         * 用于添加推送所需的content内容
+         * @param {Number} pid 项目id
+         * @param {Number} tid 台账id
+         * @param {Number} cpId 立项书id
+         * @param {Number} uid 审批人id
+         */
+        async getNoticeContent(pid, tid, cpId, uid) {
+            const noticeSql = 'SELECT * FROM (SELECT ' +
+                '  t.`id` As `tid`, ma.`cpid`, t.`name`, pa.`name` As `su_name`, pa.role As `su_role`' +
+                '  FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
+                '  LEFT JOIN ?? As m On t.`id` = m.`tid` AND m.`id` = ?' +
+                '  LEFT JOIN ?? As ma ON m.`id` = ma.`cpid`' +
+                '  LEFT JOIN ?? As pa ON pa.`id` = ?' +
+                '  WHERE  t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
+            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.changeProject.tableName, cpId, this.tableName, this.ctx.service.projectAccount.tableName, uid, pid];
+            const content = await this.db.query(noticeSql, noticeSqlParam);
+            return content.length ? JSON.stringify(content[0]) : '';
+        }
+
+        /**
+         * 审批
+         * @param {Number} cpId - 立项书id
+         * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
+         * @param {Number} times - 第几次审批
+         * @return {Promise<void>}
+         */
+        async check(cpId, checkData, times = 1) {
+            if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.back) {
+                throw '提交数据错误';
+            }
+            const pid = this.ctx.session.sessionProject.id;
+            switch (checkData.checkType) {
+                case auditConst.status.checked:
+                    await this._checked(pid, cpId, checkData, times);
+                    break;
+                case auditConst.status.back:
+                    await this._back(pid, cpId, checkData, times);
+                    break;
+                case auditConst.status.checkNo:
+                    await this._checkNo(pid, cpId, checkData, times);
+                    break;
+                default:
+                    throw '无效审批操作';
+            }
+        }
+
+        async _checked(pid, cpId, checkData, times) {
+            const time = new Date();
+
+            // 整理当前流程审核人状态更新
+            const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
+            if (!audit) {
+                throw '审核数据错误';
+            }
+
+            // 获取审核人列表
+            const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
+            const sqlParam = [this.tableName, cpId, times];
+            const auditors = await this.db.query(sql, sqlParam);
+
+            const nextAudit = await this.getDataByCondition({ cpid: cpId, times, order: audit.order + 1 });
+
+
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
+
+                // 获取推送必要信息
+                const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid);
+                // 添加推送
+                const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.checked, content: noticeContent }];
+                auditors.forEach(audit => {
+                    records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
+                });
+                await transaction.insert('zh_notice', records);
+
+                // 无下一审核人表示,审核结束
+                if (nextAudit) {
+                    // 流程至下一审批人
+                    await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
+
+                    // 同步 期信息
+                    await transaction.update(this.ctx.service.changeProject.tableName, {
+                        id: cpId, status: auditConst.status.checking,
+                    });
+
+                    // 微信模板通知
+                    // const wechatData = {
+                    //     qi: materialInfo.order,
+                    //     status: wxConst.status.check,
+                    //     tips: wxConst.tips.check,
+                    //     begin_time: Date.parse(begin_audit.begin_time),
+                    //     m_tp: this.ctx.helper.add(this.ctx.helper.round(materialInfo.m_tp, 2), this.ctx.helper.round(materialInfo.ex_tp, 2)),
+                    //     hs_m_tp: this.ctx.helper.add(this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2), this.ctx.helper.round(this.ctx.helper.mul(materialInfo.ex_tp, 1+materialInfo.rate/100), 2)),
+                    // };
+                    // await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.TC, smsTypeConst.judge.approval.toString(), wxConst.template.material, wechatData);
+                } else {
+                    // 本期结束
+                    // 生成截止本期数据 final数据
+                    // 同步 期信息
+                    await transaction.update(this.ctx.service.changeProject.tableName, {
+                        id: cpId, status: checkData.checkType,
+                    });
+
+                    // 微信模板通知
+                    // const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), materialInfo.user_id));
+                    // const wechatData = {
+                    //     qi: materialInfo.order,
+                    //     status: wxConst.status.success,
+                    //     tips: wxConst.tips.success,
+                    //     begin_time: Date.parse(begin_audit.begin_time),
+                    //     m_tp: this.ctx.helper.add(this.ctx.helper.round(materialInfo.m_tp, 2), this.ctx.helper.round(materialInfo.ex_tp, 2)),
+                    //     hs_m_tp: this.ctx.helper.add(this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2), this.ctx.helper.round(this.ctx.helper.mul(materialInfo.ex_tp, 1+materialInfo.rate/100), 2)),
+                    // };
+                    // await this.ctx.helper.sendWechat(users, smsTypeConst.const.TC, smsTypeConst.judge.result.toString(), wxConst.template.material, wechatData);
+                }
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
+        async _back(pid, cpId, checkData, times) {
+            const time = new Date();
+            // 整理当前流程审核人状态更新
+            const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
+            if (!audit) {
+                throw '审核数据错误';
+            }
+            const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
+            const sqlParam = [this.tableName, cpId, times];
+            const auditors = await this.db.query(sql, sqlParam);
+            let order = 1;
+            for (const a of auditors) {
+                a.times = times + 1;
+                a.order = order;
+                a.status = auditConst.status.uncheck;
+                order++;
+            }
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
+                // 添加到消息推送表
+                const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid);
+                const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.back, content: noticeContent }];
+                auditors.forEach(audit => {
+                    records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.back, content: noticeContent });
+                });
+                await transaction.insert(this.ctx.service.noticePush.tableName, records);
+                // 同步期信息
+                await transaction.update(this.ctx.service.changeProject.tableName, {
+                    id: cpId, status: checkData.checkType,
+                    times: times + 1,
+                });
+                // 拷贝新一次审核流程列表
+                await transaction.insert(this.tableName, auditors);
+                // 微信模板通知
+                // const begin_audit = await this.getDataByCondition({
+                //     mid: materialId,
+                //     order: 1,
+                // });
+                // const materialInfo = await this.ctx.service.material.getDataById(materialId);
+                // const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), materialInfo.user_id));
+                // const wechatData = {
+                //     qi: materialInfo.order,
+                //     status: wxConst.status.back,
+                //     tips: wxConst.tips.back,
+                //     begin_time: Date.parse(begin_audit.begin_time),
+                //     m_tp: this.ctx.helper.add(this.ctx.helper.round(materialInfo.m_tp, 2), this.ctx.helper.round(materialInfo.ex_tp, 2)),
+                //     hs_m_tp: this.ctx.helper.add(this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2), this.ctx.helper.round(this.ctx.helper.mul(materialInfo.ex_tp, 1+materialInfo.rate/100), 2)),
+                // };
+                // await this.ctx.helper.sendWechat(users, smsTypeConst.const.TC, smsTypeConst.judge.result.toString(), wxConst.template.material, wechatData);
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
+        async _checkNo(pid, cpId, checkData, times) {
+            const time = new Date();
+
+            // 整理当前流程审核人状态更新
+            const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
+            if (!audit) {
+                throw '审核数据错误';
+            }
+
+            // 获取审核人列表
+            const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
+            const sqlParam = [this.tableName, cpId, times];
+            const auditors = await this.db.query(sql, sqlParam);
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
+
+                // 获取推送必要信息
+                const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid);
+                // 添加推送
+                const records = [{ pid, type: pushType.changeProject, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
+                auditors.forEach(audit => {
+                    records.push({ pid, type: pushType.changeProject, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
+                });
+                await transaction.insert('zh_notice', records);
+                // 本期结束
+                // 生成截止本期数据 final数据
+                // 同步 期信息
+                await transaction.update(this.ctx.service.changeProject.tableName, {
+                    id: cpId, status: checkData.checkType,
+                });
+
+                // 微信模板通知
+                // const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), materialInfo.user_id));
+                // const wechatData = {
+                //     qi: materialInfo.order,
+                //     status: wxConst.status.success,
+                //     tips: wxConst.tips.success,
+                //     begin_time: Date.parse(begin_audit.begin_time),
+                //     m_tp: this.ctx.helper.add(this.ctx.helper.round(materialInfo.m_tp, 2), this.ctx.helper.round(materialInfo.ex_tp, 2)),
+                //     hs_m_tp: this.ctx.helper.add(this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2), this.ctx.helper.round(this.ctx.helper.mul(materialInfo.ex_tp, 1+materialInfo.rate/100), 2)),
+                // };
+                // await this.ctx.helper.sendWechat(users, smsTypeConst.const.TC, smsTypeConst.judge.result.toString(), wxConst.template.material, wechatData);
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
+        /**
+         * 复制上一期的审批人列表给最新一期
+         *
+         * @param transaction - 新增一期的事务
+         * @param {Object} preMaterial - 上一期
+         * @param {Object} newaMaterial - 最新一期
+         * @return {Promise<*>}
+         */
+        async copyPreChangeProjectAuditors(transaction, preChange, newChange) {
+            const auditors = await this.getAuditGroupByList(preChange.id, preChange.times);
+            const newAuditors = [];
+            for (const a of auditors) {
+                const na = {
+                    tid: preChange.tid,
+                    cpid: newChange.id,
+                    aid: a.aid,
+                    times: newChange.times,
+                    order: newAuditors.length + 1,
+                    status: auditConst.status.uncheck,
+                };
+                newAuditors.push(na);
+            }
+            const result = await transaction.insert(this.tableName, newAuditors);
+            return result.affectedRows === auditors.length;
+        }
+    }
+
+    return ChangeProjectAudit;
+};

+ 4 - 0
app/service/tender.js

@@ -111,6 +111,8 @@ module.exports = app => {
                 // 根据用户权限查阅标段
                 // tender 163条数据,project_account 68条数据测试
                 // 查询两张表耗时0.003s,查询tender左连接project_account耗时0.002s
+                const changeProjectSql = this.ctx.session.sessionProject.openChangeProject ? '    OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
+                    '        t.id IN ( SELECT cpa.`tid` FROM ' + this.ctx.service.changeProjectAudit.tableName + ' AS cpa WHERE cpa.`aid` = ' + session.sessionUser.accountId + ' GROUP BY cpa.`tid`))' : '';
                 sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, t.`total_price`, t.`deal_tp`,' +
                     '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
                     // '  FROM ?? As t, ?? As pa ' +
@@ -138,6 +140,8 @@ module.exports = app => {
                     '        t.id IN ( SELECT ma.`tid` FROM ?? AS ma WHERE ma.`aid` = ? GROUP BY ma.`tid`))' +
                     // 参与审批 预付款 的标段
                     '    OR (t.id IN ( SELECT ad.`tid` FROM ?? AS ad WHERE ad.`audit_id` = ? GROUP BY ad.`tid`))' +
+                    // 参与审批 变更立项书 的标段
+                    changeProjectSql +
                     // 游客权限的标段
                     '    OR (t.id IN ( SELECT tt.`tid` FROM ?? AS tt WHERE tt.`user_id` = ?))' +
                     // 未参与,但可见的标段

+ 110 - 0
app/view/change/project.ejs

@@ -0,0 +1,110 @@
+<% include ../tender/tender_sub_menu.ejs %>
+<div class="panel-content">
+    <div class="panel-title">
+        <div class="title-main d-flex">
+            <% include ../tender/tender_sub_mini_menu.ejs %>
+            <div>
+                <div class="d-inline-block">
+                    <div class="btn-group" id="sort-dropdown">
+                        <button type="button" class="btn btn-sm btn-light text-primary dropdown-toggle" data-toggle="dropdown" id="bpaixu">排序:发起时间</button>
+                        <div class="dropdown-menu" aria-labelledby="bpaixu">
+                            <ul class="list-unstyled px-3 mb-0" id="sort-radio">
+                                <li class="mb-2">
+                                    <div class="custom-control custom-radio">
+                                        <input type="radio" class="custom-control-input" id="pai1" name="paizhi" value="time" checked="">
+                                        <label class="custom-control-label" for="pai1">发起时间</label>
+                                    </div>
+                                </li>
+                                <li class="mb-2">
+                                    <div class="custom-control custom-radio">
+                                        <input type="radio" class="custom-control-input" id="pai3" name="paizhi" value="code">
+                                        <label class="custom-control-label" for="pai3">变更立项书编号</label>
+                                    </div>
+                                </li>
+                            </ul>
+                            <ul class="list-unstyled px-3 pt-2 mb-0 border-top" id="order-radio">
+                                <li class="mb-2">
+                                    <div class="custom-control custom-radio">
+                                        <input type="radio" class="custom-control-input" id="pdown" name="paixu" value="desc" checked="">
+                                        <label class="custom-control-label" for="pdown">降序</label>
+                                    </div>
+                                </li>
+                                <li class="mb-2">
+                                    <div class="custom-control custom-radio">
+                                        <input type="radio" class="custom-control-input" id="pup" name="paixu" value="asc">
+                                        <label class="custom-control-label" for="pup">升序</label>
+                                    </div>
+                                </li>
+                            </ul>
+                        </div>
+                    </div>
+                </div>
+                <div class="d-inline-block">
+                    <div class="btn-group">
+                        <button type="button" class="btn btn-sm btn-light text-primary dropdown-toggle" data-toggle="dropdown" id="zhankai"><% if (status !== 0) { %><%- filter.statusString[status] %>(<%- filter.count[status] %>)<% } else { %>全部<% } %></button>
+                        <div class="dropdown-menu" aria-labelledby="zhankai" id="status_select">
+                            <% if (status !== 0) { %><a class="dropdown-item" data-val="0" href="javascript:void(0);">全部</a><% } %>
+                            <% for (const fs in filter.status) { %>
+                                <% const f = filter.status[fs]; %>
+                                <% if (f !== status) { %><a class="dropdown-item" data-val="<%- f %>" href="javascript:void(0);"><%- filter.statusString[f] %>(<%- filter.count[f] %>)</a><% } %>
+                            <% } %>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <% if (tender.user_id === uid || (userPermission !== null && userPermission.tender !== undefined && userPermission.tender.indexOf('5') !== -1)) { %>
+            <div class="ml-auto">
+                <a href="#add-bj" data-toggle="modal" data-target="#add-bj" class="btn btn-sm btn-primary pull-right ml-1">新建变更立项</a>
+                <a href="#setting" data-toggle="modal" data-target="#setting" class="btn btn-sm btn-outline-primary pull-right ml-1"><i class="fa fa-cog"></i></a>
+            </div>
+            <% } %>
+        </div>
+    </div>
+    <div class="content-wrap">
+        <div class="c-body">
+            <div class="sjs-height-0">
+                <table class="table table-bordered">
+                    <thead>
+                    <tr>
+                        <th width="20%" id="sort_change">变更立项书编号</th><th width="30%">变更立项书名称</th>
+                        <th width="10%">发起人</th><th width="10%">发起类型</th><th width="10%">发起时间</th>
+                        <th width="10%">状态</th><th width="10%">操作</th>
+                    </tr>
+                    </thead>
+                    <tbody id="changeList">
+                    <% for (const c of changes) { %>
+                        <tr><td><a href="/tender/<%- tender.id %>/change/project/<%- c.id %>/information"><%- c.code %></a></td>
+                            <td><%- c.name %></td><td><%- c.account_name %></td><td><%- changeConst.project_type[c.type] %></td><td><%- ctx.helper.formatFullDate(c.in_time) %></td>
+                            <td><span class="<%- auditConst.statusClass[c.status] %>"><%- auditConst.statusString[c.status] %></span></td>
+                            <td>
+                                <% if ((c.status === auditConst.status.uncheck || c.status === auditConst.status.back) && c.uid === ctx.session.sessionUser.accountId) { %>
+                                    <a href="/tender/<%- tender.id %>/change/project/<%- c.id %>/information" class="btn <%- auditConst.statusButtonClass[c.status] %> btn-sm"><%- auditConst.statusButton[c.status] %></a>
+                                <% } else if (c.status === auditConst.status.checking && c.curAuditor && c.curAuditor.aid === ctx.session.sessionUser.accountId) { %>
+                                    <a href="/tender/<%- tender.id %>/change/project/<%- c.id %>/information" class="btn <%- auditConst.statusButtonClass[c.status] %> btn-sm"><%- auditConst.statusButton[c.status] %></a>
+                                <% } %>
+                                <% if (c.uid === uid && (c.status === auditConst.status.uncheck || c.status === auditConst.status.back)) { %><a href="#del-bg" data-toggle="modal" data-target="#del-bg" class="btn btn-outline-danger btn-sm">删除</a><% } %>
+                            </td></tr>
+                    <% } %>
+                    <!--<tr><td><a href="biangeng-lixiang-detail.html">BGYX-TJ01-001</a></td><td>关于XX</td><td>仁温书</td><td>变更意向</td><td>2021-10-7</td><td>草稿</td><td><a href="#del-bg" data-toggle="modal" data-target="#del-bg" class="btn btn-outline-danger btn-sm">删除</a></td></tr>-->
+                    <!--<tr><td><a href="#">BGJY-TJ01-002</a></td><td>关于XX</td><td>张云铭</td><td>变更建议</td><td>2021-9-18</td><td><span class="text-success">已同意</span></td><td></td></tr>-->
+                    <!--<tr><td><a href="#">BGJY-TJ01-003</a></td><td>关于XX</td><td>张云铭</td><td>变更建议</td><td>2021-9-18</td><td><span class="text-danger">不同意</span></td><td></td></tr>-->
+                    </tbody>
+                </table>
+                <!--翻页-->
+                <% include ../layout/page.ejs %>
+            </div>
+        </div>
+    </div>
+</div>
+<script>
+    autoFlashHeight();
+    const tenderId = parseInt('<%- tender.id %>');
+    const tenderName = JSON.parse(unescape('<%- escape(JSON.stringify(tender.name)) %>'));
+    const dealCode = JSON.parse(unescape('<%- escape(JSON.stringify(dealCode)) %>'));
+    const ruleConst = JSON.parse(unescape('<%- escape(JSON.stringify(ruleConst)) %>'));
+    let codeRule = JSON.parse(unescape('<%- escape(JSON.stringify(codeRule)) %>'));
+    let connectorRule = '<%- c_connector %>';
+    const cRuleFirst = parseInt('<%- c_rule_first %>');
+    const ruleType = parseInt('<%- ruleType %>');
+    const rulesType = '<%- rule_type %>';
+</script>

+ 135 - 0
app/view/change/project_information.ejs

@@ -0,0 +1,135 @@
+<% include ../tender/tender_sub_menu.ejs %>
+<div class="panel-content">
+    <div class="panel-title"><!--收起详解目录添加类名 fluid -->
+        <div class="title-main d-flex"><!--工具-->
+            <% include ../tender/tender_sub_mini_menu.ejs %>
+            <div>
+                <div class="d-inline-block">
+                    <a href="/tender/<%- tender.id %>/change/project"><i class="fa fa-chevron-left mr-2"></i><span>返回</span></a>
+                </div>
+                <div class="d-inline-block" id="change-project-code">
+                    <%- change.code %>
+                </div>
+            </div>
+            <div class="ml-auto" id="sp-btn">
+                <% if (ctx.change.status === auditConst.status.uncheck) { %>
+                    <% if (ctx.session.sessionUser.accountId === ctx.change.uid) { %>
+                        <a id="sub-sp-btn" href="javascript: void(0);" data-toggle="modal" data-target="#sub-sp" class="btn btn-primary btn-sm">上报审批</a>
+                    <% } else { %>
+                        <a id="sub-sp-btn" href="javascript: void(0);" data-toggle="modal" data-target="#sub-sp" class="btn btn-outline-secondary btn-sm">上报中</a>
+                    <% } %>
+                <% } else if (ctx.change.status === auditConst.status.checking) { %>
+                    <% if (ctx.change.curAuditor && ctx.change.curAuditor.aid === ctx.session.sessionUser.accountId) { %>
+                        <a href="#stop" data-toggle="modal" data-target="#stop" class="btn btn-sm btn-danger mr-2">终止</a>
+                        <a id="sp-done-btn" href="javascript: void(0);" data-toggle="modal" data-target="#sp-done" class="btn btn-success btn-sm">审批通过</a>
+                        <a href="#sp-back" data-toggle="modal" data-target="#sp-back" class="btn btn-warning btn-sm">审批退回</a>
+                    <% } else { %>
+                        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-secondary btn-sm">审批中</a>
+                    <% } %>
+                <% } else if (ctx.change.status === auditConst.status.checked) { %>
+                    <a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-secondary btn-sm">审批完成</a>
+                <% } else if (ctx.change.status === auditConst.status.back) { %>
+                    <a href="#sp-list"  data-type="hide" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-warning btn-sm text-muted sp-list-btn">审批退回</a>
+                    <% if (ctx.session.sessionUser.accountId === ctx.change.uid) { %>
+                        <a href="#sp-list" data-type="show" data-toggle="modal" data-target="#sp-list"  class="btn btn-primary btn-sm sp-list-btn">重新上报</a>
+                    <% } %>
+                <% } else if (ctx.change.status === auditConst.status.checkNo) { %>
+                    <a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-danger btn-sm">审批终止</a>
+                <% } %>
+            </div>
+        </div>
+    </div>
+    <div class="content-wrap">
+        <div class="c-body">
+            <div class="sjs-height-0">
+                <div class="col-xl-8 mx-auto">
+                    <h4 class="text-center py-2">变更建议/意向报告书</h4>
+                    <table class="table table-bordered" id="project-table">
+                        <tr>
+                            <th width="120" class="text-center">立项编号<b class="text-danger">*&nbsp;</b></th>
+                            <td><input class="form-control form-control-sm" value="<%- change.code %>" data-name="code" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center">变更工程名称<b class="text-danger">*&nbsp;</b></th>
+                            <td colspan="3"><input class="form-control form-control-sm" value="<%- change.name %>" data-name="name" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center">原设计图名称</th>
+                            <td  colspan="3"><input class="form-control form-control-sm" value="<%- change.org_name %>" data-name="org_name" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center">桩号</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.peg %>" data-name="peg" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                            <th width="120" class="text-center">图号</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.new_code %>" data-name="new_code" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center">工程变更类别</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.class %>" data-name="class" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                            <th width="120" class="text-center">工程变更性质</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.quality %>" data-name="quality" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center">原工程造价(元)</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.org_price %>" data-name="org_price" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center">预计变更造价(元)</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.change_price %>" data-name="change_price" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                            <th width="120" class="text-center">预计造价增减(元)</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.crease_price %>" data-name="crease_price" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center">变更原因<b class="text-danger">*&nbsp;</b></th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" id="exampleFormControlTextarea1" data-name="reason" <% if (change.readOnly) { %>readonly<% } %> rows="3"><%- change.reason %></textarea></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center">内容摘要</th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" id="exampleFormControlTextarea1" data-name="content" <% if (change.readOnly) { %>readonly<% } %> rows="3"><%- change.content %></textarea></td>
+                        </tr>
+                    </table>
+                    <table class="table table-bordered">
+                        <thead>
+                        <tr>
+                            <th></th>
+                            <th>附件</th>
+                            <th>上传者</th>
+                            <th>上传时间</th>
+                            <th>操作</th>
+                        </tr>
+                        </thead>
+                        <tbody>
+                        <!--<tr>-->
+                            <!--<td colspan="5"><button type="button" class="btn btn-primary btn-sm"  data-toggle="modal" data-target="#upload-fj">上传附件</button></td>-->
+                        <!--</tr>-->
+                        <tbody id="file-content">
+                        </tbody>
+                        <!--<tr>-->
+                            <!--<td>1</td>-->
+                            <!--<td>XXX设计图纸</td>-->
+                            <!--<td>仁温书</td>-->
+                            <!--<td>2021-12-09 16:58:47</td>-->
+                            <!--<td><a href="#" class="mr-2"><i class="fa fa-download"></i></a><a href="#" class="text-danger"><i class="fa fa-remove"></i></a></td>-->
+                        <!--</tr>-->
+                        <!--<tr>-->
+                            <!--<td>1</td>-->
+                            <!--<td>XXX资料说明</td>-->
+                            <!--<td>仁温书</td>-->
+                            <!--<td>2021-12-09 16:58:47</td>-->
+                            <!--<td><a href="#" class="mr-2"><i class="fa fa-download"></i></a><a href="#" class="text-danger"><i class="fa fa-remove"></i></a></td>-->
+                        <!--</tr>-->
+                        </tbody>
+                    </table>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script>
+    autoFlashHeight();
+    const auditConst = JSON.parse('<%- JSON.stringify(auditConst) %>');
+    const fileList = JSON.parse(unescape('<%- escape(JSON.stringify(fileList)) %>')) || [];
+    const whiteList = JSON.parse('<%- JSON.stringify(whiteList) %>');
+    const preUrl = '<%- preUrl %>';
+    const change = JSON.parse(unescape('<%- escape(JSON.stringify(change)) %>'));
+</script>

+ 765 - 0
app/view/change/project_information_modal.ejs

@@ -0,0 +1,765 @@
+<!--添加附件-->
+<div class="modal fade" id="addfujian">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title" id="myModalLabel">上传附件</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <p>大小限制:30MB,支持office等文档格式、图片格式、压缩包格式</p>
+                <!-- <p><a href="javascript: void(0);" class="btn btn-primary" id="file-modal-target">选择文件</a></p> -->
+                <input type="file" id="file-modal" multiple="multiple">
+            </div>
+            <div class="modal-footer">
+                <button id="file-cancel" type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <button id="file-ok" type="button" class="btn btn-primary">添加</button>
+            </div>
+        </div>
+    </div>
+</div>
+<% if ((ctx.change.status === auditConst.status.uncheck || ctx.change.status === auditConst.status.back) && (ctx.session.sessionUser.accountId === ctx.change.uid || ctx.tender.isTourist)) { %>
+    <!--上报审批-->
+    <div class="modal fade" id="sub-sp" data-backdrop="static">
+        <div class="modal-dialog" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">上报审批</h5>
+                </div>
+                <div class="modal-body">
+                    <div class="dropdown text-right">
+                            <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button"
+                                    id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true"
+                                    aria-expanded="false">
+                                添加审批流程
+                            </button>
+                            <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton"
+                                 style="width:220px">
+                                <div class="mb-2 p-2"><input class="form-control form-control-sm"
+                                                             placeholder="姓名/手机 检索" id="gr-search" autocomplete="off"></div>
+                                <dl class="list-unstyled book-list">
+                                    <% accountGroup.forEach((group, idx) => { %>
+                                        <dt><a href="javascript: void(0);" class="acc-btn" data-groupid="<%- idx %>" data-type="hide"><i class="fa fa-plus-square"></i></a> <%- group.groupName %></dt>
+                                        <div class="dd-content" data-toggleid="<%- idx %>">
+                                            <% group.groupList.forEach(item => { %>
+                                                <% if (item.id !== ctx.session.sessionUser.accountId) { %>
+                                                    <dd class="border-bottom p-2 mb-0 " data-id="<%- item.id %>" >
+                                                        <p class="mb-0 d-flex"><span class="text-primary"><%- item.name %></span><span
+                                                                    class="ml-auto"><%- item.mobile %></span></p>
+                                                        <span class="text-muted"><%- item.role %></span>
+                                                    </dd>
+                                                <% } %>
+                                            <% });%>
+                                        </div>
+                                    <% }) %>
+                                </dl>
+                            </div>
+                    </div>
+                    <div class="card mt-3">
+                        <div class="card-header">
+                            审批流程
+                        </div>
+                        <div class="modal-height-500" style="overflow: auto">
+                            <ul class="list-group list-group-flush" id="auditors">
+                                <% for (let i = 0, iLen = ctx.change.auditorList.length; i < iLen; i++) { %>
+                                    <li class="list-group-item" auditorId="<%- ctx.change.auditorList[i].aid %>">
+                                        <% if (ctx.session.sessionUser.accountId === ctx.change.uid && !ctx.tender.isTourist) { %>
+                                            <a href="javascript: void(0)" class="text-danger pull-right">移除</a>
+                                        <% } %>
+                                        <span><%- ctx.change.auditorList[i].order %> <%- ctx.change.auditorList[i].name %></span>
+                                        <small class="text-muted"><%- ctx.change.auditorList[i].role %></small>
+                                    </li>
+                                <% } %>
+                            </ul>
+                        </div>
+                    </div>
+                </div>
+                <form class="modal-footer" method="post" action="<%- preUrl %>/audit/start" onsubmit="return checkAuditorFrom()">
+                    <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                    <% if (ctx.session.sessionUser.accountId === ctx.change.uid) { %>
+                        <button class="btn btn-primary btn-sm" type="submit">确认上报</button>
+                    <% } %>
+                </form>
+            </div>
+        </div>
+    </div>
+<% } %>
+
+<!--审批流程/结果-->
+<div class="modal fade" id="sp-list" data-backdrop="static">
+    <div class="modal-dialog modal-lg" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title"><%- ctx.change.status === auditConst.status.checking ? '审批流程' : '重新上报' %></h5>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <div class="col-4">
+                        <% if(ctx.change.status === auditConst.status.back) { %>
+                            <a class="sp-list-item" href="#sub-sp" data-toggle="modal" data-target="#sub-sp" id="hideSp">修改审批流程</a>
+                        <% } %>
+                        <div class="card mt-3">
+                            <ul class="list-group list-group-flush" id="auditors-list">
+                                <% ctx.change.auditors2.forEach((item, idx) => { %>
+                                    <% if (idx === 0) { %>
+                                        <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                            <i class="fa fa fa-play-circle fa-rotate-90"></i> <%- item.name %>
+                                            <small class="text-muted"><%- item.role %></small>
+                                            <span class="pull-right">原报</span>
+                                        </li>
+                                    <% } else if(idx === ctx.change.auditors2.length -1 && idx !== 0) { %>
+                                        <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                            <i class="fa fa fa-stop-circle"></i> <%- item.name %>
+                                            <small class="text-muted"><%- item.role %></small>
+                                            <span class="pull-right">终审</span>
+                                        </li>
+                                    <% } else {%>
+                                        <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                            <i class="fa fa-chevron-circle-down"></i> <%- item.name %>
+                                            <small class="text-muted"><%- item.role %></small>
+                                            <span class="pull-right"><%= ctx.helper.transFormToChinese(idx) %>审</span>
+                                        </li>
+                                    <% } %>
+                                <% }) %>
+                            </ul>
+                        </div>
+                    </div>
+                    <div class="col-8 modal-height-500" style="overflow: auto">
+                        <% ctx.change.auditHistory.forEach((auditors, idx) => { %>
+                            <!-- 展开/收起历史流程 -->
+                            <% if(idx === ctx.change.auditHistory.length - 1 && ctx.change.auditHistory.length !== 1) { %>
+                                <div class="text-right">
+                                    <a href="javascript: void(0);" id="fold-btn" data-target="show">展开历史审批流程</a>
+                                </div>
+                            <% } %>
+                            <div class="<%- idx < ctx.change.auditHistory.length - 1 ? 'fold-card' : '' %>">
+                                <div class="text-center text-muted"><%- idx+1 %>#</div>
+                                <ul class="timeline-list list-unstyled mt-2">
+                                    <% auditors.forEach((auditor, index) => { %>
+                                        <% if (index === 0) { %>
+                                            <li class="timeline-list-item pb-2">
+                                                <div class="timeline-item-date">
+                                                    <%- ctx.helper.formatDate(auditor.begin_time) %>
+                                                </div>
+                                                <div class="timeline-item-tail"></div>
+                                                <div class="timeline-item-icon bg-success text-light">
+                                                    <i class="fa fa-caret-down"></i>
+                                                </div>
+                                                <div class="timeline-item-content">
+                                                    <div class="card">
+                                                        <div class="card-body p-3">
+                                                            <div class="card-text">
+                                                                <p class="mb-1"><span
+                                                                            class="h5"><%- ctx.change.user.name %></span><span
+                                                                            class="pull-right text-success"><%- idx !== 0 ? '重新' : '' %>上报审批</span>
+                                                                </p>
+                                                                <p class="text-muted mb-0"><%- ctx.change.user.role %></p>
+                                                            </div>
+                                                        </div>
+                                                    </div>
+                                                </div>
+                                            </li>
+                                            <li class="timeline-list-item pb-2">
+                                                <div class="timeline-item-date">
+                                                    <%- ctx.helper.formatDate(auditor.end_time) %>
+                                                </div>
+                                                <% if(index < auditors.length - 1) { %>
+                                                    <div class="timeline-item-tail"></div>
+                                                <% } %>
+                                                <% if(auditor.status === auditConst.status.checked) { %>
+                                                    <div class="timeline-item-icon bg-success text-light">
+                                                        <i class="fa fa-check"></i>
+                                                    </div>
+                                                <% } else if(auditor.status === auditConst.status.back) {%>
+                                                    <div class="timeline-item-icon bg-warning text-light">
+                                                        <i class="fa fa-level-up"></i>
+                                                    </div>
+                                                <% } else if(auditor.status === auditConst.status.checking) { %>
+                                                    <div class="timeline-item-icon bg-warning text-light">
+                                                        <i class="fa fa-ellipsis-h"></i>
+                                                    </div>
+                                                <% } else if(auditor.status === auditConst.status.checkNo) { %>
+                                                    <div class="timeline-item-icon bg-danger text-light">
+                                                        <i class="fa fa-ellipsis-h"></i>
+                                                    </div>
+                                                <% } else {%>
+                                                    <div class="timeline-item-icon bg-secondary text-light">
+                                                    </div>
+                                                <% } %>
+                                                <div class="timeline-item-content">
+                                                    <div class="card">
+                                                        <div class="card-body p-3">
+                                                            <div class="card-text">
+                                                                <p class="mb-1"><span class="h5"><%- auditor.name %></span><span
+                                                                            class="pull-right <%- auditConst.statusClass[auditor.status] %>"><%- auditConst.statusString[auditor.status] %></span>
+                                                                </p>
+                                                                <p class="text-muted mb-0"><%- auditor.role %></p>
+                                                            </div>
+                                                        </div>
+
+                                                        <!--审批意见-->
+                                                        <% if (auditor.opinion) { %>
+                                                            <div class="card-body p-3 border-top">
+                                                                <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                            </div>
+                                                        <% } %>
+                                                    </div>
+                                                </div>
+                                            </li>
+                                        <% } else {%>
+                                            <li class="timeline-list-item pb-2">
+                                                <div class="timeline-item-date">
+                                                    <%- ctx.helper.formatDate(auditor.end_time) %>
+                                                </div>
+                                                <% if(index < auditors.length - 1) { %>
+                                                    <div class="timeline-item-tail"></div>
+                                                <% } %>
+                                                <% if(auditor.status === auditConst.status.checked) { %>
+                                                    <div class="timeline-item-icon bg-success text-light">
+                                                        <i class="fa fa-check"></i>
+                                                    </div>
+                                                <% } else if(auditor.status === auditConst.status.back) {%>
+                                                    <div class="timeline-item-icon bg-warning text-light">
+                                                        <i class="fa fa-level-up"></i>
+                                                    </div>
+                                                <% } else if(auditor.status === auditConst.status.checking) { %>
+                                                    <div class="timeline-item-icon bg-warning text-light">
+                                                        <i class="fa fa-ellipsis-h"></i>
+                                                    </div>
+                                                <% } else if(auditor.status === auditConst.status.checkNo) { %>
+                                                    <div class="timeline-item-icon bg-danger text-light">
+                                                        <i class="fa fa-ellipsis-h"></i>
+                                                    </div>
+                                                <% } else { %>
+                                                    <div class="timeline-item-icon bg-secondary text-light">
+                                                    </div>
+                                                <% } %>
+                                                <div class="timeline-item-content">
+                                                    <div class="card">
+                                                        <div class="card-body p-3">
+                                                            <div class="card-text">
+                                                                <p class="mb-1"><span class="h5"><%- auditor.name %></span>
+                                                                    <span
+                                                                            class="pull-right
+                                                                            <%- auditConst.statusClass[auditor.status] %>"><%- auditor.status !== auditConst.status.uncheck ? auditConst.statusString[auditor.status] : ''%>
+                                                                        <%- auditor.status === auditConst.status.back ? ctx.change.user.name : '' %>
+                                                        </span>
+                                                                </p>
+                                                                <p class="text-muted mb-0"><%- auditor.role %></p>
+                                                            </div>
+                                                        </div>
+                                                        <!--审批意见-->
+                                                        <% if (auditor.opinion) { %>
+                                                            <div class="card-body p-3 border-top">
+                                                                <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                            </div>
+                                                        <% } %>
+                                                    </div>
+                                                </div>
+                                            </li>
+                                        <% } %>
+                                    <% }) %>
+                                </ul>
+                            </div>
+
+                        <% }) %>
+                    </div>
+                </div>
+            </div>
+            <form class="modal-footer" method="post" action="<%- preUrl %>/audit/start" onsubmit="return checkAuditorFrom()">
+                <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                <% if(ctx.change.status === auditConst.status.back && ctx.session.sessionUser.accountId === ctx.change.uid) { %>
+                    <button class="btn btn-primary btn-sm sp-list-item" type="submit">确认上报</button>
+                <% } %>
+            </form>
+        </div>
+    </div>
+</div>
+<% if (ctx.change.status === auditConst.status.checking) { %>
+    <% if (ctx.change.curAuditor && ctx.change.curAuditor.aid === ctx.session.sessionUser.accountId) { %>
+        <!--审批通过-->
+        <div class="modal fade sp-location-list" id="sp-done" data-backdrop="static">
+            <div class="modal-dialog modal-lg" role="document">
+                <form class="modal-content" action="<%- preUrl %>/audit/check" method="post" onsubmit="return auditCheck(0);">
+                    <div class="modal-header">
+                        <h5 class="modal-title">审批通过</h5>
+                    </div>
+                    <div class="modal-body">
+                        <div class="row">
+                            <div class="col-4">
+                                <div class="card mt-3">
+                                    <ul class="list-group list-group-flush">
+                                        <% ctx.change.auditors2.forEach((item, idx) => { %>
+                                            <% if (idx === 0) { %>
+                                                <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                                    <i class="fa fa fa-play-circle fa-rotate-90"></i> <%- item.name %>
+                                                    <small class="text-muted"><%- item.role %></small>
+                                                    <span class="pull-right">原报</span>
+                                                </li>
+                                            <% } else if(idx === ctx.change.auditors2.length -1 && idx !== 0) { %>
+                                                <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                                    <i class="fa fa fa-stop-circle"></i> <%- item.name %>
+                                                    <small class="text-muted"><%- item.role %></small>
+                                                    <span class="pull-right">终审</span>
+                                                </li>
+                                            <% } else {%>
+                                                <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                                    <i class="fa fa-chevron-circle-down"></i> <%- item.name %>
+                                                    <small class="text-muted"><%- item.role %></small>
+                                                    <span class="pull-right"><%= ctx.helper.transFormToChinese(idx) %>审</span>
+                                                </li>
+                                            <% } %>
+                                        <% }) %>
+                                    </ul>
+                                </div>
+                            </div>
+                            <div class="col-8 modal-height-500" style="overflow: auto">
+                                <% ctx.change.auditHistory.forEach((auditors, idx) => { %>
+                                    <!-- 展开/收起历史流程 -->
+                                    <% if(idx === ctx.change.auditHistory.length - 1 && ctx.change.auditHistory.length !== 1) { %>
+                                        <div class="text-right">
+                                            <a href="javascript: void(0);" id="fold-btn" data-target="show">展开历史审批流程</a>
+                                        </div>
+                                    <% } %>
+                                    <div class="<%- idx < ctx.change.auditHistory.length - 1 ? 'fold-card' : '' %>">
+                                        <div class="text-center text-muted"><%- idx+1 %>#</div>
+                                        <ul class="timeline-list list-unstyled mt-2">
+                                            <% auditors.forEach((auditor, index) => { %>
+                                                <% if (index === 0) { %>
+                                                    <li class="timeline-list-item pb-2">
+                                                        <div class="timeline-item-date">
+                                                            <%- ctx.helper.formatDate(auditor.begin_time) %>
+                                                        </div>
+                                                        <div class="timeline-item-tail"></div>
+                                                        <div class="timeline-item-icon bg-success text-light">
+                                                            <i class="fa fa-caret-down"></i>
+                                                        </div>
+                                                        <div class="timeline-item-content">
+                                                            <div class="card">
+                                                                <div class="card-body p-3">
+                                                                    <div class="card-text">
+                                                                        <p class="mb-1"><span
+                                                                                    class="h5"><%- ctx.change.user.name %></span><span
+                                                                                    class="pull-right text-success"><%- idx !== 0 ? '重新' : '' %>上报审批</span>
+                                                                        </p>
+                                                                        <p class="text-muted mb-0"><%- ctx.change.user.role %></p>
+                                                                    </div>
+                                                                </div>
+                                                            </div>
+                                                        </div>
+                                                    </li>
+                                                    <li class="timeline-list-item pb-2">
+                                                        <div class="timeline-item-date">
+                                                            <%- ctx.helper.formatDate(auditor.end_time) %>
+                                                        </div>
+                                                        <% if(index < auditors.length - 1) { %>
+                                                            <div class="timeline-item-tail"></div>
+                                                        <% } %>
+                                                        <% if(auditor.status === auditConst.status.checked) { %>
+                                                            <div class="timeline-item-icon bg-success text-light">
+                                                                <i class="fa fa-check"></i>
+                                                            </div>
+                                                        <% } else if(auditor.status === auditConst.status.back) {%>
+                                                            <div class="timeline-item-icon bg-warning text-light">
+                                                                <i class="fa fa-level-up"></i>
+                                                            </div>
+                                                        <% } else if(auditor.status === auditConst.status.checking) { %>
+                                                            <div class="timeline-item-icon bg-warning text-light">
+                                                                <i class="fa fa-ellipsis-h"></i>
+                                                            </div>
+                                                        <% } else {%>
+                                                            <div class="timeline-item-icon bg-secondary text-light">
+                                                            </div>
+                                                        <% } %>
+                                                        <div class="timeline-item-content">
+                                                            <div class="card">
+                                                                <div class="card-body p-3">
+                                                                    <div class="card-text">
+                                                                        <p class="mb-1"><span class="h5"><%- auditor.name %></span><span
+                                                                                    class="pull-right <%- auditConst.statusClass[auditor.status] %>"><%- auditConst.statusString[auditor.status] %></span>
+                                                                        </p>
+                                                                        <p class="text-muted mb-0"><%- auditor.role %></p>
+                                                                    </div>
+                                                                </div>
+                                                                <!--审批意见-->
+                                                                <% if(auditor.status !== auditConst.status.uncheck) { %>
+                                                                    <div class="card-body p-3 border-top">
+                                                                        <% if (ctx.change.times === idx + 1 && auditor.status === auditConst.status.checking) { %>
+                                                                            <label>审批意见<b class="text-danger">*</b></label>
+                                                                            <textarea class="form-control form-control-sm"
+                                                                                      name="opinion">同意</textarea>
+                                                                        <% } else { %>
+                                                                            <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                                        <% } %>
+                                                                    </div>
+                                                                <% } %>
+                                                            </div>
+                                                        </div>
+                                                    </li>
+                                                <% } else {%>
+                                                    <li class="timeline-list-item pb-2">
+                                                        <div class="timeline-item-date">
+                                                            <%- ctx.helper.formatDate(auditor.end_time) %>
+                                                        </div>
+                                                        <% if(index < auditors.length - 1) { %>
+                                                            <div class="timeline-item-tail"></div>
+                                                        <% } %>
+                                                        <% if(auditor.status === auditConst.status.checked) { %>
+                                                            <div class="timeline-item-icon bg-success text-light">
+                                                                <i class="fa fa-check"></i>
+                                                            </div>
+                                                        <% } else if(auditor.status === auditConst.status.back) {%>
+                                                            <div class="timeline-item-icon bg-warning text-light">
+                                                                <i class="fa fa-level-up"></i>
+                                                            </div>
+                                                        <% } else if(auditor.status === auditConst.status.checking) { %>
+                                                            <div class="timeline-item-icon bg-warning text-light">
+                                                                <i class="fa fa-ellipsis-h"></i>
+                                                            </div>
+                                                        <% } else { %>
+                                                            <div class="timeline-item-icon bg-secondary text-light">
+                                                            </div>
+                                                        <% } %>
+                                                        <div class="timeline-item-content">
+                                                            <div class="card">
+                                                                <div class="card-body p-3">
+                                                                    <div class="card-text">
+                                                                        <p class="mb-1"><span class="h5"><%- auditor.name %></span>
+                                                                            <span
+                                                                                    class="pull-right
+                                                                                    <%- auditConst.statusClass[auditor.status] %>"><%- auditor.status !== auditConst.status.uncheck ? auditConst.statusString[auditor.status] : ''%>
+                                                                                <%- auditor.status === auditConst.status.back ? ctx.change.user.name : '' %>
+                                                                </span>
+                                                                        </p>
+                                                                        <p class="text-muted mb-0"><%- auditor.role %></p>
+                                                                    </div>
+                                                                </div>
+                                                                <!--审批意见-->
+                                                                <% if(auditor.status !== auditConst.status.uncheck) { %>
+                                                                    <div class="card-body p-3 border-top">
+                                                                        <% if (ctx.change.times === idx + 1 && auditor.status === auditConst.status.checking) { %>
+                                                                            <label>审批意见<b class="text-danger">*</b></label>
+                                                                            <textarea class="form-control form-control-sm"
+                                                                                      name="opinion">同意</textarea>
+                                                                        <% } else { %>
+                                                                            <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                                        <% } %>
+                                                                    </div>
+                                                                <% } %>
+                                                            </div>
+                                                        </div>
+                                                    </li>
+                                                <% } %>
+                                            <% }) %>
+                                        </ul>
+                                    </div>
+                                <% }) %>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                        <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
+                        <input type="hidden" name="checkType" value="<%= auditConst.status.checked %>" />
+                        <button type="submit" class="btn btn-success btn-sm">确认通过</button>
+                    </div>
+                </form>
+            </div>
+        </div>
+        <!--审批退回-->
+        <div class="modal fade sp-location-list" id="sp-back" data-backdrop="static">
+            <div class="modal-dialog modal-lg" role="document">
+                <form class="modal-content modal-lg" action="<%- preUrl %>/audit/check" method="post"
+                      onsubmit="return auditCheck(1);">
+                    <div class="modal-header">
+                        <h5 class="modal-title">审批退回</h5>
+                    </div>
+                    <div class="modal-body">
+                        <div class="row">
+                            <div class="col-4">
+                                <div class="card mt-3">
+                                    <ul class="list-group list-group-flush">
+                                        <% ctx.change.auditors2.forEach((item, idx) => { %>
+                                            <% if (idx === 0) { %>
+                                                <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                                    <i class="fa fa fa-play-circle fa-rotate-90"></i> <%- item.name %>
+                                                    <small class="text-muted"><%- item.role %></small>
+                                                    <span class="pull-right">原报</span>
+                                                </li>
+                                            <% } else if(idx === ctx.change.auditors2.length -1 && idx !== 0) { %>
+                                                <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                                    <i class="fa fa fa-stop-circle"></i> <%- item.name %>
+                                                    <small class="text-muted"><%- item.role %></small>
+                                                    <span class="pull-right">终审</span>
+                                                </li>
+                                            <% } else {%>
+                                                <li class="list-group-item" data-auditorId="<%- item.aid %>">
+                                                    <i class="fa fa-chevron-circle-down"></i> <%- item.name %>
+                                                    <small class="text-muted"><%- item.role %></small>
+                                                    <span class="pull-right"><%= ctx.helper.transFormToChinese(idx) %>审</span>
+                                                </li>
+                                            <% } %>
+                                        <% }) %>
+                                    </ul>
+                                </div>
+                            </div>
+                            <div class="col-8 modal-height-500" style="overflow: auto">
+                                <% ctx.change.auditHistory.forEach((auditors, idx) => { %>
+                                    <!-- 展开/收起历史流程 -->
+                                    <% if(idx === ctx.change.auditHistory.length - 1 && ctx.change.auditHistory.length !== 1) { %>
+                                        <div class="text-right">
+                                            <a href="javascript: void(0);" id="fold-btn" data-target="show">展开历史审批流程</a>
+                                        </div>
+                                    <% } %>
+                                    <div class="<%- idx < ctx.change.auditHistory.length - 1 ? 'fold-card' : '' %>">
+                                        <div class="text-center text-muted"><%- idx+1 %>#</div>
+                                        <ul class="timeline-list list-unstyled mt-2">
+                                            <% auditors.forEach((auditor, index) => { %>
+                                                <% if (index === 0) { %>
+                                                    <li class="timeline-list-item pb-2">
+                                                        <div class="timeline-item-date">
+                                                            <%- ctx.helper.formatDate(auditor.begin_time) %>
+                                                        </div>
+                                                        <div class="timeline-item-tail"></div>
+                                                        <div class="timeline-item-icon bg-success text-light">
+                                                            <i class="fa fa-caret-down"></i>
+                                                        </div>
+                                                        <div class="timeline-item-content">
+                                                            <div class="card">
+                                                                <div class="card-body p-3">
+                                                                    <div class="card-text">
+                                                                        <p class="mb-1"><span
+                                                                                    class="h5"><%- ctx.change.user.name %></span><span
+                                                                                    class="pull-right text-success"><%- idx !== 0 ? '重新' : '' %>上报审批</span>
+                                                                        </p>
+                                                                        <p class="text-muted mb-0"><%- ctx.change.user.role %></p>
+                                                                    </div>
+                                                                </div>
+                                                            </div>
+                                                        </div>
+                                                    </li>
+                                                    <li class="timeline-list-item pb-2">
+                                                        <div class="timeline-item-date">
+                                                            <%- ctx.helper.formatDate(auditor.end_time) %>
+                                                        </div>
+                                                        <% if(index < auditors.length - 1) { %>
+                                                            <div class="timeline-item-tail"></div>
+                                                        <% } %>
+                                                        <% if(auditor.status === auditConst.status.checked) { %>
+                                                            <div class="timeline-item-icon bg-success text-light">
+                                                                <i class="fa fa-check"></i>
+                                                            </div>
+                                                        <% } else if(auditor.status === auditConst.status.back) {%>
+                                                            <div class="timeline-item-icon bg-warning text-light">
+                                                                <i class="fa fa-level-up"></i>
+                                                            </div>
+                                                        <% } else if(auditor.status === auditConst.status.checking) { %>
+                                                            <div class="timeline-item-icon bg-warning text-light">
+                                                                <i class="fa fa-ellipsis-h"></i>
+                                                            </div>
+                                                        <% } else {%>
+                                                            <div class="timeline-item-icon bg-secondary text-light">
+                                                            </div>
+                                                        <% } %>
+                                                        <div class="timeline-item-content">
+                                                            <div class="card">
+                                                                <div class="card-body p-3">
+                                                                    <div class="card-text">
+                                                                        <p class="mb-1"><span class="h5"><%- auditor.name %></span><span
+                                                                                    class="pull-right <%- auditConst.statusClass[auditor.status] %>"><%- auditConst.statusString[auditor.status] %></span>
+                                                                        </p>
+                                                                        <p class="text-muted mb-0"><%- auditor.role %></p>
+                                                                    </div>
+                                                                </div>
+
+                                                                <!--审批意见-->
+                                                                <% if(auditor.times === ctx.change.times && auditor.status !== auditConst.status.uncheck) { %>
+                                                                    <div class="card-body p-3 border-top">
+                                                                        <% if (ctx.change.times === idx + 1 && auditor.status === auditConst.status.checking) { %>
+                                                                            <label>审批意见<b class="text-danger">*</b></label>
+                                                                            <textarea class="form-control form-control-sm"
+                                                                                      name="opinion">不同意</textarea>
+                                                                            <% if (ctx.change.curAuditor.aid === auditor.aid) { %>
+                                                                                <div id="reject-process" class="alert alert-warning"
+                                                                                     style="margin-top: 15px;">
+                                                                                    <div class="form-check form-check-inline">
+                                                                                        <input class="form-check-input" type="radio" name="checkType"
+                                                                                               id="inlineRadio1" value="<%- auditConst.status.back %>" checked>
+                                                                                        <label class="form-check-label" for="inlineRadio1">退回原报
+                                                                                            <%- ctx.change.user.name %></label>
+                                                                                    </div>
+                                                                                </div>
+                                                                            <% } %>
+                                                                        <% } else if(auditor.status === auditConst.status.checked){ %>
+                                                                            <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                                        <% } %>
+                                                                    </div>
+                                                                <% } %>
+                                                            </div>
+                                                        </div>
+                                                    </li>
+                                                <% } else {%>
+                                                    <li class="timeline-list-item pb-2">
+                                                        <div class="timeline-item-date">
+                                                            <%- ctx.helper.formatDate(auditor.end_time) %>
+                                                        </div>
+                                                        <% if(index < auditors.length - 1) { %>
+                                                            <div class="timeline-item-tail"></div>
+                                                        <% } %>
+                                                        <% if(auditor.status === auditConst.status.checked) { %>
+                                                            <div class="timeline-item-icon bg-success text-light">
+                                                                <i class="fa fa-check"></i>
+                                                            </div>
+                                                        <% } else if(auditor.status === auditConst.status.back) {%>
+                                                            <div class="timeline-item-icon bg-warning text-light">
+                                                                <i class="fa fa-level-up"></i>
+                                                            </div>
+                                                        <% } else if(auditor.status === auditConst.status.checking) { %>
+                                                            <div class="timeline-item-icon bg-warning text-light">
+                                                                <i class="fa fa-ellipsis-h"></i>
+                                                            </div>
+                                                        <% } else { %>
+                                                            <div class="timeline-item-icon bg-secondary text-light">
+                                                            </div>
+                                                        <% } %>
+                                                        <div class="timeline-item-content">
+                                                            <div class="card">
+                                                                <div class="card-body p-3">
+                                                                    <div class="card-text">
+                                                                        <p class="mb-1"><span class="h5"><%- auditor.name %></span>
+                                                                            <span
+                                                                                    class="pull-right
+                                                                                    <%- auditConst.statusClass[auditor.status] %>"><%- auditor.status !== auditConst.status.uncheck ? auditConst.statusString[auditor.status] : ''%>
+                                                                                <%- auditor.status === auditConst.status.back ? ctx.change.user.name : '' %>
+                                                                </span>
+                                                                        </p>
+                                                                        <p class="text-muted mb-0"><%- auditor.role %></p>
+                                                                    </div>
+                                                                </div>
+                                                                <!--审批意见-->
+                                                                <% if(auditor.times === ctx.change.times && auditor.status !== auditConst.status.uncheck) { %>
+                                                                    <div class="card-body p-3 border-top">
+                                                                        <% if (ctx.change.times === idx + 1 && auditor.status === auditConst.status.checking) { %>
+                                                                            <label>审批意见<b class="text-danger">*</b></label>
+                                                                            <textarea class="form-control form-control-sm"
+                                                                                      name="opinion">不同意</textarea>
+                                                                            <% if (ctx.change.curAuditor.aid === auditor.aid ) { %>
+                                                                                <div id="reject-process" class="alert alert-warning"
+                                                                                     style="margin-top: 15px;">
+                                                                                    <div class="form-check form-check-inline">
+                                                                                        <input class="form-check-input" type="radio" name="checkType"
+                                                                                               id="inlineRadio1" value="<%- auditConst.status.back %>" checked>
+                                                                                        <label class="form-check-label" for="inlineRadio1">退回原报
+                                                                                            <%- ctx.change.user.name %></label>
+                                                                                    </div>
+                                                                                </div>
+                                                                            <% } %>
+                                                                        <% } else { %>
+                                                                            <p style="margin: 0;"><%- auditor.opinion %></p>
+                                                                        <% } %>
+
+                                                                    </div>
+
+                                                                <% } %>
+                                                            </div>
+                                                        </div>
+                                                    </li>
+                                                <% } %>
+                                            <% }) %>
+                                        </ul>
+                                    </div>
+
+                                <% }) %>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                        <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
+                        <button type="submit" class="btn btn-warning btn-sm">确认退回</button>
+                    </div>
+                </form>
+            </div>
+        </div>
+        <!-- 终止 -->
+        <div class="modal fade" id="stop" data-backdrop="static">
+            <div class="modal-dialog " role="document">
+                <form class="modal-content" action="<%- preUrl %>/audit/check" method="post" onsubmit="return auditCheck(2);">
+                    <div class="modal-header">
+                        <h5 class="modal-title">终止</h5>
+                    </div>
+                    <div class="modal-body">
+                        <div class="form-group">
+                            <label>审批意见<b class="text-danger">*</b></label>
+                            <textarea class="form-control" name="opinion" placeholder="请填写审批意见"></textarea>
+                        </div>
+                        <label class="form-text alert alert-danger m-0">审批终止,将结束本次审批。</label>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-sm btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                        <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
+                        <input type="hidden" name="checkType" value="<%= auditConst.status.checkNo %>" />
+                        <button type="submit" class="btn btn-sm btn-danger btn-sm" >确认</button>
+                    </div>
+                </form>
+            </div>
+        </div>
+    <% } %>
+<% } %>
+<% if (ctx.session.sessionUser.accountId === ctx.change.uid && (ctx.change.status === auditConst.status.uncheck || ctx.change.status === auditConst.status.back)) { %>
+    <script>
+        const accountGroup = JSON.parse(unescape('<%- escape(JSON.stringify(accountGroup)) %>'));
+        const accountList = JSON.parse(unescape('<%- escape(JSON.stringify(accountList)) %>'));
+    </script>
+<% } %>
+<script>const cur_uid = parseInt('<%- ctx.session.sessionUser.accountId %>');</script>
+<script>
+    $('.sp-location-list').on('shown.bs.modal', function () {
+        const scrollBox = $(this).find('div[class="col-8 modal-height-500"]');
+        const bdiv = (scrollBox.offset() && scrollBox.offset().top) || 0;
+        scrollBox.scrollTop(0);
+        const hdiv = divSearch($(this).find('textarea')) ? $(this).find('textarea') : null;
+        const hdheight = hdiv ? hdiv.parents('.timeline-item-content').offset().top : null;
+        if (hdiv && scrollBox.length && scrollBox[0].scrollHeight > 200 && hdheight - bdiv > 200) {
+            scrollBox.scrollTop(hdheight - bdiv);
+        }
+    });
+    function divSearch(div) {
+        if (div.length > 0) {
+            return true;
+        }
+        return false;
+    }
+
+    // 展开历史审核记录
+    $('.modal-body #fold-btn').click(function () {
+        const type = $(this).data('target')
+        const auditCard = $(this).parent().parent()
+        if (type === 'show') {
+            $(this).data('target', 'hide')
+            auditCard.find('.fold-card').slideDown('swing', () => {
+                auditCard.find('#fold-btn').text('收起历史审核记录')
+            })
+        } else {
+            $(this).data('target', 'show')
+            auditCard.find('.fold-card').slideUp('swing', () => {
+                auditCard.find('#fold-btn').text('展开历史审核记录')
+            })
+        }
+    });
+
+    $('.sp-list-btn').click(function () {
+        const type = $(this).data('type')
+        if (type === 'hide') {
+            $('.sp-list-item').hide()
+            $('.modal-title').text('审批流程')
+        } else {
+            $('.sp-list-item').show()
+            $('.modal-title').text('重新上报')
+        }
+    });
+</script>

+ 148 - 0
app/view/change/project_modal.ejs

@@ -0,0 +1,148 @@
+<!--删除标段-->
+<div class="modal fade" id="del-bg" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">确认删除变更立项书</h5>
+            </div>
+            <div class="modal-body">
+                <h5>删除后,数据无法恢复,请谨慎操作。</h5>
+            </div>
+            <form class="modal-footer" action="/tender/<%- tender.id %>/change/project/delete" method="post">
+                <input type="hidden" name="cid" id="delete-cid" value="">
+                <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">取消</button>
+                <button type="submit" class="btn btn-danger btn-sm">确定删除</button>
+            </form>
+        </div>
+    </div>
+</div>
+
+<% if (tender.user_id === uid || (userPermission !== null && userPermission.tender !== undefined && userPermission.tender.indexOf('5') !== -1)) { %>
+<!--弹出添加变更令-->
+<div class="modal fade" id="add-bj-modal" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">添加变更立项书</h5>
+            </div>
+            <div class="modal-body">
+                <div class="form-group">
+                    <label>编号<b class="text-danger">*</b></label>
+                    <div class="input-group">
+                        <input type="text" class="form-control form-control-sm is-invalid" placeholder="请输入编号" value="变更立项书编号" id="bj-code">
+                        <div class="input-group-append" id="autoCodeShow" <% if (codeRule.length === 0) { %>style="display: none"<% } %>>
+                            <button class="btn btn-sm btn-outline-secondary" type="button" title="自动编号" id="autoCode"><i class="fa fa-repeat"></i></button>
+                        </div>
+                        <div class="invalid-feedback" style="display: none" id="bjHint">您输入的编号已存在。</div>
+                    </div>
+                </div>
+                <div class="form-group">
+                    <label>变更工程名称<b class="text-danger">*</b></label>
+                    <input class="form-control form-control-sm" value="" type="text" id="bj-name">
+                    <div class="invalid-feedback" style="display: none" id="name_error_msg">名称超过100个字,请缩减名称。</div>
+                </div>
+                <div class="form-group">
+                    <label>发起类型<b class="text-danger">*</b></label>
+                    <div class="d-flex">
+                        <% if (tender.user_id === uid) { %>
+                        <div class="form-check form-check-inline">
+                            <input class="form-check-input" type="radio" id="inlineRadio1" value="option1" checked>
+                            <label class="form-check-label" for="inlineRadio1">变更建议</label>
+                        </div>
+                        <% } else { %>
+                        <div class="form-check form-check-inline">
+                            <input class="form-check-input" type="radio" id="inlineRadio2" value="option2" checked>
+                            <label class="form-check-label" for="inlineRadio2">变更意向</label>
+                        </div>
+                        <% } %>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal" id="addCancel">关闭</button>
+                <a href="javascript: void(0)" class="btn btn-primary btn-sm" id="addOk">确认添加</a>
+            </div>
+        </div>
+    </div>
+</div>
+<!--设置-->
+<div class="modal fade" id="setting" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">编号设置</h5>
+            </div>
+            <div class="modal-body">
+                <ul class="nav nav-tabs mb-3" role="tablist">
+                    <li class="nav-item">
+                        <a class="nav-link active" data-toggle="tab" href="#bianhao" role="tab" aria-controls="home" aria-selected="true">编号规则</a>
+                    </li>
+                </ul>
+                <div class="tab-content">
+                    <div class="tab-pane active" id="bianhao">
+                        <h5>
+                            当前规则:
+                            <span id="preview">
+                                <% if (codeRule && codeRule instanceof Array) { %>
+                                    <% const preview = []; %>
+                                    <% for (const rule of codeRule) { %>
+                                        <% preview.push(rule.preview); %>
+                                    <% } %>
+                                    <%- preview.join(tender.c_connector !== null && tender.c_connector !== '3' ? ruleConst.connectorString[tender.c_connector] : ''); %>
+                                <% } %>
+                            </span>
+                        </h5>
+                        <h5 id="ruleParts">
+                            <% if (codeRule && codeRule instanceof Array) { %>
+                                <% for (const rule of codeRule) { %>
+                                <span class="badge badge-light" title="<%- ruleConst.ruleString[rule.rule_type] %>">
+                                    <span>
+                                        <%- rule.preview %>
+                                    </span>
+                                    <a href="javascript: void(0);" class="text-danger" title="移除"><i class="fa fa-remove"></i></a>
+                                </span>
+                                <% } %>
+                            <% } %>
+                        </h5>
+                        <h5 class="my-3">连接符</h5>
+                        <div class="form-group">
+                            <select class="form-control form-control-sm connector-change">
+                                <option disabled selected>请选择</option>
+                                <% for (const index in ruleConst.connectorString) { %>
+                                    <option value="<%- index %>" <% if (tender.c_connector !== null && tender.c_connector === parseInt(index)) { %>selected<% } %>><%- ruleConst.connectorString[index] %></option>
+                                <% } %>
+                            </select>
+                        </div>
+                        <h5 class="my-3">添加新规则组件</h5>
+                        <div class="form-group">
+                            <select class="form-control form-control-sm rule-change">
+                                <option disabled selected>请选择组件</option>
+                                <% for (const index in ruleConst.ruleString) { %>
+                                <option value="<%- index %>"><%- ruleConst.ruleString[index] %></option>
+                                <% } %>
+                            </select>
+                        </div>
+                        <div class="form-group" id="format" style="display: none">
+                            <label>自动编号位数</label>
+                            <input min="3" class="form-control form-control-sm" step="1" max="6" value="3" type="number">
+                        </div>
+                        <div class="form-group" id="text" style="display: none">
+                            <label>起始编号</label>
+                            <input class="form-control form-control-sm" value="001" type="text">
+                        </div>
+                        <button class="btn btn-sm btn-outline-primary" id="addRule">添加组件</button>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <% if (c_rule_first) { %><button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal" id="changeFirst">暂时不需要</button><% } %>
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal" id="hide_modal" <% if (c_rule_first) { %>style="display: none"<% } %>>关闭</button>
+                <button type="button" class="btn btn-primary btn-sm" id="setRule">确定添加</button>
+            </div>
+        </div>
+    </div>
+</div>
+<% } %>
+
+

+ 31 - 1
app/view/dashboard/index.ejs

@@ -28,7 +28,7 @@
                     <div class="card">
                         <div class="card-header">需要你处理</div>
                         <div class="card-body">
-                            <% if (auditTenders.length !== 0 || auditRevise.length !== 0 || auditStages.length !== 0 || auditChanges.length !== 0 || auditMaterial.length !== 0 || auditAdvance.length !== 0) { %>
+                            <% if (auditTenders.length !== 0 || auditRevise.length !== 0 || auditStages.length !== 0 || auditChanges.length !== 0 || auditMaterial.length !== 0 || auditAdvance.length !== 0 || auditChangeProject.length !== 0) { %>
                                 <ul class="list-unstyled m-0">
                                     <% for (const t of auditTenders) { %>
                                         <% if (t.ledger_status === acLedger.status.checking) { %>
@@ -120,6 +120,20 @@
                                             </div>
                                         </li>
                                     <% } %>
+                                    <% for (const acp of auditChangeProject) { %>
+                                        <li class="media pb-3 mb-3 border-bottom-1">
+                                            <div class="media-body">
+                                                <div class="row">
+                                                    <div class="col-auto"><span class="badge badge-danger">变更立项</span></div>
+                                                    <div class="col-6"><a href="/tender/<%- acp.tid %>"><%- acp.name %></a> 变更立项 <%- acp.mcode %></div>
+                                                    <div class="col-3 ml-auto text-right pl-0"><a href="/tender/<%- acp.tid %>/change/project/<%- acp.cpid %>/information" class="btn btn-sm btn-outline-primary"><% if (acp.mstatus !== acChangeProject.status.back) { %>审批<% } else { %>重新上报<% } %></a></div>
+                                                </div>
+                                                <p class="mt-1 mb-0"><%- ctx.session.sessionUser.name %><small class="ml-1 text-muted"><%- (role ? '- ' + role : '') %></small>
+                                                    <span class="pull-right text-muted"><%- ctx.moment(acp.begin_time).format('YYYY-MM-DD HH:mm:ss') %></span>
+                                                </p>
+                                            </div>
+                                        </li>
+                                    <% } %>
                                     <% for (const am of auditMaterial) { %>
                                         <% if (am.mstatus !== acMaterial.status.checkNo) { %>
                                             <li class="media pb-3 mb-3 border-bottom-1">
@@ -271,6 +285,22 @@
                                                     </p>
                                                 </div>
                                             </li>
+                                        <% } else if(notice.type === pushType.changeProject && ctx.session.sessionProject.page_show.openChangeProject) { %>
+                                            <li class="media pb-3 mb-3 border-bottom-1">
+                                                <div class="media-body">
+                                                    <div class="row">
+                                                        <div class="col-auto"><span class="badge badge-danger">变更立项</span></div>
+                                                        <div class="col-6">
+                                                            <a href="/tender/<%- notice.tid %>"><%- notice.name %></a>
+                                                            <a href="/tender/<%- notice.tid %>/change/project/<%- notice.cpid %>"><%- notice.c_code %> </a>
+                                                            <%- acChangeProject.statusString[notice.status]%>
+                                                        </div>
+                                                    </div>
+                                                    <p class="mt-1 mb-0"><%- notice.su_name %><small class="ml-1 text-muted"><%- (notice.su_role ? '- ' + notice.su_role : '') %></small>
+                                                        <span class="pull-right text-muted"><%- ctx.helper.formatFullDate(notice.create_time) %></span>
+                                                    </p>
+                                                </div>
+                                            </li>
                                         <% } else if(notice.type === pushType.advance) { %>
                                             <li class="media pb-3 mb-3 border-bottom-1">
                                                 <div class="media-body">

+ 27 - 15
app/view/setting/fun.ejs

@@ -46,19 +46,25 @@
                             </div>
                         </div>
                         <div class="row">
-                            <!--<div class="col-6">-->
-                                <!--<div class="card mb-3">-->
-                                    <!--<div class="card-body">-->
-                                        <!--<h5 class="card-title">工程变更</h5>-->
-                                        <!--<div class="form-group">-->
-                                            <!--<div class="form-check form-check-inline">-->
-                                                <!--<input class="form-check-input" type="checkbox" id="openChangeRevise" <% if(ctx.session.sessionProject.page_show.openChangeRevise) { %>checked<% } %> onchange="updateSetting();">-->
-                                                <!--<label class="form-check-label" for="openChangeRevise">新增部位</label>-->
-                                            <!--</div>-->
-                                        <!--</div>-->
-                                    <!--</div>-->
-                                <!--</div>-->
-                            <!--</div>-->
+                            <div class="col-6">
+                                <div class="card mb-3">
+                                    <div class="card-body">
+                                        <h5 class="card-title">工程变更</h5>
+                                        <div class="form-group mb-1">
+                                            <div class="form-check form-check-inline">
+                                                <input class="form-check-input" type="checkbox" id="openChangeProject" <% if(ctx.session.sessionProject.page_show.openChangeProject) { %>checked<% } %> onchange="updateSetting(1);">
+                                                <label class="form-check-label" for="openChangeProject">显示「变更立项」页面</label>
+                                            </div>
+                                        </div>
+                                        <div class="form-group mb-1">
+                                            <div class="form-check form-check-inline">
+                                                <input class="form-check-input" type="checkbox" id="openChangeApply" <% if(ctx.session.sessionProject.page_show.openChangeApply) { %>checked<% } %> onchange="updateSetting(2);">
+                                                <label class="form-check-label" for="openChangeApply">显示「变更申请」页面</label>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
                             <div class="col-6">
                                 <div class="card mb-3">
                                     <div class="card-body">
@@ -106,13 +112,19 @@
     $(() => {
         autoFlashHeight();
     });
-    const updateSetting = function () {
+    const updateSetting = function (tab = false) {
+        if ($('#openChangeApply')[0].checked && !$('#openChangeProject')[0].checked && tab === 1) {
+            $('#openChangeApply').prop('checked', false);
+        } else if ($('#openChangeApply')[0].checked && !$('#openChangeProject')[0].checked && tab === 2) {
+            $('#openChangeProject').prop('checked', true);
+        }
         postData('/setting/fun/update', {
             imType: parseInt($('[name=im_type]:checked').val()),
             banOver: $('[name=ban_over]')[0].checked,
             hintOver: $('#hint_over')[0].checked,
             needGcl: $('#need_gcl')[0].checked,
-            // openChangeRevise: $('#openChangeRevise')[0].checked,
+            openChangeProject: $('#openChangeProject')[0].checked,
+            openChangeApply: $('#openChangeApply')[0].checked,
             openMaterialTax: $('#openMaterialTax')[0].checked,
             openMaterialChecklist: $('#openMaterialChecklist')[0].checked,
         });

+ 9 - 0
app/view/tender/tender_sub_menu.ejs

@@ -34,9 +34,18 @@
             </ul>
         </div>
         <div class="nav-box">
+            <% if (!ctx.session.sessionProject.page_show.openChangeProject && !ctx.session.sessionProject.page_show.openChangeApply) { %>
             <ul class="nav-list list-unstyled">
                 <li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change') !== -1) { %>class="active"<% } %>><a class="change_sort_link h3" href="/tender/<%- ctx.tender.id %>/change"><i class="fa fa-retweet fa-fw"></i> <span>工程变更</span></a></li>
             </ul>
+            <% } else { %>
+            <h3><i class="fa fa-retweet fa-fw"></i> 工程变更</h3>
+            <ul class="nav-list list-unstyled sub-list">
+                <% if (ctx.session.sessionProject.page_show.openChangeProject) { %><li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change/project') !== -1) { %>class="active"<% } %>><a class="change_project_sort_link" href="/tender/<%- ctx.tender.id %>/change/project"><span>变更立项</span></a></li><% } %>
+                    <% if (ctx.session.sessionProject.page_show.openChangeApply) { %><li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change/apply') !== -1) { %>class="active"<% } %>><a class="change_apply_sort_link" href="/tender/<%- ctx.tender.id %>/change/apply"><span>变更申请</span></a></li><% } %>
+                <li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change') !== -1 && ctx.url.indexOf('/tender/' + ctx.tender.id + '/change/project') === -1 && ctx.url.indexOf('/tender/' + ctx.tender.id + '/change/apply') === -1) { %>class="active"<% } %>><a class="change_sort_link" href="/tender/<%- ctx.tender.id %>/change"><span>变更方案</span></a></li>
+            </ul>
+            <% } %>
         </div>
         <div class="nav-box">
             <ul class="nav-list list-unstyled">

+ 12 - 3
app/view/tender/tender_sub_mini_menu.ejs

@@ -36,9 +36,18 @@
             </ul>
         </div>
         <div class="nav-box">
-            <ul class="nav-list list-unstyled">
-                <li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change') !== -1) { %>class="active"<% } %>><a class="change_sort_link h3" href="/tender/<%- ctx.tender.id %>/change"><i class="fa fa-retweet fa-fw"></i> <span>工程变更</span></a></li>
-            </ul>
+            <% if (!ctx.session.sessionProject.page_show.openChangeProject && !ctx.session.sessionProject.page_show.openChangeApply) { %>
+                <ul class="nav-list list-unstyled">
+                    <li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change') !== -1) { %>class="active"<% } %>><a class="change_sort_link h3" href="/tender/<%- ctx.tender.id %>/change"><i class="fa fa-retweet fa-fw"></i> <span>工程变更</span></a></li>
+                </ul>
+            <% } else { %>
+                <h3><i class="fa fa-retweet fa-fw"></i> 工程变更</h3>
+                <ul class="nav-list list-unstyled sub-list">
+                    <% if (ctx.session.sessionProject.page_show.openChangeProject) { %><li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change/project') !== -1) { %>class="active"<% } %>><a class="change_project_sort_link" href="/tender/<%- ctx.tender.id %>/change/project"><span>变更立项</span></a></li><% } %>
+                    <% if (ctx.session.sessionProject.page_show.openChangeApply) { %><li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change/apply') !== -1) { %>class="active"<% } %>><a class="change_apply_sort_link" href="/tender/<%- ctx.tender.id %>/change/apply"><span>变更申请</span></a></li><% } %>
+                    <li <% if (ctx.url.indexOf('/tender/' + ctx.tender.id + '/change') !== -1 && ctx.url.indexOf('/tender/' + ctx.tender.id + '/change/project') === -1 && ctx.url.indexOf('/tender/' + ctx.tender.id + '/change/apply') === -1) { %>class="active"<% } %>><a class="change_sort_link" href="/tender/<%- ctx.tender.id %>/change"><span>变更方案</span></a></li>
+                </ul>
+            <% } %>
         </div>
         <div class="nav-box">
             <ul class="nav-list list-unstyled">

+ 17 - 0
config/web.js

@@ -899,6 +899,23 @@ const JsFiles = {
                 ],
                 mergeFile: 'change_revise',
             },
+            project: {
+                files: ['/public/js/moment/moment.min.js'],
+                mergeFiles: [
+                    '/public/js/sub_menu.js',
+                    '/public/js/change_project.js',
+                ],
+                mergeFile: 'change_project',
+            },
+            project_information: {
+                files: ['/public/js/moment/moment.min.js'],
+                mergeFiles: [
+                    '/public/js/sub_menu.js',
+                    '/public/js/change_project_audit.js',
+                    '/public/js/change_project_information.js',
+                ],
+                mergeFile: 'change_project_information',
+            },
         },
         datacollect: {
             index: {

+ 4 - 1
sql/update.sql

@@ -264,4 +264,7 @@ ALTER TABLE `zh_stage`
 ADD COLUMN `his_id`  bigint(20) UNSIGNED NOT NULL COMMENT '历史台账id' AFTER `tp_history`;
 
 ALTER TABLE `zh_stage_pay`
-ADD COLUMN `postil`  varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '本期批注' AFTER `start_stage_order`;
+ADD COLUMN `postil`  varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '本期批注' AFTER `start_stage_order`;
+
+
+ALTER TABLE `zh_tender` ADD `c_code_rules` TEXT NULL DEFAULT NULL COMMENT '变更立项及申请的编号规则json' AFTER `c_rule_first`;