瀏覽代碼

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

TonyKang 3 年之前
父節點
當前提交
2541072e80
共有 89 個文件被更改,包括 9087 次插入467 次删除
  1. 1 0
      app/const/account_permission.js
  2. 170 0
      app/const/audit.js
  3. 12 0
      app/const/change.js
  4. 10 0
      app/const/code_rule.js
  5. 3 0
      app/const/page_show.js
  6. 4 0
      app/const/project_log.js
  7. 1131 3
      app/controller/change_controller.js
  8. 6 12
      app/controller/dashboard_controller.js
  9. 7 2
      app/controller/ledger_controller.js
  10. 24 80
      app/controller/revise_controller.js
  11. 2 1
      app/controller/setting_controller.js
  12. 11 4
      app/controller/stage_controller.js
  13. 21 4
      app/controller/tender_controller.js
  14. 10 1
      app/extend/context.js
  15. 7 0
      app/extend/helper.js
  16. 15 2
      app/lib/pay_calc.js
  17. 118 0
      app/middleware/change_apply_check.js
  18. 122 0
      app/middleware/change_project_check.js
  19. 5 1
      app/middleware/revise_check.js
  20. 5 0
      app/middleware/stage_check.js
  21. 10 0
      app/middleware/tender_check.js
  22. 290 0
      app/public/js/change_apply.js
  23. 222 0
      app/public/js/change_apply_audit.js
  24. 197 0
      app/public/js/change_apply_information.js
  25. 60 0
      app/public/js/change_apply_information_notice.js
  26. 312 0
      app/public/js/change_project.js
  27. 328 0
      app/public/js/change_project_audit.js
  28. 195 0
      app/public/js/change_project_information.js
  29. 17 1
      app/public/js/global.js
  30. 28 0
      app/public/js/material_checklist.js
  31. 1 1
      app/public/js/revise.js
  32. 1 1
      app/public/js/revise_compare.js
  33. 1 1
      app/public/js/revise_gcl_compare.js
  34. 4 4
      app/public/js/revise_history.js
  35. 0 53
      app/public/js/revise_price.js
  36. 85 91
      app/public/js/stage_pay.js
  37. 48 15
      app/router.js
  38. 313 0
      app/service/change_apply.js
  39. 137 0
      app/service/change_apply_att.js
  40. 528 0
      app/service/change_apply_audit.js
  41. 327 0
      app/service/change_project.js
  42. 137 0
      app/service/change_project_att.js
  43. 580 0
      app/service/change_project_audit.js
  44. 162 0
      app/service/change_project_xs_audit.js
  45. 3 2
      app/service/ledger_audit.js
  46. 157 0
      app/service/ledger_history.js
  47. 8 25
      app/service/ledger_revise.js
  48. 4 4
      app/service/material_bills.js
  49. 3 4
      app/service/revise_audit.js
  50. 0 27
      app/service/revise_price_change.js
  51. 4 0
      app/service/rpt_gather_memory.js
  52. 14 0
      app/service/stage_audit.js
  53. 3 3
      app/service/stage_pay.js
  54. 10 1
      app/service/tender.js
  55. 110 0
      app/view/change/apply.ejs
  56. 148 0
      app/view/change/apply_information.ejs
  57. 752 0
      app/view/change/apply_information_modal.ejs
  58. 85 0
      app/view/change/apply_information_notice.ejs
  59. 215 0
      app/view/change/apply_information_notice_modal.ejs
  60. 140 0
      app/view/change/apply_modal.ejs
  61. 3 3
      app/view/change/information.ejs
  62. 1 1
      app/view/change/information_modal.ejs
  63. 107 0
      app/view/change/project.ejs
  64. 136 0
      app/view/change/project_information.ejs
  65. 831 0
      app/view/change/project_information_modal.ejs
  66. 148 0
      app/view/change/project_modal.ejs
  67. 64 4
      app/view/dashboard/index.ejs
  68. 9 1
      app/view/material/checklist.ejs
  69. 5 5
      app/view/measure/stage.ejs
  70. 2 2
      app/view/revise/history.ejs
  71. 6 6
      app/view/revise/index.ejs
  72. 3 3
      app/view/revise/info_modal.ejs
  73. 0 42
      app/view/revise/price.ejs
  74. 1 1
      app/view/revise/sub_menu.ejs
  75. 3 4
      app/view/revise/sub_menu_list.ejs
  76. 27 15
      app/view/setting/fun.ejs
  77. 1 1
      app/view/setting/sub_menu.ejs
  78. 9 0
      app/view/tender/tender_sub_menu.ejs
  79. 12 3
      app/view/tender/tender_sub_mini_menu.ejs
  80. 2 0
      builder_report_index_define.js
  81. 2 2
      config/config.default.js
  82. 3 0
      config/config.local.js
  83. 3 0
      config/config.qa.js
  84. 4 1
      config/config.uat.js
  85. 44 15
      config/web.js
  86. 183 0
      db_script/ledger_his.js
  87. 59 0
      db_script/update_revise.js
  88. 0 15
      dev4qadx.js
  89. 96 0
      sql/update.sql

+ 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' },
         ],
     },

+ 170 - 0
app/const/audit.js

