Browse Source

1. 合同支付,附件
2. 合同支付,删除期,编辑期
3. 合同支付,上报相关

MaiXinRong 5 months ago
parent
commit
c42fb76fb6

+ 3 - 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', // 独立合同支付
 };
 
 // 期审批流程

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

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

+ 134 - 58
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 => {
 
@@ -81,12 +84,48 @@ module.exports = app => {
             }
         }
 
-        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(ctx.request.header.referer);
+            }
         }
 
-        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) {
+                console.log(err);
+                this.log(err);
+                ctx.redirect('/tender/' + ctx.tender.id + '/pay');
+            }
         }
 
         async detail(ctx) {
@@ -96,6 +135,15 @@ module.exports = app => {
                 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 renderData = {
                     pays,
                     calcBase,
@@ -103,7 +151,10 @@ 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,
                 };
                 await this.layout('phase_pay/detail.ejs', renderData, 'phase_pay/detail_modal.ejs');
             } catch (err) {
@@ -113,6 +164,35 @@ module.exports = app => {
             }
         }
 
+        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, '读取合同支付数据错误');
+            }
+        }
+
         async detailUpdate(ctx) {
             try {
                 const data = JSON.parse(ctx.request.body.data);
@@ -168,34 +248,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,59 +283,56 @@ 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 {
+            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) {
+                this.log(error);
+                ctx.ajaxErrorBody(error, '删除附件失败');
+            }
+        }
 
-                const bonus = await ctx.service.stageBonus.getStageDataById(data.b_id);
-                if (!bonus || !bonus.proof_file || !bonus.proof_file[data.index]) throw '删除的文件不存在';
+        async auditUpdate(ctx) {
+            try {
+                if (!ctx.session.sessionUser.accountId !== ctx.phasePay.create_user_id) throw '您无权进行操作';
+                if (ctx.phasePay.status !== audit.common.status.uncheck && ctx.phasePay.status !== audit.common.status.checkNo) throw '已上报,不可修改审批流程';
 
-                const fileInfo = bonus.proof_file[data.index];
-                if (fileInfo.uid !== ctx.session.sessionUser.accountId) throw '您无权删除该文件';
+                const data = JSON.parse(ctx.request.body.data);
+                await ctx.service.phasePayAudit.saveAudit(ctx.phasePay, data);
+                const auditors = await ctx.service.phasePayAudit.getUniqUserGroup(ctx.phasePay.id, ctx.phasePay.audit_times);
+                ctx.body = { err: 0, msg: '', data: auditors };
+            } catch (err) {
+                ctx.log(err);
+                ctx.body = this.ajaxErrorBody(err, '保存审批人数据失败');
+            }
+        }
 
-                const deleteFilePermission = PermissionCheck.delFile(this.ctx.session.sessionUser.permission);
-                if (ctx.stage.status === auditConst.status.checked && !fileInfo.renew && !deleteFilePermission) throw '不可删除该文件';
+        async auditSave(ctx) {
+            try {
+                if (!ctx.session.sessionUser.is_admin) throw '您无权进行操作';
+                if (ctx.phasePay.status === audit.common.status.checked) 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;
-                }
-                ctx.body = {err: 0, msg: '', data: bonus.proof_file};
+                const data = JSON.parse(ctx.request.body.data);
+                await ctx.service.phasePayAudit.saveAudit(ctx.phasePay, data);
+                const auditors = await ctx.service.phasePayAudit.getUniqUserGroup(ctx.phasePay.id, ctx.phasePay.audit_times);
+                ctx.body = { err: 0, msg: '', data: auditors };
             } catch (err) {
-                this.log(err);
-                this.ctx.ajaxErrorBody(err, '删除文件失败');
+                ctx.log(err);
+                ctx.body = this.ajaxErrorBody(err, '保存审批人数据失败');
             }
         }
     }

