瀏覽代碼

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

Tony Kang 7 月之前
父節點
當前提交
faa0115e3e
共有 43 個文件被更改,包括 3865 次插入247 次删除
  1. 1 1
      app/base/base_tree_service.js
  2. 136 3
      app/const/audit.js
  3. 2 0
      app/const/project_log.js
  4. 2 0
      app/const/shenpi.js
  5. 11 0
      app/const/sms_type.js
  6. 1 0
      app/const/tender_info.js
  7. 2 0
      app/const/wechat_template.js
  8. 266 66
      app/controller/pay_controller.js
  9. 1 1
      app/controller/tender_controller.js
  10. 4 0
      app/lib/stage_im.js
  11. 9 4
      app/lib/sum_load.js
  12. 3 0
      app/middleware/phase_pay_check.js
  13. 148 46
      app/public/js/change_information.js
  14. 10 10
      app/public/js/change_information_add_list.js
  15. 2 2
      app/public/js/material_audit.js
  16. 142 2
      app/public/js/phase_pay_detail.js
  17. 136 1
      app/public/js/phase_pay_list.js
  18. 452 0
      app/public/js/shares/phase_pay_audit.js
  19. 10 3
      app/public/js/shares/tender_select.js
  20. 1 1
      app/public/js/stage_audit.js
  21. 30 0
      app/public/js/stage_gather.js
  22. 15 4
      app/router.js
  23. 2 2
      app/service/material_audit.js
  24. 167 30
      app/service/phase_pay.js
  25. 1037 0
      app/service/phase_pay_audit.js
  26. 44 16
      app/service/phase_pay_detail.js
  27. 94 0
      app/service/phase_pay_file.js
  28. 31 0
      app/service/report_memory.js
  29. 2 2
      app/service/revise_bills.js
  30. 1 1
      app/service/settle_audit.js
  31. 16 0
      app/view/change/information.ejs
  32. 1 1
      app/view/material/audit_modal.ejs
  33. 41 0
      app/view/phase_pay/audit_btn.ejs
  34. 864 0
      app/view/phase_pay/audit_modal.ejs
  35. 78 26
      app/view/phase_pay/detail.ejs
  36. 3 1
      app/view/phase_pay/detail_modal.ejs
  37. 11 6
      app/view/phase_pay/index.ejs
  38. 48 6
      app/view/phase_pay/modal.ejs
  39. 2 1
      app/view/phase_pay/sub_menu_list.ejs
  40. 20 11
      app/view/shares/tender_select_modal.ejs
  41. 12 0
      app/view/stage/gather.ejs
  42. 1 0
      app/view/tender/shenpi.ejs
  43. 6 0
      config/web.js

+ 1 - 1
app/base/base_tree_service.js