@@ -421,6 +421,172 @@ 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 changeApply = (function() {
+    const status = {
+        uncheck: 1, // 待上报
+        checking: 2, // 待审批|审批中
+        checked: 3, // 审批通过
+        checkNo: 4, // 退回到原报人重新上报
+    };
+    const statusString = [];
+    statusString[status.uncheck] = '待上报';
+    statusString[status.checking] = '审批中';
+    statusString[status.checked] = '审批通过';
+    statusString[status.checkNo] = '审批退回';
+
+    const statusClass = [];
+    statusClass[status.uncheck] = '';
+    statusClass[status.checking] = 'text-warning';
+    statusClass[status.checked] = 'text-success';
+    statusClass[status.checkNo] = 'text-warning';
+
+    // 标段概况页
+    // 描述文本
+    const auditString = [];
+    auditString[status.uncheck] = '';
+    auditString[status.checking] = '审批中';
+    auditString[status.checked] = '审批通过';
+    auditString[status.checkNo] = '审批退回';
+    // 文字样式
+    const auditStringClass = [];
+    auditStringClass[status.uncheck] = '';
+    auditStringClass[status.checking] = 'text-warning';
+    auditStringClass[status.checked] = 'text-success';
+    auditStringClass[status.checkNo] = 'text-warning';
+    // 描述文本
+    const auditProgress = [];
+    auditProgress[status.uncheck] = '草稿';
+    auditProgress[status.checking] = '审批中';
+    auditProgress[status.checked] = '审批通过';
+    auditProgress[status.checkNo] = '审批退回';
+    // 样式
+    const auditProgressClass = [];
+    auditProgressClass[status.uncheck] = '';
+    auditProgressClass[status.checking] = 'text-warning';
+    auditProgressClass[status.checked] = 'text-success';
+    auditProgressClass[status.checkNo] = '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] = '重新上报';
+
+    // 按钮样式
+    const statusButtonClass = [];
+    statusButtonClass[status.uncheck] = 'btn-primary';
+    statusButtonClass[status.checking] = 'btn-success';
+    statusButtonClass[status.checked] = '';
+    statusButtonClass[status.checkNo] = 'btn-warning';
+    return { status, statusString, statusClass, auditString, auditStringClass, auditProgress, auditProgressClass, filter, statusButton, statusButtonClass };
+})();
+
 // 推送类型
 const pushType = {
     material: 1,
@@ -429,6 +595,8 @@ const pushType = {
     revise: 4,
     ledger: 5,
     advance: 6,
+    changeProject: 7,
+    changeApply: 8,
 };
 
 module.exports = {
@@ -449,4 +617,6 @@ module.exports = {
     filter,
     pushType,
     advance,
+    changeProject,
+    changeApply,
 };

+ 12 - 0
app/const/change.js

@@ -106,4 +106,16 @@ module.exports = {
         souban: { unit: '艘班' },
         mu: { unit: '亩' },
     },
+    // 立项类型
+    project_type: {
+        3: '变更建议',
+        4: '变更意向',
+    },
+    file_type: [
+        { key: 1, value: '图纸' },
+        { key: 2, value: '勘查资料' },
+        { key: 3, value: '报告' },
+        { key: 4, value: '会议纪要' },
+        { key: 5, value: '其他资料' },
+    ],
 };

+ 10 - 0
app/const/code_rule.js

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

+ 3 - 0
app/const/page_show.js

@@ -39,6 +39,9 @@ const defaultSetting = {
     closeWapYfSf: 0,
     openManagement: 0,
     openMaterialChecklist: 0,
+    close1stStageCheckDealParam: 0,
+    openChangeProject: 0,
+    openChangeApply: 0,
 };
 
 

+ 4 - 0
app/const/project_log.js

@@ -14,6 +14,8 @@ const type = {
     stage: 2,
     change: 3,
     material: 4,
+    changeProject: 5,
+    changeApply: 6,
 };
 
 const type_list = [
@@ -22,6 +24,8 @@ const type_list = [
     { code: 'stage', type: type.stage, name: '计量期' },
     { code: 'change', type: type.change, name: '变更令' },
     { code: 'material', type: type.material, name: '材料调差' },
+    { code: 'changeProject', type: type.changeProject, name: '变更立项' },
+    { code: 'changeApply', type: type.changeApply, name: '变更申请' },
 ];
 // 操作状态
 const status = {

文件差異過大導致無法顯示
+ 1131 - 3
app/controller/change_controller.js


+ 6 - 12
app/controller/dashboard_controller.js

@@ -29,20 +29,10 @@ 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 auditChangeApply = ctx.session.sessionProject.page_show.openChangeApply ? await ctx.service.changeApplyAudit.getAuditChangeApply(ctx.session.sessionUser.accountId) : [];
             const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
-            // const lastNotice = pa.last_notice ? pa.last_notice : (pa.last_notice === 0 ? new Date() : new Date(pa.last_login * 1000));
-            // const noticeLedger = await ctx.service.ledgerAudit.getNoticeTender(ctx.session.sessionProject.id, pa.id);
-            // const noticeStage = await ctx.service.stageAudit.getNoticeStage(ctx.session.sessionProject.id, pa.id);
-            // const noticeChange = await ctx.service.changeAudit.getNoticeChange(ctx.session.sessionProject.id, pa.id);
-            // const noticeRevise = await ctx.service.reviseAudit.getNoticeRevise(ctx.session.sessionProject.id, pa.id);
-            // const noticeMaterial = await ctx.service.materialAudit.getNoticeMaterial(ctx.session.sessionProject.id, pa.id);
-            // const noticeList = [...noticeLedger, ...noticeStage, ...noticeChange, ...noticeRevise, ...noticeMaterial].sort((a, b) => a.name.localeCompare(b.name, 'zh') && b.create_time - a.create_time).slice(0, 10);
             const noticeList = await ctx.service.noticePush.getNotice(ctx.session.sessionProject.id, pa.id);
-            // const noticeLedger = [];
-            // const noticeStage = [];
-            // const noticeChange = [];
-            // const noticeRevise = [];
-            // const noticeMaterial = [];
             const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
             // 获取销售人员数据
             const salesmanData = await ctx.service.manager.getDataById(projectData.manager_id);
@@ -64,6 +54,8 @@ module.exports = app => {
                 auditRevise,
                 auditMaterial,
                 auditAdvance,
+                auditChangeProject,
+                auditChangeApply,
                 role: pa.role,
                 authMobile: pa.auth_mobile,
                 acLedger: auditConst.ledger,
@@ -72,6 +64,8 @@ module.exports = app => {
                 acRevise: auditConst.revise,
                 acMaterial: auditConst.material,
                 acAdvance: auditConst.advance,
+                acChangeProject: auditConst.changeProject,
+                acChangeApply: auditConst.changeApply,
                 noticeList,
                 pushType: auditConst.pushType,
                 projectData,

+ 7 - 2
app/controller/ledger_controller.js

@@ -473,9 +473,14 @@ module.exports = app => {
          */
         async loadExplodeData(ctx) {
             try {
-                const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
+                const ledgerData = ctx.tender.ledgerReadOnly && ctx.tender.his
+                    ? await ctx.helper.loadLedgerDataFromOss(ctx.tender.his.bills_file)
+                    : await ctx.service.ledger.getData(ctx.tender.id);
                 const posData = this.ctx.tender.data.measure_type === measureType.tz.value
-                    ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
+                    ? (ctx.tender.ledgerReadOnly && ctx.tender.his
+                        ? await ctx.helper.loadLedgerDataFromOss(ctx.tender.his.pos_file)
+                        : await ctx.service.pos.getPosData({tid: ctx.tender.id}))
+                    : [];
                 const ledgerTags = await this.ctx.service.ledgerTag.getDatas(ctx.tender.id);
                 ctx.body = { err: 0, msg: '', data: { bills: ledgerData, pos: posData, tags: ledgerTags } };
             } catch (err) {

+ 24 - 80
app/controller/revise_controller.js

@@ -189,7 +189,7 @@ module.exports = app => {
                     throw '台账修订会影响审批中的变更令(包含新增部位),请审批完成后再创建台账修订';
                 }
                 const revise = await ctx.service.ledgerRevise.add(ctx.tender.id, ctx.session.sessionUser.accountId);
-                ctx.redirect('/tender/' + ctx.tender.id + '/revise/info');
+                ctx.redirect(`/tender/${ctx.tender.id}/revise/${revise.id}/info`);
             } catch (err) {
                 this.log(err);
                 ctx.redirect(ctx.request.header.referer);
@@ -289,13 +289,6 @@ module.exports = app => {
         }
 
         async _getDefaultReviseInfoData(ctx, revise) {
-            // const reviseBills = revise.bills_file
-            //     ? JSON.parse(await fs.readFileSync(this.ctx.app.config.filePath + revise.bills_file, 'utf8'))
-            //     : await ctx.service.reviseBills.getData(ctx.tender.id);
-
-            // const revisePos = revise.pos_file
-            //     ? JSON.parse(await fs.readFileSync(this.ctx.app.config.filePath + revise.pos_file, 'utf8'))
-            //     : await ctx.service.revisePos.getData(ctx.tender.id);
             const [ledgerSpread, posSpread] = this._getSpreadSetting(revise);
             const sjsRela = await this.ctx.service.project.getSjsRela(ctx.session.sessionProject.id);
             this.ctx.helper.refreshSpreadShow(sjsRela.ledgerCol, [ledgerSpread, posSpread]);
@@ -315,9 +308,7 @@ module.exports = app => {
             }
             return {
                 revise, tender: ctx.tender.data,
-                // reviseBills, revisePos,
                 ledgerSpread, posSpread, tenderMenu, measureType,
-                preUrl: '/tender/' + ctx.tender.id,
                 audit: audit.revise,
                 jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.revise.info),
                 stdBills,
@@ -346,6 +337,7 @@ module.exports = app => {
             renderData.history = true;
             renderData.historyRevise = await ctx.service.ledgerRevise.getAllReviseList(ctx.tender.id);
             renderData.categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
+            renderData.preUrl = ctx.url.replace('/info', '');
             await this.layout('revise/info.ejs', renderData, 'revise/info_modal.ejs');
         }
 
@@ -365,6 +357,7 @@ module.exports = app => {
             renderData.historyRevise = [];
             renderData.curAuditor = await ctx.service.reviseAudit.getCurAuditor(revise.id, revise.times);
             renderData.categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
+            renderData.preUrl = ctx.url.replace('/info', '');
             await this.layout('revise/info.ejs', renderData, 'revise/info_modal.ejs');
         }
 
@@ -388,6 +381,7 @@ module.exports = app => {
             renderData.auditorList = await ctx.service.reviseAudit.getAuditors(revise.id, revise.times);
             renderData.curAuditor = await ctx.service.reviseAudit.getCurAuditor(revise.id, revise.times);
             renderData.categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
+            renderData.preUrl = ctx.url.replace('/info', '');
             await this.layout('revise/info.ejs', renderData, 'revise/info_modal.ejs');
         }
 
@@ -417,21 +411,14 @@ module.exports = app => {
 
         async loadInfoData(ctx) {
             try {
-                const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
-                if (!revise) throw '台账修订数据有误';
+                const revise = await ctx.revise;
 
-                const billsFile = revise.status === audit.revise.status.checked && revise.bills_file
-                    ? this.ctx.app.config.filePath + revise.bills_file
-                    : undefined;
-                const reviseBills = billsFile && fs.existsSync(billsFile)
-                    ? JSON.parse(await fs.readFileSync(billsFile, 'utf8'))
+                const reviseBills = revise.readOnly
+                    ? await ctx.helper.loadLedgerDataFromOss(revise.curHis.bills_file)
                     : await ctx.service.reviseBills.getData(ctx.tender.id);
 
-                const posFile = revise.status === audit.revise.status.checked && revise.pos_file
-                    ? this.ctx.app.config.filePath + revise.pos_file
-                    : undefined;
-                const revisePos = posFile && fs.existsSync(posFile)
-                    ? JSON.parse(await fs.readFileSync(posFile, 'utf8'))
+                const revisePos = revise.readOnly
+                    ? await ctx.helper.loadLedgerDataFromOss(revise.curHis.pos_file)
                     : await ctx.service.revisePos.getData(ctx.tender.id);
 
                 if (revise.uid === ctx.session.sessionUser.accountId &&
@@ -517,6 +504,7 @@ module.exports = app => {
                 // 获取审批流程中左边列表
                 const auditors = await ctx.service.reviseAudit.getAuditorsWithOwner(revise.id, times);
                 const renderData = {
+                    preUrl: ctx.url.replace('/info', ''),
                     measureType, audit, revise,
                     ledgerSpread, posSpread,
                     readOnly: true,
@@ -534,36 +522,6 @@ module.exports = app => {
             }
         }
 
-        async historyInfo(ctx) {
-            try {
-                const data = JSON.parse(ctx.request.body.data);
-                if (!data || !data.rid || data.rid === '') throw '查询的台账修订有误';
-                const reviseInfo = await ctx.service.ledgerRevise.getRevise(ctx.tender.id, data.rid);
-                reviseInfo.end_time_str = reviseInfo.end_time ? ctx.moment(reviseInfo.end_time).format('YYYY-MM-DD HH:mm:ss') : '';
-                ctx.body = { err: 0, msg: '', data: reviseInfo };
-            } catch (err) {
-                this.log(err);
-                ctx.body = this.ajaxErrorBody(err, '获取台账修订历史数据错误');
-            }
-        }
-
-        /**
-         * 加载 数据
-         * @param {} ctx
-         */
-        async loadHistoryData(ctx) {
-            try {
-                const billsFile = await this.ctx.app.hisOss.get(ctx.app.config.hisOssPath + ctx.revise.bills_file);
-                const reviseBills = JSON.parse(billsFile.content);
-                const posFile = await this.ctx.app.hisOss.get(ctx.app.config.hisOssPath + ctx.revise.pos_file);
-                const revisePos = JSON.parse(posFile.content);
-                ctx.body = { err: 0, msg: '', data: { bills: reviseBills, pos: revisePos } };
-            } catch (error) {
-                ctx.helper.log(error);
-                this.ajaxErrorBody(error, '获取台账修订数据错误');
-            }
-        }
-
         async checkRevise(ctx) {
             const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
             if (revise.uid !== ctx.session.sessionUser.accountId) {
@@ -896,12 +854,10 @@ module.exports = app => {
 
                 await ctx.service.reviseAudit.check(revise, checkType, ctx.request.body.opinion, revise.times);
 
-                // ctx.redirect('/tender/' + ctx.tender.id + '/revise/info');
                 ctx.redirect(ctx.request.headers.referer);
             } catch (err) {
                 this.log(err);
                 this.postError(err, '审批失败');
-                // ctx.redirect('/tender/' + ctx.tender.id + '/revise/info');
                 ctx.redirect(ctx.request.headers.referer);
             }
         }
@@ -928,6 +884,7 @@ module.exports = app => {
             const lastStage = await this._getLastStage(ctx);
 
             const renderData = {
+                preUrl: ctx.url.replace('/compare', ''),
                 revise,
                 measureType,
                 lastStage,
@@ -991,10 +948,18 @@ module.exports = app => {
 
         async _loadDataByFilter(ctx, filter) {
             switch(filter) {
-                case 'bills': return await ctx.service.ledger.getAllDataByCondition({where: {tender_id: ctx.tender.id} });
-                case 'pos': return await ctx.service.pos.getAllDataByCondition({where: {tid: ctx.tender.id} });
-                case 'reviseBills': return await ctx.service.reviseBills.getAllDataByCondition({where: {tender_id: ctx.tender.id}});
-                case 'revisePos': return await ctx.service.revisePos.getAllDataByCondition({where: {tid: ctx.tender.id}});
+                case 'bills':
+                    return ctx.revise.preHis ? await this.ctx.helper.loadLedgerDataFromOss(ctx.revise.preHis.bills_file) : [];
+                case 'pos':
+                    return ctx.revise.preHis ? await this.ctx.helper.loadLedgerDataFromOss(ctx.revise.preHis.pos_file) : [];
+                case 'reviseBills':
+                    return ctx.revise.readOnly && ctx.revise.curHis
+                        ? await this.ctx.helper.loadLedgerDataFromOss(ctx.revise.curHis.bills_file)
+                        : await ctx.service.reviseBills.getAllDataByCondition({ where: { tender_id: ctx.tender.id } });
+                case 'revisePos':
+                    return ctx.revise.readOnly && ctx.revise.curHis
+                        ? await this.ctx.helper.loadLedgerDataFromOss(ctx.revise.curHis.pos_file)
+                        : await ctx.service.revisePos.getAllDataByCondition({ where: { tid: ctx.tender.id } });
                 case 'stageBills':
                 case 'stagePos':
                     if (!ctx.lastStage) ctx.lastStage = await this._getLastStage(ctx);
@@ -1011,8 +976,6 @@ module.exports = app => {
                     return spec;
                 case 'tags':
                     return await this.ctx.service.ledgerTag.getDatas(ctx.tender.id);
-                case 'price':
-                    return await this.ctx.service.revisePriceChange.getAllDataByCondition({ where: { rid: ctx.revise.id } });
             }
         }
 
@@ -1041,31 +1004,12 @@ module.exports = app => {
             if (!revise) throw '台账修订数据有误';
 
             const renderData = {
+                preUrl: ctx.url.replace('/gcl-compare', ''),
                 revise,
                 jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.revise.gclCompare),
             };
             await this.layout('revise/gcl_compare.ejs', renderData);
         }
-
-        async bwtz(ctx) {
-            const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
-            if (!revise) throw '台账修订数据有误';
-
-            const renderData = {
-                revise,
-                jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.revise.bwtz),
-            };
-            await this.layout('revise/bwtz.ejs', renderData);
-        }
-
-        async price(ctx) {
-            if (!ctx.revise) throw '台账修订数据有误';
-            const renderData = {
-                revise: ctx.revise,
-                jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.revise.price)
-            };
-            await this.layout('revise/price.ejs', renderData);
-        }
     }
 
     return ReviseController;

+ 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);

+ 11 - 4
app/controller/stage_controller.js

@@ -234,7 +234,9 @@ module.exports = app => {
         }
 
         async _getStageLedgerData(ctx) {
-            const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
+            const ledgerData = ctx.stage.ledgerHis
+                ? await ctx.helper.loadLedgerDataFromOss(ctx.stage.ledgerHis.bills_file)
+                : await ctx.service.ledger.getData(ctx.tender.id);
             const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
             for (const d of dgnData) {
                 const l = ctx.app._.find(ledgerData, { id: d.id });
@@ -947,6 +949,7 @@ module.exports = app => {
 
                 ctx.body = responseData;
             } catch (err) {
+                console.log(err);
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: null };
             }
@@ -1340,8 +1343,12 @@ module.exports = app => {
                 };
                 if (data.main) {
                     result.main = {};
-                    result.main.ledger = await ctx.service.ledger.getData(ctx.tender.id);
-                    result.main.pos = await ctx.service.pos.getPosData({ tid: ctx.tender.id });
+                    result.main.ledger = ctx.stage.ledgerHis
+                        ? await ctx.helper.loadLedgerDataFromOss(ctx.stage.ledgerHis.bills_file)
+                        : await ctx.service.ledger.getData(ctx.tender.id);
+                    result.main.pos = ctx.stage.ledgerHis
+                        ? await ctx.helper.loadLedgerDataFromOss(ctx.stage.ledgerHis.pos_file)
+                        : await ctx.service.pos.getPosData({ tid: ctx.tender.id });
                 }
                 for (const order of data.roles) {
                     const data = { order, bills: [], pos: [] };
@@ -1393,7 +1400,7 @@ module.exports = app => {
                 ctx.body = { err: 0, msg: '', data: result };
             } catch (err) {
                 this.log(err);
-                ctx.body = this.ajaxErrorBody(err, '加载合同支付数据错误');
+                ctx.body = this.ajaxErrorBody(err, '加载部位台账数据错误');
             }
         }
 

+ 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) {

+ 10 - 1
app/extend/context.js

@@ -66,5 +66,14 @@ module.exports = {
                 body: this.session.body,
             }));
         }
-    }
+    },
+
+    get hisOssPath() {
+        return this.app.config.hisOssPath;
+    },
+
+    get hisOss() {
+        return this.app.hisOss;
+    },
+
 };

+ 7 - 0
app/extend/helper.js

@@ -1472,4 +1472,11 @@ module.exports = {
     createJWT(data) {
         return jwt.sign({ data }, sign.managementApiSecretKey, { expiresIn: '15s' });
     },
+
+    async loadLedgerDataFromOss(url) {
+        const File = await this.ctx.hisOss.get(this.ctx.hisOssPath + url);
+        if (File.res.status !== 200) return '获取修订台账有误';
+        const result = JSON.parse(File.content);
+        return result;
+    },
 };

+ 15 - 2
app/lib/pay_calc.js

@@ -9,6 +9,9 @@
  */
 
 const math = require('mathjs');
+math.config({
+    number: 'BigNumber',
+});
 const PayConst = require('../const/deal_pay.js');
 const payType = PayConst.payType;
 const deadlineType = PayConst.deadlineType;
@@ -72,7 +75,12 @@ class PayCalculate {
             }
         }
         try {
-            const value = math.eval(formula);
+            // 使用mathjs计算 math.eval('17259401.95*0.9') = 15533461.754999999,正确应为 15533461.755
+            // const value = math.eval(formula);
+            // 使用逆波兰法四则运算,可防止出现误差,但是只支持四则运算,不支持科学运算
+            // const value = this.ctx.helper.calcExprStrRpn(formula);
+            // 使用mathjs的大数运算,可支持所有
+            const value = parseFloat(math.eval(formula));
             return value;
         } catch(err) {
             return 0;
@@ -92,7 +100,12 @@ class PayCalculate {
             }
         }
         try {
-            const value = math.eval(formula);
+            // 使用mathjs计算 math.eval('17259401.95*0.9') = 15533461.754999999,正确应为 15533461.755
+            // const value = math.eval(formula);
+            // 使用逆波兰法四则运算,可防止出现误差,但是只支持四则运算,不支持科学运算
+            // const value = this.ctx.helper.calcExprStrRpn(formula);
+            // 使用mathjs的大数运算,可支持所有
+            const value = parseFloat(math.eval(formula));
             return value;
         } catch(err) {
             return 0;

+ 118 - 0
app/middleware/change_apply_check.js

@@ -0,0 +1,118 @@
+'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* changeApplyCheck(next) {
+        try {
+            // 获取revise
+            if (!this.session.sessionProject.page_show.openChangeApply) {
+                throw '该功能已关闭';
+            }
+            const caid = this.params.caid || this.request.body.caid;
+            if (!caid) {
+                throw '您访问的变更立项不存在';
+            }
+            const change = yield this.service.changeApply.getDataById(caid);
+            // 读取原报、审核人数据
+            change.auditors = yield this.service.changeApplyAudit.getAuditors(change.id, change.times);
+            change.curAuditor = yield this.service.changeApplyAudit.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.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.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.checkNo ? change.times - 1 : change.times;
+                if (change.status === status.checked) {
+                    change.curOrder = _.max(_.map(change.auditors, 'order'));
+                } else if (change.status === status.checkNo) {
+                    const audit = this.service.changeApplyAudit.getDataByCondition({
+                        caid: change.id, times: change.times, status: status.checkNo,
+                    });
+                    change.curOrder = audit.order;
+                } 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.checkNo ? change.times - 1 : change.times;
+                change.curOrder = change.status === status.checked ? _.max(_.map(change.auditors, 'order')) : change.curAuditor.order - 1;
+                change.filePermission = false;
+            } else { // 其他不可见
+                throw '您无权查看该数据';
+            }
+            // 调差的readOnly 指表格和页面只能看不能改,和审批无关
+            change.readOnly = !((change.status === status.uncheck || change.status === status.checkNo) && 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);
+        }
+    };
+};

+ 122 - 0
app/middleware/change_project_check.js

@@ -0,0 +1,122 @@
+'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);
+            change.xsAuditors = yield this.service.changeProjectXsAudit.getAuditList(change.id);
+
+            if (!change) throw '变更令数据有误';
+            // 权限相关
+            // todo 校验权限 (标段参与人、分享)
+            const accountId = this.session.sessionUser.accountId,
+                auditorIds = _.map(change.auditors, 'aid'),
+                xsAuditorIds = _.map(change.xsAuditors, '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 || xsAuditorIds.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);
+        }
+    };
+};

+ 5 - 1
app/middleware/revise_check.js

@@ -25,6 +25,9 @@ module.exports = options => {
                 ? yield this.service.ledgerRevise.getRevise(this.tender.id, this.params.rid)
                 : yield this.service.ledgerRevise.getLastestRevise(this.tender.id);
             if (!revise) throw '台账修订数据有误';
+            // 修订前后,历史台账
+            revise.preHis = revise.pre_his_id ? yield this.service.ledgerHistory.getDataById(revise.pre_his_id) : null;
+            revise.curHis = revise.his_id ? yield this.service.ledgerHistory.getDataById(revise.his_id) : null;
             revise.reviseUsers = [revise.uid];
             if (revise.status !== auditConst.status.uncheck) {
                 const times = revise.status === auditConst.status.checkNo ? revise.times - 1 : revise.times;
@@ -32,7 +35,8 @@ module.exports = options => {
                 const auditorsId = this.helper._.map(auditors, 'audit_id');
                 revise.reviseUsers.push(...auditorsId);
             }
-            revise.readOnly = revise.status === auditConst.status.uncheck || revise.status === auditConst.status.checkNo;
+            revise.readOnly = revise.uid !== this.session.sessionUser.accountId ||
+                revise.status === auditConst.status.checking || revise.status === auditConst.status.checked;
             this.revise = revise;
             yield next;
         } catch (err) {

+ 5 - 0
app/middleware/stage_check.js

@@ -50,6 +50,11 @@ module.exports = options => {
             stage.auditors = yield this.service.stageAudit.getAuditors(stage.id, stage.times);
             stage.curAuditor = yield this.service.stageAudit.getCurAuditor(stage.id, stage.times);
 
+            // 历史台账
+            if (stage.status === status.checked) {
+                stage.ledgerHis = yield this.service.ledgerHistory.getDataById(stage.his_id);
+            }
+
             // 获取最新的期
             stage.highOrder = yield this.service.stage.count({
                 tid: this.tender.id,

+ 10 - 0
app/middleware/tender_check.js

@@ -46,6 +46,9 @@ module.exports = options => {
             if (tender.data.project_id !== this.session.sessionProject.id) {
                 throw '您无权查看该项目';
             }
+            tender.his = tender.data.ledger_status === auditConst.status.checkNo
+                ? yield this.service.ledgerHistory.getDataById(tender.data.his_id)
+                : null;
             const accountId = this.session.sessionUser.accountId;
             const advanceAuditors = yield this.service.advanceAudit.getAllAuditors(tender.id);
             const advanceAuditorsId = this.helper._.map(advanceAuditors, 'audit_id');
@@ -60,6 +63,12 @@ module.exports = options => {
             const reviseAuditorsId = this.helper._.map(reviseAuditors, 'audit_id');
             const materialAuditors = yield this.service.materialAudit.getAllAuditors(tender.id);
             const materialAuditorsId = this.helper._.map(materialAuditors, 'aid');
+            const changeProjectAuditors = this.session.sessionProject.page_show.openChangeProject ? yield this.service.changeProjectAudit.getAllAuditors(tender.id) : [];
+            const changeProjectAuditorsId = this.helper._.map(changeProjectAuditors, 'aid');
+            const changeProjectXsAuditors = this.session.sessionProject.page_show.openChangeProject ? yield this.service.changeProjectXsAudit.getAllAuditors(tender.id) : [];
+            const changeProjectXsAuditorsId = this.helper._.map(changeProjectXsAuditors, 'aid');
+            const changeApplyAuditors = this.session.sessionProject.page_show.openChangeApply ? yield this.service.changeApplyAudit.getAllAuditors(tender.id) : [];
+            const changeApplyAuditorsId = this.helper._.map(changeApplyAuditors, 'aid');
             const tenderPermission = this.session.sessionUser.permission ? this.session.sessionUser.permission.tender : null;
             const isTenderTourist = yield this.service.tenderTourist.getDataByCondition({ tid: tender.id, user_id: accountId });
             // 判断访问人是否具有游客身份
@@ -70,6 +79,7 @@ module.exports = options => {
                 (tenderPermission === null || tenderPermission === undefined || tenderPermission.indexOf('2') === -1) &&
                 stageAuditorsId.indexOf(accountId) === -1 && changeAuditorsId.indexOf(accountId) === -1 &&
                 reviseAuditorsId.indexOf(accountId) === -1 && materialAuditorsId.indexOf(accountId) === -1 &&
+                changeProjectAuditorsId.indexOf(accountId) === -1 && changeProjectXsAuditorsId.indexOf(accountId) === -1 && changeApplyAuditorsId.indexOf(accountId) === -1 &&
                 advanceAuditorsId.indexOf(accountId) === -1 && !this.session.sessionUser.is_admin && !isTenderTourist) {
                 throw '您无权查看该项目';
             }

+ 290 - 0
app/public/js/change_apply.js

@@ -0,0 +1,290 @@
+'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);
+        const data = {
+            code: $('#bj-code').val(),
+            project_code: $('#project-code').val(),
+        };
+        if (data.code || data.code !== '') {
+            postData('/tender/'+ tenderId +'/change/apply/add', data, function (rst) {
+                $('#bj-code').removeClass('is-invalid');
+                $('#mj-add').modal('hide');
+                $(this).attr('disabled', false);
+                window.location.href = '/tender/'+ tenderId +'/change/apply/' + 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/apply';
+       if (status !== 0) {
+           url += '/status/'+ status;
+       }
+       let orderSetting = getLocalCache('change-apply-'+ 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-caid-modal').on('click', function () {
+        $('#delete-caid').val($(this).attr('caid'));
+    });
+
+    // 排序初始化
+    let orderSetting = getLocalCache('change-apply-'+ 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-apply-'+ 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-apply-'+ 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();
+        }
+    });
+});

+ 222 - 0
app/public/js/change_apply_audit.js

@@ -0,0 +1,222 @@
+'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 === 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;
+}

文件差異過大導致無法顯示
+ 197 - 0
app/public/js/change_apply_information.js


+ 60 - 0
app/public/js/change_apply_information_notice.js

@@ -0,0 +1,60 @@
+'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);
+    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 = '';
+        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>${file.type ? _.find(fileTypeConst, {key: file.type }).value : ''}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</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>${file.type ? _.find(fileTypeConst, {key: file.type }).value : ''}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td></tr>`
+            }
+        })
+        $('#file-content').append(html);
+    }
+});

+ 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-cpid-modal').on('click', function () {
+        $('#delete-cpid').val($(this).attr('cpid'));
+    });
+
+    // 排序初始化
+    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();
+        }
+    });
+});

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

@@ -0,0 +1,328 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2019/2/27
+ * @version
+ */
+
+$(document).ready(function () {
+    let timer = null
+    let oldSearchVal = null
+    let timer2 = null
+    let oldSearchVal2 = 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>`
+                })
+                $('.search-user-list').empty()
+                $('.search-user-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>'
+                    })
+                    $('.search-user-list').empty()
+                    $('.search-user-list').append(html)
+                }
+            }
+        }, 400);
+    })
+
+    // 添加审批流程按钮逻辑
+    $('.search-user-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
+    })
+
+    // 添加到审批流程中
+    $('.search-user-list').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)) + '审');
+            }
+        });
+    });
+    // 协审人搜索
+    $('#gr-search2').bind('input propertychange', function(e) {
+        oldSearchVal2 = e.target.value;
+        timer2 && clearTimeout(timer2);
+        timer2 = setTimeout(() => {
+            const newVal = $('#gr-search2').val();
+            let html = '';
+            if (newVal && newVal === oldSearchVal2) {
+                accountList.filter(item => item && (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>`
+                })
+                $('.search-user-list2').empty();
+                $('.search-user-list2').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 => {
+                            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>'
+                    })
+                    $('.search-user-list2').empty();
+                    $('.search-user-list2').append(html);
+                }
+            }
+        }, 400);
+    })
+
+    // 添加审批流程按钮逻辑
+    $('.search-user-list2').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
+    });
+
+    // 添加到审批流程中
+    $('.search-user-list2').on('click', 'dd', function () {
+        const id = parseInt($(this).data('id'));
+        if (id) {
+            console.log(id);
+            postData(preUrl + '/xsaudit/add', { auditorId: id }, (data) => {
+                const html = [];
+                html.push('<span class="d-inline-block">\n' +
+                    '                    <span class="badge badge-light">\n' +
+                    '                      ' + data.name + '\n' +
+                    '                        <span class="dropdown">\n' +
+                    '                        <a href="javascript:void(0)" class="btn-sm text-danger px-1" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-remove"></i></a>\n' +
+                    '                        <div class="dropdown-menu">\n' +
+                    '                          <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
+                    '                          <div class="dropdown-divider"></div>\n' +
+                    '                          <div class="px-2 py-1 text-center">\n' +
+                    '                            <button class="btn btn-sm btn-danger" aid="'+ data.aid +'">移除</button>\n' +
+                    '                            <button class="btn btn-sm btn-secondary">取消</button>\n' +
+                    '                          </div>\n' +
+                    '                        </div>\n' +
+                    '                      </span>\n' +
+                    '                    </span>\n' +
+                    '                  </span> ');
+                $('#xs-list').append(html.join(''));
+            });
+        }
+    });
+
+    // 删除审批人
+    $('body').on('click', '#xs-list .btn-danger', function () {
+        const li = $(this).parents('.d-inline-block');
+        const data = {
+            auditorId: parseInt($(this).attr('aid')),
+        };
+        postData(preUrl +  '/xsaudit/delete', data, (result) => {
+            li.remove();
+        });
+    });
+
+    // 退回选择修改审批人流程
+    $('#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="/tender/${file.tid}/change/project/${file.cpid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a><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><a href="/tender/${file.tid}/change/project/${file.cpid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></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({

+ 28 - 0
app/public/js/material_checklist.js

@@ -313,6 +313,7 @@ $(document).ready(() => {
         const isCheck = $(this).is(':checked');
         let newMaterialChecklistData = materialChecklistData;
         if (isCheck) {
+            $('#bills0_checkList').prop('checked', false);
             newMaterialChecklistData = _.filter(materialChecklistData, { had_bills: 0 });
         }
         SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialChecklistData);
@@ -324,6 +325,33 @@ $(document).ready(() => {
             loadMaterialData(-1, 0);
         }
     });
+    // 筛选调差工料清单为0
+    $('#bills0_checkList').click(function () {
+        const isCheck = $(this).is(':checked');
+        let newMaterialChecklistData = materialChecklistData;
+        if (isCheck) {
+            newMaterialChecklistData = [];
+            $('#notBills_checkList').prop('checked', false);
+            const materialList0 = _.uniq(_.map(_.filter(materialListData, { quantity: 0 }), 'gcl_id'));
+            if (materialList0.length > 0) {
+                const hadMaterialChecklistData = _.filter(materialChecklistData, { had_bills: 1 });
+                for (const h of hadMaterialChecklistData) {
+                    const gcl = _.find(gclGatherData, { b_code: h.b_code, name: h.name, unit: h.unit, unit_price: h.unit_price });
+                    if (gcl && gcl.leafXmjs.length > 0 && _.indexOf(materialList0, gcl.leafXmjs[0].gcl_id) !== -1) {
+                        newMaterialChecklistData.push(h);
+                    }
+                }
+            }
+        }
+        SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialChecklistData);
+        SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
+        if (newMaterialChecklistData.length > 0) {
+            const index = _.findIndex(gclGatherData, { b_code: newMaterialChecklistData[0].b_code, name: newMaterialChecklistData[0].name, unit: newMaterialChecklistData[0].unit, unit_price: newMaterialChecklistData[0].unit_price });
+            loadMaterialData(index, 0);
+        } else {
+            loadMaterialData(-1, 0);
+        }
+    });
     // 添加调差工料
     $('#add_material_bill').click(function () {
         // 获取已选工料

+ 1 - 1
app/public/js/revise.js

@@ -2648,7 +2648,7 @@ $(document).ready(() => {
         // 修订详情 保存
         $('#save').click(function () {
             const content = $('#content').val();
-            postData('save', { content: content }, function () {
+            postData(`/tender/${window.location.pathname.split('/')[2]}/revise/save`, { content: content }, function () {
                 $('#content').attr('org-value', content);
             });
         });

+ 1 - 1
app/public/js/revise_compare.js

@@ -253,7 +253,7 @@ $(document).ready(() => {
     };
 
     // 加载清单&计量单元数据
-    postData('/tender/' + window.location.pathname.split('/')[2] + '/revise/load', {filter: 'bills;pos;reviseBills;revisePos'}, function (result) {
+    postData('load', {filter: 'bills;pos;reviseBills;revisePos'}, function (result) {
         const tenderTreeSetting = {
             id: 'ledger_id',
             pid: 'ledger_pid',

+ 1 - 1
app/public/js/revise_gcl_compare.js

@@ -149,7 +149,7 @@ $(document).ready(() => {
         $('#chapter-list').html(html.join(''));
     }
 
-    postData('/tender/' + window.location.pathname.split('/')[2] + '/revise/load', {filter: 'bills;pos;reviseBills;revisePos;dealBills;spec'}, function (data) {
+    postData('load', {filter: 'bills;pos;reviseBills;revisePos;dealBills;spec'}, function (data) {
         const setting = {
             tree: {
                 id: 'ledger_id',

+ 4 - 4
app/public/js/revise_history.js

@@ -155,15 +155,15 @@ $(document).ready(() => {
         },
     };
     // 加载清单&计量单元数据
-    postData(window.location.pathname + '/load', {}, function (result) {
-        billsTree.loadDatas(result.bills);
+    postData('load', {filter:'reviseBills;revisePos'}, function (result) {
+        billsTree.loadDatas(result.reviseBills);
         treeCalc.calculateAll(billsTree);
         SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
         SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
 
-        checkShowLast(result.bills.length);
+        checkShowLast(result.reviseBills.length);
 
-        pos.loadDatas(result.pos);
+        pos.loadDatas(result.revisePos);
         posSpreadObj.loadCurPosData();
         SpreadJsObj.resetTopAndSelect(posSheet);
     }, null);   

+ 0 - 53
app/public/js/revise_price.js

@@ -1,53 +0,0 @@
-'use strict';
-
-/**
- *
- *
- * @author Mai
- * @date
- * @version
- */
-
-$(document).ready(() => {
-    autoFlashHeight();
-
-    const priceSpread = SpreadJsObj.createNewSpread($('#price-spread')[0]);
-    const priceSheet = priceSpread.getActiveSheet();
-
-    const priceSpreadSetting = {
-        cols: [
-            { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 100, formatter: '@', readOnly: true },
-            { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 210, formatter: '@', readOnly: true },
-            { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true },
-            { title: '当前单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 80, type: 'Number', readOnly: true },
-            { title: '变更后单价', colSpan: '1', rowSpan: '2', field: 'new_price', hAlign: 2, width: 80, type: 'Number' },
-            { title: '备注', colSpan: '1', rowSpan: '2', field: 'new_price', hAlign: 2, width: 150, formatter: '@' },
-        ],
-        emptyRows: 0,
-        headRows: 1,
-        headRowHeight: [32],
-        headColWidth: [30],
-        defaultRowHeight: 21,
-        headerFont: '12px 微软雅黑',
-        font: '12px 微软雅黑',
-    };
-    SpreadJsObj.initSheet(priceSheet, priceSpreadSetting);
-
-    $.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();
-            priceSpread.refresh();
-        }
-    });
-});

+ 85 - 91
app/public/js/stage_pay.js

@@ -139,7 +139,8 @@ $(document).ready(() => {
                 title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
                 normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: 'getValue.attachment'
             },
-            {title: '状态', colSpan: '1', rowSpan: '1', field: '', hAlign: 0, width: 120, readOnly: true, getValue: 'getValue.state', foreColor: 'red', font: '8px 宋体'},
+            {title: '本期批注', colSpan: '1', rowSpan: '1', field: 'postil', hAlign: 0, width: 120},
+            // {title: '状态', colSpan: '1', rowSpan: '1', field: '', hAlign: 0, width: 120, readOnly: true, getValue: 'getValue.state', foreColor: 'red', font: '8px 宋体'},
         ],
         emptyRows: 0,
         headRows: 1,
@@ -643,49 +644,46 @@ $(document).ready(() => {
                 }
                 // 获取更新信息
                 const data = {
-                    type: (col.field === 'tp' || col.field === 'name') ? 'stage' : 'info',
-                    updateData: {}
+                    type: ['tp', 'name', 'postil'].indexOf(col.field) >= 0 ? 'stage' : 'info',
                 };
+                data.updateData = data.type === 'stage' ? { pid: select.pid } : { id: select.pid };
                 // 获取更新数据
-                if (col.field === 'tp') {
-                    data.updateData.pid = select.pid;
-                    const [valid, msg] = payBase.isSF(select)
-                        ? paySpreadObj._checkSfExpr(validText, data.updateData)
-                        : paySpreadObj._checkExpr(validText, data.updateData);
-                    if (!valid) {
-                        toastr.warning(msg);
-                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
-                        return;
-                    }
-                    // if (payBase.isSF(select)) {
-                    //     data.updateData.expr = data.updateData.tp;
-                    // }
-                } else if (col.field === 'name') {
-                    data.updateData.pid = select.pid;
-                    data.updateData.name = validText;
-                } else {
-                    data.updateData.id = select.pid;
-                    if (col.field === 'sprice') {
-                        const [valid, msg] = paySpreadObj._checkSExpr(select, validText, data.updateData);
-                        if (!valid) {
-                            toastr.warning(msg);
+                switch(col.field) {
+                    case 'tp':
+                        const [tpValid, tpMsg] = payBase.isSF(select)
+                            ? paySpreadObj._checkSfExpr(validText, data.updateData)
+                            : paySpreadObj._checkExpr(validText, data.updateData);
+                        if (!tpValid) {
+                            toastr.warning(tpMsg);
                             SpreadJsObj.reLoadRowData(info.sheet, info.row);
                             return;
                         }
-                    } else if (col.field === 'rprice') {
-                        const [valid, msg] = paySpreadObj._checkRExpr(select, validText, data.updateData);
-                        if (!valid) {
-                            toastr.warning(msg);
+                        // if (payBase.isSF(select)) {
+                        //     data.updateData.expr = data.updateData.tp;
+                        // }
+                        break;
+                    case 'name':
+                        data.updateData.name = validText;
+                        break;
+                    case 'sprice':
+                        const [sValid, sMsg] = paySpreadObj._checkSExpr(select, validText, data.updateData);
+                        if (!sValid) {
+                            toastr.warning(sMsg);
                             SpreadJsObj.reLoadRowData(info.sheet, info.row);
                             return;
                         }
-                    } else {
-                        if (validText) {
-                            data.updateData[col.field] = validText;
-                        } else {
-                            data.updateData[col.field] = null;
+                        break;
+                    case 'rprice':
+                        const [rValid, rMsg] = paySpreadObj._checkRExpr(select, validText, data.updateData);
+                        if (!rValid) {
+                            toastr.warning(rMsg);
+                            SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                            return;
                         }
-                    }
+                        break;
+                    default:
+                        data.updateData[col.field] = validText || '';
+
                 }
                 // 更新至服务器
                 postData(window.location.pathname + '/save', data, function (result) {
@@ -758,32 +756,32 @@ $(document).ready(() => {
                     toast('请勿同时删除多列数据', 'warning');
                 }
 
-                const data = {type: col.field === 'tp' ? 'stage' : 'info', updateData: []};
+                const data = {type: ['tp', 'postil'].indexOf(col.field) >= 0 ? 'stage' : 'info', updateData: []};
                 for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
                     const node = sheet.zh_data[iRow];
-                    if (node && (node.ptype === 1 || node.ptype === 3)) {
-                        const updateData = {};
-                        if (col.field === 'tp') {
-                            updateData.pid = node.pid;
-                            updateData.tp = null;
-                            updateData.expr = null;
-                        } else {
-                            updateData.id = node.pid;
-                            if (col.field === 'sprice') {
-                                const [valid, msg] = paySpreadObj._checkSExpr(node, null, updateData);
-                                if (!valid) {
-                                    toastr.warning(msg);
+                    if (node && (node.ptype === 1 || node.ptype === 3 || col.field === 'postil')) {
+                        const updateData = data.type === 'stage' ? { pid: node.pid } : { id: node.pid };
+                        switch (col.field) {
+                            case 'tp':
+                                updateData.tp = null;
+                                updateData.expr = null;
+                                break;
+                            case 'sprice':
+                                const [sValid, sMsg] = paySpreadObj._checkSExpr(node, null, updateData);
+                                if (!sValid) {
+                                    toastr.warning(sMsg);
                                     return;
                                 }
-                            } else if (col.field === 'rprice') {
-                                const [valid, msg] = paySpreadObj._checkRExpr(node, null, updateData);
-                                if (!valid) {
-                                    toastr.warning(msg);
+                                break;
+                            case 'rprice':
+                                const [rValid, rMsg] = paySpreadObj._checkRExpr(node, null, updateData);
+                                if (!rValid) {
+                                    toastr.warning(rMsg);
                                     return;
                                 }
-                            } else {
-                                updateData[col.field] = null;
-                            }
+                                break;
+                            default:
+                                updateData[col.field] = col.type === 'Number' ? 0 : '';
                         }
                         data.updateData.push(updateData);
                     }
@@ -813,56 +811,52 @@ $(document).ready(() => {
 
                 const sortData = info.sheet.zh_data;
                 const data = {
-                    type: (col.field === 'tp' || col.field === 'name') ? 'stage' : 'info',
+                    type: ['tp', 'name', 'postil'].indexOf(col.field) >= 0 ? 'stage' : 'info',
                     updateData: []
                 };
 
                 for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
                     const curRow = info.cellRange.row + iRow;
                     const node = sortData[curRow];
-                    if (node && (node.ptype === 1 || node.ptype === 3)) {
+                    if (node && (node.ptype === 1 || node.ptype === 3 || col.field === 'postil')) {
                         const validText = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
-                        const updateData = {};
-                        if (col.field === 'tp') {
-                            updateData.pid = node.pid;
-                            const [valid, msg] = payBase.isSF(node)
-                                ? paySpreadObj._checkSfExpr(validText, updateData)
-                                : paySpreadObj._checkExpr(validText, updateData);
-                            if (!valid) {
-                                toastr.warning(msg);
-                                SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
-                                return;
-                            }
-                            if (payBase.isSF(node)) {
-                                data.updateData.expr = data.updateData.tp;
-                            }
-                        } else if (col.field === 'name') {
-                            updateData.pid = node.pid;
-                            updateData.name = validText;
-                        } else {
-                            updateData.id = node.pid;
-
-                            if (col.field === 'sprice') {
-                                const [valid, msg] = paySpreadObj._checkSExpr(node, validText, updateData);
-                                if (!valid) {
-                                    toastr.warning(msg);
+                        const updateData = data.type === 'stage' ? { pid: node.pid } : { id: node.pid };
+                        switch (col.field) {
+                            case 'tp':
+                                const [tpValid, tpMsg] = payBase.isSF(node)
+                                    ? paySpreadObj._checkSfExpr(validText, updateData)
+                                    : paySpreadObj._checkExpr(validText, updateData);
+                                if (!tpValid) {
+                                    toastr.warning(tpMsg);
                                     SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
                                     return;
                                 }
-                            } else if (col.field === 'rprice') {
-                                const [valid, msg] = paySpreadObj._checkRExpr(node, validText, updateData);
-                                if (!valid) {
-                                    toastr.warning(msg);
+                                // if (payBase.isSF(node)) {
+                                //     data.updateData.expr = data.updateData.tp;
+                                // }
+                                break;
+                            case 'name':
+                                updateData.name = validText;
+                                break;
+                            case 'sprice':
+                                const [sValid, sMsg] = paySpreadObj._checkSExpr(node, validText, updateData);
+                                if (!sValid) {
+                                    toastr.warning(sMsg);
                                     SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
                                     return;
                                 }
-                            } else {
-                                if (validText) {
-                                    updateData[col.field] = validText;
-                                } else {
-                                    updateData[col.field] = null;
+                                break;
+                            case 'rprice':
+                                const [rValid, rMsg] = paySpreadObj._checkRExpr(node, validText, updateData);
+                                if (!rValid) {
+                                    toastr.warning(rMsg);
+                                    SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
+                                    return;
                                 }
-                            }
+                                break;
+                            default:
+                                updateData[col.field] = validText || '';
+
                         }
                         data.updateData.push(updateData);
                     }

+ 48 - 15
app/router.js

@@ -27,6 +27,10 @@ module.exports = app => {
     const advanceCheck = app.middlewares.advanceCheck();
     // 变更令中间件
     const changeCheck = app.middlewares.changeCheck();
+    // 变更立项书中间件
+    const changeProjectCheck = app.middlewares.changeProjectCheck();
+    // 变更申请中间件
+    const changeApplyCheck = app.middlewares.changeApplyCheck();
     // 投资进度中间件
     const scheduleCheck = app.middlewares.scheduleCheck();
     // 修订
@@ -217,24 +221,22 @@ module.exports = app => {
     // app.post('/tender/:id/revise/deal2sgfh', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.deal2sgfh');
 
     // 台账修订页面
-    app.get('/tender/:id/revise/info', sessionAuth, tenderCheck, uncheckTenderCheck, reviseAuditCheck, 'reviseController.info');
-    app.post('/tender/:id/revise/auditors', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.reviseAuditors');
-    app.post('/tender/:id/revise/info/load', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.loadInfoData');
-    app.post('/tender/:id/revise/info/update', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.update');
-    app.post('/tender/:id/revise/info/upload-excel/:ueType', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.uploadExcel');
-    app.post('/tender/:id/revise/info/check', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.checkData');
-
-    app.get('/tender/:id/revise/compare', sessionAuth, tenderCheck, uncheckTenderCheck, reviseAuditCheck, 'reviseController.compare');
-    app.get('/tender/:id/revise/gcl-compare', sessionAuth, tenderCheck, uncheckTenderCheck, reviseAuditCheck, 'reviseController.gclCompare');
-    app.post('/tender/:id/revise/load', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, reviseAuditCheck, 'reviseController.loadData');
-    // 单价调整
-    app.get('/tender/:id/revise/price', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, reviseAuditCheck, 'reviseController.price');
+    app.get('/tender/:id/revise/:rid/info', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, reviseAuditCheck, 'reviseController.info');
+    app.post('/tender/:id/revise/auditors', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.reviseAuditors');
+    app.post('/tender/:id/revise/:rid/info/load', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.loadInfoData');
+    app.post('/tender/:id/revise/:rid/info/update', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.update');
+    app.post('/tender/:id/revise/:rid/info/upload-excel/:ueType', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.uploadExcel');
+    app.post('/tender/:id/revise/:rid/info/check', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.checkData');
 
+    app.get('/tender/:id/revise/:rid/compare', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, reviseAuditCheck, 'reviseController.compare');
+    app.get('/tender/:id/revise/:rid/gcl-compare', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, reviseAuditCheck, 'reviseController.gclCompare');
+    app.post('/tender/:id/revise/:rid/load', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, reviseAuditCheck, 'reviseController.loadData');
 
     // 查看修订数据
-    app.get('/tender/:id/revise/history/:rid', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.history');
-    app.post('/tender/:id/revise/history/:rid/load', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.loadHistoryData');
-    app.post('/tender/:id/revise/history/info', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.historyInfo');
+    app.get('/tender/:id/revise/history/:rid/info', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.history');
+    app.post('/tender/:id/revise/history/:rid/load', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.loadData');
+    app.get('/tender/:id/revise/history/:rid/gcl-compare', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.gclCompare');
+    app.get('/tender/:id/revise/history/:rid/compare', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.compare');
 
     // 修订审批
     app.post('/tender/:id/revise/audit/add', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.addAuditor');
@@ -450,6 +452,37 @@ 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.post('/tender/:id/change/project/delete', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.projectDelete');
+    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.post('/tender/:id/change/project/:cpid/information/xsaudit/add', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.addProjectXsAudit');
+    app.post('/tender/:id/change/project/:cpid/information/xsaudit/delete', sessionAuth, tenderCheck, uncheckTenderCheck, changeProjectCheck, 'changeController.deleteProjectXsAudit');
+    // 变更申请
+    app.get('/tender/:id/change/apply', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.apply');
+    app.get('/tender/:id/change/apply/status/:status', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.applyStatus');
+    app.post('/tender/:id/change/apply/add', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.applyAdd');
+    app.post('/tender/:id/change/apply/delete', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.applyDelete');
+    app.get('/tender/:id/change/apply/:caid/information', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.applyInformation');
+    app.post('/tender/:id/change/apply/:caid/information/save', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.applyInformationSave');
+    app.post('/tender/:id/change/apply/:caid/information/file/upload', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.uploadApplyFile');
+    app.post('/tender/:id/change/apply/:caid/information/file/delete', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.deleteApplyFile');
+    app.get('/tender/:id/change/apply/:caid/information/file/:fid/download', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.downloadApplyFile');
+    app.post('/tender/:id/change/apply/:caid/information/audit/add', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.addApplyAudit');
+    app.post('/tender/:id/change/apply/:caid/information/audit/delete', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.deleteApplyAudit');
+    app.post('/tender/:id/change/apply/:caid/information/audit/start', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.startApplyAudit');
+    app.post('/tender/:id/change/apply/:caid/information/audit/check', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.checkApplyAudit');
+    app.get('/tender/:id/change/apply/:caid/information/notice', sessionAuth, tenderCheck, uncheckTenderCheck, changeApplyCheck, 'changeController.applyInformationNotice');
     // 材料调差
     app.get('/tender/:id/measure/material', sessionAuth, tenderCheck, uncheckTenderCheck, 'materialController.index');
     app.post('/tender/:id/measure/material/add', sessionAuth, tenderCheck, uncheckTenderCheck, 'materialController.add');

+ 313 - 0
app/service/change_apply.js

@@ -0,0 +1,313 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2018/8/14
+ * @version
+ */
+
+const audit = require('../const/audit').changeApply;
+// 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 ChangeApply extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'change_apply';
+        }
+
+        async add(tenderId, userId, code, project_code) {
+            const sql = 'SELECT COUNT(*) as count FROM ?? WHERE `tid` = ? AND `code` = ?';
+            const sqlParam = [this.tableName, tenderId, code];
+            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,
+                    in_time: new Date(),
+                    code,
+                    project_code,
+                };
+                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);
+                if (preChangeInfo) {
+                    // 并把之前存在的变更令审批人添加到zh_change_audit
+                    const auditResult = await this.ctx.service.changeApplyAudit.copyPreChangeApplyAuditors(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) {
+            const sql = 'SELECT a.* FROM ?? as a LEFT JOIN ?? as b ON a.`id` = b.`caid` WHERE a.`tid` = ? ORDER BY a.`in_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.changeApplyAudit.tableName, tenderId];
+            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.notice_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.notice_uid = p.id WHERE a.tid = ? AND ' +
+                            '(a.uid = ? OR (a.status != ? AND a.id IN (SELECT b.caid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.caid)) OR a.status = ?)';
+                        sqlParam = [
+                            this.tableName,
+                            this.ctx.service.projectAccount.tableName,
+                            tenderId,
+                            this.ctx.session.sessionUser.accountId,
+                            audit.status.uncheck,
+                            this.ctx.service.changeApplyAudit.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.notice_uid = p.id WHERE a.id in(SELECT b.caid 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.changeApplyAudit.tableName, tenderId, this.ctx.session.sessionUser.accountId, audit.status.checking, this.ctx.session.sessionUser.accountId, audit.status.uncheck, audit.status.checkNo];
+                        break;
+                    case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
+                        sql =
+                            'SELECT a.*, p.name as account_name FROM ?? AS a LEFT JOIN ?? AS p On a.notice_uid = p.id WHERE ' +
+                            // 'a.id IN (SELECT b.caid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.caid) AND ' +
+                            'a.uid = ? AND a.tid = ? AND (a.status = ? OR a.status = ?)';
+                        sqlParam = [
+                            this.tableName,
+                            this.ctx.service.projectAccount.tableName,
+                            // this.ctx.service.changeApplyAudit.tableName,
+                            this.ctx.session.sessionUser.accountId,
+                            tenderId,
+                            audit.status.uncheck,
+                            audit.status.checkNo,
+                        ];
+                        break;
+                    case 2: // 进行中(所有的)
+                    case 4: // 终止(所有的)
+                        sql =
+                            'SELECT a.*, p.name as account_name FROM ?? AS a LEFT JOIN ?? AS p On a.notice_uid = p.id WHERE ' +
+                            'a.status = ? AND a.tid = ? AND (a.uid = ? OR a.id IN (SELECT b.caid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.caid))';
+                        sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, status, tenderId, this.ctx.session.sessionUser.accountId, this.ctx.service.changeApplyAudit.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.notice_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.caid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.caid)) OR a.status != ?)';
+                    const sqlParam = [
+                        this.tableName,
+                        tenderId,
+                        this.ctx.session.sessionUser.accountId,
+                        audit.status.uncheck,
+                        this.ctx.service.changeApplyAudit.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.caid 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.changeApplyAudit.tableName, tenderId, this.ctx.session.sessionUser.accountId, audit.status.checking, this.ctx.session.sessionUser.accountId, audit.status.uncheck, audit.status.checkNo];
+                    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.caid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.caid) ' +
+                        'a.uid = ? AND a.tid = ? AND (a.status = ? OR a.status = ?)';
+                    const sqlParam2 = [
+                        this.tableName,
+                        // this.ctx.service.changeApplyAudit.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.caid FROM ?? AS b WHERE b.aid = ? AND a.times = b.times GROUP BY b.caid))';
+                    const sqlParam3 = [this.tableName, status, tenderId, this.ctx.session.sessionUser.accountId, this.ctx.service.changeApplyAudit.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(caId, postData) {
+            // 初始化事务
+            const transaction = await this.db.beginTransaction();
+            let result = false;
+            try {
+                const updateData = {
+                    id: caId,
+                };
+                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 caid
+         * @param code
+         * @param tid
+         * @return {Promise<void>}
+         */
+        async isRepeat(caId, code, tid) {
+            const sql = 'SELECT COUNT(*) as count FROM ?? WHERE `code` = ? AND `id` != ? AND `tid` = ?';
+            const sqlParam = [this.tableName, code, caId, tid];
+            const result = await this.db.queryOne(sql, sqlParam);
+            return result.count !== 0;
+        }
+
+        /**
+         * 查询可用的变更令
+         * @param { string } cid - 查询的清单
+         * @return {Promise<*>} - 可用的变更令列表
+         */
+        async delete(id) {
+            // 初始化事务
+            this.transaction = await this.db.beginTransaction();
+            let result = false;
+            try {
+                const changeInfo = await this.getDataById(id);
+                // 先删除审批人列表
+                await this.transaction.delete(this.ctx.service.changeApplyAudit.tableName, { caid: id });
+                // 再删除附件和附件文件ni zuo
+                const attList = await this.ctx.service.changeApplyAtt.getAllDataByCondition({ where: { caid: id } });
+                await this.ctx.helper.delFiles(attList);
+                await this.transaction.delete(this.ctx.service.changeApplyAtt.tableName, { caid: id });
+                // 最后删除变更令
+                await this.transaction.delete(this.tableName, { id });
+                // 记录删除日志
+                await this.ctx.service.projectLog.addProjectLog(this.transaction, projectLogConst.type.changeApply, projectLogConst.status.delete, changeInfo.code);
+                await this.transaction.commit();
+                result = true;
+            } catch (e) {
+                await this.transaction.rollback();
+                result = false;
+            }
+            return result;
+        }
+    }
+
+    return ChangeApply;
+};

+ 137 - 0
app/service/change_apply_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 ChangeApplyFile extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'change_apply_attachment';
+        }
+
+        /**
+         * 获取当前标段(期)所有上传的附件
+         * @param {Number} tid 标段id
+         * @param {Number?} mid 期id
+         * @return {Promise<void>} 数据库查询实例
+         */
+        async getAllChangeApplyAtt(tid, caid) {
+            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.caid = ? ORDER BY upload_time DESC';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, caid];
+            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/apply/${item.caid}/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 ChangeApplyFile;
+};
+

+ 528 - 0
app/service/change_apply_audit.js

@@ -0,0 +1,528 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2018/8/14
+ * @version
+ */
+
+const auditConst = require('../const/audit').changeApply;
+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 ChangeApplyAudit extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'change_apply_audit';
+        }
+
+        /**
+         * 获取 审核列表信息
+         *
+         * @param {Number} caId - 变更立项id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<*>}
+         */
+        async getAuditors(caId, 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 `caid` = ? AND `times` = ? GROUP BY `aid`) as g ' +
+                'WHERE la.`caid` = ? 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, caId, times, caId, times];
+            const result = await this.db.query(sql, sqlParam);
+            const sql2 = 'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `caid` = ? AND `times` = ? GROUP BY `aid`) as a';
+            const sqlParam2 = [this.tableName, caId, times];
+            const count = await this.db.queryOne(sql2, sqlParam2);
+            for (const i in result) {
+                result[i].max_sort = count.num;
+            }
+            return result;
+        }
+
+        /**
+         * 获取 当前审核人
+         *
+         * @param {Number} caId - 变更立项id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<*>}
+         */
+        async getCurAuditor(caId, 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.`caid` = ? and la.`status` = ? and la.`times` = ?';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, caId, 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.`caid`, la.`aid`, la.`order` ' +
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                '  WHERE la.`caid` = ? 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(caId, 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.`caid`, la.`aid`, la.`order` ' +
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
+                        '  WHERE la.`caid` = ? and la.`status` = ? ' +
+                        '  ORDER BY la.`times` desc, la.`order` desc';
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, caId, 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.`caid`, la.`aid`, la.`order` ' +
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                        '  WHERE la.`caid` = ? and la.`status` = ? and la.`times` = ?' +
+                        '  ORDER BY la.`times` desc, la.`order` desc';
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, caId, auditConst.status.checkNo, parseInt(times) - 1];
+                    auditor = await this.db.queryOne(sql, sqlParam);
+                    break;
+                case auditConst.status.uncheck :
+                    break;
+                default:break;
+            }
+            return auditor;
+        }
+
+        /**
+         * 获取审核人流程列表(包括原报)
+         * @param {Number} materialId 调差id
+         * @param {Number} times 审核次数
+         * @return {Promise<Array>} 查询结果集(包括原报)
+         */
+        async getAuditorsWithOwner(caId, times = 1) {
+            const result = await this.getAuditGroupByList(caId, times);
+            const sql =
+                'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As caid, 0 As `order`' +
+                '  FROM ' +
+                this.ctx.service.changeApply.tableName +
+                ' As s' +
+                '  LEFT JOIN ' +
+                this.ctx.service.projectAccount.tableName +
+                ' As pa' +
+                '  ON s.uid = pa.id' +
+                '  WHERE s.id = ?';
+            const sqlParam = [times, caId, caId];
+            const user = await this.db.queryOne(sql, sqlParam);
+            result.unshift(user);
+            return result;
+        }
+
+        /**
+         * 新增审核人
+         *
+         * @param {Number} caId - 立项书id
+         * @param {Number} auditorId - 审核人id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<number>}
+         */
+        async addAuditor(caId, auditorId, times = 1, is_gdzs = 0) {
+            const transaction = await this.db.beginTransaction();
+            let flag = false;
+            try {
+                let newOrder = await this.getNewOrder(caId, times);
+                // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
+                newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
+                if (is_gdzs) await this._syncOrderByDelete(transaction, caId, newOrder, times, '+');
+                const data = {
+                    tid: this.ctx.tender.id,
+                    caid: caId,
+                    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} caId - 立项书id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<number>}
+         */
+        async getNewOrder(caId, times = 1) {
+            const sql = 'SELECT Max(??) As max_order FROM ?? Where `caid` = ? and `times` = ?';
+            const sqlParam = ['order', this.tableName, caId, times];
+            const result = await this.db.queryOne(sql, sqlParam);
+            return result && result.max_order ? result.max_order + 1 : 1;
+        }
+
+        /**
+         * 移除审核人
+         *
+         * @param {Number} caId - 变更立项书id
+         * @param {Number} auditorId - 审核人id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<boolean>}
+         */
+        async deleteAuditor(caId, auditorId, times = 1) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const condition = { caid: caId, aid: auditorId, times };
+                const auditor = await this.getDataByCondition(condition);
+                if (!auditor) {
+                    throw '该审核人不存在';
+                }
+                await this._syncOrderByDelete(transaction, caId, 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} caId - 变更立项书id
+         * @param {Number} auditorId - 审核人id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<*>}
+         * @private
+         */
+        async _syncOrderByDelete(transaction, caId, order, times, selfOperate = '-') {
+            this.initSqlBuilder();
+            this.sqlBuilder.setAndWhere('caid', {
+                value: caId,
+                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} caId - 立项书id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<boolean>}
+         */
+        async start(caId, times = 1) {
+            const audit = await this.getDataByCondition({ caid: caId, 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.changeApply.tableName, {
+                    id: caId, 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 getAuditChangeApply(auditorId) {
+            const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`caid`,' +
+                '    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.`caid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`begin_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.changeApply.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
+            return await this.db.query(sql, sqlParam);
+        }
+
+        /**
+         * 用于添加推送所需的content内容
+         * @param {Number} pid 项目id
+         * @param {Number} tid 台账id
+         * @param {Number} caId 立项书id
+         * @param {Number} uid 审批人id
+         */
+        async getNoticeContent(pid, tid, caId, uid) {
+            const noticeSql = 'SELECT * FROM (SELECT ' +
+                '  t.`id` As `tid`, ma.`caid`, m.`code` as `c_code`, 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.`caid`' +
+                '  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.changeApply.tableName, caId, 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} caId - 立项书id
+         * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
+         * @param {Number} times - 第几次审批
+         * @return {Promise<void>}
+         */
+        async check(caId, checkData, times = 1) {
+            if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo) {
+                throw '提交数据错误';
+            }
+            const pid = this.ctx.session.sessionProject.id;
+            switch (checkData.checkType) {
+                case auditConst.status.checked:
+                    await this._checked(pid, caId, checkData, times);
+                    break;
+                case auditConst.status.checkNo:
+                    await this._checkNo(pid, caId, checkData, times);
+                    break;
+                default:
+                    throw '无效审批操作';
+            }
+        }
+
+        async _checked(pid, caId, checkData, times) {
+            const time = new Date();
+
+            // 整理当前流程审核人状态更新
+            const audit = await this.getDataByCondition({ caid: caId, times, status: auditConst.status.checking });
+            if (!audit) {
+                throw '审核数据错误';
+            }
+
+            // 获取审核人列表
+            const sql = 'SELECT `tid`, `caid`, `aid`, `order` FROM ?? WHERE `caid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
+            const sqlParam = [this.tableName, caId, times];
+            const auditors = await this.db.query(sql, sqlParam);
+
+            const nextAudit = await this.getDataByCondition({ caid: caId, 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, caId, audit.aid);
+                // 添加推送
+                const records = [{ pid, type: pushType.changeApply, uid: this.ctx.change.uid, status: auditConst.status.checked, content: noticeContent }];
+                auditors.forEach(audit => {
+                    records.push({ pid, type: pushType.changeApply, 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.changeApply.tableName, {
+                        id: caId, 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.changeApply.tableName, {
+                        id: caId, status: checkData.checkType,
+                        notice_code: checkData.notice_code,
+                        notice_uid: checkData.notice_uid,
+                    });
+
+                    // 微信模板通知
+                    // 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 _checkNo(pid, caId, checkData, times) {
+            const time = new Date();
+            // 整理当前流程审核人状态更新
+            const audit = await this.getDataByCondition({ caid: caId, times, status: auditConst.status.checking });
+            if (!audit) {
+                throw '审核数据错误';
+            }
+            const sql = 'SELECT `tid`, `caid`, `aid`, `order` FROM ?? WHERE `caid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
+            const sqlParam = [this.tableName, caId, 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, caId, audit.aid);
+                const records = [{ pid, type: pushType.changeApply, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
+                auditors.forEach(audit => {
+                    records.push({ pid, type: pushType.changeApply, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
+                });
+                await transaction.insert(this.ctx.service.noticePush.tableName, records);
+                // 同步期信息
+                await transaction.update(this.ctx.service.changeApply.tableName, {
+                    id: caId, 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;
+            }
+        }
+
+        /**
+         * 复制上一期的审批人列表给最新一期
+         *
+         * @param transaction - 新增一期的事务
+         * @param {Object} preMaterial - 上一期
+         * @param {Object} newaMaterial - 最新一期
+         * @return {Promise<*>}
+         */
+        async copyPreChangeApplyAuditors(transaction, preChange, newChange) {
+            const auditors = await this.getAuditGroupByList(preChange.id, preChange.times);
+            const newAuditors = [];
+            for (const a of auditors) {
+                const na = {
+                    tid: preChange.tid,
+                    caid: newChange.id,
+                    aid: a.aid,
+                    times: newChange.times,
+                    order: newAuditors.length + 1,
+                    status: auditConst.status.uncheck,
+                };
+                newAuditors.push(na);
+            }
+            const result = newAuditors.length > 0 ? await transaction.insert(this.tableName, newAuditors) : null;
+            return result ? result.affectedRows === auditors.length : true;
+        }
+
+        async getAllAuditors(tenderId) {
+            const sql = 'SELECT ma.aid, ma.tid FROM ' + this.tableName + ' ma' +
+                '  LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ma.tid = t.id' +
+                '  WHERE t.id = ?' +
+                '  GROUP BY  ma.aid';
+            const sqlParam = [tenderId];
+            return this.db.query(sql, sqlParam);
+        }
+    }
+
+    return ChangeApplyAudit;
+};

+ 327 - 0
app/service/change_project.js

@@ -0,0 +1,327 @@
+'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, 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.id IN (SELECT c.cpid FROM ?? AS c WHERE c.aid = ? AND c.tid = ?))) 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,
+                            this.ctx.service.changeProjectXsAudit.tableName,
+                            this.ctx.session.sessionUser.accountId,
+                            tenderId,
+                            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) OR a.id IN (SELECT c.cpid FROM ?? AS c WHERE c.aid = ? AND c.tid = ?))';
+                        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, this.ctx.service.changeProjectXsAudit.tableName, this.ctx.session.sessionUser.accountId, tenderId];
+                        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.id IN (SELECT c.cpid FROM ?? AS c WHERE c.aid = ? AND c.tid = ?))) 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,
+                        this.ctx.service.changeProjectXsAudit.tableName,
+                        this.ctx.session.sessionUser.accountId,
+                        tenderId,
+                        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) OR a.id IN (SELECT c.cpid FROM ?? AS c WHERE c.aid = ? AND c.tid = ?))';
+                    const sqlParam3 = [this.tableName, status, tenderId, this.ctx.session.sessionUser.accountId, this.ctx.service.changeProjectAudit.tableName, this.ctx.session.sessionUser.accountId, this.ctx.service.changeProjectXsAudit.tableName, this.ctx.session.sessionUser.accountId, tenderId];
+                    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 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;
+        }
+
+        /**
+         * 查询可用的变更令
+         * @param { string } cid - 查询的清单
+         * @return {Promise<*>} - 可用的变更令列表
+         */
+        async delete(id) {
+            // 初始化事务
+            this.transaction = await this.db.beginTransaction();
+            let result = false;
+            try {
+                const changeInfo = await this.getDataById(id);
+                // 先删除审批人列表
+                await this.transaction.delete(this.ctx.service.changeProjectAudit.tableName, { cpid: id });
+                // 再删除附件和附件文件ni zuo
+                const attList = await this.ctx.service.changeProjectAtt.getAllDataByCondition({ where: { cpid: id } });
+                await this.ctx.helper.delFiles(attList);
+                await this.transaction.delete(this.ctx.service.changeProjectAtt.tableName, { cpid: id });
+                // 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, { id });
+                // 记录删除日志
+                await this.ctx.service.projectLog.addProjectLog(this.transaction, projectLogConst.type.changeProject, projectLogConst.status.delete, changeInfo.code);
+                await this.transaction.commit();
+                result = true;
+            } catch (e) {
+                await this.transaction.rollback();
+                result = false;
+            }
+            return result;
+        }
+    }
+
+    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;
+};
+

+ 580 - 0
app/service/change_project_audit.js

@@ -0,0 +1,580 @@
+'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`, m.`code` as `c_code`, 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 = newAuditors.length > 0 ? await transaction.insert(this.tableName, newAuditors) : null;
+            return result ? result.affectedRows === auditors.length : true;
+        }
+
+        async getAllAuditors(tenderId) {
+            const sql = 'SELECT ma.aid, ma.tid FROM ' + this.tableName + ' ma' +
+                '  LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ma.tid = t.id' +
+                '  WHERE t.id = ?' +
+                '  GROUP BY  ma.aid';
+            const sqlParam = [tenderId];
+            return this.db.query(sql, sqlParam);
+        }
+    }
+
+    return ChangeProjectAudit;
+};

