Browse Source

refactor: 变更材料调差审核流程-进度40%

lanjianrong 5 years ago
parent
commit
f7cb89d8ff

+ 25 - 18
app/const/audit.js

@@ -8,7 +8,7 @@
  * @version
  */
 // 台账审批流程
-const ledger = (function () {
+const ledger = (function() {
     const status = {
         uncheck: 1, // 待上报
         checking: 2, // 待审批|审批中
@@ -41,11 +41,11 @@ const ledger = (function () {
     auditStringClass[status.checking] = 'text-warning';
     auditStringClass[status.checked] = 'text-success';
     auditStringClass[status.checkNo] = 'text-warning';
-    return { status, statusString, statusClass, auditString, auditStringClass }
+    return { status, statusString, statusClass, auditString, auditStringClass };
 })();
 
 // 台账修订 审批流程
-const revise = (function () {
+const revise = (function() {
     const status = {
         uncheck: 1, // 待上报
         checking: 2, // 待审批|审批中
@@ -93,7 +93,7 @@ const revise = (function () {
 })();
 
 // 期审批流程
-const stage = (function () {
+const stage = (function() {
     // 流程状态
     const status = {
         uncheck: 1, // 待上报
@@ -184,18 +184,18 @@ const stage = (function () {
         org: 1,
         pre: 2,
     };
-    return { status, statusString, statusClass, statusButton, statusButtonClass, auditString, auditStringClass, auditProgress, auditProgressClass, backType, timesLen: 100 }
+    return { status, statusString, statusClass, statusButton, statusButtonClass, auditString, auditStringClass, auditProgress, auditProgressClass, backType, timesLen: 100 };
 })();
 
 
 // 变更令状态
 const status = {
-    uncheck: 1,     // 待上报
-    checking: 2,    // 审批中
-    checked: 3,     // 审批完成
+    uncheck: 1, // 待上报
+    checking: 2, // 审批中
+    checked: 3, // 审批完成
     // checkNo: 4,     // 审批终止
-    back: 5,        // 重新上报
-    backnew: 6,     // 退回
+    back: 5, // 重新上报
+    backnew: 6, // 退回
 };
 const statusButton = [];
 statusButton[status.uncheck] = '上报';
@@ -233,13 +233,13 @@ statusClass[status.backnew] = 'text-warning';
 
 // 变更令审批人状态
 const auditStatus = {
-    uncheck: 1,     // 待审批
-    checking: 2,    // 审批中或者原报人待上报
-    checked: 3,     // 审批通过或者原报人上报完成
+    uncheck: 1, // 待审批
+    checking: 2, // 审批中或者原报人待上报
+    checked: 3, // 审批通过或者原报人上报完成
     // checkNo: 4,     // 审批终止
-    back: 5,       // 退回到原报人重新上报
-    backnew: 6,    // 退回到上一个审批人
-    checkAgain: 7,    // 重新审批
+    back: 5, // 退回到原报人重新上报
+    backnew: 6, // 退回到上一个审批人
+    checkAgain: 7, // 重新审批
 };
 
 const auditStatusString = [];
@@ -279,12 +279,14 @@ filter.statusString[filter.status.checked] = '已完成';
 // filter.statusString[filter.status.checkNo] = '终止';
 
 // 材料调差审批流程
-const material = (function () {
+const material = (function() {
     const status = {
         uncheck: 1, // 待上报
         checking: 2, // 待审批|审批中
         checked: 3, // 审批通过
-        checkNo: 4, // 审批退回
+        checkNo: 4, // 审批退回原报
+        checkNoPre: 5, // 审批退回上一人
+        checkAgain: 6, // 终审退回  --该状态仅可用于,终审退回时,修改原终审的审批状态,并同时新增一条新的终审审批中记录
     };
     // 流程状态提示
     const statusString = [];
@@ -292,12 +294,17 @@ const material = (function () {
     statusString[status.checking] = '审批中';
     statusString[status.checked] = '审批通过';
     statusString[status.checkNo] = '审批退回';
+    statusString[status.checkNoPre] = '审批退回';
+    statusString[status.checkAgain] = '重新审批';
+
     // 流程状态样式
     const statusClass = [];
     statusClass[status.uncheck] = '';
     statusClass[status.checking] = '';
     statusClass[status.checked] = 'text-success';
     statusClass[status.checkNo] = 'text-warning';
+    statusClass[status.checkNoPre] = 'text-warning';
+    statusClass[status.checkAgain] = 'text-warning';
 
     // 按钮
     const statusButton = [];

+ 3 - 0
app/controller/material_controller.js

@@ -326,6 +326,8 @@ module.exports = app => {
                 // const searchsql = { tid: ctx.tender.id };
                 renderData.fileList = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id, ctx.material.id);
                 renderData.auditors = ctx.material.auditors.map(audit => audit.aid);
+                // renderData.auditors = ctx.material.auditors2.map(audit => audit.aid);
+                renderData.report_id = ctx.material.user_id;
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.material.file);
                 await this.layout('material/file.ejs', renderData, 'material/file_modal.ejs');
             } catch (err) {
@@ -576,6 +578,7 @@ module.exports = app => {
                     checkType: parseInt(ctx.request.body.checkType),
                     opinion: ctx.request.body.opinion,
                 };
+                console.log(ctx.request.body);
                 if (!data.checkType || isNaN(data.checkType)) {
                     throw '提交数据错误';
                 }

+ 1 - 1
app/controller/stage_controller.js

@@ -1003,7 +1003,7 @@ module.exports = app => {
         async checkAudit(ctx) {
             try {
                 this._checkStageCanModify(ctx);
-
+                console.log(ctx.request.body);
                 if (!this.ctx.stage || (this.ctx.stage.status !== auditConst.status.checking && this.ctx.stage.status !== auditConst.status.checkNoPre)) {
                     throw '当前期数据有误';
                 }

+ 8 - 2
app/middleware/material_check.js

@@ -46,11 +46,17 @@ module.exports = options => {
 
             // 读取原报、审核人数据
             material.auditors = yield this.service.materialAudit.getAuditors(material.id, material.times);
+            console.log(material);
+            // if (material.status > 1) {
+            //     material.auditors2 === 2 ? material.auditors : (yield this.service.materialAudit.getAuditors(material.id, material.times - 1));
+            // }
             material.curAuditor = yield this.service.materialAudit.getCurAuditor(material.id, material.times);
 
             // 权限相关
             // todo 校验权限 (标段参与人、分享)
-            const accountId = this.session.sessionUser.accountId, auditorIds = _.map(material.auditors, 'aid'), shareIds = [];
+            const accountId = this.session.sessionUser.accountId,
+                auditorIds = _.map(material.auditors, 'aid'),
+                shareIds = [];
             if (accountId === material.user_id) { // 原报
                 // if (material.curAuditor) {
                 //     material.readOnly = material.status === status.checking && material.curAuditor.user_id === accountId;
@@ -75,7 +81,7 @@ module.exports = options => {
                     material.curOrder = _.max(_.map(material.auditors, 'order'));
                 } else if (material.status === status.checkNo) {
                     const audit = this.service.materialAudit.getDataByCondition({
-                        mid: material.id, times: material.times, status: status.checkNo
+                        mid: material.id, times: material.times, status: status.checkNo,
                     });
                     material.curOrder = audit.order;
                 } else {

+ 15 - 12
app/service/material_audit.js

@@ -32,7 +32,7 @@ module.exports = app => {
          * @param {Number} materialId - 材料调差期id
          * @param {Number} auditorId - 审核人id
          * @param {Number} times - 第几次审批
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getAuditor(materialId, auditorId, times = 1) {
             const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
@@ -48,7 +48,7 @@ module.exports = app => {
          *
          * @param {Number} materialId - 材料调差期id
          * @param {Number} times - 第几次审批
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getAuditors(materialId, times = 1) {
             const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
@@ -70,7 +70,7 @@ module.exports = app => {
          *
          * @param {Number} materialId - 材料调差期id
          * @param {Number} times - 第几次审批
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getCurAuditor(materialId, times = 1) {
             const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
@@ -86,7 +86,7 @@ module.exports = app => {
          *
          * @param {Number} materialId - 材料调差期id
          * @param {Number} times - 第几次审批
-         * @returns {Promise<number>}
+         * @return {Promise<number>}
          */
         async getNewOrder(materialId, times = 1) {
             const sql = 'SELECT Max(??) As max_order FROM ?? Where `mid` = ? and `times` = ?';
@@ -123,7 +123,7 @@ module.exports = app => {
          * @param {Number} materialId - 材料调差期id
          * @param {Number} auditorId - 审核人id
          * @param {Number} times - 第几次审批
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          * @private
          */
         async _syncOrderByDelete(transaction, materialId, order, times) {
@@ -411,10 +411,10 @@ module.exports = app => {
          * @param {Number} materialId - 材料调差期id
          * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
          * @param {Number} times - 第几次审批
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async check(materialId, checkData, times = 1) {
-            if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo) {
+            if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.checkNoPre) {
                 throw '提交数据错误';
             }
             switch (checkData.checkType) {
@@ -424,6 +424,9 @@ module.exports = app => {
                 case auditConst.status.checkNo:
                     await this._checkNo(materialId, checkData, times);
                     break;
+                case auditConst.status.checkNoPre:
+                    await this._checkNoPre(materialId, checkData, times);
+                    break;
                 default:
                     throw '无效审批操作';
             }
@@ -433,7 +436,7 @@ module.exports = app => {
          * 审批
          * @param {Number} materialId - 材料调差期id
          * @param {Number} times - 第几次审批
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async checkAgain(materialId, times = 1) {
             const time = new Date();
@@ -494,7 +497,7 @@ module.exports = app => {
          * 获取审核人需要审核的期列表
          *
          * @param auditorId
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getAuditMaterial(auditorId) {
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`mid`,' +
@@ -512,7 +515,7 @@ module.exports = app => {
          * @param {Number} pid - 查询标段
          * @param {Number} uid - 查询人
          * @param {Date} time - 查询时间
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getNoticeMaterial(pid, uid, time) {
             const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
@@ -535,7 +538,7 @@ module.exports = app => {
          * 获取审核人流程列表
          *
          * @param auditorId
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getAuditGroupByList(materialId, times) {
             const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`mid`, la.`aid`, la.`order` ' +
@@ -551,7 +554,7 @@ module.exports = app => {
          * @param transaction - 新增一期的事务
          * @param {Object} preMaterial - 上一期
          * @param {Object} newaMaterial - 最新一期
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async copyPreMaterialAuditors(transaction, preMaterial, newMaterial) {
             const auditors = await this.getAuditGroupByList(preMaterial.id, preMaterial.times);

+ 13 - 2
app/view/material/audit_modal.ejs

@@ -319,7 +319,19 @@
                                         <label>审批意见<b class="text-danger">*</b></label>
                                         <textarea class="form-control form-control-sm" name="opinion">不同意</textarea>
                                     </div>
-                                    <div class="alert alert-warning">审批退回,将直接退回给原报人。</div>
+                                    <div class="alert alert-warning">
+                                        <div class="form-check form-check-inline">
+                                            <input class="form-check-input" type="radio" name="checkType" id="inlineRadio1" value="<%- auditConst.status.checkNo %>" <% if (auditors[iA].order === 1 || auditors[iA].aid === auditors[0].aid) { %>checked<% } %>>
+                                            <label class="form-check-label" for="inlineRadio1">退回原报 <%- ctx.material.user.name %></label>
+                                        </div>
+                                        <% if (auditors[iA].order > 1 && auditors[iA].aid !== auditors[0].aid) { %>
+                                            <% const auditorIndex = ctx.material.auditors.findIndex(function (item) { return item.aid === auditors[iA].aid }) %>
+                                            <div class="form-check form-check-inline">
+                                                <input class="form-check-input" type="radio" name="checkType" id="inlineRadio2" value="<%- auditConst.status.checkNoPre %>" checked>
+                                                <label class="form-check-label" for="inlineRadio2">退回上一审批人 <%- ctx.material.auditors[auditorIndex-1].name %></label>
+                                            </div>
+                                        <% } %>
+                                    </div>
                                     <% } %>
                                 </li>
                                 <% } %>
@@ -331,7 +343,6 @@
             <div class="modal-footer">
                 <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
                 <input type="hidden" name="_csrf" value="<%= ctx.csrf %>" />
-                <input type="hidden" name="checkType" value="<%= auditConst.status.checkNo %>" />
                 <button type="submit" class="btn btn-warning btn-sm" >确认退回</button>
             </div>
         </form>

+ 2 - 1
app/view/material/file.ejs

@@ -3,7 +3,7 @@
   <div class="panel-title">
     <div class="title-main d-flex justify-content-between">
       <div class="d-flex justify-content-start align-items-center">
-        <% if(auditors.includes(ctx.session.sessionUser.accountId)) { %>
+        <% if(report_id === ctx.session.sessionUser.accountId || auditors.includes(ctx.session.sessionUser.accountId)) { %>
           <a href="#addfujian" data-toggle="modal" class="btn btn-sm btn-light text-primary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="添加清单"><i class="fa fa-cloud-upload" aria-hidden="true"></i> 上传附件</a>
         <% } %>
           <span class="d-flex align-items-center" style="margin-left: 5px;">
@@ -48,4 +48,5 @@
   const curMaterialStatus = '<%- material.status %>';
   const fileList = '<%- JSON.stringify(fileList) %>';
   const auditors = JSON.parse('<%- JSON.stringify(auditors) %>');
+  const report_id = '<%- JSON.stringify(report_id) %>'
 </script>

+ 1 - 1
app/view/stage/report_modal.ejs

@@ -187,4 +187,4 @@
             </div>
         </div>
     </div>
-</div>
+</div>