فهرست منبع

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

Tony Kang 2 سال پیش
والد
کامیت
5a21396105

+ 3 - 0
app/controller/payment_controller.js

@@ -605,6 +605,9 @@ module.exports = app => {
                     case 'del-audit':
                         responseData.data = await ctx.service.paymentShenpiAudit.removeAudit(data);
                         break;
+                    case 'update-report':
+                        responseData.data = await ctx.service.paymentTenderRpt.updateReport(data);
+                        break;
                     default: throw '参数有误';
                 }
                 ctx.body = responseData;

+ 122 - 5
app/public/js/payment_process.js

@@ -49,7 +49,7 @@ $(function () {
             const code = $(this).attr('data-trid');
             let html = '';
             if (newVal && newVal === oldSearchVal) {
-                accountList.filter(item => item && item.id !== cur_uid && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
+                accountList.filter(item => item && (!cur_uid || item.id !== cur_uid) && (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>
@@ -66,7 +66,7 @@ $(function () {
                         </a> ${group.groupName}</dt>
                         <div class="dd-content" data-toggleid="${idx}">`;
                         group.groupList.forEach(item => {
-                            if (item.id !== cur_uid) {
+                            if (!cur_uid || item.id !== cur_uid) {
                                 html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
                                     <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
                                             class="ml-auto">${item.mobile || ''}</span></p>
@@ -139,6 +139,58 @@ $(function () {
     function makeProcess(tr_id) {
         const trInfo = _.find(tenderRptList, { id: tr_id });
         $('#process_set').find('.card-title').text(trInfo.rpt_name);
+        cur_uid = trInfo.uid;
+        let html = '<div class="mr-2">上报人<b class="text-danger">*</b></div>';
+        let divhtml = '';
+        accountGroup.forEach((group, idx) => {
+            let didivhtml = '';
+            if(group) {
+                group.groupList.forEach(item => {
+                    didivhtml += item.id !== cur_uid ? '<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';
+            }
+        });
+        if (trInfo.uid) {
+            const userInfo = _.find(accountList, { id: trInfo.uid });
+            html += '<div class="mr-2">'+ userInfo.name +'</div>\n' +
+                '<div><span class="d-inline-block">\n' +
+                '                                                <div class="dropdown text-right">\n' +
+                '                                                    <button class="btn btn-sm btn-primary dropdown-toggle" type="button" id="' + tr_id + '_dropdownMenuButton1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
+                '                                                        替换\n' +
+                '                                                    </button>\n' +
+                '                                                    <div class="dropdown-menu dropdown-menu-right" id="' + tr_id + '_dropdownMenu1" aria-labelledby="' + tr_id + '_dropdownMenuButton1" style="width:220px">\n' +
+                '                                                        <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
+                '                                                                                     placeholder="姓名/手机 检索" autocomplete="off" data-trid="' + tr_id + '"></div>\n' +
+                '                                                        <dl class="list-unstyled book-list">\n' + divhtml +
+                '                                                        </dl>\n' +
+                '                                                    </div>\n' +
+                '                                                </div>\n' +
+                '                                            </span>\n' +
+                '</div>';;
+        } else {
+            html +='<div><span class="d-inline-block">\n' +
+                '                                                <div class="dropdown text-right">\n' +
+                '                                                    <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button" id="' + tr_id + '_dropdownMenuButton2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
+                '                                                        选择审批人\n' +
+                '                                                    </button>\n' +
+                '                                                    <div class="dropdown-menu dropdown-menu-right" id="' + tr_id + '_dropdownMenu2" aria-labelledby="' + tr_id + '_dropdownMenuButton2" style="width:220px">\n' +
+                '                                                        <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
+                '                                                                                     placeholder="姓名/手机 检索" autocomplete="off" data-trid="' + tr_id + '"></div>\n' +
+                '                                                        <dl class="list-unstyled book-list">\n' + divhtml +
+                '                                                        </dl>\n' +
+                '                                                    </div>\n' +
+                '                                                </div>\n' +
+                '                                            </span>\n' +
+                '</div>';
+        }
+        $('#rpt_user').html(html);
         $('#process_set input[name="tender_process"][value="'+ trInfo.sp_status +'"]').prop('checked', true);
         const spt = sp_status_list[trInfo.sp_status];
         $('#process_set').find('.alert-warning').text(spt.name + ':' + spt.msg);
@@ -192,8 +244,8 @@ $(function () {
         });
     });
 
-    // 选中审批人
-    $('body').on('click', 'dl dd', function () {
+    // 选中审批流里的审批
+    $('body').on('click', '.lc-show dl dd', function () {
         const id = parseInt($(this).data('id'));
         if (!id) return;
 
@@ -244,6 +296,72 @@ $(function () {
         });
     });
 
+    // 选中上报人
+    $('body').on('click', '#rpt_user dl dd', function () {
+        const id = parseInt($(this).data('id'));
+        if (!id) return;
+        console.log(id);
+
+        let this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
+        if (!this_tr_id) this_tr_id = $(this).parents('.dropdown').attr('data-trid');
+        const user = _.find(accountList, function (item) {
+            return item.id === id;
+        });
+        if (!user) toastr.error('用户列表不存在此人');
+        const prop = {
+            tr_id: this_tr_id,
+            uid: id,
+            type: 'update-report',
+        };
+        postData('/payment/' + tenderId + '/process/save', prop, function (result) {
+            tenderRptList = result.list;
+            if (result.updateRows) {
+                toastr.warning('上报人不能同时作为审批人,审批流已移除 ' + user.name);
+            }
+            makeProcess(this_tr_id);
+        });
+        //
+        // const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
+        // if (this_status === sp_status.gdspl) {
+        //     // 判断是否已存在审批人
+        //     const aid_num = $(this).parents('ul').find('.remove-audit').length;
+        //     for (let i = 0; i < aid_num; i++) {
+        //         const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
+        //         if (aid === id) {
+        //             toastr.warning('该审核人已存在,请勿重复添加');
+        //             return;
+        //         }
+        //     }
+        //
+        // }
+        // const prop = {
+        //     status: this_status,
+        //     tr_id: this_tr_id,
+        //     audit_id: id,
+        //     type: 'add-audit',
+        // };
+        // const _self = $(this);
+        // postData('/payment/' + tenderId + '/process/save', prop, function (data) {
+        //     if (this_status === sp_status.gdspl) {
+        //         _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
+        //     }
+        //     _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
+        //         '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
+        //         '                                                            <a href="javascript:void(0);" class="btn-sm text-danger px-1" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-remove"></i></a>\n' +
+        //         '                                                            <div class="dropdown-menu">\n' +
+        //         '                                                                <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
+        //         '                                                                <div class="dropdown-divider"></div>\n' +
+        //         '                                                                <div class="px-2 py-1 text-center">\n' +
+        //         '                                                                    <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
+        //         '                                                                    <button class="btn btn-sm btn-secondary">取消</button>\n' +
+        //         '                                                                </div>\n' +
+        //         '                                                            </div>\n' +
+        //         '                                                        </span> ' +
+        //         '                                            </span></span></span>\n');
+        //     // <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ user.id +'"><i class="fa fa-remove"></i></a></span> </span>');
+        // });
+    });
+
     // 移除审批人
     $('body').on('click', '.remove-audit', function () {
         const id = parseInt($(this).data('id'));
@@ -369,7 +487,6 @@ $(function () {
         if ($(this).is(':checked') && parseInt($(this).val()) === -1) {
             $(this).prop('checked', false);
             const index = $("#rpt_table input").index(this);
-            console.log(rptProjectList[index]);
             // 循环选中当前子项值
             checkedRptProjectList(rptProjectList[index].items);
         }

+ 15 - 0
app/service/payment_detail.js

@@ -229,6 +229,21 @@ module.exports = app => {
             const result = await this.db.queryOne(sql, params);
             return result ? result.count : 0;
         }
+
+        async updateReport(transaction, tr_id, uid) {
+            const details = await this.db.select(this.tableName, {
+                column: ['id', 'in_time', 'tr_id', 'uid', 'status', 'order', 'times', 'code', 's_time'],
+                where: { tr_id },
+                orders: [['order', 'desc']],
+            });
+            if (details && details.length > 0) {
+                const detailInfo = details[0];
+                if (detailInfo.status === auditConst.status.uncheck || detailInfo.status === auditConst.status.checkNo) {
+                    return await transaction.update(this.tableName, { id: detailInfo.id, uid });
+                }
+            }
+            return true;
+        }
     }
     return PaymentDetail;
 };

+ 4 - 0
app/service/payment_shenpi_audit.js

@@ -85,6 +85,10 @@ module.exports = app => {
         async delDataFromtrids(transaction, tr_ids) {
             return await transaction.delete(this.tableName, { tr_id: tr_ids });
         }
+
+        async removeAuditByReport(transaction, tr_id, audit_id) {
+            return await transaction.delete(this.tableName, { tr_id, audit_id });
+        }
     }
 
     return PaymentShenpiAudit;

+ 17 - 1
app/service/payment_tender.js

@@ -23,12 +23,28 @@ module.exports = app => {
                 const params1 = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.session.sessionProject.id];
                 return await this.db.query(sql1, params1);
             }
+            const typeValues = [];
+            const projectInfo = await this.ctx.service.project.getDataById(this.ctx.session.sessionProject.id);
+            const modes = projectInfo.payment_setting ? JSON.parse(projectInfo.payment_setting) : _.cloneDeep(paymentConst.setting_modes);
+            for (const m in paymentConst.setting_modes) {
+                if (!modes[m]) modes[m] = _.cloneDeep(paymentConst.setting_modes[m]);
+                if (modes[m].checked) {
+                    typeValues.push(modes[m].value);
+                }
+            }
+            if (typeValues.length === 0) {
+                return -1;
+            }
             const sql = 'SELECT pt.*, pa.name as user_name FROM ?? as pt LEFT JOIN ?? as pa ON pt.`uid` = pa.`id` WHERE pid = ? AND pt.`uid` = ? ' +
+                'OR pt.`id` in (SELECT pr.`tender_id` FROM ?? as pr WHERE pr.`uid` = ? AND pr.`type` IN (' + this.ctx.helper.getInArrStrSqlFilter(typeValues) + '))' +
+                'OR pt.`id` in (SELECT pd.`tender_id` FROM ?? as pd WHERE pd.`uid` = ?)' +
                 'OR pt.`id` in (SELECT pda.`tender_id` FROM ?? as pda LEFT JOIN ?? as pd ON pda.`tender_id` = pd.`tender_id` ' +
                 'WHERE pd.`status` != ' + auditConst.status.uncheck + ' AND pda.`aid` = ?)' +
                 'OR pt.`id` in (SELECT pra.`tender_id` FROM ?? as pra LEFT JOIN ?? as pd ON pra.`tender_id` = pd.`tender_id` ' +
-                'WHERE (pd.`status` != ' + auditConst.status.uncheck + ' OR pd.`status` !=' + auditConst.status.checkNo + ') AND pra.`uid` = ?)';
+                'WHERE pd.`status` != ' + auditConst.status.uncheck + ' AND pd.`status` !=' + auditConst.status.checkNo + ' AND pra.`uid` = ?)';
             const params = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.session.sessionProject.id, uid,
+                this.ctx.service.paymentTenderRpt.tableName, uid,
+                this.ctx.service.paymentDetail.tableName, uid,
                 this.ctx.service.paymentDetailAudit.tableName, this.ctx.service.paymentDetail.tableName, uid,
                 this.ctx.service.paymentRptAudit.tableName, this.ctx.service.paymentDetail.tableName, uid];
             return await this.db.query(sql, params);

+ 37 - 7
app/service/payment_tender_rpt.js

@@ -28,10 +28,11 @@ module.exports = app => {
                 return -1;
             }
             const sql = 'SELECT * FROM ?? WHERE `tender_id` = ? AND `type` IN (' + this.ctx.helper.getInArrStrSqlFilter(typeValues) + ')' +
-                ' AND (`id` in (SELECT pda.`tr_id` FROM ?? as pda LEFT JOIN ?? as pd ON pda.`tr_id` = pd.`tr_id` WHERE pd.`status` != ' + auditConst.status.uncheck + ' AND pda.`aid` = ?)' +
-                ' OR `id` in (SELECT pra.`tr_id` FROM ?? as pra LEFT JOIN ?? as pd ON pra.`tr_id` = pd.`tr_id` WHERE (pd.`status` != ' + auditConst.status.uncheck + ' OR pd.`status` != ' + auditConst.status.checkNo + ') AND pra.`uid` = ?))' +
+                ' AND `uid` = ?' +
+                ' OR `id` in (SELECT pda.`tr_id` FROM ?? as pda LEFT JOIN ?? as pd ON pda.`tr_id` = pd.`tr_id` WHERE pd.`status` != ' + auditConst.status.uncheck + ' AND pda.`aid` = ?)' +
+                ' OR `id` in (SELECT pra.`tr_id` FROM ?? as pra LEFT JOIN ?? as pd ON pra.`tr_id` = pd.`tr_id` WHERE pd.`status` != ' + auditConst.status.uncheck + ' AND pd.`status` != ' + auditConst.status.checkNo + ' AND pra.`uid` = ?)' +
                 ' ORDER BY FIELD(`type`, 1, 0), id asc';
-            const params = [this.tableName, tid, this.ctx.service.paymentDetailAudit.tableName, this.ctx.service.paymentDetail.tableName, uid,
+            const params = [this.tableName, tid, uid, this.ctx.service.paymentDetailAudit.tableName, this.ctx.service.paymentDetail.tableName, uid,
                 this.ctx.service.paymentRptAudit.tableName, this.ctx.service.paymentDetail.tableName, uid];
             return await this.db.query(sql, params);
         }
@@ -46,7 +47,7 @@ module.exports = app => {
             if (typeValues.length === 0) {
                 return -1;
             }
-            const sql = 'SELECT ptr.*, pa.name as user_name FROM ?? as ptr LEFT JOIN ?? as pa ON ptr.`uid` = pa.`id` WHERE ptr.`tender_id` = ?  AND ptr.`type` IN (' + this.ctx.helper.getInArrStrSqlFilter(typeValues) + ')';
+            const sql = 'SELECT ptr.*, pa.name as user_name FROM ?? as ptr LEFT JOIN ?? as pa ON ptr.`create_uid` = pa.`id` WHERE ptr.`tender_id` = ?  AND ptr.`type` IN (' + this.ctx.helper.getInArrStrSqlFilter(typeValues) + ')';
             const params = [this.tableName, this.ctx.service.projectAccount.tableName, id];
             return await this.db.query(sql, params);
         }
@@ -113,7 +114,7 @@ module.exports = app => {
                             tender_id: tid,
                             rpt_id: rpt.id,
                             rpt_name: rpt.name,
-                            uid: this.ctx.session.sessionUser.accountId,
+                            create_uid: this.ctx.session.sessionUser.accountId,
                             in_time: new Date(),
                         });
                     }
@@ -138,7 +139,7 @@ module.exports = app => {
                             tender_id: tid,
                             rpt_id: id,
                             rpt_name: info.name,
-                            uid: this.ctx.session.sessionUser.accountId,
+                            create_uid: this.ctx.session.sessionUser.accountId,
                             in_time: new Date(),
                         });
                     }
@@ -176,7 +177,7 @@ module.exports = app => {
             for (const rpt of paymentConst.const_rpt_list) {
                 insertData.push({
                     tender_id: tid,
-                    uid,
+                    create_uid: uid,
                     rpt_id: rpt.rpt_id,
                     rpt_name: rpt.rpt_name,
                     type: 1,
@@ -216,6 +217,35 @@ module.exports = app => {
                 throw err;
             }
         }
+
+        async updateReport(data) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const tr_id = data.tr_id;
+                if (!tr_id) throw '参数有误';
+                const trInfo = await this.getDataById(tr_id);
+                if (!trInfo) throw '表单不存在';
+                const userInfo = await this.ctx.service.projectAccount.getDataById(data.uid);
+                if (!userInfo) throw '用户不存在';
+
+                const updateData = {
+                    id: trInfo.id,
+                    uid: data.uid,
+                };
+                await transaction.update(this.tableName, updateData);
+                // 判断是否存在待上报或重新上报的表单详情,有则更改原报人
+                const result1 = await this.ctx.service.paymentDetail.updateReport(transaction, tr_id, data.uid);
+                // 判断固定审批流或固定终审是否存在上报人,有则移除
+                const result2 = await this.ctx.service.paymentShenpiAudit.removeAuditByReport(transaction, tr_id, data.uid);
+                await transaction.commit();
+                let tenderRptList = await this.getProcessList(this.ctx.tender.id);
+                tenderRptList = this._.filter(tenderRptList, { type: 0, is_del: 0 });
+                return { list: tenderRptList, updateRows: result2.affectedRows };
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
     }
     return paymentTenderRpt;
 };

+ 6 - 18
app/view/payment/process.ejs

@@ -90,6 +90,11 @@
                                             <div class="card" id="process_set" <% if (tenderRptList.length === 0) { %>style="display: none" <% } %>>
                                                 <div class="card-body">
                                                     <h5 class="card-title"></h5>
+                                                    <div  class="my-3">
+                                                        <div class="d-flex justify-content-start align-items-center mt-3" id="rpt_user">
+                                                            <div class="mr-2">上报人<b class="text-danger">*</b></div>
+                                                        </div>
+                                                    </div>
                                                     <div class="form-group">
                                                         <div class="form-group form-check">
                                                             <% for (const st in shenpi.sp_status_list) { %>
@@ -102,23 +107,6 @@
                                                     </div>
                                                     <div class="alert alert-warning mb-0 mt-3" role="alert"></div>
                                                     <div class="lc-show mt-3"></div>
-                                                    <!--<div class="d-flex justify-content-start align-items-center mt-3">-->
-                                                        <!--<div class="mr-2"><a href="#">一审</a></div>-->
-                                                        <!--<div>-->
-                                                            <!--<select class="form-control form-control-sm" id="exampleFormControlSelect1">-->
-                                                                <!--<option>选择审批人</option>-->
-                                                            <!--</select>-->
-                                                        <!--</div>-->
-                                                    <!--</div>-->
-                                                    <!--<div class="d-flex justify-content-start align-items-center mt-3">-->
-                                                        <!--<div class="mr-2"><a href="#">一审</a></div>-->
-                                                        <!--<div class="mr-2">邓莹洁</div>-->
-                                                        <!--<div><i class="fa fa-remove text-danger" aria-hidden="true"></i></div>-->
-                                                    <!--</div>-->
-                                                    <!--<div class="d-flex justify-content-start align-items-center mt-3">-->
-                                                        <!--<div class="mr-2"><a href="#"><i class="fa fa-plus" aria-hidden="true"></i></a></div>-->
-                                                        <!--<div><a href="#">添加流程</a></div>-->
-                                                    <!--</div>-->
                                                 </div>
                                             </div>
                                         </div>
@@ -139,7 +127,7 @@
     const sp_status_list = JSON.parse('<%- JSON.stringify(shenpi.sp_status_list) %>');
     const accountGroup = JSON.parse(unescape('<%- escape(JSON.stringify(accountGroup)) %>'));
     const accountList = JSON.parse(unescape('<%- escape(JSON.stringify(accountList)) %>'));
-    const cur_uid = parseInt('<%- ctx.tender.uid %>');
+    let cur_uid = null;
     let tenderRptList = JSON.parse(unescape('<%- escape(JSON.stringify(tenderRptList)) %>'));
     const rptProjectList = JSON.parse(unescape('<%- escape(JSON.stringify(rptProjectList)) %>'));
     console.log(rptProjectList);