+ 162 - 0
app/service/change_project_xs_audit.js

@@ -0,0 +1,162 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2018/8/14
+ * @version
+ */
+
+const auditConst = require('../const/audit').changeProject;
+const pushType = require('../const/audit').pushType;
+
+module.exports = app => {
+    class ChangeProjectXsAudit extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'change_project_xs_audit';
+        }
+
+        /**
+         * 获取协审人列表
+         *
+         * @param auditorId
+         * @return {Promise<*>}
+         */
+        async getAuditList(changeId) {
+            const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`cpid`, la.`aid` ' +
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                '  WHERE la.`cpid` = ? ORDER BY la.`id`';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, changeId];
+            return await this.db.query(sql, sqlParam);
+        }
+
+        /**
+         * 获取单个协审人
+         *
+         * @param auditorId
+         * @return {Promise<*>}
+         */
+        async getOneAudit(cpid, aid) {
+            const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`cpid`, la.`aid` ' +
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                '  WHERE la.`cpid` = ? AND la.`aid` = ?';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpid, aid];
+            return await this.db.queryOne(sql, sqlParam);
+        }
+
+        /**
+         * 新增协审人
+         *
+         * @param {Number} cpId - 立项书id
+         * @param {Number} auditorId - 审核人id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<number>}
+         */
+        async addAuditor(cpId, auditorId) {
+            const transaction = await this.db.beginTransaction();
+            let flag = false;
+            try {
+                const data = {
+                    tid: this.ctx.tender.id,
+                    cpid: cpId,
+                    aid: auditorId,
+                    for_aid: this.ctx.session.sessionUser.accountId,
+                    in_time: new Date(),
+                };
+                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} auditorId - 审核人id
+         * @param {Number} times - 第几次审批
+         * @return {Promise<boolean>}
+         */
+        async deleteAuditor(cpId, auditorId) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const condition = { cpid: cpId, aid: auditorId };
+                const auditor = await this.getDataByCondition(condition);
+                if (!auditor) {
+                    throw '该审核人不存在';
+                }
+                await transaction.delete(this.tableName, condition);
+                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);
+        }
+
+        /**
+         * 复制上一期的协审人列表给最新一期
+         *
+         * @param transaction - 新增一期的事务
+         * @param {Object} preMaterial - 上一期
+         * @param {Object} newaMaterial - 最新一期
+         * @return {Promise<*>}
+         */
+        async copyPreChangeProjectXsAuditors(transaction, preChange, newChange) {
+            const auditors = await this.getAuditList(preChange.id);
+            const newAuditors = [];
+            for (const a of auditors) {
+                const na = {
+                    tid: preChange.tid,
+                    cpid: newChange.id,
+                    aid: a.aid,
+                    for_aid: preChange.for_aid,
+                    in_time: new Date(),
+                };
+                newAuditors.push(na);
+            }
+            const result = await transaction.insert(this.tableName, newAuditors);
+            return result.affectedRows === auditors.length;
+        }
+
+        async getAllAuditors(tenderId) {
+            const sql = 'SELECT ma.aid, ma.tid FROM ' + this.tableName + ' ma' +
+                '  LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ma.tid = t.id' +
+                '  WHERE t.id = ?' +
+                '  GROUP BY  ma.aid';
+            const sqlParam = [tenderId];
+            return this.db.query(sql, sqlParam);
+        }
+    }
+
+    return ChangeProjectXsAudit;
+};