@@ -335,7 +335,7 @@ class TreeService extends Service {
         const cacheKey = this.setting.keyPre + mid;
         let maxId = this.setting.cacheKey ? parseInt(await this.cache.get(cacheKey)) : undefined;
         if (!maxId) {
-            const sql = 'SELECT Max(??) As max_id FROM ?? Where ' + this.db.escape(this.setting.mid) + ' = ?';
+            const sql = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
             const sqlParam = [this.setting.kid, this.tableName, mid];
             const queryResult = await this.db.queryOne(sql, sqlParam);
             maxId = queryResult.max_id || 0;

+ 136 - 3
app/const/audit.js

@@ -11,8 +11,8 @@
 const auditType = (function () {
     const types = [
         { key: 'common', name: '个人', value: 1, short: '', long: '', class: '', },
-        { key: 'and', name: '会签', value: 2, short: '会', long: '多人会签', class: 'primary', valid: ['ledger', 'revise', 'stage', 'change', 'material', 'financial'] },
-        { key: 'or', name: '或签', value: 3, short: '或', long: '多人或签', class: 'success', valid: ['ledger', 'revise', 'stage', 'change', 'material', 'financial'] },
+        { key: 'and', name: '会签', value: 2, short: '会', long: '多人会签', class: 'primary', valid: ['ledger', 'revise', 'stage', 'change', 'material', 'financial', 'phasePay'] },
+        { key: 'or', name: '或签', value: 3, short: '或', long: '多人或签', class: 'success', valid: ['ledger', 'revise', 'stage', 'change', 'material', 'financial', 'phasePay'] },
         { key: 'union', name: '协同', value: 4, short: '协', long: '多人协同', class: 'warning', valid: ['stage']},
     ];
     const key = {};
@@ -29,7 +29,7 @@ const auditMasterType = {
     material: 'material',
     ledger: 'ledger',
     revise: 'revise',
-    pay: 'pay', // 独立合同支付
+    phasePay: 'phasePay', // 独立合同支付
 };
 
 // 期审批流程
@@ -294,6 +294,136 @@ const stage = (function() {
     };
 })();
 
+const phasePay = (function() {
+    // 流程状态
+    const status = {
+        uncheck: 1, // 待上报
+        checking: 2, // 待审批|审批中
+        checked: 3, // 审批通过
+        checkNo: 4, // 审批退回原报
+        checkNoPre: 5, // 审批退回上一人
+        checkAgain: 6, // 重新审批 // 该状态仅可用于,终审退回时,修改原终审的审批状态,并同时新增一条新的终审审批中记录
+        checkCancel: 7, // 撤回 // 该状态为上一审批人可发起,回到它到审批阶段,并同时新增一条新的审批中记录
+        checkSkip: 8, // 跳过
+    };
+
+    // 流程状态提示
+    const statusString = [];
+    statusString[status.uncheck] = '待上报';
+    statusString[status.checking] = '审批中';
+    statusString[status.checked] = '审批通过';
+    statusString[status.checkNo] = '审批退回';
+    statusString[status.checkNoPre] = '审批退回';
+    statusString[status.checkAgain] = '重新审批';
+    statusString[status.checkCancel] = '撤回';
+
+    // 流程状态样式
+    const statusClass = [];
+    statusClass[status.uncheck] = '';
+    statusClass[status.checking] = 'text-warning';
+    statusClass[status.checked] = 'text-success';
+    statusClass[status.checkNo] = 'text-warning';
+    statusClass[status.checkNoPre] = 'text-warning';
+    statusClass[status.checkAgain] = 'text-warning';
+    statusClass[status.checkCancel] = 'text-warning';
+
+    /**
+     * 期列表,审批状态一列
+     */
+        // 按钮
+    const statusButton = [];
+    statusButton[status.uncheck] = '待上报';
+    statusButton[status.checking] = '审批';
+    statusButton[status.checked] = '';
+    statusButton[status.checkNo] = '重新上报';
+    statusButton[status.checkNoPre] = '重新审批';
+    statusButton[status.checkAgain] = '重新审批';
+    statusButton[status.checkCancel] = '撤回';
+    // 按钮样式
+    const statusButtonClass = [];
+    statusButtonClass[status.uncheck] = 'btn-primary';
+    statusButtonClass[status.checking] = 'btn-success';
+    statusButtonClass[status.checked] = '';
+    statusButtonClass[status.checkNo] = 'btn-warning';
+    statusButtonClass[status.checkNoPre] = 'btn-warning';
+    statusButtonClass[status.checkAgain] = 'btn-warning';
+    statusButtonClass[status.checkCancel] = 'btn-warning';
+    // 描述文本
+    const auditString = [];
+    auditString[status.uncheck] = '';
+    auditString[status.checking] = '审批中';
+    auditString[status.checked] = '审批通过';
+    auditString[status.checkNo] = '审批退回';
+    auditString[status.checkNoPre] = '审批退回';
+    auditString[status.checkAgain] = '重新审批';
+    auditString[status.checkCancel] = '撤回';
+    auditString[status.checkSkip] = '审批通过';
+    // 文字样式
+    const auditStringClass = [];
+    auditStringClass[status.uncheck] = '';
+    auditStringClass[status.checking] = 'text-warning';
+    auditStringClass[status.checked] = 'text-success';
+    auditStringClass[status.checkNo] = 'text-warning';
+    auditStringClass[status.checkNoPre] = 'text-warning';
+    auditStringClass[status.checkAgain] = 'text-warning';
+    auditStringClass[status.checkCancel] = 'text-warning';
+    auditStringClass[status.checkSkip] = 'text-success';
+    /* ------------------------------------------------------- */
+
+    /**
+     * 期列表,审批进度一列
+     */
+        // 描述文本
+    const auditProgress = [];
+    auditProgress[status.uncheck] = '待上报';
+    auditProgress[status.checking] = '审批中';
+    auditProgress[status.checked] = '审批通过';
+    auditProgress[status.checkNo] = '审批退回';
+    auditProgress[status.checkNoPre] = '审批退回';
+    auditProgress[status.checkAgain] = '重新审批';
+    auditProgress[status.checkCancel] = '撤回';
+    // 样式
+    const auditProgressClass = [];
+    auditProgressClass[status.uncheck] = '';
+    auditProgressClass[status.checking] = 'text-warning';
+    auditProgressClass[status.checked] = 'text-success';
+    auditProgressClass[status.checkNo] = 'text-warning';
+    auditProgressClass[status.checkNoPre] = 'text-warning';
+    auditProgressClass[status.checkAgain] = 'text-warning';
+    auditProgressClass[status.checkCancel] = 'text-warning';
+    /* ------------------------------------------------------- */
+
+    const tiStatusString = [];
+    tiStatusString[status.uncheck] = '待上报';
+    tiStatusString[status.checking] = '审批中';
+    tiStatusString[status.checked] = '审批通过';
+    tiStatusString[status.checkNo] = '审批退回';
+    tiStatusString[status.checkNoPre] = '审批中';
+    tiStatusString[status.checkAgain] = '审批中';
+    tiStatusString[status.checkCancel] = '撤回';
+    const tiStatusStringClass = [];
+    tiStatusStringClass[status.uncheck] = '';
+    tiStatusStringClass[status.checking] = 'text-warning';
+    tiStatusStringClass[status.checked] = 'text-success';
+    tiStatusStringClass[status.checkNo] = 'text-warning';
+    tiStatusStringClass[status.checkNoPre] = 'text-warning';
+    tiStatusStringClass[status.checkAgain] = 'text-warning';
+    tiStatusStringClass[status.checkCancel] = 'text-warning';
+    const backType = {
+        org: 1,
+        pre: 2,
+    };
+    return {
+        status, statusString, statusClass,
+        statusButton, statusButtonClass,
+        auditString, auditStringClass,
+        auditProgress, auditProgressClass,
+        backType,
+        timesLen: 100,
+        tiStatusString, tiStatusStringClass,
+    };
+})();
+
 // 结算
 const settle = (function() {
     // 流程状态
@@ -1258,13 +1388,16 @@ const pushType = {
     changePlan: 9,
     settle: 10,
     financial: 11,
+    phasePay: 12,
 };
 
 module.exports = {
+    auditMasterType,
     common,
     auditType,
     ledger,
     stage,
+    phasePay,
     settle,
     revise,
     material,

+ 2 - 0
app/const/project_log.js

@@ -18,6 +18,7 @@ const type = {
     changeApply: 6,
     changePlan: 7,
     settle: 8,
+    phasePay: 9,
 };
 
 const type_list = [
@@ -30,6 +31,7 @@ const type_list = [
     { code: 'changeApply', type: type.changeApply, name: '变更申请' },
     { code: 'changePlan', type: type.changePlan, name: '变更方案' },
     { code: 'settle', type: type.settle, name: '计量结算' },
+    { code: 'phasePay', type: type.phasePay, name: '计量结算' },
 ];
 // 操作状态
 const status = {

+ 2 - 0
app/const/shenpi.js

@@ -17,6 +17,7 @@ const sp_type = {
     change: 5,
     material: 6,
     // financial: 8, // 资金支付审批流程设置不出现在这里,但请别用8这个类型控制审批流程,因为数据库我用了8来表示资金支付固定审批流
+    phasePay: 9,
 };
 const sp_other_type = {
     financial: 8,
@@ -38,6 +39,7 @@ const sp_lc = [
     { code: 'change', type: sp_type.change, name: '工程变更审批' },
     { code: 'material', type: sp_type.material, name: '材料调差审批' },
     // { code: 'financial', type: sp_type.financial, name: '资金支付审批' },
+    { code: 'phasePay', type: sp_type.phasePay, name: '合同支付审批' },
 ];
 
 const sp_status = {

+ 11 - 0
app/const/sms_type.js

@@ -15,6 +15,7 @@ const smsConst = {
     TC: 'TC',
     YFK: 'YFK',
     JS: 'JS',
+    PAY: 'PAY',
 };
 const judgeConst = {
     approval: 1,
@@ -91,6 +92,16 @@ const smsType = {
             { title: '审批结果', value: 2 },
         ],
     },
+    PAY: {
+        name: '合同支付',
+        path: '',
+        wechat: true,
+        sms: true,
+        children: [
+            { title: '需要我审批', value: 1 },
+            { title: '审批结果', value: 2 },
+        ],
+    },
 };
 
 module.exports = {

+ 1 - 0
app/const/tender_info.js

@@ -191,6 +191,7 @@ const defaultInfo = {
         settle: 1,
         change: 1,
         material: 1,
+        phasePay: 1,
     },
     ledger_check: {
         same_code: true,

+ 2 - 0
app/const/wechat_template.js

@@ -15,6 +15,7 @@ const template = {
     material: 4,
     advance: 5,
     settle: 6,
+    phasePay: 7,
 };
 const templateId = {
     stage: '5vU3WmR90yDajbs4LWIWH4OQhunYlS1HXTiesIGxrsk',
@@ -24,6 +25,7 @@ const templateId = {
     material: 'Y9ov80rev3LHcoM2hOQE6jrK_5xZsqE-PZ0Z6HS9VGA',
     advance: 'rgZHkyiLzrqaSGnQ2nSCCrOdUz2RJJZ_JA34L_MnQik',
     settle: '5vU3WmR90yDajbs4LWIWH4OQhunYlS1HXTiesIGxrsk', // todo 暂使用计量期模板
+    phasePay: '5vU3WmR90yDajbs4LWIWH4OQhunYlS1HXTiesIGxrsk', // todo 暂使用计量期模板
 };
 const status = {
     check: '待审批',

+ 266 - 66
app/controller/pay_controller.js

@@ -9,6 +9,9 @@
  */
 
 const audit = require('../const/audit');
+const shenpiConst = require('../const/shenpi');
+const sendToWormhole = require('stream-wormhole');
+const path = require('path');
 
 module.exports = app => {
 
@@ -29,8 +32,7 @@ module.exports = app => {
                 const relaStage = [];
                 for (const p of phasePays) {
                     // todo 加载当前审批人
-                    // if (p.audit_status !== checked) await this.ctx.service.phasePay.loadUser(p);
-                    p.curAuditors = [];
+                    if (p.audit_status !== audit.common.status.checked) await this.ctx.service.phasePay.loadUser(p);
                     relaStage.push(...p.rela_stage);
                 }
                 const stages = await this.ctx.service.stage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['order', 'AEC']] });
@@ -39,6 +41,7 @@ module.exports = app => {
                 });
                 this.ctx.service.phasePay.calculatePhasePay(phasePays);
                 const renderData = {
+                    auditType: audit.auditType,
                     phasePays,
                     validStages,
                     auditConst: audit.common,
@@ -46,7 +49,8 @@ module.exports = app => {
                 };
                 await this.layout('phase_pay/index.ejs', renderData, 'phase_pay/modal.ejs');
             } catch (err) {
-                ctx.helper.log(err);
+                ctx.log(err);
+                ctx.redirect(ctx.request.header.referer);
             }
         }
 
@@ -70,32 +74,98 @@ module.exports = app => {
                 const newPhase = await ctx.service.phasePay.add(ctx.tender.id, stages, date, memo);
                 if (!newPhase) throw '新增期失败';
                 newPhase.curTimes = 1;
-                newPhase.curOrder = 0;
+                newPhase.curSort = 0;
                 await ctx.service.phasePayDetail.calculateSave(newPhase);
 
-                ctx.redirect('/tender/' + ctx.tender.id + '/pay' + newPhase.phase_order);
+                ctx.redirect('/tender/' + ctx.tender.id + '/pay/' + newPhase.phase_order + '/detail');
             } catch (err) {
-                this.log(err);
+                ctx.log(err);
                 ctx.postError(err, '新增期失败');
-                ctx.redirect(ctx.request.header.referer);
+                ctx.redirect('/tender/' + ctx.tender.id + '/pay');
             }
         }
 
-        async del() {
+        async del(ctx) {
+            try {
+                if (!ctx.session.sessionUser.is_admin && ctx.request.body.confirm !== '确认删除本期') throw '请输入文本确认删除本期';
+                const phase_id = ctx.request.body.phase_id;
+                const phasePay = await ctx.service.phasePay.getDataById(phase_id);
+                if (!phasePay) throw '删除的期不存在,请刷新页面';
+                if (!ctx.session.sessionUser.is_admin && phasePay.create_user_id !== ctx.session.sessionUser.accountId) throw '您无权删除本期';
+                // 获取最新的期数
+                const phasePayCount = await ctx.service.phasePay.count({ tid: ctx.tender.id });
+                if (phasePay.phase_order !== phasePayCount) throw '非最新一期,不可删除';
 
+                await ctx.service.phasePay.delete(phase_id);
+                // todo 刷新金额概况缓存
+                // await ctx.service.tenderCache.refreshPayCache(phasePay.tenderId);
+                ctx.redirect('/tender/' + ctx.tender.id + '/pay');
+            } catch (err) {
+                ctx.log(err);
+                ctx.redirect('/tender/' + ctx.tender.id + '/pay');
+            }
         }
 
-        async save() {
+        async save(ctx) {
+            try {
+                const phase_id = ctx.request.body.phase_id;
+                const data = {
+                    phase_date: ctx.request.body.date,
+                    memo: ctx.request.body.memo,
+                };
+                const phasePay = await ctx.service.phasePay.getPhasePay(phase_id);
+                if (!phasePay) throw '删除的期不存在,请刷新页面';
+                if (!ctx.session.sessionUser.is_admin && phasePay.create_user_id !== ctx.session.sessionUser.accountId) throw '您无权修改该数据';
+                await this.ctx.service.phasePay.save(phasePay, data);
+                if (phasePay.audit_status === audit.common.status.uncheck && ctx.request.body.stage) {
+                    const stages = await ctx.service.stage.getAllDataByCondition({ where: { tid: ctx.tender.id, order: ctx.request.body.stage } });
+                    await this.ctx.service.phasePay.resetRelaStageId(phasePay, stages);
+                }
+                ctx.redirect('/tender/' + ctx.tender.id + '/pay');
+            } catch (err) {
+                ctx.log(err);
+                ctx.redirect('/tender/' + ctx.tender.id + '/pay');
+            }
+        }
 
+        /**
+         * 期审批流程(POST)
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async loadAuditors(ctx) {
+            try {
+                const order = JSON.parse(ctx.request.body.data).order;
+                const tenderId = ctx.params.id;
+                const phasePay = await ctx.service.phasePay.getPhasePayByOrder(tenderId, order);
+                await ctx.service.phasePay.loadUser(phasePay);
+                await ctx.service.phasePay.loadAuditViewData(phasePay);
+                ctx.body = { err: 0, msg: '', data: phasePay };
+            } catch (error) {
+                ctx.log(error);
+                ctx.body = { err: 1, msg: error.toString(), data: null };
+            }
         }
 
         async detail(ctx) {
             try {
                 // await this.ctx.service.phasePayDetail.calculateSave(ctx.phasePay);
+                await this.ctx.service.phasePay.loadAuditViewData(ctx.phasePay);
                 const pays = await this.ctx.service.phasePayDetail.getDetailData(ctx.phasePay);
                 const calcBase = this.ctx.service.phasePay.getPhasePayCalcBase(ctx.phasePay, ctx.tender.info);
                 const projectFunInfo = await this.ctx.service.project.getFunRela(ctx.session.sessionProject.id);
                 const lastStage = await this.ctx.service.stage.getLastestCompleteStage(ctx.tender.id);
+                const accountList = await ctx.service.projectAccount.getAllDataByCondition({
+                    where: { project_id: ctx.session.sessionProject.id, enable: 1 },
+                    columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
+                });
+                const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
+                const accountGroup = unitList.map(item => {
+                    const groupList = accountList.filter(item1 => item1.company === item.name);
+                    return { groupName: item.name, groupList };
+                });
+                // 是否已验证手机短信
+                const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
                 const renderData = {
                     pays,
                     calcBase,
@@ -103,13 +173,47 @@ module.exports = app => {
                     auditConst: audit.common,
                     deadlineType: this.ctx.service.phasePayDetail.deadlineType,
                     maxStageOrder: lastStage.order,
-                    jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.phasePay.detail)
+                    jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.phasePay.detail),
+                    accountList,
+                    accountGroup,
+                    shenpiConst,
+                    auditType: audit.auditType,
+                    authMobile: pa.auth_mobile,
                 };
                 await this.layout('phase_pay/detail.ejs', renderData, 'phase_pay/detail_modal.ejs');
             } catch (err) {
-                ctx.helper.log(err);
+                ctx.log(err);
                 ctx.postError(err, '读取合同支付数据错误');
-                ctx.redirect(ctx.request.headers.referer);
+                ctx.redirect('/tender/' + ctx.tender.id + '/pay');
+            }
+        }
+
+        async detailLoad(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data.filter) throw '参数错误';
+                const filter = data.filter.split(',');
+
+                const result = {};
+                for (const f of filter) {
+                    switch(f) {
+                        case 'pay':
+                            result.pay = await this.ctx.service.phasePayDetail.getDetailData(ctx.phasePay);
+                            break;
+                        case 'base':
+                            result.base = this.ctx.service.phasePay.getPhasePayCalcBase(ctx.phasePay, ctx.tender.info);
+                            break;
+                        case 'add':
+                            result.add = ctx.phasePay.calc_base;
+                            break;
+                        case 'file':
+                            result.file = await this.ctx.service.phasePayFile.getData(ctx.phasePay.id, 'pay');
+                    }
+                }
+                ctx.body = { err: 0, msg: '', data: result };
+            } catch (err) {
+                ctx.log(err);
+                ctx.ajaxErrorBody(err, '读取合同支付数据错误');
             }
         }
 
@@ -159,8 +263,7 @@ module.exports = app => {
                 }
                 ctx.body = responseData;
             } catch (err) {
-                console.log(err);
-                this.log(err);
+                ctx.log(err);
                 ctx.body = this.ajaxErrorBody(err, '数据错误');
             }
         }
@@ -168,34 +271,33 @@ module.exports = app => {
         async uploadFile(ctx) {
             let stream;
             try {
-                const parts = ctx.multipart({ autoFields: true });
+                const parts = ctx.multipart({autoFields: true});
+
                 let index = 0;
                 const create_time = Date.parse(new Date()) / 1000;
                 let stream = await parts();
-                const bonus = await ctx.service.stageBonus.getStageDataById(parts.field.bonus_id);
-                //if (!bonus || bonus.sid !== ctx.stage.id) throw '该奖罚金,当前不允许上传附件';
+                const user = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
+                const rela_type = parts.fields.type;
+                const rela_id = parts.field.rela_id;
+
+                const uploadfiles = [];
                 while (stream !== undefined) {
-                    if (!stream.filename) {
-                        throw '未发现上传文件!';
-                    }
+                    if (!stream.filename) throw '未发现上传文件!';
 
                     const fileInfo = path.parse(stream.filename);
-                    const dirName = 'app/public/upload/extra/' + moment().format('YYYYMMDD');
-                    const fileName = create_time + '_' + index + fileInfo.ext;
+                    const filepath = `app/public/upload/${ctx.phasePay.tid}/phasePay/${ctx.moment().format('YYYYMMDD')}/${create_time + '_' + index + fileInfo.ext}`;
 
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
+                    await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
                     await sendToWormhole(stream);
 
                     // 插入到stage_pay对应的附件列表中
-                    bonus.proof_file.push({
+                    uploadfiles.push({
+                        rela_id,
                         filename: fileInfo.name,
                         fileext: fileInfo.ext,
                         filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
-                        filepath: path.join(dirName, fileName),
-                        uid: ctx.session.sessionUser.accountId,
-                        in_time: moment(create_time * 1000).format('YYYY-MM-DD'),
-                        renew: bonus.sid === ctx.stage.id ? ctx.stage.status === auditConst.status.checked : true,
+                        filepath,
                     });
                     ++index;
                     if (Array.isArray(parts.field.size) && index < parts.field.size.length) {
@@ -204,60 +306,158 @@ module.exports = app => {
                         stream = undefined;
                     }
                 }
-                const result = await ctx.service.stageBonus.updateDatas({
-                    update: [
-                        { id: bonus.id, proof_file: bonus.proof_file },
-                    ]
-                });
-                for (const pf of bonus.proof_file) {
-                    pf.username = (await ctx.service.projectAccount.getAccountInfoById(pf.uid)).name;
-                    if (ctx.helper.canPreview(pf.fileext)){
-                        pf.viewpath = pf.filepath.substr(3, pf.filepath.length - 3);
-                    }
-                    delete pf.filepath;
-                }
-                ctx.body = {err: 0, msg: '', data: bonus.proof_file};
+
+                const result = await ctx.service.phasePayFile.addFiles(ctx.phasePay, 'pay', uploadfiles, user);
+                ctx.body = {err: 0, msg: '', data: result};
             } catch (error) {
-                ctx.helper.log(error);
+                ctx.log(error);
                 // 失败需要消耗掉stream 以防卡死
-                if (stream) {
-                    await sendToWormhole(stream);
-                }
+                if (stream) await sendToWormhole(stream);
                 ctx.body = this.ajaxErrorBody(error, '上传附件失败,请重试');
             }
         }
 
         async deleteFile(ctx) {
+            try{
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data) throw '缺少参数';
+                const result = await ctx.service.phasePayFile.delFiles(data);
+                ctx.body = { err: 0, msg: '', data: result };
+            } catch(error) {
+                ctx.log(error);
+                ctx.ajaxErrorBody(error, '删除附件失败');
+            }
+        }
+
+        /**
+         * 添加审批人
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async addAudit(ctx) {
             try {
                 const data = JSON.parse(ctx.request.body.data);
+                const id = this.app._.toInteger(data.auditorId);
+                if (isNaN(id) || id <= 0) throw '参数错误';
 
-                const bonus = await ctx.service.stageBonus.getStageDataById(data.b_id);
-                if (!bonus || !bonus.proof_file || !bonus.proof_file[data.index]) throw '删除的文件不存在';
+                // 检查权限等
+                if (ctx.phasePay.create_user_id !== ctx.session.sessionUser.accountId) throw '您无权添加审核人';
+                if (ctx.phasePay.audit_status !== audit.common.status.uncheck && ctx.phasePay.audit_status !== audit.common.status.checkNo) {
+                    throw '当前不允许添加审核人';
+                }
 
-                const fileInfo = bonus.proof_file[data.index];
-                if (fileInfo.uid !== ctx.session.sessionUser.accountId) throw '您无权删除该文件';
+                // 检查审核人是否已存在
+                const exist = await ctx.service.phasePayAudit.getDataByCondition({ phase_id: ctx.phasePay.id, audit_times: ctx.phasePay.audit_times, audit_id: id });
+                if (exist) throw '该审核人已存在,请勿重复添加';
 
-                const deleteFilePermission = PermissionCheck.delFile(this.ctx.session.sessionUser.permission);
-                if (ctx.stage.status === auditConst.status.checked && !fileInfo.renew && !deleteFilePermission) throw '不可删除该文件';
+                const auditorInfo = await this.ctx.service.projectAccount.getDataById(id);
+                if (!auditorInfo) throw '添加的审批人不存在';
 
-                // 先删除文件
-                await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));
-                // 再删除数据库
-                bonus.proof_file.splice(data.index, 1);
-                const result = await ctx.service.stageBonus.updateDatas({
-                    update: [
-                        { id: bonus.id, proof_file: bonus.proof_file },
-                    ]
-                });
-                for (const pf of bonus.proof_file) {
-                    delete pf.filepath;
-                    pf.username = (await ctx.service.projectAccount.getAccountInfoById(pf.uid)).name;
+                const shenpiInfo = await ctx.service.shenpiAudit.getDataByCondition({ tid: ctx.tender.id, sp_type: shenpiConst.sp_type.phasePay, sp_status: shenpiConst.sp_status.gdzs });
+                const is_gdzs = shenpiInfo && ctx.tender.info.shenpi.phasePay === shenpiConst.sp_status.gdzs ? 1 : 0;
+                const result = await ctx.service.phasePayAudit.addAuditor(ctx.phasePay.id, auditorInfo, ctx.phasePay.audit_times, is_gdzs);
+                if (!result) throw '添加审核人失败';
+
+                const auditors = await ctx.service.phasePayAudit.getAuditorGroup(ctx.phasePay.id, ctx.phasePay.audit_times);
+                ctx.body = { err: 0, msg: '', data: auditors };
+            } catch (err) {
+                ctx.log(err);
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
+        /**
+         * 移除审批人
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async deleteAudit(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                const id = data.auditorId instanceof Number ? data.auditorId : this.app._.toNumber(data.auditorId);
+                if (isNaN(id) || id <= 0) throw '参数错误';
+
+                const result = await ctx.service.phasePayAudit.deleteAuditor(ctx.phasePay.id, id, ctx.phasePay.audit_times);
+                if (!result) throw '移除审核人失败';
+
+                const auditors = await ctx.service.phasePayAudit.getAuditors(ctx.phasePay.id, ctx.phasePay.audit_times);
+                ctx.body = { err: 0, msg: '', data: auditors };
+            } catch (err) {
+                ctx.log(err);
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
+        async auditStart(ctx) {
+            try {
+                if (ctx.phasePay.create_user_id !== ctx.session.sessionUser.accountId) throw '您无权上报该期数据';
+                if (ctx.phasePay.revising) throw '台账修订中,不可上报';
+                if (ctx.phasePay.audit_status !== audit.common.status.uncheck && ctx.phasePay.audit_status !== audit.common.status.checkNo) throw '该期数据当前无法上报';
+
+                await ctx.service.phasePayAudit.start(ctx.phasePay);
+                ctx.redirect(ctx.request.header.referer);
+            } catch (err) {
+                ctx.log(err);
+                ctx.postError(err, '上报失败');
+                ctx.redirect(`/tender/${ctx.phasePay.tid}/pay/${ctx.phasePay.phase_order}/detail`);
+            }
+        }
+        async auditCheck(ctx) {
+            try {
+                if (!ctx.phasePay || (ctx.phasePay.audit_status !== audit.common.status.checking && ctx.phasePay.audit_status !== audit.common.status.checkNoPre)) {
+                    throw '当前期数据有误';
+                }
+                if (ctx.phasePay.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) < 0) {
+                    throw '您无权进行该操作';
+                }
+                if (ctx.phasePay.revising) throw '台账修订中,不可审批';
+
+                const checkType = parseInt(ctx.request.body.checkType);
+                const opinion = ctx.request.body.opinion.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
+                await ctx.service.phasePayAudit.check(ctx.phasePay, checkType, opinion);
+            } catch (err) {
+                ctx.log(err);
+                ctx.postError(err, '审批失败');
+            }
+            ctx.redirect(ctx.request.header.referer);
+        }
+        async auditCheckAgain(ctx) {
+            try {
+                if (ctx.phasePay.isLatest) throw '非最新一期,不可重新审批';
+                if (ctx.phasePay.audit_status !== audit.common.status.checked) throw '未审批完成,不可重新审批';
+                if (ctx.phasePay.revising) throw '台账修订中,不可重审';
+
+                if (ctx.session.sessionUser.loginStatus === 0) {
+                    const user = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
+                    if (!user.auth_mobile) throw '未绑定手机号';
+
+                    const code = ctx.request.body.code;
+                    const cacheKey = 'smsCode:' + ctx.session.sessionUser.accountId;
+                    const cacheCode = await app.redis.get(cacheKey);
+                    if (cacheCode === null || code === undefined || cacheCode !== (code + pa.auth_mobile)) {
+                        throw '验证码不正确!';
+                    }
                 }
-                ctx.body = {err: 0, msg: '', data: bonus.proof_file};
+
+                const adminCheckAgain = ctx.request.body.confirm === '确认设置终审审批' && ctx.session.sessionUser.is_admin;
+                if (ctx.phasePay.finalAuditorIds.indexOf(ctx.session.sessionUser.accountId) < 0 && !adminCheckAgain) throw '您无权重新审批';
+
+                await ctx.service.phasePayAudit.checkAgain(ctx.phasePay, adminCheckAgain);
+            } catch (err) {
+                ctx.log(err);
+                ctx.postError(err, '重新审批失败');
+            }
+            ctx.redirect(ctx.request.header.referer);
+        }
+        async auditCheckCancel(ctx) {
+            try {
+                if (ctx.phasePay.revising) throw '台账修订中,不可撤回';
+                if (!ctx.phasePay.cancancel) throw '您无权进行该操作';
+
+                await ctx.service.phasePayAudit.checkCancel(ctx.phasePay);
             } catch (err) {
-                this.log(err);
-                this.ctx.ajaxErrorBody(err, '删除文件失败');
+                ctx.log(err);
+                ctx.postError(err, '撤回失败');
             }
+            ctx.redirect(ctx.request.header.referer);
         }
     }
 

+ 1 - 1
app/controller/tender_controller.js

@@ -1466,7 +1466,7 @@ module.exports = app => {
                         ctx.body = {err: 0, msg: '', data: refreshData};
                         break;
                     case 'revise':
-                        const reviseData = await this.ctx.service.reviseBills.sumLoad(data.lid, this.ctx.revise.id, data.tenders);
+                        const reviseData = await this.ctx.service.reviseBills.sumLoad(data.lid, this.ctx.revise.id, data.tenders, data.subUp);
                         ctx.body = {err: 0, msg: '', data: reviseData};
                         break;
                     case 'stage':

+ 4 - 0
app/lib/stage_im.js

@@ -1128,6 +1128,10 @@ class StageIm {
             delete im.changes;
         }
     }
+
+    getRelaBills(im) {
+        return this.billsTree.find(x => { return x.id === im.lid; });
+    }
 }
 
 module.exports = StageIm;

+ 9 - 4
app/lib/sum_load.js

@@ -31,6 +31,7 @@ class loadGclBaseTree {
         this.ignoreParent = setting.ignoreParent;
         this.ignoreNotFind = setting.ignoreNotFind;
         this.loadChange = setting.loadChange;
+        this.useSubUp = setting.useSubUp;
 
         // 缓存
         this.keyNodeId = setting.maxId ? setting.maxId + 1 : 1;
@@ -145,6 +146,7 @@ class loadGclBaseTree {
                 quantity: 0,
                 is_leaf: source.is_leaf,
                 hasPos: false,
+                sub_up: source.unit_price || 0,
             };
             this.keyNodeId += 1;
             parent.children.push(node);
@@ -186,8 +188,11 @@ class loadGclBaseTree {
 
             if (!node.unit_price) {
                 const db = dealBills.find(x => { return x.code === node.b_code && x.name === node.name && x.unit === node.unit });
-                if (!db) return;
-                node.unit_price = db.unit_price;
+                if (db) {
+                    node.unit_price = db.unit_price;
+                } else if (this.useSubUp) {
+                    node.unit_price = this.ctx.helper.round(node.sub_up, this.ctx.tender.info.decimal.up);
+                }
             }
             node.deal_tp = this.ctx.helper.mul(node.deal_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
             node.sgfh_tp = this.ctx.helper.mul(node.sgfh_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
@@ -482,9 +487,9 @@ class sumLoad {
         }
     }
 
-    async loadGatherGcl(select, maxId, tenders, defaultData) {
+    async loadGatherGcl(select, maxId, tenders, defaultData, subUp) {
         this.loadTree = new loadLedgerGclTree(this.ctx, {
-            parent: select, maxId, type: 'ledger', defaultData,
+            parent: select, maxId, type: 'ledger', defaultData, subUp,
         });
         for (const tender of tenders) {
             const billsData = await this.ctx.service.ledger.getData(tender.tid);

+ 3 - 0
app/middleware/phase_pay_check.js

@@ -40,6 +40,9 @@ module.exports = options => {
 
             // 读取原报、审核人数据
             yield this.service.phasePay.doCheckPhase(phasePay);
+            phasePay.latestOrder = yield this.service.phasePay.count({ tid: this.tender.id });
+            phasePay.isLatest = phasePay.latestOrder === phasePay.phase_order;
+            yield this.service.phasePay.checkShenpi(phasePay);
             this.phasePay = phasePay;
             yield next;
         } catch (err) {

+ 148 - 46
app/public/js/change_information.js

@@ -753,6 +753,7 @@ $(document).ready(() => {
                         SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, []);
                         return;
                     }
+                    console.log(info);
                     changeSpreadObj.refreshXmjData();
                     if (!readOnly) changeSpreadObj.refreshActn();
                 }
@@ -825,11 +826,11 @@ $(document).ready(() => {
         },
         calcNodeTp: function (node) {
             node.change_amount = ZhCalc.add(node.oamount2, node.camount);
-            node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-            node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-            node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-            const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-            node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || 0 :  ZhCalc.add(node.oa_tp, node.ca_tp) || 0;
+            node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+            node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+            node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+            const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+            node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null :  ZhCalc.add(node.oa_tp, node.ca_tp) || null;
         },
         refreshXmjData: function() {
             SpreadJsObj.resetTopAndSelect(xmjSheet);
@@ -917,7 +918,7 @@ $(document).ready(() => {
                     changeSpreadObj.calcOneSum(node);
                     if (readOnly) {
                         for (const aid of aidList) {
-                            node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
+                            node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
                         }
                     }
                 }
@@ -1811,7 +1812,7 @@ $(document).ready(() => {
             const next = changeSpreadSheet.zh_data[row + count];
             const nextUpdates = [];
             if (next && next.id) {
-                preUpdates.push({ id: next.id });
+                nextUpdates.push({ id: next.id });
             } else if (next && next.children && next.children.length > 0) {
                 for (const item of next.children) {
                     nextUpdates.push({ id: item.id });
@@ -1917,6 +1918,11 @@ $(document).ready(() => {
                 changeSpreadObj.calcOneSum(select);
                 changeSpreadObj.countSum();
                 changeSpreadObj.refreshActn();
+                if (SpreadJsObj.getSelectObject(changeSpreadSheet) === select) {
+                    if (select.children && select.children.length === 1) {
+                        changeSpreadObj.refreshXmjData();
+                    }
+                }
             }, function () {
                 select.camount = orgValue;
                 select.camount_expr = orgExprValue;
@@ -2017,6 +2023,7 @@ $(document).ready(() => {
             }
 
             const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
+            console.log(info.sheet.zh_data);
             const cInfo = _.find(changeList, { id: select.id });
             if (!cInfo) {
                 toastr.error('数据错误,请刷新页面重试');
@@ -2114,18 +2121,28 @@ $(document).ready(() => {
             select[col.field] = validText;
             console.log(cInfo);
             delete cInfo.waitingLoading;
+            const children = info.sheet.zh_data;
 
             // 更新至服务器
             postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
                 const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
-                node.children = info.sheet.zh_data;
+                node.children = children;
                 if (node.children && node.children.length === 1) {
                     node[col.field] = validText;
+                    if (col.field === 'camount') {
+                        node.spamount = select.spamount;
+                        node.camount_expr = select.camount_expr;
+                    }
                 }
                 xmjSpreadObj.loadExprToInput();
                 changeSpreadObj.calcOneSum(node);
-                changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
+                console.log(node);
+                if (SpreadJsObj.getSelectObject(changeSpreadSheet) !== node) {
+                    SpreadJsObj.reLoadRowData(changeSpreadSheet, billIndex);
+                } else {
+                    changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
+                }
                 changeSpreadObj.countSum();
             }, function () {
                 select[col.field] = orgValue;
@@ -2382,6 +2399,37 @@ $(document).ready(() => {
             }
             return;
         };
+        xmjSpreadObj.setAllValuation = function (is_valuation) {
+            const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
+            if (!select) {
+                toastr.error('未选中清单');
+                return;
+            }
+            if (!select.children || select.children.length === 0) {
+                toastr.warning('暂无清单无法设置清单计价');
+                return;
+            }
+            const needChangeList = _.filter(select.children, { is_valuation: is_valuation ? 0 : 1 });
+            if (needChangeList.length === 0) {
+                toastr.warning('全部已设置清单'+ (is_valuation ? '' : '不') +'计价');
+                return;
+            }
+            const realNeedChangeList = [];
+            for (const nc of needChangeList) {
+                if (_.findIndex(changeUsedData, { cbid: nc.id }) === -1) {
+                    realNeedChangeList.push(nc.id);
+                }
+            }
+            if (realNeedChangeList.length === 0) {
+                toastr.warning('全部已设置清单'+ (is_valuation ? '' : '不') +'计价');
+                return;
+            }
+            postData(window.location.pathname + '/save', { type:'set_all_valuation', ids: realNeedChangeList, is_valuation }, function (result) {
+                changeList = result;
+                const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
+                changeSpreadObj.reloadSheet(newChangeList);
+            });
+        };
 
         // 表达式判断
         $('#xmj-camount-expr').change(function () {
@@ -2716,21 +2764,37 @@ $(document).ready(() => {
                         return isUsed;
                     }
                 },
-                // sprEdit: '----',
-                // 'allNotValuation': {
-                //     name: '设置全部清单不计价',
-                //     icon: 'fa-magic',
-                //     callback: function (key, opt) {
-                //         changeSpreadObj.setAllValuation(0);
-                //     },
-                // },
-                // 'allValuation': {
-                //     name: '设置全部清单计价',
-                //     icon: 'fa-magic',
-                //     callback: function (key, opt) {
-                //         changeSpreadObj.setAllValuation(1);
-                //     },
-                // },
+                sprEdit: '----',
+                'allNotValuation': {
+                    name: '设置全部不计价',
+                    icon: 'fa-magic',
+                    callback: function (key, opt) {
+                        xmjSpreadObj.setAllValuation(0);
+                    },
+                    disabled: function (key, opt) {
+                        const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
+                        if (select.children && select.children.length > 0) {
+                            return false;
+                        } else {
+                            return true;
+                        }
+                    }
+                },
+                'allValuation': {
+                    name: '设置全部计价',
+                    icon: 'fa-magic',
+                    callback: function (key, opt) {
+                        xmjSpreadObj.setAllValuation(1);
+                    },
+                    disabled: function (key, opt) {
+                        const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
+                        if (select.children && select.children.length > 0) {
+                            return false;
+                        } else {
+                            return true;
+                        }
+                    }
+                },
             }
         });
     }
@@ -2767,7 +2831,8 @@ $(document).ready(() => {
                     indent: 16,
                     getColor: function (index, data) {
                         if (!data) return;
-                        if ((!data.clid && data.cid) || (data.clid && data.gcl_id && _.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1)) {
+                        if ((!data.clid && data.id && (_.findIndex(changeLedgerList, { id: data.id }) !== -1 || _.findIndex(changePosList, { lid: data.id }) !== -1))
+                            || (data.clid && data.gcl_id && _.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1)) {
                             return '#dc3545';
                         }
                         if (data.lid == 0) {
@@ -2925,25 +2990,25 @@ $(document).ready(() => {
                     node.samount = samount;
                     node.spamount = spamount;
                     node.change_amount = ZhCalc.add(oamount2, camount);
-                    node.oa_tp = ZhCalc.round(ZhCalc.mul(oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-                    node.ca_tp = ZhCalc.round(ZhCalc.mul(camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-                    node.sa_tp = ZhCalc.round(ZhCalc.mul(samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-                    const spa_tp = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-                    node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || 0 :  ZhCalc.add(node.oa_tp, node.ca_tp) || 0;
+                    node.oa_tp = ZhCalc.round(ZhCalc.mul(oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+                    node.ca_tp = ZhCalc.round(ZhCalc.mul(camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+                    node.sa_tp = ZhCalc.round(ZhCalc.mul(samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+                    const spa_tp = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+                    node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null :  ZhCalc.add(node.oa_tp, node.ca_tp) || null;
                 }
                 node.is_valuation = is_valuation;
             } else if (node.clid) {
                 // node.oamount2 = ZhCalc.round(node.oamount2, findDecimal(node.unit));
                 // node.camount = ZhCalc.round(node.camount, findDecimal(node.unit));
                 // node.change_amount = ZhCalc.add(node.oamount2, node.camount);
-                node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-                node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-                node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-                const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
-                node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || 0 : ZhCalc.add(node.oa_tp, node.ca_tp) || 0;
+                node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+                node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+                node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+                const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
+                node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
                 if (readOnly) {
                     for (const aid of aidList) {
-                        node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
+                        node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
                     }
                 }
             }
@@ -3520,7 +3585,6 @@ $(document).ready(() => {
             } else {
                 cInfo[col.field] = validText;
             }
-            cInfo[col.field] = validText;
             select[col.field] = validText;
             console.log(cInfo);
             delete cInfo.waitingLoading;
@@ -4742,6 +4806,9 @@ $(document).ready(() => {
         changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
         SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
 
+        xmjSpreadObj.editStarting = function (e, info) {
+            xmjSpreadObj.billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
+        };
         xmjSpreadObj.editEnded = function (e, info) {
             if (!info.sheet.zh_setting) {
                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -4763,7 +4830,7 @@ $(document).ready(() => {
                 return;
             }
 
-            const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
+            const node = xmjSpreadObj.billsNode;
             if (!node) {
                 toastr.error('数据错误,请选择清单节点后再试');
                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -4967,7 +5034,7 @@ $(document).ready(() => {
             }
             return;
         };
-
+        xmjSpread.bind(spreadNS.Events.EditStarting, xmjSpreadObj.editStarting);
         xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
         xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
         SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
@@ -5469,6 +5536,37 @@ $(document).ready(() => {
         }
     }
 
+    // 显示层次
+    (function (select, sheet) {
+        $(select).click(function () {
+            if (!sheet.zh_tree) return;
+            const tag = $(this).attr('tag');
+            const tree = sheet.zh_tree;
+            setTimeout(() => {
+                showWaitingView();
+                switch (tag) {
+                    case "1":
+                    case "2":
+                    case "3":
+                    case "4":
+                    case "5":
+                        tree.expandByLevel(parseInt(tag));
+                        SpreadJsObj.refreshTreeRowVisible(sheet);
+                        break;
+                    case "last":
+                        tree.expandByCustom(() => { return true; });
+                        SpreadJsObj.refreshTreeRowVisible(sheet);
+                        break;
+                    case "leafXmj":
+                        tree.expandToLeafXmj();
+                        SpreadJsObj.refreshTreeRowVisible(sheet);
+                        break;
+                }
+                closeWaitingView();
+            }, 100);
+        });
+    })('a[name=showLevel]', ledgerSheet);
+
     function makeLedgerAndPosData() {
         const changeLedgers = _.filter(ledgerList, function (item) {
             return _.findIndex(changeList, { gcl_id: item.id}) !== -1;
@@ -5534,7 +5632,6 @@ $(document).ready(() => {
                 cloneCl.ledger_pid = firstChangeLedger.ledger_id;
                 cloneCl.ledger_id = maxLedgerId;
                 cloneCl.full_path = firstChangeLedger.full_path + '-' + maxLedgerId;
-                console.log(cloneCl);
                 changeLedgers.push(cloneCl);
                 maxLedgerId++;
                 firstOrder++;
@@ -5800,12 +5897,17 @@ $(document).ready(() => {
                 toastr.error('请添加变更清单!');
                 returnFlag = true;
             } else {
-                for (const [i,cl] of changeSpreadSheet.zh_data.entries()) {
-                    if (cl.name === '') {
-                        toastr.error('清单第' + (i+1) + '行未完整填写数据(名称不可为空)');
-                        returnFlag = true;
-                    }
-                }
+                const whiteList = _.filter(changeList, item => item.lid == 0 && (item.name === '' || item.name === null));
+                if (whiteList.length > 0) {
+                    toastr.error('存在空白清单未完整填写数据(名称不可为空)');
+                    returnFlag = true;
+                }
+                // for (const [i,cl] of changeSpreadSheet.zh_data.entries()) {
+                //     if (cl.name === '') {
+                //         toastr.error('清单第' + (i+1) + '行未完整填写数据(名称不可为空)');
+                //         returnFlag = true;
+                //     }
+                // }
             }
             if(!checkAuditorFrom ()) {
                 returnFlag = true;

+ 10 - 10
app/public/js/change_information_add_list.js

@@ -399,16 +399,16 @@ $(document).ready(() => {
             if (hadcid !== 0) gclGatherData[ggd].cid = 1;
         }
         // 数组去重
-        const dealBillList = result.dealBills;
-        for (const db of gclGatherData) {
-            const exist_index = dealBillList.findIndex(function (item) {
-                return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
-            });
-            if (exist_index !== -1) {
-                dealBillList.splice(exist_index, 1);
-            }
-        }
-        changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
+        // const dealBillList = result.dealBills;
+        // for (const db of gclGatherData) {
+        //     const exist_index = dealBillList.findIndex(function (item) {
+        //         return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
+        //     });
+        //     if (exist_index !== -1) {
+        //         dealBillList.splice(exist_index, 1);
+        //     }
+        // }
+        changeListData = gclGatherData.sort(sortByCode);
         for (const gcl of changeListData) {
             gcl.unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
             gcl.quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (gcl.unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity).toString() : '0';

+ 2 - 2
app/public/js/material_audit.js

@@ -122,8 +122,8 @@ $(document).ready(function () {
         }
     });
     // 删除审批人
-    $('body').on('click', '#auditors li>a', function () {
-        const li = $(this).parent();
+    $('body').on('click', '#auditors li a', function () {
+        const li = $(this).parents('li');
         const data = {
             auditorId: parseInt(li.attr('auditorId')),
         };

+ 142 - 2
app/public/js/phase_pay_detail.js

@@ -1,6 +1,31 @@
 'use strict';
 
+const showSideTools = function (show) {
+    const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
+    if (show) {
+        right.show();
+        autoFlashHeight();
+        /**
+         * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
+         * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
+         * 故需要通过最终的parent.width再计算一次left.width
+         *
+         * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
+         * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
+         *
+         */
+            //left.css('width', parent.width() - right.outerWidth());
+            //left.css('width', parent.width() - right.outerWidth());
+        const percent = 100 - right.outerWidth() /parent.width() * 100;
+        left.css('width', percent + '%');
+    } else {
+        left.width(parent.width());
+        right.hide();
+    }
+};
+
 $(document).ready(() => {
+    autoFlashHeight();
     const payUtils = {
         tips: {
             name: function(data) {
@@ -69,7 +94,14 @@ $(document).ready(() => {
                 } else {
                     return payUtils.check.isWC(data) || payUtils.check.isSF(data) || payUtils.check.isYf(data) || !(payUtils.check.isOwner(data) || payUtils.check.isYB());
                 }
-            }
+            },
+            rangeTpReadOnly: function(data) {
+                if (payUtils.check.isOld(data)) {
+                    return !payUtils.check.isYB(data) || payUtils.check.isLock(data);
+                } else {
+                    return payUtils.check.isWC(data) || payUtils.check.isYF(data) || !(payUtils.check.isOwner(data) || payUtils.check.isYB());
+                }
+            },
         },
         menuVisible: {
             pause: function (data) {
@@ -463,7 +495,6 @@ $(document).ready(() => {
                 {title: '起扣金额',  colSpan: '1', rowSpan: '1', field: 'start_tp', hAlign: 2, width: 100, type: 'Number'},
                 {title: '付(扣)款限额',  colSpan: '1', rowSpan: '1', field: 'range_tp', hAlign: 2, width: 100, cellType: 'tip', type: 'Number', getTip: payUtils.tips.range_tp},
                 {title: '汇总',  colSpan: '1', rowSpan: '1', field: 'is_gather', hAlign: 1, width: 60, cellType: 'signalCheckbox', show: payUtils.check.isGatherValid},
-                {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: 'postil', hAlign: 0, width: 120, formatter: '@', cellType: 'autoTip'},
             ],
             emptyRows: 0,
@@ -803,6 +834,56 @@ $(document).ready(() => {
             $('a[name="base-opr"]').click(function () {
                 payEvent.baseOpr(this.getAttribute('type'));
             });
+            $('#pay-expr').bind('change onblur', function () {
+                if (this.readOnly) return;
+
+                const expr = $(this);
+                const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
+                const select = payTree.nodes[row];
+                const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
+                if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
+
+                const data = { postType: 'update' };
+                if (field === 'expr') {
+                    data.postData = { id: select.id, tp: 0, expr: newValue };
+                    const [valid, msg] = payUtils.check.isSf(select)
+                        ? payCalc.checkSfExpr(newValue, data.postData, select, payTree)
+                        : payCalc.checkExpr(newValue, data.postData, select, payTree);
+                    if (!valid) {
+                        toastr.warning(msg);
+                        this.value = select.expr;
+                        return;
+                    }
+                } else if (field === 'start_expr') {
+                    data.updateData = {id: select.id};
+                    const [valid, msg] = payCalc.checkStartExpr(select, newValue, data.postData);
+                    if (!valid) {
+                        toastr.warning(msg);
+                        this.value = select.start_expr;
+                        return;
+                    }
+                } else if (field === 'range_expr') {
+                    data.updateData = {id: select.id};
+                    const [valid, msg] = payCalc.checkRangeExpr(select, newValue, data.postData);
+                    if (!valid) {
+                        toastr.warning(msg);
+                        this.value = select.range_expr;
+                        return;
+                    }
+                } else {
+                    expr.val('');
+                    return;
+                }
+                // 更新至服务器
+                postData('update', data, function (result) {
+                    if (result.reload) {
+                        payEvent.reloadPays(result.reload);
+                    } else {
+                        const refreshData = payTree.loadPostData(result);
+                        payEvent.refreshTree(refreshData);
+                    }
+                });
+            });
             $('#calc-all').click(function() {
                 payEvent.calculateAll();
             });
@@ -971,6 +1052,65 @@ $(document).ready(() => {
     })();
     payObj.loadDatas(details);
 
+    const payFile = $.ledger_att({
+        selector: '#fujian',
+        key: 'uuid',
+        masterKey: 'rela_id',
+        uploadUrl: 'file/upload',
+        deleteUrl: 'file/delete',
+        checked: false,
+        zipName: `附件.zip`,
+        readOnly: false,
+        fileIdType: 'string',
+        fileInfo: {
+            user_name: 'user_name',
+            user_id: 'user_id',
+            create_time: 'create_time',
+        },
+        getCurHint: function(node) {
+            return`${node.name || ''}`;
+        },
+        locate: function (att) {
+            if (!att) return;
+            SpreadJsObj.locateTreeNode(payObj.sheet, att.node.tree_id, true);
+            payFile.getCurAttHtml(att.node);
+        }
+    });
+    // 展开收起标准清单
+    $('a', '#side-menu').bind('click', function (e) {
+        e.preventDefault();
+        const tab = $(this), tabPanel = $(tab.attr('content'));
+        // 展开工具栏、切换标签
+        if (!tab.hasClass('active')) {
+            // const close = $('.active', '#side-menu').length === 0;
+            $('a', '#side-menu').removeClass('active');
+            $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
+            tab.addClass('active');
+            tabPanel.addClass('active');
+            // $('.tab-content .tab-pane').removeClass('active');
+            showSideTools(tab.hasClass('active'));
+        } else { // 收起工具栏
+            tab.removeClass('active');
+            tabPanel.removeClass('active');
+            showSideTools(tab.hasClass('active'));
+        }
+        payObj.spread.refresh();
+    });
+    postData('load', {filter: 'file'}, function(result) {
+        for (const f of result.file) {
+            f.node = payObj.payTree.datas.find(x => { return x.uuid === f.rela_id; });
+        }
+        payFile.loadDatas(result.file);
+        payFile.getCurAttHtml(SpreadJsObj.getSelectObject(payObj.sheet));
+    });
+    // 工具栏spr
+    $.divResizer({
+        select: '#right-spr',
+        callback: function () {
+            payObj.spread.refresh();
+        }
+    });
+
     // todo 加载审批列表
     $.subMenu({
         menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',

+ 136 - 1
app/public/js/phase_pay_list.js

@@ -1,7 +1,142 @@
 'use strict';
 
 $(document).ready(() => {
-    // todo 加载审批列表
+    $('#audit-list').on('click', 'a', 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('#end-target').text($(this).data('idx') + '#')
+                auditCard.find('#fold-btn').text('收起历史审核记录')
+            })
+        } else {
+            $(this).data('target', 'show')
+            auditCard.find('.fold-card').slideUp('swing', () => {
+                auditCard.find('#end-target').text('1#')
+                auditCard.find('#fold-btn').text('展开历史审核记录')
+            })
+        }
+    });
+
+    const getGroupAuditHtml = function (group) {
+        return group.map(u => { return `<small class="d-inline-block text-dark mx-1" title="${u.role}" data-auditorId="${u.aid}">${u.name}</small>`; }).join('');
+    };
+    const getAuditTypeHtml = function (type) {
+        if (type === auditType.key.common) return '';
+        return `<div class="li-subscript"><span class="badge badge-pill badge-${auditType.info[type].class} p-1 badge-bg-small"><small>${auditType.info[type].short}</small></span></div>`;
+    };
+    const getAuditTypeText = function (type) {
+        if (type === auditType.key.common) return '';
+        return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
+    };
+    const getAuditorsHtml = function (auditors) {
+        const auditorsHTML = [];
+        auditors.forEach((group, idx) => {
+            if (idx === 0) {
+                auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
+                    <span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>
+                <span class="text-muted">${getGroupAuditHtml(group)}</span>
+                <span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>
+                </li>`);
+            } else if(idx === auditors.length -1 && idx !== 0) {
+                auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
+                    <span class="mr-1"><i class="fa fa fa-stop-circle fa-rotate-90"></i></span>
+                <span class="text-muted">${getGroupAuditHtml(group)}</span>
+                <div class="d-flex ml-auto">
+                ${getAuditTypeHtml(group[0].audit_type)}
+                <span class="badge badge-light badge-pill ml-auto"><small>终审</small></span>
+                </div>
+                </li>`);
+            } else {
+                auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
+                    <span class="mr-1"><i class="fa fa fa-chevron-circle-down"></i></span>
+                <span class="text-muted">${getGroupAuditHtml(group)}</span>
+                <div class="d-flex ml-auto">
+                ${getAuditTypeHtml(group[0].audit_type)}
+                <span class="badge badge-light badge-pill"><small>${transFormToChinese(idx)}审</small></span>
+                </div>
+                </li>`);
+            }
+        });
+        return auditorsHTML;
+    }
+    const getAuditHistroyHtml = function (auditHistory) {
+        const historyHTML = [];
+        auditHistory.forEach((his, idx) => {
+            if (idx === auditHistory.length - 1 && auditHistory.length !== 1) {
+                historyHTML.push(`<div class="text-right"><a href="javascript: void(0);" id="fold-btn" data-target="show">展开历史审批流程</a></div>`);
+            }
+            historyHTML.push(`<div class="${idx < auditHistory.length - 1 ? 'fold-card' : ''}">`);
+            historyHTML.push(`<div class="text-center text-muted">${idx+1}#</div>`);
+            historyHTML.push(`<ul class="timeline-list list-unstyled mt-2 ${ idx === auditHistory.length - 1 && auditHistory.length !== 1 ? 'last-auditor-list' : '' }">`);
+            his.forEach((group) => {
+                historyHTML.push(`<li class="timeline-list-item pb-2 ${ group.audit_status === auditConst.status.uncheck && idx === auditHistory.length - 1 && auditHistory.length !== 1 ? 'is_uncheck' : ''}">`);
+                if (group.auditYear) {
+                    historyHTML.push(`<div class="timeline-item-date">${group.auditYear}<span>${group.auditDate}</span><span>${group.auditTime}</span></div>`);
+                }
+                if (group.audit_order < his.length - 1) {
+                    historyHTML.push('<div class="timeline-item-tail"></div>');
+                }
+                if (group.audit_status === auditConst.status.checked) {
+                    historyHTML.push('<div class="timeline-item-icon bg-success text-light"><i class="fa fa-check"></i></div>');
+                } else if (group.audit_status === auditConst.status.checkNo || group.audit_status === auditConst.status.checkNoPre || group.status === auditConst.status.checkCancel) {
+                    historyHTML.push('<div class="timeline-item-icon bg-warning text-light"><i class="fa fa-level-up"></i></div>');
+                } else if (group.audit_status === auditConst.status.checking) {
+                    historyHTML.push('<div class="timeline-item-icon bg-warning text-light"><i class="fa fa-ellipsis-h"></i></div>');
+                } else {
+                    historyHTML.push('<div class="timeline-item-icon bg-secondary text-light"></div>');
+                }
+
+                historyHTML.push('<div class="timeline-item-content">');
+                if (group.audit_order > 0) {
+                    const statuStr = group.audit_status !== auditConst.status.uncheck ?
+                        `<span class="pull-right ${auditConst.info[group.audit_status].class}">${auditConst.info[group.audit_status].title}</span>` : '';
+                    historyHTML.push(`<div class="py-1">
+                        <span class="text-black-50">
+                        ${ !group.is_final ? group.audit_order + '' : '终' }审 ${getAuditTypeText(group.audit_type)}
+                        </span>
+                        ${statuStr}
+                    </div>`);
+                } else {
+                    historyHTML.push(` <div class="py-1">
+                        <span class="text-black-50">原报</span>
+                        <span class="pull-right text-success">${idx !== 0 ? '重新' : '' }上报审批</span>
+                    </div>`);
+                }
+                historyHTML.push('<div class="card"><div class="card-body px-3 py-0">');
+                for (const [i, auditor] of group.auditors.entries()) {
+                    historyHTML.push(`<div class="card-text p-2 py-3 row ${ ( i > 0 ? 'border-top' : '') }">`);
+                    historyHTML.push(`<div class="col"><span class="h6">${auditor.name}</span><span class="text-muted ml-1">${auditor.role}</span></div>`);
+                    historyHTML.push('<div class="col">');
+                    if (auditor.audit_status === auditConst.status.checked) {
+                        historyHTML.push('<span class="pull-right text-success"><i class="fa fa-check-circle"></i></span>');
+                    } if (auditor.audit_status === auditConst.status.checkNo || auditor.audit_status === auditConst.status.checkNoPre || auditor.audit_status === auditConst.status.checkCancel) {
+                        historyHTML.push('<span class="pull-right text-warning"><i class="fa fa-share-square fa-rotate-270"></i></span>');
+                    }
+                    historyHTML.push('</div>');
+                    if (group.audit_order > 0 && auditor.opinion) {
+                        historyHTML.push(`<div class="col-12 py-1 bg-light"><i class="fa fa-commenting-o mr-1"></i>${auditor.opinion}</div>`);
+                    }
+                    historyHTML.push('</div>');
+                }
+                historyHTML.push('</div></div>');
+                historyHTML.push('</div>');
+                historyHTML.push('</li>');
+            });
+            historyHTML.push('</div>');
+            historyHTML.push('</ul>');
+        });
+        return historyHTML.join('');
+    }
+    // 获取审批流程
+    $('a[data-target="#sp-list" ]').on('click', function () {
+        postData('pay/auditors', { order: $(this).attr('phase-order') }, function (result) {
+            $('#auditor-list').html(getAuditorsHtml(result.hisUserGroup));
+            $('#audit-list').html(getAuditHistroyHtml(result.auditHistory));
+        });
+    });
+
     $.subMenu({
         menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
         toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',

+ 452 - 0
app/public/js/shares/phase_pay_audit.js

@@ -0,0 +1,452 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2019/2/27
+ * @version
+ */
+
+// 检查上报情况
+function checkAuditorFrom () {
+    if ($('#auditors li').length === 0) {
+        if(shenpi_status === shenpiConst.sp_status.gdspl) {
+            toastr.error('请联系管理员添加审批人');
+        } else {
+            toastr.error('请先选择审批人,再上报数据');
+        }
+        return false;
+    }
+    $('#hide-all').show();
+    return true;
+}
+// 点击验证码
+function codeSuccess(btn) {
+    let counter = 60;
+    btn.addClass('disabled').text('重新获取 ' + counter + 'S');
+    btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
+    const bindBtn = $("#bind-btn");
+    bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
+
+    const countDown = setInterval(function() {
+        const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
+        // 倒数结束后
+        if (countString === '') {
+            clearInterval(countDown);
+            btn.removeClass('disabled');
+        }
+        const text = '重新获取' + countString;
+        btn.text(text);
+        counter -= 1;
+    }, 1000);
+}
+
+$(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 && phaseUserId !== 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><spanclass="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 !== phaseUserId) {
+                                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);
+    });
+
+    // 添加审批流程按钮逻辑
+    $('body').on('click', '.book-list 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
+    });
+
+    // 添加到审批流程
+    $('#book-list').on('click', 'dd', function () {
+        const id = parseInt($(this).data('id'));
+        if (id !== 0) {
+            postData('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 d-flex" auditorId="'+ data[0].audit_id +'">');
+                        html.push(`<div class="col-auto">${index}</div>`);
+                        html.push('<div class="col">');
+                        for (const auditor of data) {
+                            html.push(`<div class="d-inline-block mx-1"><i class="fa fa-user text-muted"></i> ${auditor.name} <small class="text-muted">${auditor.role}</small></div>`);
+                        }
+                        html.push('</div>');
+                        html.push('<div class="col-auto">');
+                        // todo 添加会签或签时
+                        // html.push('<span class="badge badge-pill badge-primary badge-bg-small"><small></small></span>');
+                        if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
+                            html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
+                        }
+                        html.push('</div>');
+                        html.push('</li>');
+                    }
+                    auditorshtml.push('<li class="list-group-item" data-auditorid="' + data.audit_id + '">');
+                    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').html(auditorshtml.join(''));
+            });
+        }
+    });
+    // 删除审批人
+    $('body').on('click', '#auditors li a', function () {
+        const li = $(this).parents('li');
+        const data = {
+            auditorId: parseInt(li.attr('auditorId')),
+        };
+        postData('audit/delete', data, (result) => {
+            li.remove();
+            for (const rst of result) {
+                const aLi = $('li[auditorId=' + rst.audit_id + ']');
+                $('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');
+            }
+            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 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').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');
+    });
+
+    // 重新审批获取手机验证码
+    // 获取验证码
+    let isPosting = false;
+    $("#get-code").click(function() {
+        if (isPosting) return false;
+
+        const btn = $(this);
+        $.ajax({
+            url: '/profile/code',
+            type: 'post',
+            data: { mobile: authMobile, type: 'shenpi' },
+            dataTye: 'json',
+            error: function() {
+                isPosting = false;
+                let csrfToken = Cookies.get('csrfToken_j');
+                xhr.setRequestHeader('x-csrf-token', csrfToken);
+            },
+            beforeSend: function() {
+                isPosting = true;
+            },
+            success: function(response) {
+                isPosting = false;
+                if (response.err === 0) {
+                    codeSuccess(btn);
+                    $("input[name='code']").removeAttr('readonly');
+                    $("#re-shenpi-btn").removeAttr('disabled');
+                } else {
+                    toast(response.msg, 'error');
+                }
+            }
+        });
+    });
+
+    // 管理员更改审批流程js部分
+    let timer2 = null;
+    let oldSearchVal2 = null;
+    $('body').on('input propertychange', '.gr-search', function(e) {
+        oldSearchVal2 = e.target.value;
+        timer2 && clearTimeout(timer2);
+        timer2 = setTimeout(() => {
+            const newVal = $(this).val();
+            const code = $(this).attr('data-code');
+            let html = '';
+            if (newVal && newVal === oldSearchVal2) {
+                accountList.filter(item => item && item.id !== phaseUserId && (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>`
+                });
+                $('#' + code + '_dropdownMenu .book-list').empty();
+                $('#' + code + '_dropdownMenu .book-list').append(html);
+            } else {
+                if (!$('#' + code + '_dropdownMenu .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 !== phaseUserId) {
+                                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>';
+                    });
+                    $('#' + code + '_dropdownMenu .book-list').empty();
+                    $('#' + code + '_dropdownMenu .book-list').append(html);
+                }
+            }
+        }, 400);
+    });
+
+    const getAdminEditShenpiListHtml = function(auditGroup) {
+        const html = [];
+        for (const [i, group] of auditGroup.entries()) {
+            if (i === 0) continue;
+            for (const [j, auditor] of group.entries()) {
+                html.push('<tr>');
+                if (j === 0) {
+                    const auditTypeHtml = auditor.type === auditType.key.common ? '' : `<span class="ml-2 badge badge-pill badge-${auditType.info[auditor.audit_type].class} p-1"><small>${auditType.info[auditor.audit_type].short}</small></span>`;
+                    html.push(`<td class="text-left d-flex">${i + '审'}${auditTypeHtml}</td>`);
+                } else {
+                    html.push(`<td class="text-left d-flex"></td>`);
+                }
+                html.push(`<td></span> ${auditor.name} <small class="text-muted">${auditor.role}</small></td>`);
+                html.push(`<td style="text-align: center"><span class="${auditConst.auditStringClass[auditor.audit_status]}">${ auditor.audit_status !== auditConst.status.uncheck ? auditConst.auditString[auditor.audit_status] : '待审批' }</span></td>`);
+                html.push('<td style="text-align: center">');
+                if (auditor.audit_status === auditConst.status.checking && j === group.length - 1) {
+                    html.push('<span class="dropdown mr-2">',
+                        `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
+                        makeSelectAudit(auditor.audit_id+'_add', auditor.audit_id, 'add'),'</div>', '</span>');
+                }
+                if (auditor.audit_status === auditConst.status.uncheck) {
+                    if (j === group.length - 1) {
+                        html.push('<span class="dropdown mr-2">',
+                            `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
+                            makeSelectAudit(auditor.audit_id+'_add', auditor.audit_id, 'add'),'</div>', '</span>');
+                        if (auditor.audit_type !== auditType.key.common) {
+                            html.push('<span class="dropdown mr-2">',
+                                `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">平级</a>`,
+                                makeSelectAudit(auditor.audit_id+'_add-sibling', auditor.audit_id, 'add-sibling'),'</div>', '</span>');
+                        }
+                    }
+                    html.push('<span class="dropdown mr-2">',
+                        `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">更换</a>`,
+                        makeSelectAudit(auditor.audit_id+'_change', auditor.audit_id, 'change'),'</div>', '</span>');
+                    html.push(`<span class="dropdown">
+                                    <a href="javascript: void(0)" class="text-danger" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">移除</a>
+                                    <div class="dropdown-menu">
+                                        <span class="dropdown-item" href="javascript:void(0);">确认移除审批人?</span>
+                                        <div class="dropdown-divider"></div>
+                                        <div class="px-2 py-1 text-center">
+                                            <button class="remove-audit btn btn-sm btn-danger" data-id="${auditor.audit_id}">移除</button>
+                                            <button class="btn btn-sm btn-secondary">取消</button>
+                                        </div>
+                                    </div>
+                                    </span>`);
+                }
+                html.push('</td>');
+                html.push('</tr>');
+            }
+        }
+        return html.join('');
+    };
+
+    $('body').on('click', '#admin-edit-shenpi dl dd', function () {
+        const id = parseInt($(this).attr('data-id'));
+        if (!id) return;
+
+        let this_aid = parseInt($(this).parents('.book-list').attr('data-aid'));
+        let this_operate = $(this).parents('.book-list').attr('data-operate');
+        const user = _.find(accountList, function (item) {
+            return item.id === id;
+        });
+        const auditorIndex = _.findIndex(auditorList, { audit_id: id });
+        if (auditorIndex !== -1) {
+            toastr.warning('该审核人已存在,请勿重复添加');
+            return;
+        }
+        const prop = {
+            operate: this_operate,
+            old_aid: this_aid,
+            new_aid: user.id,
+        };
+        postData('audit/save', prop, (datas) => {
+            $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas));
+            changeLiucheng(datas);
+        });
+    });
+
+    // 管理员移除审批人
+    $('body').on('click', '.remove-audit', function () {
+        const id = parseInt($(this).attr('data-id'));
+        const prop = {
+            operate: 'del',
+            old_aid: id,
+        };
+        postData('audit/save', prop, (datas) => {
+            $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas));
+            changeLiucheng(datas);
+        });
+    });
+
+    const getAuditTypeText = function (type) {
+        if (type === auditType.key.common) return '';
+        return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
+    };
+
+    function changeLiucheng(datas) {
+        const auditorshtml = [];
+        let lastAuditorHtml = [];
+        for (const [index,data] of datas.entries()) {
+            auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center">');
+            if (index === 0) {
+                auditorshtml.push('<span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>');
+            } else if (index+1 === datas.length) {
+                auditorshtml.push('<span class="mr-1"><i class="fa fa fa-stop-circle"></i></span>');
+            } else {
+                auditorshtml.push('<span class="mr-1"><i class="fa fa-chevron-circle-down"></i></span>');
+            }
+            auditorshtml.push('<span class="text-muted">');
+            for (const u of data) {
+                auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${u.role}" data-auditorId="${u.audit_id}">${u.name}</small>`);
+            }
+            auditorshtml.push('</span>');
+            auditorshtml.push('<div class="d-flex ml-auto">');
+            if (data[0].audit_type !== auditType.key.common) auditorshtml.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} p-1"><small>${auditType.info[data[0].audit_type].short}</small></span>`);
+            if (index === 0) {
+                auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
+            } else if (index+1 === datas.length) {
+                auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
+            } else {
+                auditorshtml.push('<span class="badge badge-light badge-pill"><small>'+ transFormToChinese(index) +'审</small></span>');
+            }
+            auditorshtml.push('</div>');
+            auditorshtml.push('</li>');
+            if (data[0].audit_status === sam_auditConst.status.uncheck) {
+                lastAuditorHtml.push('<li class="timeline-list-item pb-2 is_uncheck">');
+                if (index < datas.length - 1) {
+                    lastAuditorHtml.push('<div class="timeline-item-tail"></div>');
+                }
+                lastAuditorHtml.push('<div class="timeline-item-icon bg-secondary text-light"></div>');
+
+                lastAuditorHtml.push('<div class="timeline-item-content">');
+                lastAuditorHtml.push(`<div class="py-1">
+                        <span class="text-black-50">
+                        ${ !index === datas.length - 1 ? data[0].audit_order + '' : '终' }审 ${getAuditTypeText(data[0].audit_type)}
+                        </span>
+                    </div>`);
+                lastAuditorHtml.push('<div class="card"><div class="card-body px-3 py-0">');
+                for (const [i, auditor] of data.entries()) {
+                    lastAuditorHtml.push(`<div class="card-text p-2 py-3 row ${ ( i > 0 ? 'border-top' : '') }">`);
+                    lastAuditorHtml.push(`<div class="col"><span class="h6">${auditor.name}</span><span class="text-muted ml-1">${auditor.role}</span></div>`);
+                    lastAuditorHtml.push('<div class="col">');
+                    lastAuditorHtml.push('</div>');
+                    lastAuditorHtml.push('</div>');
+                }
+                lastAuditorHtml.push('</div></div>');
+                lastAuditorHtml.push('</div>');
+                lastAuditorHtml.push('</li>');
+            }
+        }
+        $('.last-auditor-list .is_uncheck').remove();
+        $('.last-auditor-list').append(lastAuditorHtml.join(''));
+        $('.auditors-list').html(auditorshtml.join(''));
+
+    }
+
+    // 审批流程-选择审批人html 生成
+    function makeSelectAudit(code, aid, status) {
+        let divhtml = '';
+        accountGroup.forEach((group, idx) => {
+            let didivhtml = '';
+            if(group) {
+                group.groupList.forEach(item => {
+                    didivhtml += item.id !== phaseUserId ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
+                        '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
+                        '                                                                                class="ml-auto">' + item.mobile + '</span></p>\n' +
+                        '                                                                    <span class="text-muted">' + item.role + '</span>\n' +
+                        '                                                                    </dd>\n' : '';
+                });
+                divhtml += '<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>\n' +
+                    '                                                                <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
+                    '                                                                </div>\n';
+            }
+        });
+        let html = '<div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
+            '                                                        <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
+            '                                                                                     placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
+            '                                                        <dl class="list-unstyled book-list" data-aid="'+ aid +'" data-operate="'+ status +'">\n' + divhtml +
+            '                                                        </dl>\n' +
+            '                                                    </div>\n' +
+            '                                                </div>\n' +
+            '                                            </span>\n' +
+            '                                        </span>\n' +
+            '                                        </li>';
+        return html;
+    }
+});

+ 10 - 3
app/public/js/shares/tender_select.js

@@ -175,9 +175,14 @@ const TenderSelect = function (setting) {
             this.tenderSpread.bind(spreadNS.Events.ButtonClicked, tsObj.tsButtonClicked);
             if (this.setting.type === 'stage') {
                 this.resultSpread.bind(spreadNS.Events.EditEnded, tsObj.trEditEnded);
-                $('#tender-select-option').show();
-            } else {
-                $('#tender-select-option').hide();
+                $('#stage-select-option').show();
+                $('#ledger-select-option').hide();
+            } else if (this.setting.type === 'revise') {
+                $('#stage-select-option').hide();
+                $('#ledger-select-option').show();
+            } else if (this.setting.type === 'ledger') {
+                $('#stage-select-option').hide();
+                $('#ledger-select-option').hide();
             }
 
             $('#tender-select-ok').click(() => {
@@ -186,6 +191,8 @@ const TenderSelect = function (setting) {
                     updateData.cover = $('#ts-cover')[0].checked;
                     updateData.ignore = $('#ts-ignore')[0].checked;
                     updateData.change = $('#ts-change')[0].checked;
+                } else if (tsObj.setting.type === 'revise') {
+                    updateData.subUp = $('#ts-subUp')[0].checked;
                 }
                 if (updateData.tenders.length > 0) {
                     postData(window.location.pathname + '/sumLoad', updateData, result => {

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

@@ -75,7 +75,7 @@ $(document).ready(function () {
             })
         }
         return false
-    })
+    });
 
     // 搜索审批人
     // $('#searchAccount').click(() => {

+ 30 - 0
app/public/js/stage_gather.js

@@ -405,4 +405,34 @@ $(document).ready(function () {
 
         SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('.sidebar-title').attr('data-original-title') + "-清单汇总.xlsx");
     });
+    // 显示层次
+    (function (select, sheet) {
+        $(select).click(function () {
+            if (!sheet.zh_data) return;
+            const tag = $(this).attr('tag');
+            const datas = sheet.zh_data;
+            setTimeout(() => {
+                showWaitingView();
+                switch (tag) {
+                    case "all":
+                        datas.forEach(x => { x.visible = true; });
+                        break;
+                    case "curMeasure":
+                        datas.forEach(x => { x.visible = !!x.contract_qty || !!x.qc_qty || !!x.contract_tp || !!x.qc_tp; });
+                        break;
+                    case "endMeasure":
+                        datas.forEach(x => { x.visible = !!x.contract_qty || !!x.qc_qty || !!x.contract_tp || !!x.qc_tp || !!x.end_contract_qty || !!x.end_qc_qty || !!x.end_contract_tp || !!x.end_qc_tp; });
+                        break;
+                }
+                SpreadJsObj.refreshTreeRowVisible(sheet);
+                const node = SpreadJsObj.getSelectObject(sheet);
+                if (!node.visible) {
+                    const showIndex = datas.findIndex(x => { return x.visible; });
+                    SpreadJsObj.locateRow(sheet, showIndex);
+                    loadRelaData(showIndex);
+                }
+                closeWaitingView();
+            }, 100);
+        });
+    })('a[name=showData]', gclSpread.getActiveSheet());
 });

+ 15 - 4
app/router.js

@@ -227,14 +227,14 @@ module.exports = app => {
     app.get('/tender/:id/advance/:order/detail', sessionAuth, tenderCheck, advanceCheck, 'advanceController.detail');
     app.post('/tender/:id/advance/:order/audit/add', sessionAuth, tenderCheck, advanceCheck, 'advanceController.addAudit');
     app.post('/tender/:id/advance/:order/audit/delete', sessionAuth, tenderCheck, advanceCheck, 'advanceController.deleteAudit');
-    app.post('/tender/:id/advance/:order/audit/start', sessionAuth, tenderCheck, tenderBuildCheck, advanceCheck, tenderBuildCheck, 'advanceController.start');
-    app.post('/tender/:id/advance/:order/audit/check', sessionAuth, tenderCheck, tenderBuildCheck, advanceCheck, tenderBuildCheck, 'advanceController.checkAudit');
+    app.post('/tender/:id/advance/:order/audit/start', sessionAuth, tenderCheck, tenderBuildCheck, advanceCheck, 'advanceController.start');
+    app.post('/tender/:id/advance/:order/audit/check', sessionAuth, tenderCheck, tenderBuildCheck, advanceCheck, 'advanceController.checkAudit');
     app.post('/tender/:id/advance/:order/update', sessionAuth, tenderCheck, advanceCheck, 'advanceController.update');
     app.post('/tender/:id/advance/:order/file/upload', sessionAuth, tenderCheck, advanceCheck, 'advanceController.upload');
     app.get('/tender/:id/advance/:order/file/:fid/download', sessionAuth, tenderCheck, 'advanceController.downloadFile');
     app.post('/tender/:id/advance/:order/file/del', sessionAuth, tenderCheck, advanceCheck, 'advanceController.deleteFile');
     app.post('/tender/:id/advance/:type/:order/auditors', sessionAuth, tenderCheck, advanceCheck, 'advanceController.getAuditors');
-    app.post('/tender/:id/advance/:order/check/again', sessionAuth, tenderCheck, uncheckTenderCheck, tenderBuildCheck, advanceCheck, 'advanceController.checkAgain');
+    app.post('/tender/:id/advance/:order/check/again', sessionAuth, tenderCheck, tenderBuildCheck, advanceCheck, 'advanceController.checkAgain');
 
     // 标段协作办公
     app.get('/tender/:id/cooperation', sessionAuth, tenderCheck, 'tenderController.tenderCooperation');
@@ -394,10 +394,21 @@ module.exports = app => {
 
     app.get('/tender/:id/pay', sessionAuth, tenderCheck, 'payController.index');
     app.post('/tender/:id/pay/add', sessionAuth, tenderCheck, 'payController.add');
-    app.post('/tender/:id/pay/del', sessionAuth, tenderCheck, 'payController.del');
+    app.post('/tender/:id/pay/delete', sessionAuth, tenderCheck, 'payController.del');
     app.post('/tender/:id/pay/save', sessionAuth, tenderCheck, 'payController.save');
+    app.post('/tender/:id/pay/auditors', sessionAuth, tenderCheck, 'payController.loadAuditors');
     app.get('/tender/:id/pay/:order/detail', sessionAuth, tenderCheck, phasePayCheck, 'payController.detail');
+    app.post('/tender/:id/pay/:order/load', sessionAuth, tenderCheck, phasePayCheck, 'payController.detailLoad');
     app.post('/tender/:id/pay/:order/update', sessionAuth, tenderCheck, phasePayCheck, 'payController.detailUpdate');
+    app.post('/tender/:id/pay/:order/file/upload', sessionAuth, tenderCheck, phasePayCheck, 'payController.uploadFile');
+    app.post('/tender/:id/pay/:order/file/delete', sessionAuth, tenderCheck, phasePayCheck, 'payController.deleteFile');
+    // 合同支付审批
+    app.post('/tender/:id/pay/:order/audit/add', sessionAuth, tenderCheck, uncheckTenderCheck, phasePayCheck, 'payController.addAudit');
+    app.post('/tender/:id/pay/:order/audit/delete', sessionAuth, tenderCheck, uncheckTenderCheck, phasePayCheck, 'payController.deleteAudit');
+    app.post('/tender/:id/pay/:order/audit/start', sessionAuth, tenderCheck, uncheckTenderCheck, phasePayCheck, 'payController.auditStart');
+    app.post('/tender/:id/pay/:order/audit/check', sessionAuth, tenderCheck, uncheckTenderCheck, phasePayCheck, 'payController.auditCheck');
+    app.post('/tender/:id/pay/:order/audit/checkAgain', sessionAuth, tenderCheck, uncheckTenderCheck, phasePayCheck, 'payController.auditCheckAgain');
+    app.post('/tender/:id/pay/:order/audit/checkCancel', sessionAuth, tenderCheck, uncheckTenderCheck, phasePayCheck, 'payController.auditCheckCancel');
 
     // 变更概况
     app.get('/tender/:id/measure/stage/:order/change', sessionAuth, tenderCheck, uncheckTenderCheck, stageCheck, 'stageController.change');

+ 2 - 2
app/service/material_audit.js

@@ -834,9 +834,9 @@ module.exports = app => {
                     await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.TC, {
                         pid: this.ctx.session.sessionProject.id,
                         tid: this.ctx.tender.id,
-                        uid: checkingAuditors.aid,
+                        uid: a.aid,
                         sp_type: 'material',
-                        sp_id: checkingAuditors.id,
+                        sp_id: a.id,
                         table_name: this.tableName,
                         template: wxConst.template.material,
                         wx_data: wechatData,

+ 167 - 30
app/service/phase_pay.js

@@ -9,6 +9,8 @@
  */
 
 const audit = require('../const/audit').common;
+const projectLogConst = require('../const/project_log');
+const shenpiConst = require('../const/shenpi');
 const calcBase = [
     {name: '签约合同价', code: 'htj', sort: 10},
     {name: '暂列金额', code: 'zlje', sort: 2},
@@ -54,7 +56,6 @@ module.exports = app => {
                 x.calc_base = x.calc_base ? JSON.parse(x.calc_base) : [];
             });
         }
-
         calculatePhasePay(data) {
             const helper = this.ctx.helper;
             const datas = data instanceof Array ? data : [data];
@@ -86,13 +87,11 @@ module.exports = app => {
             this.analysisPhasePay(result);
             return result;
         }
-
         async getPhasePay(id) {
             const result = await this.getDataById(id);
             this.analysisPhasePay(result);
             return result;
         }
-
         async getPhasePayByOrder(tid, phaseOrder) {
             const result = await this.getDataByCondition({ tid, phase_order: phaseOrder });
             this.analysisPhasePay(result);
@@ -116,7 +115,6 @@ module.exports = app => {
             }
             return false;
         }
-
         async getCalcBase(relaStage, prePhase) {
             const result = {};
             for (const stage of relaStage) {
@@ -174,7 +172,6 @@ module.exports = app => {
             }
             return result;
         }
-
         /**
          * 获取 当期的 计算基数
          * @return {Promise<any>}
@@ -271,14 +268,39 @@ module.exports = app => {
                 const result = await transaction.insert(this.tableName, data);
                 if (result.affectedRows !== 1) throw '新增合同支付失败';
 
-                await this.ctx.service.phasePayDetail.initPhaseData(transaction, data);
+                await this.ctx.service.phasePayDetail.initPhaseData(transaction, data, prePhase);
+                await this.ctx.service.phasePayAudit.copyPreAuditors(transaction, prePhase, data);
                 await transaction.commit();
+                this.analysisPhasePay(data);
                 return data;
             } catch(err) {
                 await transaction.rollback();
                 throw err;
             }
         }
+        async delete(id) {
+            const info = await this.getDataById(id);
+            const conn = await this.db.beginTransaction();
+            try {
+                await conn.delete(this.tableName, { id });
+                await conn.delete(this.ctx.service.phasePayDetail.tableName, { phase_id: id });
+                const files = await this.ctx.service.phasePayFile.getFiles({ where: { phase_id: id} });
+                for (const f of files) {
+                    this.ctx.app.fujianOss.delete(f.filepath);
+                }
+                await conn.delete(this.ctx.service.phasePayFile.tableName, { phase_id: id });
+                await conn.delete(this.ctx.service.phasePayAudit.tableName, { phase_id: id });
+                // 记录删除日志
+                await this.ctx.service.projectLog.addProjectLog(conn, projectLogConst.type.phasePay, projectLogConst.status.delete, `第${info.phase_order}期`);
+                await conn.commit();
+            } catch (err) {
+                await conn.rollback();
+                throw err;
+            }
+        }
+        async save(phasePay, data) {
+            await this.defaultUpdate({id: phasePay.id, phase_date: data.phase_date, memo: data.memo});
+        }
 
         async refreshCalcBase(phasePay) {
             const prePhase = phasePay.phase_order > 1 ? await this.getPhasePayByOrder(phasePay.tid, phasePay.phase_order - 1) : null;
@@ -323,49 +345,164 @@ module.exports = app => {
         }
 
         async loadUser(phasePay) {
-            // todo 加载审批人
             phasePay.user = await this.ctx.service.projectAccount.getAccountInfoById(phasePay.create_user_id);
-            phasePay.curAuditors = [];
-            // phasePay.curAuditors = await this.ctx.service.phasePayAudit.getAllDataByCondition({
-            //     where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_status: audit.status.checking }
-            // });
+            phasePay.auditors = await this.ctx.service.phasePayAudit.getAuditors(phasePay.id, phasePay.curTimes || phasePay.audit_times);
+            phasePay.auditorIds = this._.map(phasePay.auditors, 'audit_id');
+            phasePay.curAuditors = phasePay.auditors.filter(x => { return x.audit_status === audit.status.checking; });
             phasePay.curAuditorIds = phasePay.curAuditors.map(x => { return x.audit_id; });
-            phasePay.flowAuditors = phasePay.curAuditors.length === 0 ? []
-                : await this.ctx.service.phasePayAudit.getAllDataByCondition({
-                    where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_sort: phasePay.curAuditors[0].audit_sort }
-                });
+            phasePay.flowAuditors = phasePay.curAuditors.length === 0 ? [] : phasePay.auditors.filter(x => { return x.active_order === phasePay.curAuditors[0].active_order; });
             phasePay.flowAuditorIds = phasePay.curAuditors.map(x => { return x.audit_id; });
+            phasePay.nextAuditors = phasePay.curAuditors.length > 0 ? phasePay.auditors.filter(x => { return x.active_order === phasePay.curAuditors[0].active_order + 1; }) : [];
+            phasePay.nextAuditorIds = this._.map(phasePay.nextAuditors, 'audit_id');
+            phasePay.auditorGroups = this.ctx.helper.groupAuditors(phasePay.auditors, 'active_order');
+            phasePay.userGroups = this.ctx.helper.groupAuditorsUniq(phasePay.auditorGroups);
+            phasePay.finalAuditorIds = phasePay.userGroups.length > 1 ? phasePay.userGroups[phasePay.userGroups.length - 1].map(x => { return x.audit_id; }) : [];
+            phasePay.userIds = phasePay.audit_status === audit.status.uncheck // 当前流程下全部参与人id
+                ? [phasePay.user_id]
+                : phasePay.auditorIds;
+        }
+        async loadAuditViewData(phasePay) {
+            if (!phasePay.user) phasePay.user = await this.ctx.service.projectAccount.getAccountInfoById(phasePay.user_id);
+            const auditTimes = phasePay.audit_status === audit.status.checkNo ? phasePay.audit_times - 1 : phasePay.audit_times;
+            phasePay.auditHistory = await this.ctx.service.phasePayAudit.getAuditorHistory(phasePay.id, auditTimes);
+            // 获取审批流程中左边列表
+            if (phasePay.audit_status === audit.status.checkNo && phasePay.create_user_id !== this.ctx.session.sessionUser.accountId) {
+                const auditors = await this.ctx.service.phasePayAudit.getAuditors(phasePay.id, phasePay.audit_times - 1); // 全部参与的审批人
+                const auditorGroups = this.ctx.helper.groupAuditors(auditors);
+                phasePay.hisUserGroup = this.ctx.helper.groupAuditorsUniq(auditorGroups);
+            } else {
+                phasePay.hisUserGroup = phasePay.userGroups;
+            }
+        }
+        /**
+         * cancancel = 0 不可撤回
+         * cancancel = 1 原报撤回
+         * cancancel = 2 审批人撤回 审批通过
+         * cancancel = 3 审批人撤回 审批退回上一人
+         * cancancel = 4 审批人撤回 退回原报
+         * cancancel = 5 会签未全部审批通过时,审批人撤回 审批通过
+         *
+         * @param phasePay
+         * @returns {Promise<void>}
+         */
+        async doCheckCanCancel(phasePay) {
+            // 默认不可撤回
+            phasePay.cancancel = 0;
+            // 获取当前审批人的上一个审批人,判断是否是当前登录人,并赋予撤回功能,(当审批人存在有审批过时,上一人不允许再撤回)
+            const status = audit.status;
+            if (phasePay.audit_status === status.checked || phasePay.audit_status === status.uncheck) return;
+
+            const accountId = this.ctx.session.sessionUser.accountId;
+            if (phasePay.audit_status !== status.checkNo) {
+                // 找出当前操作人上一个审批人,包括审批完成的和退回上一个审批人的,同时当前操作人为第一人时,就是则为原报
+                if (phasePay.flowAuditors.find(x => { return x.audit_status !== status.checking}) && phasePay.flowAuditorIds.indexOf(accountId) < 0) return; // 当前流程存在审批人审批通过时,不可撤回
+                if (phasePay.curAuditorIds.indexOf(accountId) < 0 && phasePay.flowAuditorIds.indexOf(accountId) >= 0) {
+                    phasePay.cancancel = 5; // 会签未全部审批通过时,审批人撤回审批通过
+                    return;
+                }
+
+                const preAuditors = phasePay.curAuditors[0] && phasePay.curAuditors[0].active_order !== 1 ? phasePay.auditors.filter(x => { return x.active_order === phasePay.curAuditors[0].active_order - 1; }) : [];
+                const preAuditorCheckAgain = preAuditors.find(pa => { return pa.audit_status === status.checkAgain; });
+                const preAuditorCheckCancel = preAuditors.find(pa => { return pa.audit_status === status.checkCancel; });
+                const preAuditorHasOld = preAuditors.find(pa => { return pa.is_old === 1; });
+                const preAuditorIds = (preAuditorCheckAgain ? [] : preAuditors.map(x => { return x.audit_id })); // 重审不可撤回
+                if ((this._.isEqual(phasePay.flowAuditorIds, preAuditorIds) && preAuditorCheckCancel) || preAuditorHasOld) {
+                    return; // 不可以多次撤回
+                }
+
+                const preAuditChecked = preAuditors.find(pa => { return pa.audit_status === status.checked && pa.audit_id === accountId; });
+                const preAuditCheckNoPre = preAuditors.find(pa => { return pa.audit_status === status.checkNoPre && pa.audit_id === accountId; });
+                if (preAuditorIds.indexOf(accountId) >= 0) {
+                    if (preAuditChecked) {
+                        phasePay.cancancel = 2;// 审批人撤回审批通过
+                    } else if (preAuditCheckNoPre) {
+                        phasePay.cancancel = 3;// 审批人撤回审批退回上一人
+                    }
+                    phasePay.preAuditors = preAuditors;
+                } else if (preAuditors.length === 0 && accountId === phasePay.create_user_id) {
+                    phasePay.cancancel = 1;// 原报撤回
+                }
+            } else {
+                const lastAuditors = await this.ctx.service.phasePayAudit.getAuditors(phasePay.id, phasePay.audit_times - 1);
+                const onAuditor = this._.findLast(lastAuditors, { audit_status: status.checkNo });
+                if (onAuditor.audit_id === accountId) {
+                    phasePay.cancancel = 4;// 审批人撤回退回原报
+                    phasePay.preAuditors = lastAuditors.filter(x => { return x.active_order === onAuditor.active_order });
+                }
+            }
         }
         async doCheckPhase(phasePay) {
-            await this.loadUser(phasePay);
             const accountId = this.ctx.session.sessionUser.accountId;
+            // 审批退回时,原报读取本轮流程,其他人读取上一轮流程
+            if (phasePay.audit_status === audit.status.checkNo) {
+                phasePay.curTimes = phasePay.create_user_id === accountId ? phasePay.audit_times : phasePay.audit_times - 1;
+            } else {
+                phasePay.curTimes = phasePay.audit_times;
+            }
+            // 加载参与人
+            await this.loadUser(phasePay);
 
             if (phasePay.audit_status === audit.status.uncheck) {
                 phasePay.readOnly = accountId !== phasePay.create_user_id;
-                phasePay.curTimes = phasePay.audit_times;
-                phasePay.curOrder = 0;
+                phasePay.curSort = 0;
             } else if (phasePay.audit_status === audit.status.checkNo) {
                 phasePay.readOnly = accountId !== phasePay.create_user_id;
                 if (!phasePay.readOnly) {
-                    phasePay.curTimes = phasePay.times;
-                    phasePay.curOrder = 0;
+                    phasePay.curSort = 0;
                 } else {
                     const checkNoAudit = await this.service.phasePayAudit.getDataByCondition({
-                        phase_id: phasePay.id, audit_times: phasePay.audit_times - 1, status: audit.status.checkNo,
+                        phase_id: phasePay.id, audit_times: phasePay.audit_times - 1, audit_status: audit.status.checkNo,
                     });
-                    phasePay.curTimes = phasePay.times - 1;
-                    phasePay.curOrder = checkNoAudit.audit_order;
+                    phasePay.curSort = checkNoAudit.active_order;
                 }
             } else if (phasePay.audit_status === audit.status.checked) {
                 phasePay.readOnly = true;
-                phasePay.curTimes = phasePay.audit_times;
-                phasePay.curOrder = phasePay.audit_max_order;
+                phasePay.curSort = phasePay.audit_max_sort;
             } else {
-                // 会签,会签人部分审批通过时,只读,但是curOrder需按原来的取值
-                phasePay.curTimes = phasePay.audit_times;
-                phasePay.curOrder = phasePay.flowAuditorIds.indexOf(accountId) < 0 ? phasePay.curAuditors[0].order : phasePay.curAuditors[0].order - 1;
-                phasePay.readOnly = !_.isEqual(stage.flowAuditorIds, stage.curAuditorIds);
-                phasePay.canCheck = phasePay.readOnly && stage.curAuditorIds.indexOf(accountId) > 0;
+                // 会签,会签人部分审批通过时,只读,但是curSort需按原来的取值
+                phasePay.curSort = phasePay.flowAuditorIds.indexOf(accountId) >= 0 ? phasePay.curAuditors[0].active_order : phasePay.curAuditors[0].active_order - 1;
+                phasePay.readOnly = phasePay.curAuditorIds.indexOf(accountId) < 0;
+                phasePay.canCheck = phasePay.readOnly && phasePay.curAuditorIds.indexOf(accountId) > 0;
+            }
+            await this.doCheckCanCancel(phasePay);
+        }
+        async checkShenpi(phasePay) {
+            const status = audit.status;
+            const info = this.ctx.tender.info;
+            const shenpi_status = info.shenpi.phasePay;
+            if ((phasePay.audit_status === status.uncheck || phasePay.audit_status === status.checkNo) && shenpi_status !== shenpiConst.sp_status.sqspr) {
+                // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
+                const auditList = await this.ctx.service.phasePayAudit.getAllDataByCondition({ where: { phase_id: phasePay.id, audit_times: phasePay.audit_times }, orders: [['audit_order', 'asc']] });
+                auditList.shift();
+                if (shenpi_status === shenpiConst.sp_status.gdspl) {
+                    const shenpiList = await this.ctx.service.shenpiAudit.getAllDataByCondition({ where: { tid: phasePay.tid, sp_type: shenpiConst.sp_type.phasePay, sp_status: shenpi_status } });
+                    // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
+                    let sameAudit = auditList.length === shenpiList.length;
+                    if (sameAudit) {
+                        for (const audit of auditList) {
+                            const shenpi = shenpiList.find(x => { return x.audit_id === audit.audit_id; });
+                            if (!shenpi || shenpi.audit_order !== audit.audit_order || shenpi.audit_type !== audit.audit_type) {
+                                sameAudit = false;
+                                break;
+                            }
+                        }
+                    }
+                    if (!sameAudit) {
+                        await this.ctx.service.phasePayAudit.updateNewAuditList(phasePay, shenpiList);
+                        await this.loadUser(phasePay);
+                    }
+                } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
+                    const shenpiInfo = await this.ctx.service.shenpiAudit.getDataByCondition({ tid: phasePay.tid, sp_type: shenpiConst.sp_type.phasePay, sp_status: shenpi_status });
+                    // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
+                    const lastAuditors = auditList.filter(x => { x.active_order === auditList.active_order; });
+                    if (shenpiInfo && (lastAuditors.length === 0 || (lastAuditors.length > 1 || shenpiInfo.audit_id !== lastAuditors[0].audit_id))) {
+                        await this.ctx.service.phasePayAudit.updateLastAudit(phasePay, auditList, shenpiInfo.audit_id);
+                        await this.loadUser(phasePay);
+                    } else if (!shenpiInfo) {
+                        // 不存在终审人的状态下这里恢复为授权审批人
+                        this.tender.info.shenpi.phasePay = shenpiConst.sp_status.sqspr;
+                    }
+                }
             }
         }
     }

File diff suppressed because it is too large
+ 1037 - 0
app/service/phase_pay_audit.js


+ 44 - 16
app/service/phase_pay_detail.js

@@ -12,14 +12,14 @@ const payType = {
     bqsf: 'bqsf', bqyf: 'bqyf', gcjl: 'gcjl', qtfk: 'qtfk', qtkk: 'qtkk'
 };
 const defaultPays = [
-    { tree_id: 1, tree_pid: -1, tree_level: 1, tree_order: 1, tree_is_leaf: 1, tree_full_path: '1', pay_type: 'bqyf', is_minus: 0, is_fixed: 1, name: '本期应付' },
-    { tree_id: 2, tree_pid: -1, tree_level: 1, tree_order: 2, tree_is_leaf: 1, tree_full_path: '2', pay_type: 'bqsf', is_minus: 0, is_fixed: 1, name: '本期实付' },
-    { tree_id: 3, tree_pid: -1, tree_level: 1, tree_order: 3, tree_is_leaf: 0, tree_full_path: '3', pay_type: 'gcjl', is_minus: 0, is_fixed: 1, name: '工程计量款' },
-    { tree_id: 4, tree_pid: -1, tree_level: 1, tree_order: 4, tree_is_leaf: 0, tree_full_path: '4', pay_type: 'qtfk', is_minus: 0, is_fixed: 1, name: '其他付款项' },
-    { tree_id: 5, tree_pid: -1, tree_level: 1, tree_order: 5, tree_is_leaf: 0, tree_full_path: '5', pay_type: 'qtkk', is_minus: 1, is_fixed: 1, name: '其他扣款项' },
+    { tree_id: 1, tree_pid: -1, tree_level: 1, tree_order: 1, tree_is_leaf: 1, tree_full_path: '1', pay_type: 'bqyf', is_minus: 0, is_fixed: 1, name: '本期应付', expr: '' },
+    { tree_id: 2, tree_pid: -1, tree_level: 1, tree_order: 2, tree_is_leaf: 1, tree_full_path: '2', pay_type: 'bqsf', is_minus: 0, is_fixed: 1, name: '本期实付', expr: '' },
+    { tree_id: 3, tree_pid: -1, tree_level: 1, tree_order: 3, tree_is_leaf: 0, tree_full_path: '3', pay_type: 'gcjl', is_minus: 0, is_fixed: 1, name: '工程计量款', expr: '' },
+    { tree_id: 4, tree_pid: -1, tree_level: 1, tree_order: 4, tree_is_leaf: 0, tree_full_path: '4', pay_type: 'qtfk', is_minus: 0, is_fixed: 1, name: '其他付款项', expr: '' },
+    { tree_id: 5, tree_pid: -1, tree_level: 1, tree_order: 5, tree_is_leaf: 0, tree_full_path: '5', pay_type: 'qtkk', is_minus: 1, is_fixed: 1, name: '其他扣款项', expr: '' },
     { tree_id: 6, tree_pid: 3, tree_level: 2, tree_order: 1, tree_is_leaf: 1, tree_full_path: '3-6', pay_type: '', is_minus: 0, is_fixed: 0, name: '本期完成计量', expr: 'bqwc' },
-    { tree_id: 7, tree_pid: 4, tree_level: 2, tree_order: 1, tree_is_leaf: 1, tree_full_path: '4-7', pay_type: '', is_minus: 0, is_fixed: 0, name: '新增付款项' },
-    { tree_id: 8, tree_pid: 5, tree_level: 2, tree_order: 1, tree_is_leaf: 1, tree_full_path: '5-8', pay_type: '', is_minus: 1, is_fixed: 0, name: '新增扣款项' },
+    { tree_id: 7, tree_pid: 4, tree_level: 2, tree_order: 1, tree_is_leaf: 1, tree_full_path: '4-7', pay_type: '', is_minus: 0, is_fixed: 0, name: '新增付款项', expr: '' },
+    { tree_id: 8, tree_pid: 5, tree_level: 2, tree_order: 1, tree_is_leaf: 1, tree_full_path: '5-8', pay_type: '', is_minus: 1, is_fixed: 0, name: '新增扣款项', expr: '' },
 ];
 const TreeService = require('../base/base_tree_service');
 const Ledger = require('../lib/ledger');
@@ -232,7 +232,7 @@ class PayCalculator {
     _calculateYf(yf, pays) {
         yf.tp = 0;
         for (const p of pays) {
-            if (p.payType || !p.is_gather || !p.tree_is_leaf) continue;
+            if (p.pay_type || !p.is_gather || !p.tree_is_leaf) continue;
             yf.tp = !p.is_minus ? this.ctx.helper.add(yf.tp, p.tp) : this.ctx.helper.sub(yf.tp, p.tp);
         }
         const bqyf = this.bases.find(function (x) {return x.code === 'bqyf'});
@@ -336,7 +336,7 @@ class PhasePayDetail extends TreeService {
 
     getMasterKey(phasePay) {
         return phasePay.curTimes
-            ? `${phasePay.id}-${phasePay.curTimes}-${phasePay.curOrder}`
+            ? `${phasePay.id}-${phasePay.curTimes}-${phasePay.curSort}`
             : `${phasePay.id}-${phasePay.audit_times}-${phasePay.audit_max_sort}`;
     }
 
@@ -345,7 +345,8 @@ class PhasePayDetail extends TreeService {
         const insertData = [];
         for (const dp of defaultPays) {
             insertData.push({
-                tid: phasePay.tid, phase_id: phasePay.id, create_user_id: user_id, update_user_id: user_id,
+                tid: phasePay.tid, phase_id: phasePay.id, create_phase_id: phasePay.id, master_id: phasePay.id + '-1-0',
+                create_user_id: user_id, update_user_id: user_id,
                 uuid: this.uuid.v4(), ...dp,
             });
         }
@@ -358,6 +359,8 @@ class PhasePayDetail extends TreeService {
         });
         for (const pd of preData) {
             delete pd.id;
+            pd.phase_id = phasePay.id;
+            pd.master_id = phasePay.id + '-1-0';
             pd.audit_times = 1;
             pd.audit_sort = 0;
         }
@@ -365,7 +368,7 @@ class PhasePayDetail extends TreeService {
     }
 
     async initPhaseDataByAudit(conn, phasePay, newTimes, newSort) {
-        const preData = await this.getDetailData(phasePay);
+        const preData = await conn.select(this.tableName, { where: { master_id: this.getMasterKey(phasePay)}});
         for (const pd of preData) {
             delete pd.id;
             pd.master_id = `${phasePay.id}-${newTimes}-${newSort}`;
@@ -375,9 +378,20 @@ class PhasePayDetail extends TreeService {
         await conn.insert(this.tableName, preData);
     }
 
-    async initPhaseData(conn, phasePay){
+    async initPhaseDataByAuditCancel(conn, phasePay, oldTimes, oldSort, newTimes, newSort) {
+        const masterId = `${phasePay.id}-${oldTimes}-${oldSort}`;
+        const preData = await conn.select(this.tableName, { where: { master_id: masterId } });
+        for (const pd of preData) {
+            delete pd.id;
+            pd.master_id = `${phasePay.id}-${newTimes}-${newSort}`;
+            pd.audit_times = newTimes;
+            pd.audit_sort = newSort;
+        }
+        await conn.insert(this.tableName, preData);
+    }
+
+    async initPhaseData(conn, phasePay, prePhase){
         if (!conn) throw '内部错误';
-        const prePhase = await this.ctx.service.phasePay.getPhasePayByOrder(phasePay.tid, phasePay.phase_order - 1);
         if (prePhase) {
             await this.initPhaseDataByPre(conn, phasePay, prePhase);
         } else {
@@ -400,6 +414,20 @@ class PhasePayDetail extends TreeService {
         return payTree.getDefaultDatas();
     }
 
+    getPayTp(datas, type) {
+        const pay = datas.find(x => { return x.pay_type === type });
+        return pay ? pay.tp || 0 : 0;
+    }
+    getPaySum(datas) {
+        const result = {};
+        result.yf_tp = this.getPayTp(datas, payType.bqyf);
+        result.sf_tp = this.getPayTp(datas, payType.bqsf);
+        result.calc_tp = this.getPayTp(datas, payType.gcjl);
+        result.pay_tp = this.ctx.helper.add(this.getPayTp(datas, payType.qtfk), result.calc_tp);
+        result.cut_tp = this.getPayTp(datas, payType.qtkk);
+        return result;
+    }
+
     async calculateSave(phasePay, transaction) {
         const details = await this.getDetailData(phasePay);
         if (details.length === 0) return false;
@@ -408,14 +436,14 @@ class PhasePayDetail extends TreeService {
         const updateData = calcResult.filter(x => { return x.calcUpdate; }).map(x => {
             return { id: x.id, tp: x.tp, start_tp: x.start_tp, range_tp: x.range_tp, end_tp: x.end_tp };
         });
-        if (updateData.length === 0) return false;
+        if (updateData.length === 0) return this.getPaySum(calcResult);
 
         if (transaction) {
             await transaction.updateRows(this.tableName, updateData);
         } else {
             await this.defaultUpdateRows(updateData);
         }
-        return true;
+        return this.getPaySum(calcResult);
     }
 
     _getDefaultData(data, phasePay, parent) {
@@ -433,7 +461,7 @@ class PhasePayDetail extends TreeService {
     }
 
     async addChild(phasePay, select, count = 1) {
-        if (select.payType === payType.bqsf || select.payType === payType.bqyf) throw '不可新增子项';
+        if (select.pay_type === payType.bqsf || select.pay_type === payType.bqyf) throw '不可新增子项';
         if (select.tree_level >= 2) throw '不可新增子项';
 
         const masterId = this.getMasterKey(phasePay);

+ 94 - 0
app/service/phase_pay_file.js

@@ -0,0 +1,94 @@
+'use strict';
+
+/**
+ *
+ *  附件
+ * @author Ellisran
+ * @date 2019/1/11
+ * @version
+ */
+
+module.exports = app => {
+    class SubProjFile extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'phase_pay_file';
+        }
+
+        _analysisData(files) {
+            const helper = this.ctx.helper;
+            const userId = this.ctx.session.sessionUser.accountId;
+            const ossPath = this.ctx.app.config.fujianOssPath;
+            files.forEach(x => {
+                x.viewpath = helper.canPreview(x.fileext) ? ossPath + x.filepath : '';
+                x.filepath = ossPath + x.filepath;
+                x.fileext_str = helper.fileExtStr(x.fileext);
+                x.canEdit = x.user_id === userId;
+            });
+        }
+
+        async getData(phase_id, type) {
+            const data = await this.getAllDataByCondition({
+                where: { type, phase_id, is_deleted: 0 },
+                orders: [['create_time', 'desc']],
+            });
+            this._analysisData(data);
+            return data;
+        }
+
+        async getFiles(condition) {
+            condition.orders = [['create_time', 'desc']];
+            const result = await this.getAllDataByCondition(condition);
+            this._analysisData(result);
+            return result;
+        }
+
+        async addFiles(phasePay, type, fileInfo, user) {
+            const conn = await this.db.beginTransaction();
+            const result = {};
+            try {
+                const insertData = fileInfo.map(x => {
+                    return {
+                        id: this.uuid.v4(), tid: phasePay.tid, phase_id: phasePay.id, type, rela_id: x.rela_id,
+                        user_id: user.id, user_name: user.name, user_company: user.company, user_role: user.role,
+                        filename: x.filename, fileext: x.fileext, filesize: x.filesize, filepath: x.filepath,
+                    };
+                });
+                await conn.insert(this.tableName, insertData);
+                await conn.commit();
+                result.files = { id: insertData.map(x => { return x.id; })};
+            } catch (err) {
+                await conn.rollback();
+                throw err;
+            }
+            return await this.getFiles({ where: result.files });
+        }
+
+        async delFiles(files) {
+            if (files.length === 0) return;
+
+            const fileDatas = await this.getAllDataByCondition({ where: { id: files } });
+            const result = {};
+
+            const conn = await this.db.beginTransaction();
+            try {
+                const updateData = fileDatas.map(x => { return { id: x.id, is_deleted: 1 }; });
+                if (updateData.length > 0) await conn.updateRows(this.tableName, updateData);
+                await conn.commit();
+                result.del = files;
+            } catch (err) {
+                await conn.rollback();
+                throw err;
+            }
+            return result;
+        }
+    }
+
+    return SubProjFile;
+};

+ 31 - 0
app/service/report_memory.js

@@ -217,6 +217,36 @@ module.exports = app => {
             // }
         }
 
+        async _loadImAuditorAssistData(stageIm) {
+            const auditorGroups = JSON.parse(JSON.stringify(this.ctx.stage.userGroups));
+            auditorGroups.forEach(group => {
+                group.forEach(auditor => {
+                    auditor.ass_ledger_id = auditor.ass_ledger_id ? auditor.ass_ledger_id.split(',') : [];
+                });
+            });
+
+            for (const im of stageIm.ImData) {
+                const relas = [];
+                const bills = stageIm.getRelaBills(im);
+                if (!bills) continue;
+                const relaIds = bills ? bills.full_path.split('-').reverse() : [];
+                for (const [i, group] of auditorGroups.entries()) {
+                    if (group[0].audit_type === auditConst.auditType.key.union) {
+                        const auditors = group.filter(x => {
+                            for (const id of relaIds) {
+                                if (x.ass_ledger_id.indexOf(id + '') >= 0) return true;
+                            }
+                            return false;
+                        });
+                        relas.push(auditors.map(x => { return x.aid; }).join(','));
+                    } else {
+                        relas.push(group.map(x => { return x.aid; }).join(','));
+                    }
+                }
+                im.users = relas.join(';');
+            }
+        }
+
         async _generateStageIm(tid, sid, isTz = true) {
             if (isTz && [imType.tz.value, imType.bb.value].indexOf(this.ctx.stage.im_type) === -1) {
                 throw '您查看的报表跟设置不符,请查看“总量控制”的报表';
@@ -225,6 +255,7 @@ module.exports = app => {
             }
             const stageIm = new StageIm(this.ctx);
             await stageIm.buildImData();
+            // await this._loadImAuditorAssistData(stageIm);
             this.stageImData.main = stageIm.ImData;
             if (isTz) {
                 this.stageImData.bills = stageIm.ImBillsData;

+ 2 - 2
app/service/revise_bills.js

@@ -236,7 +236,7 @@ module.exports = app => {
             return result;
         }
 
-        async sumLoad(lid, rid, tenders) {
+        async sumLoad(lid, rid, tenders, subUp) {
             const conn = await this.db.beginTransaction();
             try {
                 const maxId = await this._getMaxLid(this.ctx.tender.id);
@@ -244,7 +244,7 @@ module.exports = app => {
                 const sumLoad = new SumLoad(this.ctx);
                 const loadTree = await sumLoad.updateGatherGcl(select, maxId, tenders, {
                     crid: rid,
-                });
+                }, subUp);
                 const result = loadTree.getUpdateData();
                 if (result.errors.length > 100) throw '您导入的数据存在大量数据错误,请您仔细检查';
 

+ 1 - 1
app/service/settle_audit.js

@@ -30,7 +30,7 @@ module.exports = app => {
         // ***** 查询审批人相关
         // 获取全部参与人
         async getAuditors(settleId, auditTimes) {
-            return await this.getAllDataByCondition({ where: { settle_id: settleId, audit_times: auditTimes } }); // 全部参与的审批人
+            return await this.getAllDataByCondition({ where: { settle_id: settleId, audit_times: auditTimes }, orders: [['active_order', 'asc']] }); // 全部参与的审批人
         }
         // 获取全部参与人 分组
         async getAuditorGroup(settleId, auditTimes) {

+ 16 - 0
app/view/change/information.ejs

@@ -404,6 +404,22 @@
                                             <a href="javascript:void(0);" class="btn btn-sm btn-light text-primary" id="add-white-btn" data-original-title="添加清单"><i class="fa fa-plus" aria-hidden="true"></i> <span class="order_text"><% if (change.order_by === 0) { %>添加<% } else { %>插入<% } %></span>空白清单</a>
                                         </div>
                                     <% } %>
+                                    <div class="d-inline-block mr-2 judge-show" style="display: none;">
+                                        <div class="dropdown">
+                                            <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+                                                <i class="fa fa-list-ol"></i> 显示层级
+                                            </button>
+                                            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
+                                                <a class="dropdown-item" name="showLevel" tag="1" href="javascript: void(0);">第一层</a>
+                                                <a class="dropdown-item" name="showLevel" tag="2" href="javascript: void(0);">第二层</a>
+                                                <a class="dropdown-item" name="showLevel" tag="3" href="javascript: void(0);">第三层</a>
+                                                <a class="dropdown-item" name="showLevel" tag="4" href="javascript: void(0);">第四层</a>
+                                                <a class="dropdown-item" name="showLevel" tag="5" href="javascript: void(0);">第五层</a>
+                                                <a class="dropdown-item" name="showLevel" tag="last" href="javascript: void(0);">最底层</a>
+                                                <a class="dropdown-item" name="showLevel" tag="leafXmj" href="javascript: void(0);">只显示项目节</a>
+                                            </div>
+                                        </div>
+                                    </div>
                                     <div class="d-inline-block mr-2 judge-hide">
                                         <button type="button" class="btn btn-sm btn-light text-primary dropdown-toggle" data-toggle="dropdown" id="bpaixu">清单排序:<% if (change.order_by === 0) { %>清单编号<% } else { %>添加顺序<% } %></button>
                                         <div class="dropdown-menu" aria-labelledby="bpaixu">

+ 1 - 1
app/view/material/audit_modal.ejs

@@ -18,7 +18,7 @@
                                  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">
+                                <dl class="list-unstyled book-list" id="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 %>">

+ 41 - 0
app/view/phase_pay/audit_btn.ejs

@@ -0,0 +1,41 @@
+<div class="contarl-box">
+    <% if (ctx.phasePay.audit_status === auditConst.status.uncheck) { %>
+        <% if (ctx.session.sessionUser.accountId === ctx.phasePay.create_user_id) { %>
+            <a id="sub-sp-btn" href="javascript: void(0);" data-toggle="modal" data-target="#sub-sp" class="btn btn-primary btn-sm btn-block">上报审批</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 btn-block">上报中</a>
+        <% } %>
+    <% } %>
+
+    <% if (ctx.phasePay.audit_status === auditConst.status.checking) { %>
+        <% if (ctx.phasePay.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) >= 0) { %>
+            <a id="sp-done-btn" href="javascript: void(0);" data-toggle="modal" data-target="#sp-done" class="btn btn-success btn-sm btn-block">审批通过</a>
+            <a href="#sp-back" data-toggle="modal" data-target="#sp-back" class="btn btn-warning btn-sm btn-block">审批退回</a>
+        <% } else { %>
+            <a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-secondary btn-sm btn-block">审批中</a>
+        <% } %>
+    <% } %>
+
+    <% if (ctx.phasePay.audit_status === auditConst.status.checked) { %>
+        <a href="#sp-list" data-type="hide" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-secondary btn-sm btn-block sp-list-btn">审批完成</a>
+    <% } %>
+
+    <% if (ctx.phasePay.audit_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 btn-block text-muted sp-list-btn">审批退回</a>
+        <% if (ctx.session.sessionUser.accountId === ctx.phasePay.create_user_id) { %>
+            <a href="#sp-list" data-type="show" data-toggle="modal" data-target="#sp-list"  class="btn btn-primary btn-sm btn-block sp-list-btn">重新上报</a>
+        <% } %>
+    <% } %>
+
+    <% if (ctx.phasePay.finalAuditorIds.indexOf(ctx.session.sessionUser.accountId) >= 0 && ctx.phasePay.audit_status === auditConst.status.checked && ctx.phasePay.isLatest) { %>
+        <a href="javascript: void(0);" data-toggle="modal" data-target="#sp-down-back" class="btn btn-warning btn-sm btn-block">重新审批</a>
+    <% } %>
+
+    <% if (ctx.phasePay.cancancel) { %>
+        <a href="javascript: void(0);" data-toggle="modal" data-target="#sp-down-cancel" class="btn btn-danger btn-sm btn-block">撤回</a>
+    <% } %>
+
+    <% if (ctx.phasePay.create_user_id === ctx.session.sessionUser.accountId && ctx.phasePay.isLatest && (ctx.phasePay.audit_status === auditConst.status.checkNo || ctx.phasePay.audit_status === auditConst.status.uncheck)) { %>
+        <a href="#del-qi" data-toggle="modal" data-target="#del-qi" class="btn btn-outline-danger btn-sm btn-block mt-5">删除本期</a>
+    <% } %>
+</div>

+ 864 - 0
app/view/phase_pay/audit_modal.ejs

@@ -0,0 +1,864 @@
+<% if (ctx.phasePay && (ctx.phasePay.audit_status === auditConst.status.uncheck || ctx.phasePay.audit_status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === ctx.phasePay.create_user_id) { %>
+<!--上报审批-->
+<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">
+                    <% if (ctx.tender.info.shenpi.phasePay !== shenpiConst.sp_status.gdspl && ctx.session.sessionUser.accountId === ctx.phasePay.create_user_id) { %>
+                    <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" id="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.phasePay.auditorGroups.length; i < iLen; i++) { %>
+                            <% if (ctx.phasePay.auditorGroups[i][0].audit_order === 0) continue; %>
+                            <li class="list-group-item d-flex" auditorId="<%- ctx.phasePay.auditorGroups[i][0].audit_id %>">
+                                <div class="col-auto"><%- ctx.phasePay.auditorGroups[i][0].audit_order %></div>
+                                <div class="col">
+                                    <% for (const auditor of ctx.phasePay.auditorGroups[i]) { %>
+                                    <div class="d-inline-block mx-1" auditorId="<%- auditor.audit_id %>">
+                                        <i class="fa fa-user text-muted"></i> <%- auditor.name %> <small class="text-muted"><%- auditor.role %></small>
+                                    </div>
+                                    <% } %>
+                                </div>
+                                <div class="col-auto">
+                                    <% if (ctx.phasePay.auditorGroups[i][0].audit_type !== auditType.key.common) { %>
+                                    <span class="badge badge-pill badge-<%- auditType.info[ctx.phasePay.auditorGroups[i][0].audit_type].class %> badge-bg-small"><small><%- auditType.info[ctx.phasePay.auditorGroups[i][0].audit_type].long%></small></span>
+                                    <% } %>
+                                    <% if ((ctx.tender.info.shenpi.phasePay === shenpiConst.sp_status.sqspr ||
+                                                    (ctx.tender.info.shenpi.phasePay === shenpiConst.sp_status.gdzs && i+1 !== iLen)) && ctx.session.sessionUser.accountId === ctx.phasePay.create_user_id && !ctx.tender.isTourist) { %>
+                                    <a href="javascript: void(0)" class="text-danger pull-right">移除</a>
+                                    <% } %>
+                                </div>
+                            </li>
+                            <% } %>
+                        </ul>
+                    </div>
+                </div>
+            </div>
+            <form class="modal-footer" method="post" action="audit/start" name="phase-start">
+                <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.phasePay.create_user_id) { %>
+                <button class="btn btn-primary btn-sm" type="submit">确认上报</button>
+                <% } %>
+            </form>
+        </div>
+    </div>
+</div>
+<% } %>
+<% if(ctx.phasePay && (ctx.phasePay.audit_status !== auditConst.status.uncheck)) { %>
+<!--审批流程/结果-->
+<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.phasePay.audit_status === auditConst.status.checkNo && ctx.session.sessionUser.accountId === ctx.phasePay.create_user_id) { %>
+                        <a class="sp-list-item" href="#sub-sp" data-toggle="modal" data-target="#sub-sp"
+                           id="hideSp">修改审批流程</a>
+                        <% } else if(ctx.phasePay.audit_status !== auditConst.status.checked && ctx.session.sessionUser.is_admin) { %>
+                        <a class="sp-list-item" href="#sub-sp2" data-toggle="modal" data-target="#sub-sp2"
+                           id="hideSp">修改审批流程</a>
+                        <% } %>
+                        <div class="card modal-height-500 mt-3" style="overflow: auto">
+                            <ul class="list-group list-group-flush auditors-list" id="auditors-list">
+                                <% ctx.phasePay.userGroups.forEach((item, idx) => { %>
+                                <% if (idx === 0) { %>
+                                <li class="list-group-item d-flex justify-content-between align-items-center">
+                                    <span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>
+                                    <span class="text-muted">
+                                        <% for (const u of item) { %>
+                                        <small class="d-inline-block text-dark mx-1" title="<%- u.role %>" data-auditorId="<%- u.audit_id %>"><%- u.name %></small>
+                                        <% } %>
+                                    </span>
+                                    <span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>
+                                </li>
+                                <% } else if(idx === ctx.phasePay.userGroups.length -1 && idx !== 0) { %>
+                                <li class="list-group-item d-flex justify-content-between align-items-center">
+                                    <span class="mr-1"><i class="fa fa fa-stop-circle"></i></span>
+                                    <span class="text-muted">
+                                        <% for (const u of item) { %>
+                                        <small class="d-inline-block text-dark mx-1" title="<%- u.role %>" data-auditorId="<%- u.audit_id %>"><%- u.name %></small>
+                                        <% } %>
+                                    </span>
+                                    <div class="d-flex ml-auto">
+                                        <% if (item[0].audit_type !== auditType.key.common) { %>
+                                        <span class="badge badge-pill badge-<%-  auditType.info[item[0].audit_type].class %> p-1"><small><%- auditType.info[item[0].audit_type].short %></small></span>
+                                        <% } %>
+                                        <span class="badge badge-light badge-pill"><small>终审</small></span>
+                                    </div>
+                                </li>
+                                <% } else {%>
+                                <li class="list-group-item d-flex justify-content-between align-items-center">
+                                    <span class="mr-1"><i class="fa fa-chevron-circle-down"></i></span>
+                                    <span class="text-muted">
+                                        <% for (const u of item) { %>
+                                        <small class="d-inline-block text-dark mx-1" title="<%- u.role %>" data-auditorId="<%- u.audit_id %>"><%- u.name %></small>
+                                        <% } %>
+                                    </span>
+                                    <div class="d-flex ml-auto">
+                                        <% if (item[0].audit_type !== auditType.key.common) { %>
+                                        <span class="badge badge-pill badge-<%- auditType.info[item[0].audit_type].class %> p-1"><small><%- auditType.info[item[0].audit_type].short %></small></span>
+                                        <% } %>
+                                        <span class="badge badge-light badge-pill"><small><%= ctx.helper.transFormToChinese(idx) %>审</small></span>
+                                    </div>
+                                </li>
+                                <% } %>
+                                <% }) %>
+                            </ul>
+                        </div>
+                    </div>
+                    <div class="col-8 modal-height-500" style="overflow: auto">
+                        <% ctx.phasePay.auditHistory.forEach((his, idx) => { %>
+                        <!-- 展开/收起历史流程 -->
+                        <% if(idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>
+                        <div class="text-right">
+                            <a href="javascript: void(0);" id="fold-btn" data-target="show" >展开历史审批流程</a>
+                        </div>
+                        <% } %>
+                        <div class="<%- idx < ctx.phasePay.auditHistory.length - 1 ? 'fold-card' : '' %>">
+                            <div class="text-center text-muted"><%- idx+1 %>#</div>
+                            <ul class="timeline-list list-unstyled mt-2 <% if (idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>last-auditor-list<% } %>">
+                                <% his.forEach((group, index) => { %>
+                                <li class="timeline-list-item pb-2 <% if (group.audit_status === auditConst.status.uncheck && idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>is_uncheck<% } %>">
+                                    <% if (group.auditYear) { %>
+                                    <div class="timeline-item-date">
+                                        <%- group.auditYear %>
+                                        <span><%- group.auditDate %></span>
+                                        <span><%- group.auditTime %></span>
+                                    </div>
+                                    <% } %>
+                                    <% if (index < his.length - 1) { %>
+                                    <div class="timeline-item-tail"></div>
+                                    <% } %>
+                                    <% if (group.audit_order === 0) { %>
+                                    <div class="timeline-item-icon bg-success text-light"><i class="fa fa-caret-down"></i></div>
+                                    <% } else if (group.audit_status === auditConst.status.checked) { %>
+                                    <div class="timeline-item-icon bg-success text-light"><i class="fa fa-check"></i></div>
+                                    <% } else if (group.audit_status === auditConst.status.checkNo || group.audit_status === auditConst.status.checkNoPre || group.audit_status === auditConst.status.checkCancel) { %>
+                                    <div class="timeline-item-icon bg-warning text-light"><i class="fa fa-level-up"></i></div>
+                                    <% } else if (group.audit_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="py-1">
+                                            <span class="text-black-50">
+                                                <%- group.auditName %>
+                                                <% if (group.audit_type !== auditType.key.common) { %><span class="text-<%- auditType.info[group.audit_type].class %> "><%- auditType.info[group.audit_type].long %></span><% } %>
+                                            </span>
+                                            <% if (group.audit_order === 0) { %>
+                                            <span class="pull-right text-success"><%- idx !== 0 ? '重新' : '' %>上报审批</span>
+                                            <% } else if (group.audit_status !== auditConst.status.uncheck) { %>
+                                            <span class="pull-right <%- auditConst.info[group.audit_status].class %>"><%- auditConst.info[group.audit_status].title %></span>
+                                            <% } %>
+                                        </div>
+                                        <div class="card">
+                                            <div class="card-body px-3 py-0">
+                                                <% for (const [i, auditor] of group.auditors.entries()) { %>
+                                                <div class="card-text p-2 py-3 row <%- ( i > 0 ? 'border-top' : '') %>">
+                                                    <div class="col">
+                                                        <span class="h6"><%- auditor.name %></span>
+                                                        <span class="text-muted ml-1"><%- auditor.role %></span>
+                                                    </div>
+                                                    <div class="col">
+                                                        <% if (auditor.audit_status === auditConst.status.checked) { %>
+                                                        <span class="pull-right text-success"><i class="fa fa-check-circle"></i></span>
+                                                        <% } if (auditor.audit_status === auditConst.status.checkNo || auditor.audit_status === auditConst.status.checkNoPre || auditor.audit_status === auditConst.status.checkCancel) { %>
+                                                        <span class="pull-right text-warning"><i class="fa fa-share-square fa-rotate-270"></i></span>
+                                                        <% } %>
+                                                    </div>
+                                                    <% if (auditor.opinion) { %>
+                                                    <div class="col-12 py-1 bg-light"><i class="fa fa-commenting-o mr-1"></i><%- auditor.opinion%></div>
+                                                    <% } %>
+                                                </div>
+                                                <% } %>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </li>
+                                <% }) %>
+                            </ul>
+                        </div>
+                        <% }) %>
+                    </div>
+                </div>
+            </div>
+            <form class="modal-footer" method="post" action="audit/start" name="phase-start">
+                <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                <% if(ctx.phasePay.audit_status === auditConst.status.checkNo && ctx.session.sessionUser.accountId === ctx.phasePay.create_user_id) { %>
+                <button class="btn btn-primary btn-sm sp-list-item" type="submit">确认上报</button>
+                <% } %>
+            </form>
+        </div>
+    </div>
+</div>
+<% } %>
+<% if (ctx.phasePay && (ctx.phasePay.audit_status === auditConst.status.checking || ctx.phasePay.audit_status === auditConst.status.checkNoPre) && ctx.phasePay.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) >= 0) { %>
+<!--审批通过-->
+<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="audit/check" method="post" id="audit-check">
+            <div class="modal-header">
+                <h5 class="modal-title">审批通过</h5>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <div class="col-4">
+                        <% if(ctx.phasePay.audit_status !== auditConst.status.checked && ctx.session.sessionUser.is_admin) { %>
+                        <a class="sp-list-item" href="#sub-sp2" data-toggle="modal" data-target="#sub-sp2" id="hideSp">修改审批流程</a>
+                        <% } %>
+                        <div class="card modal-height-500 mt-3" style="overflow: auto">
+                            <ul class="list-group list-group-flush auditors-list">
+                                <% ctx.phasePay.userGroups.forEach((item, idx) => { %>
+                                <li class="list-group-item d-flex justify-content-between align-items-center">
+                                    <% if (idx === 0) { %>
+                                    <span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>
+                                    <% } else if (idx === ctx.phasePay.userGroups.length -1 && idx !== 0) { %>
+                                    <span class="mr-1"><i class="fa fa fa-stop-circle"></i></span>
+                                    <% } else { %>
+                                    <span class="mr-1"><i class="fa fa-chevron-circle-down"></i></span>
+                                    <% } %>
+                                    <span class="text-muted">
+                                        <% for (const u of item) { %>
+                                        <small class="d-inline-block text-dark mx-1" title="<%- u.role %>" data-auditorId="<%- u.audit_id %>"><%- u.name %></small>
+                                        <% } %>
+                                    </span>
+                                    <div class="d-flex ml-auto">
+                                        <% if (item[0].audit_type !== auditType.key.common) { %>
+                                        <span class="badge badge-pill badge-<%-  auditType.info[item[0].audit_type].class %> p-1"><small><%- auditType.info[item[0].audit_type].short %></small></span>
+                                        <% } %>
+                                        <span class="badge badge-light badge-pill"><small><%- item.auditName %></small></span>
+                                    </div>
+                                </li>
+                                <% }) %>
+                            </ul>
+                        </div>
+                    </div>
+                    <div class="col-8 modal-height-500" style="overflow: auto">
+                        <% ctx.phasePay.auditHistory.forEach((his, idx) => { %>
+                        <!-- 展开/收起历史流程 -->
+                        <% if(idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>
+                        <div class="text-right"><a href="javascript: void(0);" id="fold-btn" data-target="show">展开历史审批流程</a></div>
+                        <% } %>
+                        <div class="<%- idx < ctx.phasePay.auditHistory.length - 1 ? 'fold-card' : '' %>">
+                            <div class="text-center text-muted"><%- idx+1 %>#</div>
+                            <ul class="timeline-list list-unstyled mt-2 <% if (idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>last-auditor-list<% } %>">
+                                <% his.forEach((group, index) => { %>
+                                <li class="timeline-list-item pb-2 <% if (group.audit_status === auditConst.status.uncheck && idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>is_uncheck<% } %>">
+                                    <% if (group.auditYear) { %>
+                                    <div class="timeline-item-date">
+                                        <%- group.auditYear %>
+                                        <span><%- group.auditDate %></span>
+                                        <span><%- group.auditTime %></span>
+                                    </div>
+                                    <% } %>
+                                    <% if (index < his.length - 1) { %>
+                                    <div class="timeline-item-tail"></div>
+                                    <% } %>
+                                    <% if (group.audit_order === 0) { %>
+                                    <div class="timeline-item-icon bg-success text-light"><i class="fa fa-caret-down"></i></div>
+                                    <% } else if (group.audit_status === auditConst.status.checked) { %>
+                                    <div class="timeline-item-icon bg-success text-light"><i class="fa fa-check"></i></div>
+                                    <% } else if (group.audit_status === auditConst.status.checkNo || group.audit_status === auditConst.status.checkNoPre || group.audit_status === auditConst.status.checkCancel) { %>
+                                    <div class="timeline-item-icon bg-warning text-light"><i class="fa fa-level-up"></i></div>
+                                    <% } else if (group.audit_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="py-1">
+                                            <span class="text-black-50">
+                                                <%- group.auditName %>
+                                                <% if (group.audit_type !== auditType.key.common) { %><span class="text-<%- auditType.info[group.audit_type].class %> "><%- auditType.info[group.audit_type].long %></span><% } %>
+                                            </span>
+                                            <% if (group.audit_order === 0) { %>
+                                            <span class="pull-right text-success"><%- idx !== 0 ? '重新' : '' %>上报审批</span>
+                                            <% } else if (group.audit_status !== auditConst.status.uncheck) { %>
+                                            <span class="pull-right <%- auditConst.info[group.audit_status].class %>"><%- auditConst.info[group.audit_status].title %></span>
+                                            <% } %>
+                                        </div>
+                                        <div class="card">
+                                            <div class="card-body px-3 py-0">
+                                                <% for (const [i, auditor] of group.auditors.entries()) { %>
+                                                <div class="card-text p-2 py-3 row <%- ( i > 0 ? 'border-top' : '') %>">
+                                                    <div class="col">
+                                                        <span class="h6"><%- auditor.name %></span>
+                                                        <span class="text-muted ml-1"><%- auditor.role %></span>
+                                                    </div>
+                                                    <div class="col">
+                                                        <% if (auditor.audit_status === auditConst.status.checked) { %>
+                                                        <span class="pull-right text-success"><i class="fa fa-check-circle"></i></span>
+                                                        <% } if (auditor.audit_status === auditConst.status.checkNo || auditor.audit_status === auditConst.status.checkNoPre || auditor.audit_status === auditConst.status.checkCancel) { %>
+                                                        <span class="pull-right text-warning"><i class="fa fa-share-square fa-rotate-270"></i></span>
+                                                        <% } else if (auditor.audit_status === auditConst.status.checking) { %>
+                                                        <span class="pull-right text-warning"><i class="fa fa-commenting"></i></span>
+                                                        <% } %>
+                                                    </div>
+                                                    <% if (auditor.audit_status !== auditConst.status.uncheck && auditor.opinion) { %>
+                                                    <div class="col-12 py-1 bg-light"><i class="fa fa-commenting-o mr-1"></i><%- auditor.opinion%></div>
+                                                    <% } %>
+                                                    <% if (auditor.audit_status === auditConst.status.checking && auditor.audit_id === ctx.session.sessionUser.accountId) { %>
+                                                    <div class="col-12 py-1 bg-light">
+                                                        <textarea class="form-control form-control-sm" name="opinion">同意</textarea>
+                                                    </div>
+                                                    <% } %>
+                                                </div>
+                                                <% } %>
+                                            </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="audit/check" method="post" id="audit-check-no">
+            <div class="modal-header">
+                <h5 class="modal-title">审批退回</h5>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <div class="col-4">
+                        <% if(ctx.phasePay.audit_status !== auditConst.status.checked && ctx.session.sessionUser.is_admin) { %>
+                        <a class="sp-list-item" href="#sub-sp2" data-toggle="modal" data-target="#sub-sp2" id="hideSp">修改审批流程</a>
+                        <% } %>
+                        <div class="card modal-height-500 mt-3" style="overflow: auto">
+                            <ul class="list-group list-group-flush auditors-list">
+                                <% ctx.phasePay.userGroups.forEach((item, idx) => { %>
+                                <li class="list-group-item d-flex justify-content-between align-items-center">
+                                    <% if (idx === 0) { %>
+                                    <span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>
+                                    <% } else if (idx === ctx.phasePay.userGroups.length -1 && idx !== 0) { %>
+                                    <span class="mr-1"><i class="fa fa fa-stop-circle"></i></span>
+                                    <% } else { %>
+                                    <span class="mr-1"><i class="fa fa-chevron-circle-down"></i></span>
+                                    <% } %>
+                                    <span class="text-muted">
+                                        <% for (const u of item) { %>
+                                        <small class="d-inline-block text-dark mx-1" title="<%- u.role %>" data-auditorId="<%- u.audit_id %>"><%- u.name %></small>
+                                        <% } %>
+                                    </span>
+                                    <div class="d-flex ml-auto">
+                                        <% if (item[0].audit_type !== auditType.key.common) { %>
+                                        <span class="badge badge-pill badge-<%-  auditType.info[item[0].audit_type].class %> p-1"><small><%- auditType.info[item[0].audit_type].short %></small></span>
+                                        <% } %>
+                                        <span class="badge badge-light badge-pill"><small><%- item.auditName %></small></span>
+                                    </div>
+                                </li>
+                                <% }) %>
+                            </ul>
+                        </div>
+                    </div>
+                    <div class="col-8 modal-height-500" style="overflow: auto">
+                        <% ctx.phasePay.auditHistory.forEach((his, idx) => { %>
+                        <!-- 展开/收起历史流程 -->
+                        <% if(idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>
+                        <div class="text-right"><a href="javascript: void(0);" id="fold-btn" data-target="show" data-idx="<%- idx + 1 %>">展开历史审批流程</a></div>
+                        <% } %>
+                        <div class="<%- idx < ctx.phasePay.auditHistory.length - 1 ? 'fold-card' : '' %>">
+                            <div class="text-center text-muted"><%- idx+1 %>#</div>
+                            <ul class="timeline-list list-unstyled mt-2 <% if (idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>last-auditor-list<% } %>">
+                                <% his.forEach((group, index) => { %>
+                                <li class="timeline-list-item pb-2 <% if (group.audit_status === auditConst.status.uncheck && idx === ctx.phasePay.auditHistory.length - 1 && ctx.phasePay.auditHistory.length !== 1) { %>is_uncheck<% } %>">
+                                    <% if (group.auditYear) { %>
+                                    <div class="timeline-item-date">
+                                        <%- group.auditYear %>
+                                        <span><%- group.auditDate %></span>
+                                        <span><%- group.auditTime %></span>
+                                    </div>
+                                    <% } %>
+                                    <% if (index < his.length - 1) { %>
+                                    <div class="timeline-item-tail"></div>
+                                    <% } %>
+                                    <% if (group.audit_order === 0) { %>
+                                    <div class="timeline-item-icon bg-success text-light"><i class="fa fa-caret-down"></i></div>
+                                    <% } else if (group.audit_status === auditConst.status.checked) { %>
+                                    <div class="timeline-item-icon bg-success text-light"><i class="fa fa-check"></i></div>
+                                    <% } else if (group.audit_status === auditConst.status.checkNo || group.audit_status === auditConst.status.checkNoPre || group.audit_status === auditConst.status.checkCancel) { %>
+                                    <div class="timeline-item-icon bg-warning text-light"><i class="fa fa-level-up"></i></div>
+                                    <% } else if (group.audit_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="py-1">
+                                            <span class="text-black-50">
+                                                <%- group.auditName %>
+                                                <% if (group.audit_type !== auditType.key.common) { %><span class="text-<%- auditType.info[group.audit_type].class %> "><%- auditType.info[group.audit_type].long %></span><% } %>
+                                            </span>
+                                            <% if (group.audit_order === 0) { %>
+                                            <span class="pull-right text-success"><%- idx !== 0 ? '重新' : '' %>上报审批</span>
+                                            <% } else if (group.audit_status !== auditConst.status.uncheck) { %>
+                                            <span class="pull-right <%- auditConst.info[group.audit_status].class %>"><%- auditConst.info[group.audit_status].title %></span>
+                                            <% } %>
+                                        </div>
+                                        <div class="card">
+                                            <div class="card-body px-3 py-0">
+                                                <% for (const [i, auditor] of group.auditors.entries()) { %>
+                                                <div class="card-text p-2 py-3 row <%- ( i > 0 ? 'border-top' : '') %>">
+                                                    <div class="col">
+                                                        <span class="h6"><%- auditor.name %></span>
+                                                        <span class="text-muted ml-1"><%- auditor.role %></span>
+                                                    </div>
+                                                    <div class="col">
+                                                        <% if (auditor.audit_status === auditConst.status.checked) { %>
+                                                        <span class="pull-right text-success"><i class="fa fa-check-circle"></i></span>
+                                                        <% } if (auditor.audit_status === auditConst.status.checkNo || auditor.audit_status === auditConst.status.checkNoPre || auditor.audit_status === auditConst.status.checkCancel) { %>
+                                                        <span class="pull-right text-warning"><i class="fa fa-share-square fa-rotate-270"></i></span>
+                                                        <% } else if (auditor.audit_status === auditConst.status.checking) { %>
+                                                        <span class="pull-right text-warning"><i class="fa fa-commenting"></i></span>
+                                                        <% } %>
+                                                    </div>
+                                                    <% if (auditor.audit_status !== auditConst.status.uncheck && auditor.opinion) { %>
+                                                    <div class="col-12 py-1 bg-light"><i class="fa fa-commenting-o mr-1"></i><%- auditor.opinion%></div>
+                                                    <% } %>
+                                                    <% if (auditor.audit_status === auditConst.status.checking && auditor.audit_id === ctx.session.sessionUser.accountId) { %>
+                                                    <div class="col-12 py-1 bg-light">
+                                                        <textarea class="form-control form-control-sm" name="opinion">不同意</textarea>
+                                                        <div id="reject-process" class="alert alert-warning mt-1 mb-0 p-2">
+                                                            <div class="form-check form-check-inline">
+                                                                <input class="form-check-input" type="radio" name="checkType" id="inlineRadio1" value="<%- auditConst.status.checkNo %>">
+                                                                <label class="form-check-label" for="inlineRadio1">退回原报 <%- ctx.phasePay.user.name %></label>
+                                                            </div>
+                                                            <% if (auditor.audit_order > 1) { %>
+                                                            <div class="form-check form-check-inline">
+                                                                <input class="form-check-input" type="radio" name="checkType" id="inlineRadio2" value="<%- auditConst.status.checkNoPre %>">
+                                                                <label class="form-check-label" for="inlineRadio2">退回上一审批人
+                                                                    <% const pre = his.find(x => { return x.audit_order === auditor.audit_order - 1}); %>
+                                                                    <%- ( pre ? pre.name : '') %>
+                                                                </label>
+                                                            </div>
+                                                            <% } %>
+                                                        </div>
+                                                    </div>
+                                                    <% } %>
+                                                </div>
+                                                <% } %>
+                                            </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.phasePay && ctx.phasePay.finalAuditorIds.indexOf(ctx.session.sessionUser.accountId) >= 0 && ctx.phasePay.audit_status === auditConst.status.checked && ctx.phasePay.isLatest) { %>
+<% if (!authMobile && ctx.session.sessionUser.loginStatus === 0) { %>
+<!--终审重新审批-->
+<div class="modal fade" id="sp-down-back" 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>
+                <h5>您目前还没设置认证手机,请先设置。</h5>
+            </div>
+            <div class="modal-footer">
+                <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
+                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
+                <a href="/profile/sms" class="btn btn-sm btn-primary">去设置</a>
+            </div>
+        </div>
+    </div>
+</div>
+<% } else { %>
+<div class="modal fade" id="sp-down-back" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <form class="modal-content" method="post" action="audit/checkAgain" name="pay-checkAgain">
+            <div class="modal-header">
+                <h5 class="modal-title">重新审批</h5>
+            </div>
+            <div class="modal-body">
+                <h5>确认由「终审-<%= ctx.session.sessionUser.name %>」重新审批「第<%= ctx.phasePay.phase_order %>期」?
+                </h5>
+                <% if (ctx.session.sessionUser.loginStatus === 0) { %>
+                <div class="form-group">
+                    <label>重审需要验证码确认,验证码将发送至尾号<%- authMobile.slice(-4) %>的手机</label>
+                    <div class="input-group input-group-sm mb-3">
+                        <input class="form-control" type="text" readonly="readonly" name="code"
+                               placeholder="输入短信中的6位验证码" />
+                        <div class="input-group-append">
+                            <button class="btn btn-outline-secondary" type="button" id="get-code">获取验证码</button>
+                        </div>
+                    </div>
+                </div>
+                <% } %>
+            </div>
+            <div class="modal-footer">
+                <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                <button <% if (ctx.session.sessionUser.loginStatus === 0) { %>disabled<% } %> id="re-shenpi-btn" class="btn btn-warning btn-sm" type="submit">确定重审</button>
+            </div>
+        </form>
+    </div>
+</div>
+<% } %>
+<% } %>
+<% if (ctx.phasePay && ctx.phasePay.create_user_id === ctx.session.sessionUser.accountId && ctx.phasePay.isLatest && (ctx.phasePay.audit_status === auditConst.status.checkNo || ctx.phasePay.audit_status === auditConst.status.uncheck)) { %>
+<div class="modal fade" id="del-qi" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <form class="modal-content" action='/tender/<%= ctx.tender.id %>/pay/delete' method="post">
+            <div class="modal-header">
+                <h5 class="modal-title">删除期</h5>
+            </div>
+            <div class="modal-body">
+                <h5>确认删除「第<%= ctx.phasePay.phase_order %>期」?</h5>
+                <h5>删除后,数据无法恢复,请谨慎操作。</h5>
+            </div>
+            <div class="modal-footer">
+                <input type="hidden" name="phase_id" value="<%= ctx.phasePay.id %>">
+                <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>
+            </div>
+        </form>
+    </div>
+</div>
+<% } %>
+<% if (ctx.phasePay && ctx.phasePay.cancancel) { %>
+<div class="modal fade" id="sp-down-cancel" 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="audit/checkCancel" method="post">
+                <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" type="submit">确定撤回</button>
+            </form>
+        </div>
+    </div>
+</div>
+<% } %>
+<% if (ctx.phasePay && ctx.phasePay.audit_status !== auditConst.status.checked && ctx.session.sessionUser.is_admin) { %>
+<!--上报审批-->
+<div class="modal fade" id="sub-sp2" data-backdrop="static">
+    <div class="modal-dialog" style="max-width: 650px" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">修改审批流程</h5>
+            </div>
+            <div class="modal-body">
+                <div class="card mt-1">
+                    <div class="modal-height-500" style="overflow: auto">
+                        <style>
+                            #admin-edit-shenpi thead th {
+                                border-bottom: 0;
+                            }
+                            #admin-edit-shenpi td, #admin-edit-shenpi th {
+                                padding: 0.75rem;
+                            }
+                            #admin-edit-shenpi th {
+                                background: none;
+                                color: #212529;
+                                border-top: 0;
+                            }
+                        </style>
+                        <table class="table table-hover" id="admin-edit-shenpi">
+                            <thead>
+                            <tr class="card-header text-center">
+                                <th width="100px">审批流程</th>
+                                <th>审批人员</th>
+                                <th width="80" style="text-align: center">审批状态</th>
+                                <th width="200" style="text-align: center">操作</th>
+                            </tr>
+                            </thead>
+                            <tbody id="admin-edit-shenpi-list">
+                            <% for (const [i, group] of ctx.phasePay.userGroups.entries()) { %>
+                            <% if (i === 0) continue; %>
+                            <% for (const [j, auditor] of group.entries()) { %>
+                            <tr>
+                                <td class="text-left d-flex">
+                                    <% if (j === 0) { %>
+                                    <%- i + '审' %>
+                                    <% if (auditor.audit_type !== auditType.key.common) { %>
+                                    <span class="ml-2 badge badge-pill badge-<%-  auditType.info[auditor.audit_type].class %> p-1"><small><%- auditType.info[auditor.audit_type].short %></small></span>
+                                    <% } %>
+                                    <% } %>
+                                </td>
+                                <td></span> <%- auditor.name %> <small class="text-muted"><%- auditor.role %></small></td>
+                                <td style="text-align: center"><span class="<%- auditConst.info[auditor.audit_status].class %>"><%- auditor.audit_status !== auditConst.status.uncheck ? auditConst.info[auditor.audit_status].title : '待审批'  %></span></td>
+                                <td style="text-align: center">
+                                    <% if (auditor.audit_status === auditConst.status.checking && j === group.length - 1) { %>
+                                    <span class="dropdown mr-2">
+                                    <a href="javascript: void(0)" class="add-audit" id="<%- auditor.audit_id %>_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>
+                                    <div class="dropdown-menu dropdown-menu-right" id="<%- auditor.audit_id %>_add_dropdownMenu" aria-labelledby="<%- auditor.audit_id %>_add_dropdownMenuButton" style="width:220px">
+                                        <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"
+                                                                     placeholder="姓名/手机 检索" autocomplete="off" data-code="<%- auditor.audit_id %>_add"></div>
+                                        <dl class="list-unstyled book-list" data-aid="<%- auditor.audit_id %>" data-operate="add">
+                                            <% 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.phasePay.create_user_id) { %>
+                                                    <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>
+                                    </span>
+                                    <% } %>
+                                    <% if (auditor.audit_status === auditConst.status.uncheck) { %>
+                                    <% if (j === group.length - 1) { %>
+                                    <span class="dropdown mr-2">
+                                    <a href="javascript: void(0)" class="add-audit" id="<%- auditor.audit_id %>_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>
+                                        <div class="dropdown-menu dropdown-menu-right" id="<%- auditor.audit_id %>_add_dropdownMenu" aria-labelledby="<%- auditor.audit_id %>_add_dropdownMenuButton" style="width:220px">
+                                            <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"
+                                                                         placeholder="姓名/手机 检索" autocomplete="off" data-code="<%- auditor.audit_id %>_add"></div>
+                                            <dl class="list-unstyled book-list" data-aid="<%- auditor.audit_id %>" data-operate="add">
+                                                <% 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.phasePay.create_user_id) { %>
+                                                        <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>
+                                    </span>
+                                    <% if (auditor.audit_type !== auditType.key.common) { %>
+                                    <span class="dropdown mr-2">
+                                    <a href="javascript: void(0)" class="add-audit" id="<%- auditor.audit_id %>_add-sibling_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">平级</a>
+                                        <div class="dropdown-menu dropdown-menu-right" id="<%- auditor.audit_id %>_add-sibling_dropdownMenu" aria-labelledby="<%- auditor.audit_id %>_add-sibling_dropdownMenuButton" style="width:220px">
+                                            <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"
+                                                                         placeholder="姓名/手机 检索" autocomplete="off" data-code="<%- auditor.audit_id %>_add-sibling"></div>
+                                            <dl class="list-unstyled book-list" data-aid="<%- auditor.audit_id %>" data-operate="add-sibling">
+                                                <% 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.phasePay.create_user_id) { %>
+                                                        <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>
+                                    </span>
+                                    <% } %>
+                                    <% } %>
+                                    <span class="dropdown mr-2">
+                                        <a href="javascript: void(0)" class="change-audit" id="<%- auditor.audit_id %>_change_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">更换</a>
+                                        <div class="dropdown-menu dropdown-menu-right" id="<%- auditor.audit_id %>_change_dropdownMenu" aria-labelledby="<%- auditor.audit_id %>_change_dropdownMenuButton" style="width:220px">
+                                            <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"
+                                                                         placeholder="姓名/手机 检索" autocomplete="off" data-code="<%- auditor.audit_id %>_change"></div>
+                                            <dl class="list-unstyled book-list" data-aid="<%- auditor.audit_id %>" data-operate="change">
+                                                <% 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.phasePay.create_user_id) { %>
+                                                        <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>
+                                    </span>
+                                    <span class="dropdown">
+                                    <a href="javascript: void(0)" class="text-danger" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">移除</a>
+                                    <div class="dropdown-menu">
+                                        <span class="dropdown-item" href="javascript:void(0);">确认移除审批人?</span>
+                                        <div class="dropdown-divider"></div>
+                                        <div class="px-2 py-1 text-center">
+                                            <button class="remove-audit btn btn-sm btn-danger" data-id="<%- auditor.audit_id %>">移除</button>
+                                            <button class="btn btn-sm btn-secondary">取消</button>
+                                        </div>
+                                    </div>
+                                    </span>
+                                    <% } %>
+                                </td>
+                            </tr>
+                            <% } %>
+                            <% } %>
+                            </tbody>
+                        </table>
+                    </div>
+                </div>
+            </div>
+            <form class="modal-footer">
+                <div class="mr-auto text-warning">
+                    <span class="mr-3">增加:后级审核人</span>
+                    <span class="">平级:会签/或签增加平级审核人</span>
+                </div>
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+            </form>
+        </div>
+    </div>
+</div>
+<% } %>
+<script>
+    const accountGroup = JSON.parse(unescape('<%- escape(JSON.stringify(accountGroup)) %>'));
+    const accountList = JSON.parse(unescape('<%- escape(JSON.stringify(accountList)) %>'));
+    const shenpi_status = <%- ctx.tender.info.shenpi.phasePay %>;
+    const shenpiConst =  JSON.parse('<%- JSON.stringify(shenpiConst) %>');
+    const phaseUserId = parseInt('<%= ctx.phasePay.create_user_id %>');
+</script>
+<script>
+    $('[name=phase-start]').submit(function (e) {
+        if (checkAuditorFrom()) {
+            $(this).parent().parent().parent().modal('hide');
+            $('#hide-all').hide();
+        } else {
+            return false;
+        }
+    });
+    $('#audit-check-no').submit(function (e) {
+        const checkType = parseInt($('[name=checkType]:checked').val());
+        if ($('#warning-text').length) $('#warning-text').remove();
+        if (!checkType && !$('#warning-text').length) {
+            $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
+            return false;
+        }
+        $('#hide-all').hide();
+    });
+
+    $('.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('展开历史审核记录')
+            })
+        }
+    });
+
+    // 重新审批
+    $('[name=phase-checkAgain]').submit(function (e) {
+        <% if (ctx.session.sessionUser.loginStatus === 0) { %>
+        const code = $("#sp-down-back input[name='code']").val();
+        if ($(this).hasClass('disabled')) return false;
+        if (code.length < 6) {
+            toast('请填写正确的验证码', 'error');
+            return false;
+        }
+        <% } %>
+        $('#hide-all').hide();
+    });
+</script>

+ 78 - 26
app/view/phase_pay/detail.ejs

@@ -29,42 +29,94 @@
             </div>
         </div>
     </div>
-    <div class="content-wrap">
+    <div class="content-wrap pr-46">
         <div class="c-header p-0"></div>
+        <!--核心内容(两栏)-->
         <div class="row w-100 sub-content">
-            <div class="c-body col-8">
+            <!--左栏-->
+            <div class="c-body" id="left-view" style="width: 100%">
                 <div class="sjs-height-1" id="pay-spread">
                 </div>
             </div>
-            <div class="c-body col">
-                <div class="side-bar-1"></div>
-                <div class="sjs-sh-1">
-                    <table class="table table-bordered">
-                        <tr><th></th><th>可选基数</th><th>计算代号</th><th>值</th></tr>
-                        <tbody id="base-list">
-                        <% for (let iBase = 0; iBase < calcBase.length; iBase++) { %>
-                        <tr>
-                            <td><%- iBase + 1 %></td>
-                            <td><%- calcBase[iBase].name %></td>
-                            <td><%- calcBase[iBase].code %></td>
-                            <% if (calcBase[iBase].code === 'bqyf') { %>
-                            <td class="text-right">--</td>
-                            <% } else {%>
-                            <td class="text-right"><%- (ctx.tender.info.display.thousandth ? ctx.helper.formatNum(calcBase[iBase].value, '#,##0.######') : calcBase[iBase].value) %></td>
-                            <% } %>
-                        </tr>
-                        <% } %>
-                        </tbody>
-                    </table>
+            <div class="c-body" id="right-view" style="display: none; width: 33%;">
+                <div class="resize-x" id="right-spr" r-Type="width" div1="#left-view" div2="#right-view" title="调整大小" a-type="percent"><!--调整左右高度条--></div>
+                <div class="tab-content">
+                    <div id="calcBase" class="tab-pane tab-select-show">
+                        <div class="side-bar-1"></div>
+                        <div class="sjs-sh-1">
+                            <table class="table table-bordered">
+                                <tr><th></th><th>可选基数</th><th>计算代号</th><th>值</th></tr>
+                                <tbody id="base-list">
+                                <% for (let iBase = 0; iBase < calcBase.length; iBase++) { %>
+                                <tr>
+                                    <td><%- iBase + 1 %></td>
+                                    <td><%- calcBase[iBase].name %></td>
+                                    <td><%- calcBase[iBase].code %></td>
+                                    <% if (calcBase[iBase].code === 'bqyf') { %>
+                                    <td class="text-right">--</td>
+                                    <% } else {%>
+                                    <td class="text-right"><%- (ctx.tender.info.display.thousandth ? ctx.helper.formatNum(calcBase[iBase].value, '#,##0.######') : calcBase[iBase].value) %></td>
+                                    <% } %>
+                                </tr>
+                                <% } %>
+                                </tbody>
+                            </table>
+                        </div>
+                    </div>
+                    <div id="fujian" class="tab-pane tab-select-show">
+                        <div class="sjs-bar">
+                            <ul class="nav nav-tabs">
+                                <li class="nav-item">
+                                    <a class="nav-link active" data-toggle="tab" href="#cur-att" role="tab" fujian-content="cur-att">当前节点</a>
+                                </li>
+                                <li class="nav-item">
+                                    <a class="nav-link" data-toggle="tab" href="#all-att" role="tab" fujian-content="all-att">所有附件</a>
+                                </li>
+                                <li class="nav-item ml-auto pt-1">
+                                    <button  id="batch-download-att" class="btn btn-sm btn-primary" type="curr">批量下载</button>
+                                    <!--所有附件 翻页-->
+                                    <span id="showPage" style="display: none"><a href="javascript:void(0);" class="page-select ml-3" content="pre"><i class="fa fa-chevron-left"></i></a> <span id="currentPage">1</span>/<span id="totalPage">10</span> <a href="javascript:void(0);" class="page-select mr-3" content="next"><i class="fa fa-chevron-right"></i></a></span>
+                                    <a href="#upload" data-toggle="modal" data-target="#upload" class="btn btn-sm btn-outline-primary ml-3">上传</a>
+                                </li>
+                            </ul>
+                        </div>
+                        <div class="tab-content">
+                            <div class="tab-pane active" id="cur-att">
+                                <div class="sjs-sh-3" style="overflow:auto; overflow-x:hidden;">
+                                    <table class="table table-sm table-bordered table-hover" style="word-break:break-all; table-layout: fixed">
+                                        <tr><th width="25"><input type="checkbox" class="check-all-file"><th>文件名</th><th width="80">上传</th></tr>
+                                        <tbody id="cur-att-list" class="list-table">
+                                        </tbody>
+                                    </table>
+                                </div>
+                            </div>
+                            <div class="tab-pane" id="all-att">
+                                <div class="sjs-sh-3" style="overflow:auto; overflow-x:hidden;">
+                                    <table class="table table-sm table-bordered table-hover" style="word-break:break-all; table-layout: fixed">
+                                        <tr><th width="25"><input type="checkbox" class="check-all-file"></th><th>文件名</th><th width="80">上传</th></tr>
+                                        <tbody id="all-att-list" class="list-table">
+                                        </tbody>
+                                    </table>
+                                </div>
+                            </div>
+                        </div>
+                    </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="#calcBase" href="javascript: void(0);">计算基数</a>
+                </li>
+                <li class="nav-item">
+                    <a class="nav-link" content="#fujian" href="javascript: void(0);">附件</a>
+                </li>
+            </ul>
+        </div>
     </div>
 </div>
-<div style="display: none">
-    <img src="/public/images/file_clip.png" id="rela-file-icon" />
-    <img src="/public/images/file_clip_hover.png" id="rela-file-hover" />
-</div>
 <script>
     const lockPayExpr = <%- lockPayExpr %>;
     const phasePay = JSON.parse('<%- JSON.stringify(ctx.phasePay) %>');

+ 3 - 1
app/view/phase_pay/detail_modal.ejs

@@ -56,4 +56,6 @@
             </div>
         </div>
     </div>
-</div>
+</div>
+<% include ../shares/upload_att.ejs %>
+<% include ./audit_modal.ejs %>

+ 11 - 6
app/view/phase_pay/index.ejs

@@ -54,13 +54,13 @@
                         <td class="text-right"><%- pay.display_end_sf_tp %></td>
                         <td class="<%- auditConst.info[pay.audit_status].class %>">
                             <% if (pay.audit_status === auditConst.status.checked && pay.final_auditor_str) { %>
-                                <a href="#sp-list" data-toggle="modal" data-target="#sp-list" s-order="<%- pay.phase_order %>"><%- pay.final_auditor_str %></a>
+                                <a href="#sp-list" data-toggle="modal" data-target="#sp-list" phase-order="<%- pay.phase_order %>"><%- pay.final_auditor_str %></a>
                             <% } else { %>
                                 <% if (pay.curAuditors.length > 0) { %>
                                     <% if (pay.curAuditors[0].audit_type === auditType.key.common) { %>
-                                        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" s-order="<%- pay.phase_order %>"><%- pay.curAuditors[0].name %><%if (pay.curAuditors[0].role !== '' && pay.curAuditors[0].role !== null) { %>-<%- pay.curAuditors[0].role %><% } %></a>
+                                        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" phase-order="<%- pay.phase_order %>"><%- pay.curAuditors[0].name %><%if (pay.curAuditors[0].role !== '' && pay.curAuditors[0].role !== null) { %>-<%- pay.curAuditors[0].role %><% } %></a>
                                     <% } else { %>
-                                        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" s-order="<%- pay.phase_order %>"><%- ctx.helper.transFormToChinese(pay.curAuditors[0].audit_order) + '审' %></a>
+                                        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" phase-order="<%- pay.phase_order %>"><%- ctx.helper.transFormToChinese(pay.curAuditors[0].audit_order) + '审' %></a>
                                     <% } %>
                                 <% } %>
                             <% } %>
@@ -69,12 +69,12 @@
                         <td class="text-center">
                             <% if (pay.audit_status === auditConst.status.uncheck && pay.create_user_id === ctx.session.sessionUser.accountId) { %>
                             <a href="<%- '/tender/' + pay.tid + '/pay/' + pay.phase_order %>" target="_blank" class="btn <%- auditConst.info[pay.audit_status].btnClass %> btn-sm"><%- auditConst.info[pay.audit_status].btnTitle %></a>
-                            <% } else if (s.status === auditConst.status.checkNo && s.user_id === ctx.session.sessionUser.accountId) { %>
+                            <% } else if (pay.status === auditConst.status.checkNo && pay.user_id === ctx.session.sessionUser.accountId) { %>
                             <a href="<%- '/tender/' + pay.tid + '/pay/' + pay.phase_order %>" target="_blank" class="btn <%- auditConst.info[pay.audit_status].btnClass %> btn-sm"><%- auditConst.info[pay.audit_status].btnTitle %></a>
-                            <% } else if ((s.status === auditConst.status.checking || s.status === auditConst.status.checkNoPre) && s.curAuditors && s.curAuditors.findIndex(x => { return x.aid === ctx.session.sessionUser.accountId; }) >= 0) { %>
+                            <% } else if ((pay.status === auditConst.status.checking || pay.status === auditConst.status.checkNoPre) && pay.curAuditors && pay.curAuditors.findIndex(x => { return x.aid === ctx.session.sessionUser.accountId; }) >= 0) { %>
                             <a href="<%- '/tender/' + pay.tid + '/pay/' + pay.phase_order %>" target="_blank" class="btn <%- auditConst.info[pay.audit_status].btnClass %> btn-sm"><%- auditConst.info[pay.audit_status].btnTitle %></a>
                             <% } else { %>
-                            <span class="<%- auditConst.info[pay.audit_status].btnClass %>"><%- auditConst.info[pay.audit_status].btnTitle %></span>
+                            <span class="<%- auditConst.info[pay.audit_status].class %>"><%- auditConst.info[pay.audit_status].title %></span>
                             <% } %>
                         </td>
                         <td> <%- pay.memo %></td>
@@ -86,3 +86,8 @@
         </div>
     </div>
 </div>
+<script>
+    const phasePays = JSON.parse('<%- JSON.stringify(phasePays) %>');
+    const auditType = JSON.parse('<%- JSON.stringify(auditType) %>');
+    const auditConst = JSON.parse('<%- JSON.stringify(auditConst) %>');
+</script>

+ 48 - 6
app/view/phase_pay/modal.ejs

@@ -30,25 +30,25 @@
             <div class="modal-footer">
                 <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
                 <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">关闭</button>
-                <button type="submit" class="btn btn-sm btn-primary" id="add-qi-ok">确定</button>
+                <button type="submit" class="btn btn-sm btn-primary">确定</button>
             </div>
         </form>
     </div>
 </div>
 <div class="modal" id="edit-qi" data-backdrop="static" aria-modal="true" role="dialog">
     <div class="modal-dialog" role="document">
-        <div class="modal-content" action="pay/save" method="POST" onsubmit="return checkEditValid();">
+        <form class="modal-content" action="pay/save" method="POST" onsubmit="return checkEditValid();">
             <div class="modal-header">
                 <h5 class="modal-title">编辑</h5>
             </div>
             <div class="modal-body">
                 <div class="form-group form-group-sm">
                     <label>支付期</label>
-                    <input class="form-control form-control-sm" value="第 <%- (phasePays.length + 1) %> 期" type="text" readonly="">
+                    <input class="form-control form-control-sm" id="edit-name" value="第 <%- (phasePays.length + 1) %> 期" type="text" readonly="">
                 </div>
                 <div class="form-group form-group-sm">
                     <label>支付年月</label>
-                    <input class="datepicker-here form-control form-control-sm" name="date" placeholder="点击选择年月" data-view="months" data-min-view="months" data-date-format="yyyy-MM" data-language="zh" type="text">
+                    <input class="datepicker-here form-control form-control-sm" id="edit-date" name="date" placeholder="点击选择年月" data-view="months" data-min-view="months" data-date-format="yyyy-MM" data-language="zh" type="text">
                 </div>
                 <div class="form-group form-group-sm">
                     <label>支付期备注</label>
@@ -59,7 +59,32 @@
                 <input type="hidden" value="" name="phase_id">
                 <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
                 <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">关闭</button>
-                <button type="button" class="btn btn-sm btn-primary" id="add-qi-ok">确定</button>
+                <button type="submit" class="btn btn-sm btn-primary">确定</button>
+            </div>
+        </form>
+    </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">审批流程</h5>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <div class="col-4 modal-height-500" style="overflow: auto">
+                        <div class="card mt-3">
+                            <ul class="list-group list-group-flush" id="auditor-list">
+                            </ul>
+                        </div>
+                    </div>
+                    <div class="col-8 modal-height-500" style="overflow: auto" id="audit-list">
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
             </div>
         </div>
     </div>
@@ -80,6 +105,23 @@
         }
     }
     const checkEditValid = function() {
-
+        if ($('[name=date]', '#edit-qi').val() == '') {
+            toastr.error('请选择计量年月');
+            return false;
+        }
     }
+    $('.edit-pay').on('click', function () {
+        const id = $(this).data('id');
+        const phasePay = phasePays.find(x => { return x.id === id; });
+        if (!phasePay) return;
+
+        const editDate = $('#edit-date').datepicker().data('datepicker');
+        $('#edit-name').val('第 ' + phasePay.phase_order + ' 期');
+        if (phasePay.phase_date) {
+            editDate.selectDate(new Date(phasePay.phase_date));
+        }
+        $('[name=memo]', '#edit-qi').html(phasePay.memo);
+        $('[name=phase_id]', '#edit-qi').val(phasePay.id);
+        $('#edit-qi').modal('show');
+    })
 </script>

+ 2 - 1
app/view/phase_pay/sub_menu_list.ejs

@@ -1,3 +1,4 @@
 <nav-menu title="返回" url="/tender/<%= ctx.tender.id %>/pay" tclass="text-primary" ml="1" icon="fa-chevron-left"></nav-menu>
 <nav-menu title="支付明细" url="/tender/<%= ctx.tender.id %>/pay/<%= ctx.phasePay.order + '/detail'%>" ml="3" active="<%= (ctx.url.indexOf('detail') >= 0 ? 1 : -1) %>"></nav-menu>
-<nav-menu title="输出报表" url="/tender/<%= ctx.tender.id %>/pay/<%= ctx.phasePay.order + '/report'%>" ml="3" active="<%= (ctx.url.indexOf('report') >= 0 ? 1 : -1) %>"></nav-menu>
+<nav-menu title="输出报表" url="/tender/<%= ctx.tender.id %>/pay/<%= ctx.phasePay.order + '/report'%>" ml="3" active="<%= (ctx.url.indexOf('report') >= 0 ? 1 : -1) %>"></nav-menu>
+<% include ./audit_btn.ejs %>

+ 20 - 11
app/view/shares/tender_select_modal.ejs

@@ -18,18 +18,27 @@
                         <h5>已选标段 </h5>
                         <div class="modal-height-300" id="ts-result-spread">
                         </div>
-                        <div id="tender-select-option" style="display: none;">
-                            <div class="form-check form-check-inline">
-                                <input class="form-check-input" type="checkbox" id="ts-cover">
-                                <label class="form-check-label" for="ts-cover">覆盖数据</label>
+                        <div id="tender-select-option">
+                            <div id="ledger-select-option" type="ledger" style="display: none;">
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="ts-subUp">
+                                    <label class="form-check-label" for="ts-subUp">总包无签约单价时使用分包单价</label>
+                                </div>
                             </div>
-                            <div class="form-check form-check-inline">
-                                <input class="form-check-input" type="checkbox" id="ts-ignore">
-                                <label class="form-check-label" for="ts-ignore">以本标段清单为准</label>
-                            </div>
-                            <div class="form-check form-check-inline">
-                                <input class="form-check-input" type="checkbox" id="ts-change" checked>
-                                <label class="form-check-label" for="ts-change">含变更</label>
+                            <div id="stage-select-option" type="stage" style="display: none;">
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="ts-cover">
+                                    <label class="form-check-label" for="ts-cover">覆盖数据</label>
+                                </div>
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="ts-ignore">
+                                    <label class="form-check-label" for="ts-ignore">以本标段清单为准</label>
+                                </div>
+                                <div class="form-check form-check-inline">
+                                    <input class="form-check-input" type="checkbox" id="ts-change" checked>
+                                    <label class="form-check-label" for="ts-change">含变更</label>
+                                </div>
+
                             </div>
                         </div>
                     </div>

+ 12 - 0
app/view/stage/gather.ejs

@@ -45,6 +45,18 @@
                 <div class="d-inline-block">
                     <button href="#zjhj" class="btn btn-sm btn-light text-primary" data-toggle="modal" data-target="#zjhj">章节合计</button>
                 </div>
+                <div class="d-inline-block">
+                    <div class="dropdown">
+                        <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+                            <i class="fa fa-list-ol"></i> 数据过滤
+                        </button>
+                        <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
+                            <a class="dropdown-item" name="showData" tag="all" href="javascript: void(0);">显示全部</a>
+                            <a class="dropdown-item" name="showData" tag="curMeasure" href="javascript: void(0);">只显示本期计量</a>
+                            <a class="dropdown-item" name="showData" tag="endMeasure" href="javascript: void(0);">只显示截止本期计量</a>
+                        </div>
+                    </div>
+                </div>
                 <% if (ctx.app.config.is_debug) { %>
                 <div class="d-inline-block ml-3">
                     <a id="exportExcel" class="btn btn-primary btn-sm" href="javascript: void(0)">导出清单汇总Excel</a>

+ 1 - 0
app/view/tender/shenpi.ejs

@@ -32,6 +32,7 @@
                                             <% } %>
                                         </div>
                                     </div>
+                                    <% console.log(sp, sp.status) %>
                                     <div class="alert alert-warning"><%- shenpi.sp_status_list[sp.status].name %>:<%- shenpi.sp_status_list[sp.status].msg %></div>
                                     <div class="lc-show">
                                     <% if (sp.status === shenpi.sp_status.gdspl) { %>

+ 6 - 0
config/web.js

@@ -695,6 +695,7 @@ const JsFiles = {
                 mergeFiles: [
                     '/public/js/component/menu.js',
                     '/public/js/sub_menu.js',
+                    '/public/js/phase_pay_list.js',
                 ],
                 mergeFile: 'phase_pay_list',
             },
@@ -703,13 +704,18 @@ const JsFiles = {
                     '/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js',
                     '/public/js/decimal.min.js',
                     '/public/js/math.min.js',
+                    '/public/js/axios/axios.min.js', '/public/js/js-xlsx/jszip.min.js', '/public/js/file-saver/FileSaver.min.js',
                 ],
                 mergeFiles: [
+                    '/public/js/div_resizer.js',
+                    '/public/js/shares/ali_oss.js',
                     '/public/js/component/menu.js',
                     '/public/js/sub_menu.js',
                     '/public/js/spreadjs_rela/spreadjs_zh.js',
                     '/public/js/path_tree.js',
+                    '/public/js/shares/tools_att.js',
                     '/public/js/shares/sjs_setting.js',
+                    '/public/js/shares/phase_pay_audit.js',
                     '/public/js/phase_pay_detail.js',
                 ],
                 mergeFile: 'phase_pay_detail',