+ 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;
+
             this.phasePay = phasePay;
             yield next;
         } catch (err) {

+ 136 - 0
app/public/js/phase_pay_audit.js

@@ -0,0 +1,136 @@
+'use strict';
+
+$(document).ready(() => {
+    const auditFlow = {
+        getAuditTypeText: function (type) {
+            if (type === auditType.key.common) return '';
+            return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
+        },
+        getSimpleAuditFlow: function(groups) {
+            const html = [];
+            for (const group of groups) {
+                html.push(`<li class="list-group-item" data-auditorid="${group[0].audit_id}">`);
+                html.push(`<i class="fa ${(group[0].is_final ? 'fa-stop-circle' : 'fa-chevron-circle-down')}"></i>`);
+                html.push(`${group[0].name} <small class="text-muted">${group[0].role}</small>`);
+                html.push('<span class="pull-right">${group[0].flow_name}</span>');
+                html.push('</li>');
+            }
+            return html.join('');
+        },
+        getStartAuditFlow: function(groups) {
+            const html = [];
+            for (const group of groups) {
+                if (group[0].audit_order === 0) continue;
+                html.push('<li class="list-group-item d-flex" auditorId="'+ group[0].audit_id +'">');
+                html.push(`<div class="col-auto">${group[0].audit_order}</div>`);
+                html.push('<div class="col">');
+                for (const auditor of group) {
+                    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">');
+                if (group[0].audit_type !== auditType.key.common) {
+                    html.push(`<span class="badge badge-pill badge-${auditType.info[group[0].audit_type].class} badge-bg-small"><small>${auditType.info[group[0].audit_type].long}</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 ml-1">移除</a>');
+                }
+                html.push('</div>');
+                html.push('</li>');
+            }
+            return html.join('');
+        },
+        saveAudit: function(data, callback) {
+            postData('audit/save', data, (result) => {
+                callback(result);
+            });
+        }
+    };
+    // 搜索
+    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 && userID !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
+                    html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
+                        <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
+                                class="ml-auto">${item.mobile || ''}</span></p>
+                        <span class="text-muted">${item.role || ''}</span>
+                    </dd>`
+                });
+                $('.book-list').empty();
+                $('.book-list').append(html);
+            } else {
+                if (!$('.acc-btn').length) {
+                    accountGroup.forEach((group, idx) => {
+                        if (!group) return;
+                        html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
+                        </a> ${group.groupName}</dt>
+                        <div class="dd-content" data-toggleid="${idx}">`;
+                        group.groupList.forEach(item => {
+                            if (item.id !== userID) {
+                                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) return;
+        auditFlow.saveAudit({ operate: 'add', audit_id: id }, (result) => {
+            $('#auditors').html(auditFlow.getStartAuditFlow(result));
+            $('#auditors-list').html(auditFlow.getSimpleAuditFlow(result));
+        });
+    });
+    // 移除审批人
+    $('body').on('click', '#auditors li a', function () {
+        const li = $(this).parents('li');
+        const data = {
+            operate: 'del',
+            audit_id: parseInt(li.attr('auditorId')),
+        };
+        auditFlow.saveAudit(data, (result) => {
+            $('#auditors').html(auditFlow.getStartAuditFlow(result));
+        });
+    });
+    $('body').on('click', '.remove-audit', function () {
+        const id = parseInt($(this).attr('data-id'));
+        postData('audit/save', { operate: 'del', audit_id: id }, (datas) => {
+            $('#admin-edit-shenpi-list').html(auditFlow.getStartAuditFlow(datas));
+            auditFlow.getStartAuditFlow(datas);
+        });
+    });
+});

+ 84 - 1
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) {
@@ -463,7 +488,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,
@@ -971,6 +995,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',

+ 2 - 0
app/public/js/phase_pay_list.js

@@ -1,6 +1,8 @@
 'use strict';
 
 $(document).ready(() => {
+
+
     // todo 加载审批列表
     $.subMenu({
         menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',

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

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

+ 5 - 0
app/router.js

@@ -397,7 +397,12 @@ module.exports = app => {
     app.post('/tender/:id/pay/del', sessionAuth, tenderCheck, 'payController.del');
     app.post('/tender/:id/pay/save', sessionAuth, tenderCheck, 'payController.save');
     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/audit/update', sessionAuth, tenderCheck, phasePayCheck, 'payController.auditUpdate');
+    app.post('/tender/:id/pay/:order/audit/save', sessionAuth, tenderCheck, phasePayCheck, projectManagerCheck, 'payController.auditUpdate');
+    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.get('/tender/:id/measure/stage/:order/change', sessionAuth, tenderCheck, uncheckTenderCheck, stageCheck, 'stageController.change');

+ 26 - 9
app/service/phase_pay.js

@@ -323,18 +323,17 @@ 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 = [];
+            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.audit_sort === phasePay.curAuditors[0].audit_sort; });
             phasePay.flowAuditorIds = phasePay.curAuditors.map(x => { return x.audit_id; });
+            phasePay.nextAuditors = phasePay.curAuditors.length > 0 ? phasePay.auditors.filter(x => { return x.audit_sort === phasePay.curAuditors[0].audit_sort + 1; }) : [];
+            phasePay.nextAuditorIds = this._.map(phasePay.nextAuditors, 'audit_id');
+            phasePay.auditorGroups = this.ctx.helper.groupAuditors(phasePay.auditors, 'audit_sort');
+            phasePay.userGroups = this.ctx.helper.groupAuditorsUniq(phasePay.auditorGroups, 'audit_order');
+            phasePay.finalAuditorIds = phasePay.userGroups.length > 1 ? phasePay.userGroups[phasePay.userGroups.length - 1].map(x => { return x.audit_id; }) : [];
         }
         async doCheckPhase(phasePay) {
             await this.loadUser(phasePay);
@@ -368,6 +367,24 @@ module.exports = app => {
                 phasePay.canCheck = phasePay.readOnly && stage.curAuditorIds.indexOf(accountId) > 0;
             }
         }
+
+        async delete(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 });
+                // todo 不确定是否真删除,是否需要防止用户找回附件 ?
+                // await conn.delete(this.ctx.service.phasePayAtt.tableName, { phase_id: id });
+                await conn.delete(this.ctx.service.phasePayAudit.tableName, { phase_id: id });
+            } 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});
+        }
     }
 
     return 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;
+};

+ 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="#audit-start" class="btn btn-primary btn-sm btn-block">上报审批</a>
+        <% } else { %>
+            <a id="sub-sp-btn" href="javascript: void(0);" data-toggle="modal" data-target="#audit-start" 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>

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

@@ -0,0 +1,86 @@
+<% 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="audit-start" 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++) { %>
+                            <li class="list-group-item d-flex" auditorId="<%- ctx.phasePay.auditorGroups[i][0].aid %>">
+                                <div class="col-auto"><%- i+1 %></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) { %>
+                                    <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="stage-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>
+<% } %>
+<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) %>');
+</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 %>

+ 3 - 0
app/view/phase_pay/index.ejs

@@ -86,3 +86,6 @@
         </div>
     </div>
 </div>
+<script>
+    const phasePays = JSON.parse('<%- JSON.stringify(phasePays) %>');
+</script>

+ 24 - 7
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,9 +59,9 @@
                 <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>
-        </div>
+        </form>
     </div>
 </div>
 <script>
@@ -80,6 +80,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 %>

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

+ 5 - 0
config/web.js

@@ -703,13 +703,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/phase_pay_audit.js',
                     '/public/js/phase_pay_detail.js',
                 ],
                 mergeFile: 'phase_pay_detail',