+ 3 - 2
app/service/ledger_audit.js

@@ -278,6 +278,8 @@ module.exports = app => {
                 }
             }
             const sum = await this.ctx.service.ledger.addUp({ tender_id: tenderId /* , is_leaf: true*/ });
+            // 拷贝备份台账数据
+            const his_id = await this.ctx.service.ledgerHistory.backupLedgerHistory(this.ctx.tender.data);
 
             // 拷贝备份台账数据
             const [billsHis, posHis] = await this.backupLedgerHistoryFile();
@@ -294,8 +296,7 @@ module.exports = app => {
                     ledger_status: auditConst.status.checking,
                     total_price: sum.total_price,
                     deal_tp: sum.deal_tp,
-                    bills_file: billsHis,
-                    pos_file: posHis,
+                    his_id: his_id,
                 });
 
                 // 添加短信通知-需要审批提醒功能

+ 157 - 0
app/service/ledger_history.js

@@ -0,0 +1,157 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+module.exports = app => {
+
+    class LedgerTag extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'ledger_history';
+        }
+
+        /** 获取最新数据
+         *
+         * @param {Number}tid - 标段id
+         * @return {Promise<*>} 最新数据
+         */
+        async getLatestHistory(tid) {
+            const his = await this.db.select(this.tableName, {
+                where: { tid },
+                orders: [['in_time', 'desc']],
+                limit: 1, offset: 0,
+            });
+            return his[0];
+        }
+
+        /**
+         * 备份
+         * @param {Object} tender - 标段
+         * @return {Promise<void>} - 新增备份id
+         * @private
+         */
+        async backupLedgerHistory(tender) {
+            const now = new Date();
+            const timestamp = (now).getTime();
+
+            const billsHis = `${this.ctx.session.sessionProject.id}/${tender.id}/ledger/bills${timestamp}.json`;
+            const bills = await this.ctx.service.ledger.getData(tender.id);
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
+
+            const posHis = `${this.ctx.session.sessionProject.id}/${tender.id}/ledger/pos${timestamp}.json`;
+            const pos = await this.ctx.service.pos.getPosData({ tid: tender.id });
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
+
+            const result = await this.db.insert(this.tableName, {
+                pid: this.ctx.session.sessionProject.id, tid: tender.id,
+                in_time: now,
+                bills_file: billsHis, pos_file: posHis,
+            });
+
+            return result.insertId;
+        }
+
+        /**
+         * 备份
+         * @param {Object} tender - 标段
+         * @return {Promise<void>} - 新增备份id
+         * @private
+         */
+        async backupStageLedgerHistory(stage) {
+            const now = new Date();
+            const timestamp = (now).getTime();
+
+            const billsHis = `${this.ctx.session.sessionProject.id}/${stage.tid}/ledger/bills${timestamp}-s.json`;
+            const bills = await this.ctx.service.ledger.getData(stage.tid);
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
+
+            const posHis = `${this.ctx.session.sessionProject.id}/${stage.tid}/ledger/pos${timestamp}-s.json`;
+            const pos = await this.ctx.service.pos.getPosData({ tid: stage.tid });
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
+
+            const result = await this.db.insert(this.tableName, {
+                pid: this.ctx.session.sessionProject.id, tid: stage.tid, sid: stage.id,
+                in_time: now,
+                bills_file: billsHis, pos_file: posHis,
+            });
+
+            return result.insertId;
+        }
+
+        /**
+         * 备份
+         * @param {Object} revise - 修订
+         * @return {Promise<void>} - 新增备份id
+         * @private
+         */
+        async backupReviseLedgerHistory(revise) {
+            const now = new Date();
+            const timestamp = (now).getTime();
+
+            const billsHis = `${this.ctx.session.sessionProject.id}/${revise.tid}/ledger/bills${timestamp}-r.json`;
+            const bills = await this.ctx.service.reviseBills.getData(revise.tid);
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
+
+            const posHis = `${this.ctx.session.sessionProject.id}/${revise.tid}/ledger/pos${timestamp}-r.json`;
+            const pos = await this.ctx.service.revisePos.getData(revise.tid);
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
+
+            const result = await this.db.insert(this.tableName, {
+                pid: this.ctx.session.sessionProject.id, tid: revise.tid,
+                rid: revise.id, rorder: revise.corder,
+                in_time: now,
+                bills_file: billsHis, pos_file: posHis,
+            });
+
+            return result.insertId;
+        }
+
+        /**
+         * 备份 (预留功能)
+         * @param {Object} transaction - 事务
+         * @param {Object} change - 工程变更
+         * @param {Array} newBillsNode - 新增项目节节点
+         * @param {Array} newPosNode - 新增计量单元节点
+         * @return {Promise<void>} - 新增备份id
+         * @private
+         */
+        async backupChangeHistory(transaction, change, newBillsNodes, newPosNodes) {
+            if ((newBillsNodes || newBillsNodes === 0) && (newPosNodes || newPosNodes.length === 0)) return;
+            const now = new Date();
+            const timestamp = (now).getTime();
+
+            const billsHis = `${this.ctx.session.sessionProject.id}/${change.tid}/ledger/bills${timestamp}-c.json`;
+            const bills = await this.ctx.service.ledger.getData(change.tid);
+            if (newBillsNodes.length > 0) bills.push(...newBillsNodes);
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
+
+            const posHis = `${this.ctx.session.sessionProject.id}/${change.tid}/ledger/pos${timestamp}-c.json`;
+            const pos = await this.ctx.service.pos.getPosData({ tid: change.tid });
+            if (newPosNodes.length > 0) pos.push(...newPosNodes);
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
+
+            const result = await transaction.insert(this.tableName, {
+                pid: this.ctx.session.sessionProject.id, tid: change.tid,
+                cid: change.cid,
+                in_time: now,
+                bills_file: billsHis, pos_file: posHis,
+            });
+
+            return result.insertId;
+        }
+    }
+
+    return LedgerTag;
+};

+ 8 - 25
app/service/ledger_revise.js

@@ -30,7 +30,7 @@ module.exports = app => {
          * @returns {Promise<*>} - ledger_change下所有数据,并关联 project_account(读取提交人名称、单位、公司)
          */
         async getReviseList (tid) {
-            const sql = 'SELECT lc.id, lc.tid, lc.corder, lc.in_time, lc.uid, lc.begin_time, lc.end_time, lc.times, lc.status, lc.valid, lc.content, lc.bills_file,' +
+            const sql = 'SELECT lc.id, lc.tid, lc.corder, lc.in_time, lc.uid, lc.begin_time, lc.end_time, lc.times, lc.status, lc.valid, lc.content, lc.pre_his_id, lc.his_id,' +
                 '    pa.name As user_name, pa.role As user_role, pa.company As user_company' +
                 '  FROM ' + this.tableName + ' As lc' +
                 '  INNER JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa ON lc.uid = pa.id' +
@@ -48,7 +48,7 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAllReviseList (tid) {
-            const sql = 'SELECT lc.id, lc.tid, lc.corder, lc.in_time, lc.uid, lc.begin_time, lc.end_time, lc.times, lc.status, lc.valid,' +
+            const sql = 'SELECT lc.id, lc.tid, lc.corder, lc.in_time, lc.uid, lc.begin_time, lc.end_time, lc.times, lc.status, lc.valid, lc.pre_his_id, lc.his_id,' +
                 '    pa.name As user_name, pa.role As user_role, pa.company As user_company' +
                 '  FROM ' + this.tableName + ' As lc' +
                 '  INNER JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa ON lc.uid = pa.id' +
@@ -150,26 +150,6 @@ module.exports = app => {
         }
 
         /**
-         * 备份
-         * @param {Object} revise - 修订
-         * @returns {Promise<void>}
-         * @private
-         */
-        async backupReviseHistoryFile(revise) {
-            const timestamp = (new Date()).getTime();
-
-            const billsHis = `${this.ctx.session.sessionProject.id}/${this.ctx.tender.id}/bills${timestamp}.json`;
-            const bills = await this.ctx.service.reviseBills.getData(revise.tid);
-            await this.ctx.app.hisOss.put(this.ctx.app.config.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
-
-            const posHis = `${this.ctx.session.sessionProject.id}/${this.ctx.tender.id}/pos${timestamp}.json`;
-            const pos = await this.ctx.service.revisePos.getData(revise.tid);
-            await this.ctx.app.hisOss.put(this.ctx.app.config.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
-
-            return [billsHis, posHis];
-        }
-
-        /**
          * 新增修订
          * @param {Number}tid - 标段id
          * @param {Number}uid - 提交人id
@@ -180,9 +160,11 @@ module.exports = app => {
                 throw '数据错误';
             }
             const maxOrder = await this.getNewOrder(tid);
+            const latest = await this.ctx.service.ledgerHistory.getLatestHistory(tid);
+            if (!latest) throw '台账历史数据有误';
             const data = {
                 id: this.uuid.v4(), tid: tid, uid: uid,
-                corder: maxOrder + 1, in_time: new Date(), status: audit.status.uncheck,
+                corder: maxOrder + 1, in_time: new Date(), status: audit.status.uncheck, pre_his_id: latest.id,
             };
             const transaction = await this.db.beginTransaction();
             try {
@@ -209,13 +191,14 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async cancelRevise(revise) {
+            const his_id = await this.ctx.service.ledgerHistory.backupReviseLedgerHistory(revise);
             const transaction = await this.db.beginTransaction();
             try {
-                const [billsHis, posHis] = await this.backupReviseHistoryFile(revise);
                 const result = await transaction.update(this.tableName, {
                     id: revise.id, valid: false, end_time: new Date(),
-                    bills_file: billsHis, pos_file: posHis,
+                    his_id,
                 });
+                await transaction.update(this.ctx.service.ledgerHistory.tableName, { id: his_id, valid: 0 });
                 // 投资进度改变状态
                 await transaction.update(this.ctx.service.schedule.tableName, { revising: 0 }, { where: { tid: this.ctx.tender.id } });
                 await transaction.commit();

+ 4 - 4
app/service/material_bills.js

@@ -261,9 +261,9 @@ module.exports = app => {
                     m_spread: newm_spread,
                     origin: null,
                     m_tp: newTp,
-                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), decimal.tp) : mb.pre_tp,
+                    pre_tp: mb.m_tp !== null ? this.ctx.helper.add(mb.pre_tp, mb.m_tp) : mb.pre_tp,
                     m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp),
-                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), decimal.tp) : mb.tax_pre_tp,
+                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp) : mb.tax_pre_tp,
                 };
                 await transaction.update(this.tableName, updateData);
                 const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), decimal.tp) : 0;
@@ -281,9 +281,9 @@ module.exports = app => {
                     m_spread: newm_spread,
                     origin: null,
                     m_tp: newTp,
-                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), decimal.tp) : mb.pre_tp,
+                    pre_tp: mb.m_tp !== null ? this.ctx.helper.add(mb.pre_tp, mb.m_tp) : mb.pre_tp,
                     m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp),
-                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), decimal.tp) : mb.tax_pre_tp,
+                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp) : mb.tax_pre_tp,
                 };
                 await transaction.update(this.tableName, updateData);
                 const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(quantity, newm_spread), decimal.tp) : 0;

+ 3 - 4
app/service/revise_audit.js

@@ -231,7 +231,7 @@ module.exports = app => {
             const time = new Date();
 
             // 拷贝备份台账数据
-            const [billsHis, posHis] = await this.ctx.service.ledgerRevise.backupReviseHistoryFile(revise);
+            const his_id = await this.ctx.service.ledgerHistory.backupReviseLedgerHistory(revise);
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -245,8 +245,7 @@ module.exports = app => {
                 const reviseData = {
                     id: revise.id,
                     status: auditConst.status.checking,
-                    bills_file: billsHis,
-                    pos_file: posHis,
+                    his_id,
                 };
                 if (revise.times === 1) {
                     reviseData.begin_time = time;
@@ -653,7 +652,7 @@ module.exports = app => {
         async getNoticeContent(pid, tid, rid, uid) {
             const noticeSql =
                 'SELECT * FROM (SELECT ' +
-                '  t.`id` As `tid`, t.`name`, r.`corder`, pa.`name` As `su_name`, pa.role As `su_role`' +
+                '  t.`id` As `tid`, t.`name`, r.`corder`, r.`id` As rid, pa.`name` As `su_name`, pa.role As `su_role`' +
                 '  FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
                 '  LEFT JOIN ?? As r On r.`id` = ? ' +
                 '  LEFT JOIN ?? As pa ON pa.`id` = ? ' +

+ 0 - 27
app/service/revise_price_change.js

@@ -1,27 +0,0 @@
-'use strict';
-
-/**
- *
- *
- * @author Mai
- * @date
- * @version
- */
-
-module.exports = app => {
-    class RevisePriceChange extends app.BaseService {
-
-        /**
-         * 构造函数
-         *
-         * @param {Object} ctx - egg全局变量
-         * @return {void}
-         */
-        constructor(ctx) {
-            super(ctx);
-            this.tableName = 'revise_price_change';
-        }
-    }
-
-    return RevisePriceChange;
-};

+ 4 - 0
app/service/rpt_gather_memory.js

@@ -25,12 +25,14 @@ const gatherUtils = {
             for (const cd of completeDatas) {
                 data[cd.prefix + 'id'] = cd.id;
                 data[cd.prefix + 'name'] = cd.name;
+                data[cd.prefix + 'category'] = cd.category;
             }
         }
     },
     gatherStage: function (tender, gatherNode, sourceNode, prefix, helper) {
         gatherNode[prefix + 'id'] = tender.id;
         gatherNode[prefix + 'name'] = tender.name;
+        gatherNode[prefix + 'category'] = tender.category;
 
         gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
         gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
@@ -99,6 +101,7 @@ const gatherUtils = {
     gatherZone: function (tender, gatherNode, sourceNode, prefix, helper) {
         gatherNode[prefix + 'id'] = tender.id;
         gatherNode[prefix + 'name'] = tender.name;
+        gatherNode[prefix + 'category'] = tender.category;
 
         gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
         gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
@@ -131,6 +134,7 @@ const gatherUtils = {
     gatherLedger: function (tender, gatherNode, sourceNode, prefix, helper) {
         gatherNode[prefix + 'id'] = tender.id;
         gatherNode[prefix + 'name'] = tender.name;
+        gatherNode[prefix + 'category'] = tender.category;
 
         gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
         gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);

+ 14 - 0
app/service/stage_audit.js

@@ -470,6 +470,19 @@ module.exports = app => {
                     await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
                 } else {
                     await this.ctx.service.tenderTag.saveTenderTag(this.ctx.tender.id, {stage_time: new Date()}, transaction);
+                    let his_id;
+                    if (this.ctx.tender.measureType === measureType.tz.value) {
+                        const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(this.ctx.tender.id);
+                        his_id = ledgerHis.id;
+                    } else {
+                        const sapCount = await this.ctx.service.pos.count({ add_stage: this.ctx.stage.id });
+                        if (sapCount > 0) {
+                            his_id = await this.ctx.service.ledgerHistory.backupStageLedgerHistory(this.ctx.stage);
+                        } else {
+                            const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(this.ctx.tender.id);
+                            his_id = ledgerHis.id;
+                        }
+                    }
                     // 本期结束
                     // 生成截止本期数据 final数据
                     await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
@@ -485,6 +498,7 @@ module.exports = app => {
                         sf_tp: sfPay.tp,
                         tp_history: JSON.stringify(this.ctx.stage.tp_history),
                         cache_time_r: this.ctx.stage.cache_time_l,
+                        his_id,
                     });
 
                     // 添加短信通知-审批通过提醒功能

+ 3 - 3
app/service/stage_pay.js

@@ -207,6 +207,7 @@ module.exports = app => {
                 if (data.expr !== undefined) { updateData.expr = data.expr }
                 if (data.tp !== undefined) { updateData.tp = data.tp }
                 if (data.pause !== undefined) { updateData.pause = data.pause }
+                if (data.postil !== undefined) updateData.postil = data.postil;
                 updateDatas.push(updateData);
             }
             const result = await this.db.updateRows(this.tableName, updateDatas);
@@ -229,7 +230,6 @@ module.exports = app => {
             const PayCalculator = require('../lib/pay_calc');
             const payCalculator = new PayCalculator(this.ctx, stage, this.ctx.tender.info);
             await payCalculator.calculateAll(stagePays);
-            console.log(stagePays);
             const srUpdate = [], update = [];
             for (const sp of stagePays) {
                 update.push({
@@ -289,9 +289,9 @@ module.exports = app => {
                 throw '数据错误';
             }
             const sql = 'INSERT INTO ?? (`tid`, `sid`, `pid`, `stimes`, `sorder`, `name`, `tp`, `expr`, `pause`,' +
-                        '    `pre_tp`, `end_tp`, `pre_used`, `pre_finish`, `start_stage_order`) ' +
+                        '    `pre_tp`, `end_tp`, `pre_used`, `pre_finish`, `start_stage_order`, `postil`) ' +
                         '  SELECT SP.`tid`, SP.`sid`, SP.`pid`, ?, ?, SP.name, SP.`tp`, SP.`expr`, SP.`pause`,' +
-                        '     SP.`pre_tp`, SP.`end_tp`, SP.`pre_used`, SP.`pre_finish`, SP.`start_stage_order` ' +
+                        '     SP.`pre_tp`, SP.`end_tp`, SP.`pre_used`, SP.`pre_finish`, SP.`start_stage_order`, SP.`postil` ' +
                         '  FROM ?? As SP' +
                         '  WHERE SP.`sid` = ? AND SP.`stimes` = ? AND SP.`sorder` = ?';
             const sqlParam = [this.tableName, times, order, this.tableName, stage.id, stage.curTimes, stage.curOrder];

+ 10 - 1
app/service/tender.js

@@ -15,7 +15,7 @@ const fs = require('fs');
 const path = require('path');
 const commonQueryColumns = [
     'id', 'project_id', 'name', 'status', 'category', 'ledger_times', 'ledger_status', 'measure_type', 'user_id', 'valuation',
-    'total_price', 'deal_tp', 'copy_id', 's2b_gxby_check', 's2b_gxby_limit', 's2b_dagl_check', 's2b_dagl_limit', 'has_rela',
+    'total_price', 'deal_tp', 'copy_id', 's2b_gxby_check', 's2b_gxby_limit', 's2b_dagl_check', 's2b_dagl_limit', 'has_rela', 'his_id',
 ];
 
 module.exports = app => {
@@ -111,6 +111,13 @@ module.exports = app => {
                 // 根据用户权限查阅标段
                 // tender 163条数据,project_account 68条数据测试
                 // 查询两张表耗时0.003s,查询tender左连接project_account耗时0.002s
+                const changeProjectSql = this.ctx.session.sessionProject.page_show.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`))' : '';
+                const changeApplySql = this.ctx.session.sessionProject.page_show.openChangeApply ? '    OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
+                    '        t.id IN ( SELECT caa.`tid` FROM ' + this.ctx.service.changeApplyAudit.tableName + ' AS caa WHERE caa.`aid` = ' + session.sessionUser.accountId + ' GROUP BY caa.`tid`))' : '';
+                // 协审sql
+                const changeProjectXsSql = this.ctx.session.sessionProject.page_show.openChangeProject ? '    OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
+                    '        t.id IN ( SELECT cpxa.`tid` FROM ' + this.ctx.service.changeProjectXsAudit.tableName + ' AS cpxa WHERE cpxa.`aid` = ' + session.sessionUser.accountId + ' GROUP BY cpxa.`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 +145,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 + changeApplySql + changeProjectXsSql +
                     // 游客权限的标段
                     '    OR (t.id IN ( SELECT tt.`tid` FROM ?? AS tt WHERE tt.`user_id` = ?))' +
                     // 未参与,但可见的标段

+ 110 - 0
app/view/change/apply.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) { %>
+            <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="10%">创建人</th>
+                        <th width="10%">创建时间</th><th width="10%">状态</th><th width="15%">立项编号</th>
+                        <th width="15%">变更通知书</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/apply/<%- c.id %>/information"><%- c.code %></a></td>
+                            <td><%- apply_username %></td><td><%- ctx.helper.formatFullDate(c.in_time) %></td>
+                            <td><span class="<%- auditConst.statusClass[c.status] %>"><%- auditConst.statusString[c.status] %></span></td>
+                            <td><%- c.project_code %></td>
+                            <td><% if (c.notice_code) { %><a href="/tender/<%- tender.id %>/change/apply/<%- c.id %>/information/notice"><%- c.notice_code %></a><% } %></td>
+                            <td><%- c.account_name %></td>
+                            <td>
+                                <% if ((c.status === auditConst.status.uncheck || c.status === auditConst.status.checkNo) && c.uid === ctx.session.sessionUser.accountId) { %>
+                                    <a href="/tender/<%- tender.id %>/change/apply/<%- 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/apply/<%- 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.checkNo)) { %><a href="#del-bg" caid="<%= c.id %>" data-toggle="modal" data-target="#del-bg" class="btn btn-outline-danger btn-sm delete-caid-modal">删除</a><% } %>
+                            </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>

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

@@ -0,0 +1,148 @@
+<% 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/apply"><i class="fa fa-chevron-left mr-2"></i><span>返回</span></a>
+                </div>
+                <div class="d-inline-block" id="change-apply-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 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-success btn-sm">审批完成</a>
+                <% } else if (ctx.change.status === auditConst.status.checkNo) { %>
+                    <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>
+                    <% } %>
+                <% } %>
+            </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="apply-table">
+                        <tr>
+                            <th width="120" class="text-center" style="vertical-align: middle">变更申请编号<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" style="vertical-align: middle">变更工程名称<b class="text-danger">*&nbsp;</b></th>
+                            <td><input class="form-control form-control-sm" value="<%- change.name %>" data-name="name" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder=""></td>
+                            <th width="140" class="text-center" style="vertical-align: middle">桩号</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.peg %>" data-name="peg" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="" class="text-center" style="vertical-align: middle">原设计图名称</th>
+                            <td><input class="form-control form-control-sm" value="<%- change.org_name %>" data-name="org_name" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder=""></td>
+                            <th width="" class="text-center" style="vertical-align: middle">图号</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="" class="text-center" style="vertical-align: middle">变更设计名称</th>
+                            <td><input class="form-control form-control-sm" value="<%- change.design_name %>" data-name="design_name" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder=""></td>
+                            <th width="" class="text-center" style="vertical-align: middle">变更图号</th>
+                            <td><input class="form-control form-control-sm" value="<%- change.c_new_code %>" data-name="c_new_code" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="" class="text-center" style="vertical-align: middle">变更意向编号</th>
+                            <td><input class="form-control form-control-sm" value="<%- change.project_code %>" data-name="project_code" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder="自动读取,没有就为空,可编辑"></td>
+                            <th width="" class="text-center" style="vertical-align: middle">原工程造价(元)</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="" class="text-center" style="vertical-align: middle">工程变更类别</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="" class="text-center" style="vertical-align: middle">变更后工程造价(元)</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>
+                        </tr>
+                        <tr>
+                            <th width="" class="text-center" style="vertical-align: middle">工程变更性质</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- change.quality %>" data-name="quality" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                            <th width="" class="text-center" style="vertical-align: middle">工程造价增减(元)</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="" class="text-center" style="vertical-align: middle">变更原因<b class="text-danger">*&nbsp;</b></th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" data-name="reason" <% if (change.readOnly) { %>readonly<% } %> rows="3"><%- change.reason %></textarea></td>
+                        </tr>
+                        <tr>
+                            <th width="" class="text-center" style="vertical-align: middle">原设计情况描述</th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" data-name="org_content" <% if (change.readOnly) { %>readonly<% } %> rows="3"><%- change.org_content %></textarea></td>
+                        </tr>
+                        <tr>
+                            <th width="" class="text-center" style="vertical-align: middle">现场实际情况描述</th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" data-name="site_content" <% if (change.readOnly) { %>readonly<% } %> rows="3"><%- change.site_content %></textarea></td>
+                        </tr>
+                        <tr>
+                            <th width="" class="text-center" style="vertical-align: middle">内容摘要</th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" 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>
+                            <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 fileTypeConst = JSON.parse(unescape('<%- escape(JSON.stringify(changeConst.file_type)) %>'));
+    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>

+ 752 - 0
app/view/change/apply_information_modal.ejs

@@ -0,0 +1,752 @@
+<!--添加附件-->
+<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">
+                <div class="form-group">
+                    <label for="file-modal">大小限制:30MB,支持office等文档格式、图片格式、压缩包格式</label>
+                    <!-- <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>
+                    <% for (const t of changeConst.file_type) { %>
+                    <div class="form-check form-check-inline">
+                        <input class="form-check-input" type="radio" name="type" id="file_type_<%- t.key %>" value="<%- t.key %>">
+                        <label class="form-check-label" for="file_type_<%- t.key %>"><%- t.value %></label>
+                    </div>
+                    <% } %>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button id="file-cancel" type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">取消</button>
+                <button id="file-ok" type="button" class="btn btn-primary btn-sm">添加</button>
+            </div>
+        </div>
+    </div>
+</div>
+<% if ((ctx.change.status === auditConst.status.uncheck || ctx.change.status === auditConst.status.checkNo) && (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.checkNo) { %>
+                            <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.checkNo) {%>
+                                                    <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.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.checkNo) {%>
+                                                    <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.checkNo ? 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.checkNo && 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.checkNo) {%>
+                                                            <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.checkNo) {%>
+                                                            <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.checkNo ? 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>
+                                                                            <% if (auditors[auditors.length - 1].aid === auditor.aid) { %>
+                                                                            <!--终审填写批复编号-->
+                                                                            <div class="form-group mt-3">
+                                                                                <label><b class="text-danger">*&nbsp;</b>变更通知书</label>
+                                                                                <input class="form-control form-control-sm" value="BGTZ-<%- change.code %>" name="notice_code" type="text">
+                                                                                <input type="hidden" name="notice_uid" value="<%- auditor.aid %>">
+                                                                            </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 %>" />
+                        <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.checkNo) {%>
+                                                            <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.checkNo %>" 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.checkNo) {%>
+                                                            <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.checkNo ? 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.checkNo %>" 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>
+    <% } %>
+<% } %>
+<% if (ctx.session.sessionUser.accountId === ctx.change.uid && (ctx.change.status === auditConst.status.uncheck || ctx.change.status === auditConst.status.checkNo)) { %>
+    <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>

+ 85 - 0
app/view/change/apply_information_notice.ejs

@@ -0,0 +1,85 @@
+<% 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/apply"><i class="fa fa-chevron-left mr-2"></i><span>返回</span></a>
+                </div>
+                <div class="d-inline-block" id="change-apply-code">
+                    <%- change.code %>
+                </div>
+            </div>
+            <div class="ml-auto" id="sp-btn">
+                <% if (ctx.change.status === auditConst.status.checked) { %>
+                    <a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-success 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="apply-table">
+                        <tr>
+                            <th width="" class="text-center">项目名称</th>
+                            <td colspan="3"><input class="form-control form-control-sm" value="<%- ctx.tender.info.deal_info.buildName %>" <% 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" value="<%- change.name %>" data-name="name" <% if (change.readOnly) { %>readonly<% } %> type="text" placeholder=""></td>
+                            <th width="140" class="text-center">编号</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- ctx.tender.info.deal_info.dealCode %>" data-name="peg" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="" class="text-center">承包人</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- ctx.tender.info.construction_unit.contract1.company %>" data-name="class" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                            <th width="" class="text-center">合同段</th>
+                            <td><input class="form-control form-control-sm" type="text" value="<%- ctx.tender.info.deal_info.dealName %>" data-name="change_price" <% if (change.readOnly) { %>readonly<% } %> placeholder=""></td>
+                        </tr>
+                        <tr>
+                            <th width="" 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="" 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="" class="text-center">变更原因</th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" data-name="reason" <% if (change.readOnly) { %>readonly<% } %> rows="3"><%- change.reason %></textarea></td>
+                        </tr>
+                        <tr>
+                            <th width="" class="text-center">变更内容</th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" 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>
+                        <tbody id="file-content">
+                        </tbody>
+                        </tbody>
+                    </table>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script>
+    autoFlashHeight();
+    const auditConst = JSON.parse('<%- JSON.stringify(auditConst) %>');
+    const fileTypeConst = JSON.parse(unescape('<%- escape(JSON.stringify(changeConst.file_type)) %>'));
+    const fileList = JSON.parse(unescape('<%- escape(JSON.stringify(fileList)) %>')) || [];
+    const preUrl = '<%- preUrl %>';
+    const change = JSON.parse(unescape('<%- escape(JSON.stringify(change)) %>'));
+</script>

+ 215 - 0
app/view/change/apply_information_notice_modal.ejs

@@ -0,0 +1,215 @@
+<!--审批流程/结果-->
+<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">审批流程</h5>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <div class="col-4">
+                        <% if(ctx.change.status === auditConst.status.checkNo) { %>
+                            <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.checkNo) {%>
+                                                    <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.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.checkNo) {%>
+                                                    <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.checkNo ? 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>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+            </div>
+        </div>
+    </div>
+</div>
+<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('展开历史审核记录')
+            })
+        }
+    });
+</script>

+ 140 - 0
app/view/change/apply_modal.ejs

@@ -0,0 +1,140 @@
+<!--删除标段-->
+<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/apply/delete" method="post">
+                <input type="hidden" name="caid" id="delete-caid" 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) { %>
+<!--弹出添加变更令-->
+<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>
+                <% if (ctx.session.sessionProject.page_show.openChangeProject) { %>
+                <div class="form-group">
+                    <label>关联变更立项</label>
+                    <select class="form-control form-control-sm" id="project-code">
+                        <option></option>
+                        <% for (const cp of changeProjectList) { %>
+                        <option><%- cp.code %></option>
+                        <% } %>
+                    </select>
+                </div>
+                <% } else { %>
+                    <input type="hidden" value="" id="project-code">
+                <% } %>
+            </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>
+<% } %>
+
+

+ 3 - 3
app/view/change/information.ejs

@@ -448,7 +448,7 @@
     let changeInfo = Object.assign({}, back_changeInfo);
     let changeUsedData = JSON.parse(unescape('<%- escape(JSON.stringify(changeUsedData)) %>'));
 </script>
-<script src="/public/js/change_information_set.js"></script>
+<script src="/public/js/change_information_set.js?202001181"></script>
 <script src="/public/js/change_audit.js"></script>
 <% } else if (auditStatus === 3 || auditStatus === 4 || auditStatus === 5 || auditStatus === 7 || auditStatus === 8) { %>
 <script>
@@ -456,7 +456,7 @@
     const aidList = _.map(auditList2, 'uid');
     aidList.splice(0, 1);
 </script>
-<script src="/public/js/change_information_show.js"></script>
+<script src="/public/js/change_information_show.js?202001181"></script>
 <% } else if (auditStatus === 6) { %>
 <script>
     const auditList2 = JSON.parse(unescape('<%- escape(JSON.stringify(auditList2)) %>'));
@@ -466,5 +466,5 @@
     const changeLedgerList = JSON.parse(unescape('<%- escape(JSON.stringify(changeLedgerList)) %>'));
     const changePosList = JSON.parse(unescape('<%- escape(JSON.stringify(changePosList)) %>'));
 </script>
-<script src="/public/js/change_information_approval.js"></script>
+<script src="/public/js/change_information_approval.js?202001181"></script>
 <% } %>

+ 1 - 1
app/view/change/information_modal.ejs

@@ -142,7 +142,7 @@
                             <div class="col-6 p-0 search-group">
                                 <div class="input-group input-group-sm pb-1">
                                     <div class="input-group-prepend"></div>
-                                    <input class="form-control form-control-sm" id="code-input" placeholder="输入 项目节编号、名称、计量单元 检索">
+                                    <input class="form-control form-control-sm" id="code-input" placeholder="输入 项目节编号、细目、计量单元 检索">
                                     <a href="javascript:void(0);" style="display: none" data-btn="code" class="text-danger remove-btn" title="移除关键词"><i class="fa fa-times-circle "></i></a>
                                 </div>
                             </div>

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

@@ -0,0 +1,107 @@
+<% 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" cpid="<%= c.id %>" data-toggle="modal" data-target="#del-bg" class="btn btn-outline-danger btn-sm delete-cpid-modal">删除</a><% } %>
+                            </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>

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

@@ -0,0 +1,136 @@
+<% 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">
+                <a href="#xieshen" data-toggle="modal" data-target="#xieshen" class="btn btn-sm btn-primary mr-2">添加协审</a>
+                <% 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"><%- changeConst.project_type[change.type] %>报告书</h4>
+                    <table class="table table-bordered" id="project-table">
+                        <tr>
+                            <th width="120" class="text-center" style="vertical-align: middle">立项编号<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" style="vertical-align: middle">变更工程名称<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" style="vertical-align: middle">原设计图名称</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" style="vertical-align: middle">桩号</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" style="vertical-align: middle">图号</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" style="vertical-align: middle">工程变更类别</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" style="vertical-align: middle">工程变更性质</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" style="vertical-align: middle">原工程造价(元)</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" style="vertical-align: middle">预计变更造价(元)</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" style="vertical-align: middle">预计造价增减(元)</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" style="vertical-align: middle">变更原因<b class="text-danger">*&nbsp;</b></th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" data-name="reason" <% if (change.readOnly) { %>readonly<% } %> rows="3"><%- change.reason %></textarea></td>
+                        </tr>
+                        <tr>
+                            <th width="120" class="text-center" style="vertical-align: middle">内容摘要</th>
+                            <td colspan="3"><textarea class="form-control form-control-sm" 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>

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

@@ -0,0 +1,831 @@
+<!--添加附件-->
+<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 btn-sm" data-dismiss="modal">取消</button>
+                <button id="file-ok" type="button" class="btn btn-primary btn-sm">添加</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 search-user-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>
+    <% } %>
+<% } %>
+<!--弹出添加协审-->
+<div class="modal fade" id="xieshen" 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 modal-height">
+                <div class="mb-3">协审帐号可以查看本变更,上传附件。</div>
+                <div>
+                    <div class="dropdown mb-3">
+                        <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button"
+                                id="dropdownMenuButton2" data-toggle="dropdown" aria-haspopup="true"
+                                aria-expanded="false">
+                            选择协审人
+                        </button>
+                        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton2"
+                             style="width:220px">
+                            <div class="mb-2 p-2"><input class="form-control form-control-sm"
+                                                         placeholder="姓名/手机 检索" id="gr-search2" autocomplete="off"></div>
+                            <dl class="list-unstyled book-list search-user-list2">
+                                <% 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 => { %>
+                                            <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="modal-height-max100" id="xs-list">
+                        <% for (const xs of change.xsAuditors) { %>
+                  <span class="d-inline-block">
+                    <span class="badge badge-light">
+                      <%- xs.name %>
+                        <% if (ctx.helper._.indexOf(ctx.helper._.map(change.auditors2, 'aid'), ctx.session.sessionUser.accountId) !== -1) { %>
+                        <span class="dropdown">
+                        <a href="javascript:void(0)" class="btn-sm text-danger px-1" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-remove"></i></a>
+                        <div class="dropdown-menu">
+                          <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>
+                          <div class="dropdown-divider"></div>
+                          <div class="px-2 py-1 text-center">
+                            <button class="btn btn-sm btn-danger" aid="<%- xs.aid %>">移除</button>
+                            <button class="btn btn-sm btn-secondary">取消</button>
+                          </div>
+                        </div>
+                      </span>
+                        <% } %>
+                    </span>
+                  </span>
+                            <% } %>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+            </div>
+        </div>
+    </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="cpid" id="delete-cpid" 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"><% if (tender.user_id === uid) { %>变更建议<% } else { %>变更意向<% } %>编号设置</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>
+<% } %>
+
+

+ 64 - 4
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) { %>
@@ -65,7 +65,7 @@
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-info">台账修订</span></div>
                                                     <div class="col-6"><a href="/tender/<%- revise.t_id %>"><%- revise.t_name %></a> 台账修订(第<%- revise.corder %>次)</div>
-                                                    <div class="col-3 ml-auto text-right pl-0"><a href="/tender/<%- revise.t_id %>/revise/info" class="btn btn-sm btn-outline-primary"><% if (revise.status === acRevise.status.checking) { %>审批<% } else if (revise.status === acRevise.status.checkNo) { %>重新上报<% } %></a></div>
+                                                    <div class="col-3 ml-auto text-right pl-0"><a href="/tender/<%- revise.t_id %>/revise/<%- revise.id %>/info" class="btn btn-sm btn-outline-primary"><% if (revise.status === acRevise.status.checking) { %>审批<% } else if (revise.status === acRevise.status.checkNo) { %>重新上报<% } %></a></div>
                                                 </div>
                                                 <p class="mt-1 mb-0"><%- revise.audit_name %><small class="ml-1 text-muted"><%- (revise.audit_role ? '- ' + revise.audit_role: '') %></small>
                                                     <span class="pull-right text-muted"><%- (
@@ -120,7 +120,35 @@
                                             </div>
                                         </li>
                                     <% } %>
-                                    <% for (const am of auditMaterial) { %>
+                                    <% 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 aca of auditChangeApply) { %>
+                                        <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/<%- aca.tid %>"><%- aca.name %></a> 变更申请 <%- aca.mcode %></div>
+                                                    <div class="col-3 ml-auto text-right pl-0"><a href="/tender/<%- aca.tid %>/change/apply/<%- aca.caid %>/information" class="btn btn-sm btn-outline-primary"><% if (aca.mstatus !== acChangeApply.status.checkNo) { %>审批<% } 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(aca.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">
                                                 <div class="media-body">
@@ -246,7 +274,7 @@
                                                         <div class="col-auto"><span class="badge badge-info">台账修订</span></div>
                                                         <div class="col-6">
                                                             <a href="/tender/<%- notice.tid %>"><%- notice.name %></a>
-                                                            <a href="/tender/<%- notice.tid %>/revise/info">台账修订(第<%- notice.corder %>次)</a>
+                                                            <a href="/tender/<%- notice.tid %>/revise/<%- notice.rid %>/info">台账修订(第<%- notice.corder %>次)</a>
                                                             <%- acRevise.statusString[notice.status]%>
                                                         </div>
                                                     </div>
@@ -271,6 +299,38 @@
                                                     </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 %>/information"><%- 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.changeApply && ctx.session.sessionProject.page_show.openChangeApply) { %>
+                                            <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/apply/<%- notice.caid %>/information"><%- notice.c_code %> </a>
+                                                            <%- acChangeApply.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">

+ 9 - 1
app/view/material/checklist.ejs

@@ -13,7 +13,15 @@
                     <a class="btn btn-sm btn-light">
                         <div class="custom-control custom-checkbox">
                             <input type="checkbox" class="custom-control-input" id="notBills_checkList">
-                            <label class="custom-control-label text-primary" for="notBills_checkList">筛选无调差工料清单</label>
+                            <label class="custom-control-label text-primary" for="notBills_checkList">无调差工料</label>
+                        </div>
+                    </a>
+                </div>
+                <div class="d-inline-block">
+                    <a class="btn btn-sm btn-light">
+                        <div class="custom-control custom-checkbox">
+                            <input type="checkbox" class="custom-control-input" id="bills0_checkList">
+                            <label class="custom-control-label text-primary" for="bills0_checkList">工料含量为0</label>
                         </div>
                     </a>
                 </div>

+ 5 - 5
app/view/measure/stage.ejs

@@ -9,11 +9,11 @@
             <div class="ml-auto">
                 <% if (ctx.session.sessionUser.accountId === ctx.tender.data.user_id && ctx.tender.data.ledger_status === auditConst.status.checked &&
                         (stages.length === 0 || stages[0].status === auditConst.status.checked)) { %>
-                <% if (ctx.helper.checkZero(ctx.tender.info.deal_param.contractPrice) && stages.length === 0) { %>
-                    <a href="#add-qi" data-toggle="modal" data-target="#tips" class="btn btn-primary btn-sm">开始新一期</a>
-                <% } else { %>
-                    <a href="#add-qi" data-toggle="modal" data-target="#add-qi" class="btn btn-primary btn-sm">开始新一期</a>
-                <% } %>
+                    <% if (!ctx.session.sessionProject.page_show.close1stStageCheckDealParam && ctx.helper.checkZero(ctx.tender.info.deal_param.contractPrice) && stages.length === 0) { %>
+                        <a href="#add-qi" data-toggle="modal" data-target="#tips" class="btn btn-primary btn-sm">开始新一期</a>
+                    <% } else { %>
+                        <a href="#add-qi" data-toggle="modal" data-target="#add-qi" class="btn btn-primary btn-sm">开始新一期</a>
+                    <% } %>
                 <% } %>
             </div>
         </div>

+ 2 - 2
app/view/revise/history.ejs

@@ -1,8 +1,8 @@
-<% include ../tender/tender_sub_menu.ejs %>
+<% include ./sub_menu.ejs %>
 <div class="panel-content">
     <div class="panel-title">
         <div class="title-main d-flex justify-content-between">
-            <% include ../tender/tender_sub_mini_menu.ejs %>
+            <% include ./sub_mini_menu.ejs %>
             <!--工具-->
             <div>
                 <div class="d-inline-block">

+ 6 - 6
app/view/revise/index.ejs

@@ -64,19 +64,19 @@
                         <td>
                             <% if (lr.valid) { %>
                             <% if (lr.status === auditConst.status.uncheck && lr.uid === ctx.session.sessionUser.accountId) { %>
-                            <a href="<%- preUrl + '/revise/info' %>" class="btn btn-primary btn-sm">修订</a>
+                            <a href="<%- preUrl + '/revise/' + lr.id + '/info' %>" class="btn btn-primary btn-sm">修订</a>
                             <a href="#remove" data-toggle="modal" data-target="#remove" class="btn btn-secondary btn-sm">作废</a>
                             <% } else if (lr.status === auditConst.status.checking && lr.curAuditor.audit_id === ctx.session.sessionUser.accountId) { %>
-                            <a href="<%- preUrl + '/revise/info' %>" class="btn btn-success btn-sm">审批</a>
+                            <a href="<%- preUrl + '/revise/' + lr.id + '/info' %>" class="btn btn-success btn-sm">审批</a>
                             <% } else if (lr.status === auditConst.status.checkNo && lr.uid === ctx.session.sessionUser.accountId) { %>
-                            <a href="<%- preUrl + '/revise/info' %>" class="btn btn-primary btn-sm">重新上报</a>
+                            <a href="<%- preUrl + '/revise/'  + lr.id + '/info' %>" class="btn btn-primary btn-sm">重新上报</a>
                             <a href="#remove" data-toggle="modal" data-target="#remove" class="btn btn-secondary btn-sm">作废</a>
                             <% } else if (lr.status !== auditConst.status.checked) { %>
-                            <a href="<%- preUrl + '/revise/info' %>">查看修订内容</a>
+                            <a href="<%- preUrl + '/revise/' + lr.id + '/info' %>">查看修订内容</a>
                             <% } %>
                             <% } %>
-                            <% if (lr.bills_file && (lr.status === auditConst.status.checked || lr.valid)) { %>
-                                <a href="<%- preUrl + '/revise/history/' + lr.id %>">查看修订内容</a>
+                            <% if (lr.his_id && (lr.status === auditConst.status.checked && lr.valid)) { %>
+                                <a href="<%- preUrl + '/revise/history/' + lr.id + '/info' %>">查看修订内容</a>
                             <% } %>
                         </td>
                     </tr>

+ 3 - 3
app/view/revise/info_modal.ejs

@@ -113,7 +113,7 @@
 <<!--审批通过-->
     <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 %>/revise/audit/check" method="post"
+            <form class="modal-content" action="/tender/<%- ctx.tender.id %>/revise/audit/check" method="post"
                 onsubmit="return auditCheck(0);">
                 <div class="modal-header">
                     <h5 class="modal-title">审批通过</h5>
@@ -304,7 +304,7 @@
     <!--审批退回-->
     <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 %>/revise/audit/check" method="post"
+            <form class="modal-content modal-lg" action="/tender/<%- ctx.tender.id %>/revise/audit/check" method="post"
                 onsubmit="return auditCheck(1);">
                 <div class="modal-header">
                     <h5 class="modal-title">审批退回</h5>
@@ -711,7 +711,7 @@
                         </div>
                     </div>
                 </div>
-                <form class="modal-footer" method="post" action="<%- preUrl %>/revise/audit/start"
+                <form class="modal-footer" method="post" action="/tender/<%- ctx.tender.id %>/revise/audit/start"
                     name="revise-start">
                     <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
                     <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>

+ 0 - 42
app/view/revise/price.ejs

@@ -1,42 +0,0 @@
-<% include ./sub_menu.ejs %>
-<div class="panel-content">
-    <div class="panel-title">
-        <div class="title-main  d-flex">
-            <% include ./sub_mini_menu.ejs %>
-            单价调整
-        </div>
-    </div>
-    <div class="content-wrap row pr-46">
-        <div class="c-header p-0 col-12"></div>
-        <!--核心内容(两栏)-->
-        <div class="row w-100 sub-content">
-            <!--左栏-->
-            <div class="c-body" id="left-view" style="width: 100%">
-                <!--0号台账模式-->
-                <div class="sjs-height-0" style="overflow: hidden" id="price-spread">
-                </div>
-            </div>
-            <!--右栏-->
-            <div class="c-body" id="right-view" style="display: none; width: 33%;">
-                <div class="resize-x" id="revise-right-spr" r-Type="width" div1="#left-view" div2="#right-view" title="调整大小" a-type="percent"><!--调整左右高度条--></div>
-                <div class="tab-content">
-                    <div id="ledgerGcl" class="tab-pane">
-                    </div>
-                </div>
-            </div>
-        </div>
-        <!--右侧菜单-->
-        <div class="side-menu">
-            <!--右侧菜单-->
-            <ul class="nav flex-column right-nav" id="side-menu">
-                <li class="nav-item">
-                    <a class="nav-link" content="#ledgerGcl" href="javascript: void(0);">台账清单</a>
-                </li>
-            </ul>
-        </div>
-    </div>
-</div>
-<script src="/public/js/moment/moment.min.js"></script>
-<script>
-    const readOnly = <%- ctx.revise.readOnly %>;
-</script>

+ 1 - 1
app/view/revise/sub_menu.ejs

@@ -1,5 +1,5 @@
 <div class="panel-sidebar" id="sub-menu">
-    <div class="sidebar-title" data-toggle="tooltip" data-placement="right" data-original-title="<%- revise.corder %># 台账修订"><%- revise.corder %># 台账修订</div>
+    <div class="sidebar-title" data-toggle="tooltip" data-placement="right" data-original-title="<%- ctx.revise.corder %># 台账修订"><%- ctx.revise.corder %># 台账修订</div>
     <div class="scrollbar-auto">
         <% include ./sub_menu_list.ejs %>
         <div class="side-fold"><a href="javascript: void(0)" data-toggle="tooltip" data-placement="top" data-original-title="折叠侧栏" id="to-mini-menu"><i class="fa fa-upload fa-rotate-270"></i></a></div>

+ 3 - 4
app/view/revise/sub_menu_list.ejs

@@ -1,5 +1,4 @@
 <nav-menu title="返回" url="/tender/<%= ctx.tender.id %>/revise" tclass="text-primary" ml="1" icon="fa-chevron-left"></nav-menu>
-<nav-menu title="台账修订" url="/tender/<%= ctx.tender.id %>/revise/info" ml="3" active="<%= ctx.url.indexOf('revise/info') %>"></nav-menu>
-<nav-menu title="单价调整" url="/tender/<%= ctx.tender.id %>/revise/price" ml="3" active="<%= ctx.url.indexOf('revise/price') %>"></nav-menu>
-<nav-menu title="台账对比" url="/tender/<%= ctx.tender.id %>/revise/compare" ml="3" active="<%= ctx.url.indexOf('revise/compare') %>"></nav-menu>
-<nav-menu title="清单对比" url="/tender/<%= ctx.tender.id %>/revise/gcl-compare" ml="3" active="<%= ctx.url.indexOf('revise/gcl-compare') %>"></nav-menu>
+<nav-menu title="台账修订" url="<%= preUrl %>/info" ml="3" active="<%= ctx.url.indexOf('/info') %>"></nav-menu>
+<nav-menu title="台账对比" url="<%= preUrl %>/compare" ml="3" active="<%= ctx.url.indexOf('/compare') %>"></nav-menu>
+<nav-menu title="清单对比" url="<%= preUrl %>/gcl-compare" ml="3" active="<%= ctx.url.indexOf('/gcl-compare') %>"></nav-menu>

+ 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', true);
+        } else if (!$('#openChangeApply')[0].checked && $('#openChangeProject')[0].checked && tab === 2) {
+            $('#openChangeProject').prop('checked', false);
+        }
         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,
         });

+ 1 - 1
app/view/setting/sub_menu.ejs

@@ -5,7 +5,7 @@
     <div class="scrollbar-auto">
         <div class="nav-box">
             <ul class="nav-list list-unstyled">
-                <% if (projectData.user_account === ctx.session.sessionUser.account) { %>
+                <% if (ctx.session.sessionUser.is_admin) { %>
                 <% for (const index in ctx.subMenu) { %>
                 <% if (!ctx.subMenu[index].display) continue; %>
                 <li <% if (ctx.url.indexOf(ctx.subMenu[index].url) !== -1) { %>class="active"<% } %>>

+ 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">

+ 2 - 0
builder_report_index_define.js

@@ -1105,6 +1105,8 @@ const gather_stage_bills = {
         { name: '(合计)合同-设计数量2', field: 's_deal_dgn_qty2', type: dataType.currency },
         { name: '(合计)变更-设计数量1', field: 's_c_dgn_qty1', type: dataType.currency },
         { name: '(合计)变更-设计数量2', field: 's_c_dgn_qty2', type: dataType.currency },
+
+        { name: '标段-分类', field: 't_category', type: dataType.str },
     ],
 };
 const gather_tender_info = {

+ 2 - 2
config/config.default.js

@@ -229,7 +229,7 @@ module.exports = appInfo => {
     config.syncUrl = 'http://sync.jl.smartcost.com.cn/';
 
     // 项目管理跳转路径
-    config.managementPath = 'http://pm.smartcost.com.cn/';
-    config.managementProxyPath = 'http://pm.smartcost.com.cn/';
+    config.managementPath = 'http://pm.smartcost.com.cn';
+    config.managementProxyPath = 'http://pm.smartcost.com.cn';
     return config;
 };

+ 3 - 0
config/config.local.js

@@ -100,6 +100,9 @@ module.exports = appInfo => {
             fujian: {
                 bucket: 'jiliang-qa',
             },
+            his: {
+                bucket: 'jiliang-his',
+            }
         },
         default: {
             accessKeyId: 'LTAIALMjBHOs9PLA',

+ 3 - 0
config/config.qa.js

@@ -62,6 +62,9 @@ module.exports = appInfo => {
             fujian: {
                 bucket: 'jiliang-qa',
             },
+            his: {
+                bucket: 'jiliang-his',
+            }
         },
         default: {
             accessKeyId: 'LTAIALMjBHOs9PLA',

+ 4 - 1
config/config.uat.js

@@ -68,6 +68,9 @@ module.exports = appInfo => {
             fujian: {
                 bucket: 'jiliang-qa',
             },
+            his: {
+                bucket: 'jiliang-his',
+            }
         },
         default: {
             accessKeyId: 'LTAIALMjBHOs9PLA',
@@ -80,7 +83,7 @@ module.exports = appInfo => {
     config.fujianOssPath = 'https://jiliang-qa-oss.smartcost.com.cn/uat/';
     config.fujianOssFolder = 'uat/';
 
-    config.syncUrl = 'http://sync.jluat.smartcost.com.cn/';
+    config.syncUrl = 'https://jluat-sync.smartcost.com.cn/';
 
     // 项目管理跳转路径
     config.managementPath = 'https://pmuat.smartcost.com.cn';

+ 44 - 15
config/web.js

@@ -248,7 +248,7 @@ const JsFiles = {
                 mergeFile: 'revise',
             },
             history: {
-                files: ['/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js', '/public/js/decimal.min.js'],
+                files: ['/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js', '/public/js/decimal.min.js', '/public/js/component/menu.js'],
                 mergeFiles: [
                     '/public/js/sub_menu.js',
                     '/public/js/div_resizer.js',
@@ -261,20 +261,6 @@ const JsFiles = {
                 ],
                 mergeFile: 'revise_history',
             },
-            price: {
-                files: ['/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js', '/public/js/component/menu.js'],
-                mergeFiles: [
-                    '/public/js/sub_menu.js',
-                    '/public/js/div_resizer.js',
-                    '/public/js/spreadjs_rela/spreadjs_zh.js',
-                    '/public/js/shares/sjs_setting.js',
-                    '/public/js/zh_calc.js',
-                    '/public/js/gcl_gather.js',
-                    '/public/js/path_tree.js',
-                    '/public/js/revise_price.js',
-                ],
-                mergeFile: 'revise_price',
-            },
             compare: {
                 files: [
                     '/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js',
@@ -913,6 +899,49 @@ 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',
+            },
+            apply: {
+                files: ['/public/js/moment/moment.min.js'],
+                mergeFiles: [
+                    '/public/js/sub_menu.js',
+                    '/public/js/change_apply.js',
+                ],
+                mergeFile: 'change_apply',
+            },
+            apply_information: {
+                files: ['/public/js/moment/moment.min.js'],
+                mergeFiles: [
+                    '/public/js/sub_menu.js',
+                    '/public/js/change_apply_audit.js',
+                    '/public/js/change_apply_information.js',
+                ],
+                mergeFile: 'change_apply_information',
+            },
+            apply_information_notice: {
+                files: ['/public/js/moment/moment.min.js'],
+                mergeFiles: [
+                    '/public/js/sub_menu.js',
+                    '/public/js/change_apply_audit.js',
+                    '/public/js/change_apply_information_notice.js',
+                ],
+                mergeFile: 'change_apply_information_notice',
+            },
         },
         datacollect: {
             index: {

+ 183 - 0
db_script/ledger_his.js

@@ -0,0 +1,183 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const fs = require('fs');
+const path = require('path');
+var util = require('util');
+var logPath = path.join(__dirname, 'update_revise.log');
+var logFile = fs.createWriteStream(logPath, { flags: 'a' });
+
+console.log = function() {
+    logFile.write(util.format.apply(null, arguments) + '\n');
+    process.stdout.write(util.format.apply(null, arguments) + '\n');
+};
+
+const audit = require('../app/const/audit');
+const measureType = require('../app/const/message_type');
+
+const mysql = require('mysql');
+const oss = require('ali-oss');
+const config = process.argv.splice(2)[0];
+if (['local', 'uat', 'default'].indexOf(config) < 0) throw `参数错误: ${config}`;
+const options = require(`../config/config.${config}`)({ baseDir: __dirname + '/app', root: __dirname, name: 'calc' });
+
+const pool = mysql.createPool(options.mysql.client);
+const ossOption = {
+    bucket: options.oss.clients.his.bucket,
+    accessKeyId: options.oss.default.accessKeyId,
+    accessKeySecret: options.oss.default.accessKeySecret,
+    endpoint: options.oss.default.endpoint,
+    timeout: options.oss.default.timeout,
+};
+const ossClient = new oss(ossOption);
+
+const querySql = async function(sql, sqlParam) {
+    return new Promise(function(resolve, reject) {
+        pool.getConnection(function(err, conn) {
+            if (err) {
+                if (err) console.log(err);
+                reject(err);
+            } else {
+                conn.query(sql, sqlParam, function(err, rows, fields) {
+                    if (err) console.log(err);
+                    // 释放连接
+                    conn.release();
+                    // 传递Promise回调对象
+                    resolve(rows);
+                });
+            }
+        });
+    });
+};
+
+const getTableName = function(tender, table) {
+    // switch(table) {
+    //     case 'ledger': return 'zh_ledger_' + (tender.id % 10);
+    //     case 'pos': return 'zh_pos_' + (tender.id % 20);
+    //     case 'revise_bills': return 'zh_revise_bills_' + (tender.id % 10);
+    //     case 'revise_pos': return 'zh_revise_pos_' + (tender.id % 20);
+    // }
+    return table.indexOf('pos') > 0 ? `zh_${table}_${tender.id % 20}` : `zh_${table}_${tender.id % 10}`;
+};
+
+const saveLedgerHis = async function(tender) {
+    const now = new Date();
+    const timestamp = (now).getTime();
+
+    const billsHis = `${tender.project_id}/${tender.id}/ledger/bills${timestamp}.json`;
+    const bills = await querySql('Select * From ?? where tender_id = ?', [getTableName(tender, 'ledger'), tender.id]);
+    console.log(`saveBillsFile: ${billsHis}(${bills.length})`);
+    await ossClient.put(options.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
+
+    const posHis = `${tender.project_id}/${tender.id}/ledger/pos${timestamp}.json`;
+    const pos = await querySql('Select * From ?? where tid = ?', [getTableName(tender, 'pos'), tender.id]);
+    console.log(`savePosFile: ${posHis}(${pos.length})`);
+    await ossClient.put(options.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
+
+    const result = await querySql('Insert Into zh_ledger_history(pid, tid, in_time, bills_file, pos_file) Values(?, ?, ?, ?, ?)',
+        [tender.project_id, tender.id, now, billsHis, posHis]);
+
+    if (!result) throw 'err';
+    return result.insertId;
+};
+
+const saveReviseLedgerHis = async function (tender, revise) {
+    const now = new Date();
+    const billsHis = revise.bills_file;
+    const posHis = revise.pos_file;
+
+    const result = await querySql('Insert Into zh_ledger_history(pid, tid, in_time, bills_file, pos_file, rid, rorder, valid) Values(?, ?, ?, ?, ?, ?, ?, ?)',
+        [tender.project_id, tender.id, now, billsHis, posHis, revise.id, revise.corder, revise.valid]);
+
+    if (!result) throw 'err';
+    return result.insertId;
+};
+
+const doCompleteTender = async function(t) {
+    const revise = await querySql('Select * From zh_ledger_revise where tid = ? order By in_time asc', [t.id]);
+    if (revise.length > 0) {
+        let his_id, withoutHisRevise = [];
+        for (const r of revise) {
+            const preRevise = revise.find(x => { return x.status === audit.revise.status.checked && x.corder === r.corder - 1});
+            if (preRevise) {
+                await querySql('Update zh_ledger_revise Set pre_his_id = ? Where id = ?', [preRevise.his_id, r.id]);
+            }
+            if (r.bills_file) {
+                r.his_id = await saveReviseLedgerHis(t, r);
+                if (r.valid) his_id = r.his_id;
+                await querySql('Update zh_ledger_revise Set his_id = ? Where id = ?', [his_id, r.id]);
+            } else {
+                if (r.status !== 1) withoutHisRevise.push(r);
+            }
+        }
+        if (!his_id || t.measure_type === measureType.gcl.value) his_id = await saveLedgerHis(t);
+        await querySql('Update zh_tender Set his_id = ? Where id = ?', [his_id, t.id]);
+        const stages = await querySql('Select * From zh_stage where tid = ? and status = ?', [t.id, audit.stage.status.checked]);
+        for (const s of stages) {
+            if (s.status === audit.stage.status.checked) {
+                await querySql('Update zh_stage Set his_id = ? Where id = ?', [his_id, s.id]);
+            }
+        }
+        for (const r of withoutHisRevise) {
+            await querySql('Update zh_ledger_revise Set pre_his_id = ?, his_id = ? Where id = ?', [his_id, his_id, r.id]);
+        }
+    } else {
+        const ledgerHis = await saveLedgerHis(t);
+        console.log(`saveLedgerHis: ${t.name}(${t.id})`);
+        await querySql('Update zh_tender Set his_id = ? Where id = ?', [ledgerHis, t.id]);
+        const stages = await querySql('Select * From zh_stage where tid = ? and status = ?', [t.id, audit.stage.status.checked]);
+        for (const s of stages) {
+            if (s.status === audit.stage.status.checked) {
+                await querySql('Update zh_stage Set his_id = ? Where id = ?', [ledgerHis, s.id]);
+            }
+        }
+    }
+};
+
+const doComplete = async function() {
+    try {
+        const tenders = await querySql('Select * From zh_tender where ledger_status <> ?', [audit.ledger.status.uncheck]);
+        for (const t of tenders) {
+            await doCompleteTender(t);
+        }
+    } catch (err) {
+        console.log(err);
+    }
+    pool.end();
+};
+doComplete();
+
+// const doCompleteTender2 = async function(t) {
+//     const revise = await querySql('Select * From zh_ledger_revise where tid = ? order By in_time asc', [t.id]);
+//     if (revise.length > 0) {
+//         for (const r of revise) {
+//             const preRevise = revise.find(x => { return x.status === audit.revise.status.checked && x.corder === r.corder - 1});
+//             if (!preRevise && !r.pre_his_id) {
+//                 await querySql('Update zh_ledger_revise Set pre_his_id = ? Where id = ?', [r.his_id, r.id]);
+//             }
+//         }
+//     }
+// };
+//
+// const doCompeletTest = async function() {
+//     try {
+//         const tenders = await querySql('Select * From zh_tender where ledger_status <> ?', [audit.ledger.status.uncheck]);
+//         //const tenders = await querySql('Select * From zh_tender where id = ?', [3863]);
+//         for (const t of tenders) {
+//             await doCompleteTender2(t);
+//         }
+//     } catch (err) {
+//         console.log(err);
+//     }
+//     pool.end();
+// };
+
+// doCompeletTest();
+

+ 59 - 0
db_script/update_revise.js

@@ -0,0 +1,59 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const fs = require('fs');
+const path = require('path');
+var util = require('util');
+const oss = require('ali-oss');
+const config = process.argv.splice(2)[0];
+if (['local', 'uat', 'default'].indexOf(config) < 0) throw `参数错误: ${config}`;
+const options = require(`../config/config.${config}`)({ baseDir: __dirname + '/app', root: __dirname, name: 'calc' });
+
+const ossOption = {
+    bucket: options.oss.clients.his.bucket,
+    accessKeyId: options.oss.default.accessKeyId,
+    accessKeySecret: options.oss.default.accessKeySecret,
+    endpoint: options.oss.default.endpoint,
+    timeout: options.oss.default.timeout,
+};
+const ossClient = new oss(ossOption);
+
+var logPath = path.join(__dirname, 'update_revise.log');
+var logFile = fs.createWriteStream(logPath, { flags: 'a' });
+
+console.log = function() {
+    logFile.write(util.format.apply(null, arguments) + '\n');
+    process.stdout.write(util.format.apply(null, arguments) + '\n');
+};
+
+const filepath = ['/etc/calc/files/revise', 'mnt/files/calc/revise'];
+// const filepath = ['/etc/calc/files/xx'];
+
+let iCount = 0;
+const updatePath = async function (filepath) {
+    console.log(`UpdatePath: ${filepath}`);
+    const files = fs.readdirSync(filepath);
+    for (const f of files) {
+        const stat = fs.statSync(path.join(filepath, f));
+        const ossPath = options.hisOssPath + 'revise/' + f;
+        if (stat.isFile()) await ossClient.put(ossPath, path.join(filepath, f));
+        console.log(`UpdateOss: ${path.join(filepath, f)} --> ${ossPath}`);
+        iCount++;
+    }
+    console.log('');
+};
+const updateAll = async function () {
+    for (const p of filepath) {
+        await updatePath(p);
+    }
+    console.log(`UpdateOss: ${iCount} files`);
+};
+
+updateAll();

+ 0 - 15
dev4qadx.js

@@ -1,15 +0,0 @@
-'use strict';
-
-/**
- *
- *
- * @author Mai
- * @date
- * @version
- */
-
-const fs = require('fs');
-const packageJSON = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8'));
-packageJSON.name = 'calc_dx' ;
-packageJSON.scripts['start-qadx'] = "egg-scripts start --daemon --port 7006";
-fs.writeFileSync(__dirname + '/package.json', JSON.stringify(packageJSON, '', '\t'));

+ 96 - 0
sql/update.sql

@@ -221,5 +221,101 @@ ALTER TABLE `zh_tender`
 ADD COLUMN `bills_file`  varchar(255) NOT NULL DEFAULT '' COMMENT '台账-清单文件' AFTER `has_rela`,
 ADD COLUMN `pos_file`  varchar(255) NOT NULL DEFAULT '' COMMENT '台账-计量单元文件' AFTER `bills_file`;
 
+CREATE TABLE `zh_material_checklist`  (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `tid` int(11) NOT NULL COMMENT '标段id',
+  `mid` int(11) NOT NULL COMMENT '调差期id',
+  `b_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '清单编号',
+  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '清单名称',
+  `unit` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '单位',
+  `unit_price` decimal(30, 8) NOT NULL COMMENT '单价',
+  `quantity` decimal(30, 8) NOT NULL COMMENT '数量(工程量)',
+  `total_price` decimal(30, 8) NOT NULL COMMENT '金额',
+  `had_bills` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已添加工料',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '默认清单设置功能';
+
+CREATE TABLE `zh_ledger_history` (
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  `pid` bigint(20) unsigned NOT NULL COMMENT '项目id',
+  `tid` bigint(20) unsigned NOT NULL COMMENT '标段id',
+  `rid` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '修订id',
+  `rorder` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '修订序号',
+  `cid` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '工程变更id',
+  `in_time` datetime NOT NULL,
+  `bills_file` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目节数据文件',
+  `pos_file` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '计量单元数据文件',
+  `valid`  tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否有效',
+  PRIMARY KEY (`id`),
+  KEY `idx_tid_valid_time` (`tid`,`valid`,`in_time`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+ALTER TABLE `zh_ledger_revise`
+ADD COLUMN `his_id`  bigint(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT '修订后,台账历史数据id' AFTER `content`,
+ADD COLUMN `pre_his_id`  bigint(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT '修订前,台账历史数据id' AFTER `his_id`;
+
+ALTER TABLE `zh_tender`
+ADD COLUMN `his_id`  bigint(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT '台账历史数据id' AFTER `s2b_dagl_limit`;
+
+ALTER TABLE `zh_stage`
+ADD COLUMN `his_id`  bigint(20) UNSIGNED NOT NULL DEFAULT 0 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`;
+
+ALTER TABLE `zh_tender` ADD `c_code_rules` TEXT NULL DEFAULT NULL COMMENT '变更立项及申请的编号规则json' AFTER `c_rule_first`;
+
+CREATE TABLE `zh_change_project`  (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `tid` int(11) NOT NULL COMMENT '标段id',
+  `uid` int(11) NOT NULL COMMENT '发起人',
+  `code` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '立项书编号',
+  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '立项书名称',
+  `in_time` datetime NOT NULL COMMENT '发起时间',
+  `status` tinyint(2) NOT NULL COMMENT '立项状态',
+  `times` tinyint(2) NOT NULL COMMENT '审批次数',
+  `type` tinyint(1) NOT NULL COMMENT '立项书类型',
+  `org_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '原设计图名称',
+  `peg` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '桩号',
+  `new_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '图号',
+  `class` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '变更类别',
+  `quality` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '变更性质',
+  `org_price` decimal(30, 8) NULL DEFAULT NULL COMMENT '原工程造价(元)',
+  `change_price` decimal(30, 8) NULL DEFAULT NULL COMMENT '预计变更造价(元)',
+  `crease_price` decimal(30, 8) NULL DEFAULT NULL COMMENT '预计造价增减(元)',
+  `reason` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '变更原因',
+  `content` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '内容摘要',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '变更立项表';
+
+CREATE TABLE `zh_change_project_attachment`  (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `tid` int(11) NOT NULL COMMENT '标段id',
+  `cpid` int(11) NOT NULL COMMENT '立项id',
+  `uid` int(11) NOT NULL COMMENT '上传者id',
+  `filename` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件名称',
+  `fileext` varchar(5) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件后缀',
+  `filesize` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件大小',
+  `filepath` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件存储路径',
+  `upload_time` datetime NOT NULL COMMENT '上传时间',
+  `extra_upload` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否为审核通过后再次上传的文件,0为否',
+  PRIMARY KEY (`id`) USING BTREE,
+  INDEX `idx_cid`(`cpid`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '变更立项附件表';
+
+CREATE TABLE `zh_change_project_audit`  (
+  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
+  `tid` int(11) NOT NULL COMMENT '标段id',
+  `cpid` int(11) NOT NULL COMMENT '立项id',
+  `aid` int(11) NOT NULL COMMENT '审批人id',
+  `order` int(11) NOT NULL COMMENT '审批顺序',
+  `times` int(11) NOT NULL COMMENT '审批次数',
+  `status` tinyint(1) NOT NULL COMMENT '审批状态',
+  `begin_time` datetime NULL DEFAULT NULL COMMENT '开始审批时间',
+  `end_time` datetime NULL DEFAULT NULL COMMENT '结束审批时间',
+  `opinion` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '审批意见',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '变更立项审批表';
+
 UPDATE `zh_ledger_revise` SET bills_file = replace(bills_file, '/revise', 'revise') WHERE not ISNULL(bills_file);
 UPDATE `zh_ledger_revise` SET pos_file = replace(pos_file, '/revise', 'revise') WHERE not ISNULL(pos_file);