浏览代码

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

TonyKang 5 年之前
父节点
当前提交
debee20412

+ 9 - 9
app/const/account_permission.js

@@ -30,15 +30,15 @@ const permission = {
             { title: '查阅所有标段', value: 2 },
         ],
     },
-    cooperation: {
-        class: '',
-        title: '协作办公',
-        type: 'radio',
-        children: [
-            { title: '启用', value: 1 },
-            { title: '关闭', value: 0 },
-        ],
-    },
+    // cooperation: {
+    //     class: '',
+    //     title: '协作办公',
+    //     type: 'radio',
+    //     children: [
+    //         { title: '启用', value: 1 },
+    //         { title: '关闭', value: 0 },
+    //     ],
+    // },
 };
 
 module.exports = {

+ 12 - 0
app/const/tender.js

@@ -56,6 +56,17 @@ const measureType = {
     },
 };
 
+const valuationField = function (mt) {
+    switch (mt) {
+        case measureType.tz.value:
+            return { std_bills: 'bill_id', std_xmj: 'chapter_id', template: 'template_id' };
+        case measureType.gcl.value:
+            return { std_bills: 'list_bill_id', std_xmj: 'list_chapter_id', template: 'list_template_id' };
+        default:
+            return null;
+    }
+};
+
 const imType = {
     zl: { value: 0, name: '总量控制' },
     tz: { value: 1, name: '0号台账' },
@@ -77,4 +88,5 @@ module.exports = {
     manageTableCol,
     measureType,
     imType,
+    valuationField,
 };

+ 27 - 0
app/controller/change_controller.js

@@ -769,6 +769,33 @@ module.exports = app => {
                 this.ajaxErrorBody(err, '获取变更清单失败');
             }
         }
+
+        /**
+         * 最后审批人审批成功检查批复编号和其它变更令是否出现重名情况
+         * @param ctx
+         * @returns {Promise<void>}
+         */
+        async checkCodeRepeat(ctx) {
+            const responseData = {
+                err: 0,
+                msg: '',
+                data: '',
+            };
+            try {
+                const tenderId = ctx.params.id;
+                const cid = ctx.params.cid;
+                const data = JSON.parse(ctx.request.body.data);
+                const result = await ctx.service.change.isRepeat(cid, data.p_code, tenderId);
+                if (result) {
+                    throw '该变更令号(批复编号)已使用';
+                }
+            } catch (err) {
+                responseData.err = 1;
+                responseData.msg = err;
+            }
+
+            ctx.body = responseData;
+        }
     }
 
     return ChangeController;

+ 6 - 3
app/controller/ledger_controller.js

@@ -120,7 +120,8 @@ module.exports = app => {
                         auditHistory.push(await ctx.service.ledgerAudit.getAuditors(ctx.tender.id, i));
                     }
                 }
-                const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(ctx.tender.data.valuation);
+                const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(
+                    ctx.tender.data.valuation, ctx.tender.data.measure_type);
                 const renderData = {
                     tender: tender.data,
                     tenderInfo: tender.info,
@@ -151,7 +152,8 @@ module.exports = app => {
 
                 await this.layout('ledger/explode.ejs', renderData, 'ledger/explode_modal.ejs');
             } catch (err) {
-                this.log(err);
+                ctx.helper.log(err);
+                this.postError(err, '标段数据错误');
                 await this.redirect('/dashboard');
             }
         }
@@ -479,7 +481,8 @@ module.exports = app => {
                 const responseData = { err: 0, msg: '', data: {}, };
                 switch (ueType) {
                     case 'tz':
-                        const templateId = await this.ctx.service.valuation.getValuationTemplate(this.ctx.tender.data.valuation);
+                        const templateId = await this.ctx.service.valuation.getValuationTemplate(
+                            this.ctx.tender.data.valuation, this.ctx.tender.data.measure_type);
                         responseData.data = await ctx.service.ledger.importExcel(templateId, data);
                         break;
                     case 'gcl2xmj':

+ 4 - 2
app/controller/revise_controller.js

@@ -72,7 +72,8 @@ module.exports = app => {
                     }
                 }
                 const addValid = await this._getAddReviseValid(ctx);
-                const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(ctx.tender.data.valuation);
+                const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(
+                    ctx.tender.data.valuation, ctx.tender.data.measure_type);
                 const renderData = {
                     tender: ctx.tender.data,
                     tenderMenu: this.menu.tenderMenu,
@@ -214,7 +215,8 @@ module.exports = app => {
                 ? JSON.parse(await fs.readFileSync(this.ctx.app.config.filePath + revise.pos_file, 'utf8'))
                 : await ctx.service.revisePos.getData(ctx.tender.id);
             const [ledgerSpread, posSpread] = this._getSpreadSetting(revise);
-            const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(ctx.tender.data.valuation);
+            const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(
+                ctx.tender.data.valuation, ctx.tender.data.measure_type);
             const curAuditor = await ctx.service.reviseAudit.getCurAuditor(revise.id, revise.times);
             const auditors = await ctx.service.reviseAudit.getAuditors(revise.id, revise.times);
             const user = await ctx.service.projectAccount.getAccountInfoById(revise.uid);

+ 9 - 8
app/controller/tender_controller.js

@@ -391,11 +391,12 @@ module.exports = app => {
                     throw '标段数据错误';
                 }
                 if (!tender.measure_type) {
-                    await ctx.service.tender.update({ measure_type: type }, { id: tender.id });
+                    await ctx.service.tender.setTenderType(tender, parseInt(type));
                 }
                 ctx.redirect('/tender/' + tenderId);
             } catch (error) {
-                this.log(error);
+                ctx.helper.log(error);
+                this.postError(error, '设置标段类型错误');
                 ctx.redirect('/list');
             }
         }
@@ -438,7 +439,7 @@ module.exports = app => {
                 };
                 await this.layout('tender/cooperation.ejs', renderData, 'tender/cooperationModal.ejs');
             } catch (error) {
-                this.log(error);
+                ctx.helper.log(error);
                 this.ctx.redirect('/tender/' + tenderId);
             }
         }
@@ -459,7 +460,7 @@ module.exports = app => {
                     throw '新增标段失败';
                 }
             } catch (error) {
-                this.log(error);
+                ctx.helper.log(error);
                 this.setMessage(error.toString(), this.messageType.ERROR);
             }
 
@@ -515,7 +516,7 @@ module.exports = app => {
 
                 this.setMessage('保存标段数据成功', this.messageType.SUCCESS);
             } catch (error) {
-                this.setMessage(error.toString(), this.messageType.ERROR);
+                this.postError(error, '保存标段数据失败');
             }
             ctx.redirect(ctx.request.header.referer);
         }
@@ -542,7 +543,7 @@ module.exports = app => {
 
                 this.setMessage('删除标段成功', this.messageType.SUCCESS);
             } catch (error) {
-                this.setMessage(error.toString(), this.messageType.ERROR);
+                this.postError(error, '删除标段失败');
             }
 
             ctx.redirect(ctx.request.header.referer);
@@ -579,7 +580,7 @@ module.exports = app => {
                     throw '更新规则失败';
                 }
             } catch (err) {
-                this.log(err);
+                ctx.helper.log(err);
                 responseData.err = 1;
                 responseData.msg = err.toString();
             }
@@ -608,7 +609,7 @@ module.exports = app => {
                     throw '更新规则失败';
                 }
             } catch (err) {
-                this.log(err);
+                ctx.helper.log(err);
                 responseData.err = 1;
                 responseData.msg = err.toString();
             }

+ 1 - 1
app/extend/helper.js

@@ -82,7 +82,7 @@ module.exports = {
      * @return {string} - 结果
      */
     accMul(arg1, arg2) {
-        if (!arg1 || !arg2) {
+        if (arg1 === '' || arg1 === null || arg1 === undefined || arg2 === '' || arg2 === null || arg2 === undefined) {
             return '';
         }
         let m = 0;

+ 49 - 2
app/public/js/change_approval.js

@@ -58,6 +58,15 @@ $(document).ready(() => {
             if ($('input[name="p_code"]').val() === '') {
                 toastr.error('变更令号(批复编号)不能为空!');
                 returnflag = false;
+            } else if ($('input[name="p_code"]').val() !== undefined) {
+                $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
+                const postData = {
+                    p_code: $('input[name="p_code"]').val(),
+                };
+                postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
+                }, function (data) {
+                    returnflag = false;
+                });
             }
             // 判断并提交变更清单表格数据到表单中
             const clist = [];
@@ -73,7 +82,8 @@ $(document).ready(() => {
             $('#change-list-approval').val(clist.join(','));
 
             if(returnflag) {
-                $('input[name="w_code"]').val($('#w_code').val());
+                $('input[name="w_code"]').val($.trim($('#w_code').val()));
+
                 $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
                 $('#success-approval').submit();
             }
@@ -90,9 +100,46 @@ $(document).ready(() => {
             }
             if(returnflag) {
                 $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
-                $('input[name="w_code"]').val($('#w_code').val());
+                $('input[name="w_code"]').val($.trim($('#w_code').val()));
                 $('#fail-approval').submit();
             }
         }
     })
 });
+
+const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
+    if (showWaiting) showWaitingView();
+    $.ajax({
+        type:"POST",
+        url: url,
+        data: {'data': JSON.stringify(data)},
+        dataType: 'json',
+        cache: false,
+        async: false,
+        timeout: 60000,
+        beforeSend: function(xhr) {
+            let csrfToken = Cookies.get('csrfToken');
+            xhr.setRequestHeader('x-csrf-token', csrfToken);
+        },
+        success: function(result){
+            if (result.err === 0) {
+                if (successCallback) {
+                    successCallback(result.data);
+                }
+            } else {
+                toastr.error(result.msg);
+                if (errorCallBack) {
+                    errorCallBack(result.msg);
+                }
+            }
+            if (showWaiting) closeWaitingView();
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            toastr.error('error: ' + textStatus + " " + errorThrown);
+            if (errorCallBack) {
+                errorCallBack();
+            }
+            if (showWaiting) closeWaitingView();
+        }
+    });
+};

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

@@ -114,7 +114,7 @@ $(document).ready(function() {
         // 移除签名
         $('#delete-sign').click(function () {
             postData('/profile/sign/delete', {}, function (result) {
-                $('#sign-show').remove();
+                $('#sign-show').html('');
                 toast('移除成功', 'success');
             })
         });

+ 0 - 6
app/public/js/setting.js

@@ -171,9 +171,6 @@ function checkUserForm(status) {
             if ($('#add-user input[name="role"]').val() == '') {
                 throw '职位名称不能为空';
             }
-            if ($('#add-user input[name="mobile"]').val() == '') {
-                throw '手机号不能为空';
-            }
         } else {
             if ($('#edit-user select[name="account_group"]').val() == 0) {
                 throw '请选择账号组';
@@ -190,9 +187,6 @@ function checkUserForm(status) {
             if ($('#edit-user input[name="role"]').val() == '') {
                 throw '职位名称不能为空';
             }
-            if ($('#edit-user input[name="mobile"]').val() == '') {
-                throw '手机号不能为空';
-            }
         }
     } catch (err) {
         toastr.error(err);

+ 13 - 4
app/public/js/stage.js

@@ -1044,6 +1044,11 @@ $(document).ready(() => {
                     } else if (!posData) {
                         if (newText !== '') {
                             data.updateType = 'add';
+                            if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
+                                toastr.error('无计量单元的清单,计量后,不可新增计量单元');
+                                SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                                return;
+                            }
                             const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
                             data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
                         } else {
@@ -1128,7 +1133,6 @@ $(document).ready(() => {
             }
         },
         clipboardPasted: function (e, info) {
-            const self = this;
             if (info.sheet.zh_setting) {
                 const data = { updateType: '', updateData: [], };
                 const sortData = info.sheet.zh_data;
@@ -1137,7 +1141,12 @@ $(document).ready(() => {
                     data.updateType = 'add';
                     if (info.cellRange.col !== 0) {
                         toastr.warning('新增部位请先输入名称');
-                        self.loadCurPosData();
+                        stagePosSpreadObj.loadCurPosData();
+                        return;
+                    }
+                    if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
+                        toastr.error('无计量单元的清单,计量后,不可新增计量单元');
+                        stagePosSpreadObj.loadCurPosData();
                         return;
                     }
                     const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
@@ -1157,7 +1166,7 @@ $(document).ready(() => {
                                         newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
                                     } catch(err) {
                                         toastr.error('输入的表达式非法');
-                                        self.loadCurPosData();
+                                        stagePosSpreadObj.loadCurPosData();
                                         return;
 
                                     }
@@ -1186,7 +1195,7 @@ $(document).ready(() => {
                                             newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
                                         } catch(err) {
                                             toastr.error('输入的表达式非法');
-                                            self.loadCurPosData();
+                                            stagePosSpreadObj.loadCurPosData();
                                             return;
                                         }
                                     }

+ 2 - 0
app/router.js

@@ -221,6 +221,8 @@ module.exports = app => {
     app.post('/change/approval', sessionAuth, 'changeController.approval');
     app.post('/change/check/again', sessionAuth, 'changeController.checkAgain');
 
+    app.post('/tender/:id/change/:cid/check/codeRepeat', sessionAuth, tenderCheck, 'changeController.checkCodeRepeat');
+
     // 变更单位管理
     app.post('/change/update/company', sessionAuth, 'changeController.updateCompany');
 

+ 18 - 1
app/service/change.js

@@ -77,7 +77,10 @@ module.exports = app => {
         }
 
         async add(tenderId, userId, code, name) {
-            const count = await this.count({ tid: tenderId, code });
+            const sql = 'SELECT COUNT(*) as count FROM ?? WHERE `tid` = ? AND ((`code` = ? AND `status` != ?) OR (`p_code` = ? AND `status` = ?))';
+            const sqlParam = [this.tableName, tenderId, code, audit.flow.status.checked, code, audit.flow.status.checked];
+            const codeCount = await this.db.queryOne(sql, sqlParam);
+            const count = codeCount.count;
             if (count > 0) {
                 throw '变更令号重复';
             }
@@ -1003,6 +1006,20 @@ module.exports = app => {
             }
             return result;
         }
+
+        /**
+         * 判断是否有重名的变更令
+         * @param cid
+         * @param code
+         * @param tid
+         * @returns {Promise<void>}
+         */
+        async isRepeat(cid, code, tid) {
+            const sql = 'SELECT COUNT(*) as count FROM ?? WHERE ((`code` = ? AND `status` != ?) OR (`p_code` = ? AND `status` = ?)) AND `cid` != ? AND `tid` = ?';
+            const sqlParam = [this.tableName, code, audit.flow.status.checked, code, audit.flow.status.checked, cid, tid];
+            const result = await this.db.queryOne(sql, sqlParam);
+            return result.count !== 0;
+        }
     }
     return Change;
 };

+ 0 - 2
app/service/project_account.js

@@ -78,7 +78,6 @@ module.exports = app => {
                         name: { type: 'string', required: true },
                         company: { type: 'string', required: true },
                         role: { type: 'string', required: true },
-                        mobile: { type: 'mobile', required: true },
                     };
                     break;
                 case 'modify':
@@ -87,7 +86,6 @@ module.exports = app => {
                         name: { type: 'string', required: true },
                         company: { type: 'string', required: true },
                         role: { type: 'string', required: true },
-                        mobile: { type: 'mobile', required: true },
                     };
                     break;
                 default:

+ 22 - 8
app/service/tender.js

@@ -162,7 +162,6 @@ module.exports = app => {
          */
         async add(data) {
             let result = false;
-            const templateId = await this.ctx.service.valuation.getValuationTemplate(data.valuation);
             this.transaction = await this.db.beginTransaction();
             try {
                 // 获取当前用户信息
@@ -186,13 +185,6 @@ module.exports = app => {
                     throw '新增标段数据失败';
                 }
 
-                // 获取标段项目节点模板
-                const tenderNodeTemplateData = await this.ctx.service.tenderNodeTemplate.getData(templateId);
-                // 复制模板数据到标段数据表
-                result = await this.ctx.service.ledger.innerAdd(tenderNodeTemplateData, operate.insertId, this.transaction);
-                if (!result) {
-                    throw '新增标段项目节点失败';
-                }
 
                 // 获取合同支付模板 并添加到标段
                 result = await this.ctx.service.pay.addDefaultPayData(operate.insertId, this.transaction);
@@ -341,6 +333,28 @@ module.exports = app => {
             this.ctx.tender = tender;
         }
 
+        async setTenderType(tender, type) {
+            const templateId = await this.ctx.service.valuation.getValuationTemplate(tender.valuation, type);
+            if (templateId === -1) throw '该模式下,台账模板不存在';
+
+            // 获取标段项目节点模板
+            const tenderNodeTemplateData = await this.ctx.service.tenderNodeTemplate.getData(templateId);
+            const conn = await this.db.beginTransaction();
+            try {
+                await conn.update(this.tableName, {id: tender.id, measure_type: type});
+
+                // 复制模板数据到标段数据表
+                const result = await this.ctx.service.ledger.innerAdd(tenderNodeTemplateData, tender.id, conn);
+                if (!result) {
+                    throw '初始化台账失败';
+                }
+                await conn.commit();
+            } catch (err) {
+                await conn.rollback();
+                throw err;
+            }
+        }
+
     }
 
     return Tender;

+ 17 - 5
app/service/valuation.js

@@ -8,6 +8,8 @@
  * @version
  */
 
+const tenderConst = require('../const/tender');
+
 module.exports = app => {
 
     class Valuation extends app.BaseService {
@@ -32,15 +34,25 @@ module.exports = app => {
             });
         }
 
-        async getValuationTemplate(id) {
+        async getValuationTemplate(id, measureType) {
+            const valuationField = tenderConst.valuationField(measureType);
+            if (!valuationField) return -1;
+
             const valuation = await this.getDataById(id);
-            return parseInt(valuation.template_id);
+            return parseInt(valuation[valuationField.template]);
         }
 
-        async getValuationStdList(id) {
+        async getValuationStdList(id, measureType) {
+            const valuationField = tenderConst.valuationField(measureType);
+            if (!valuationField) return [[], []];
+
             const valuation = await this.getDataById(id);
-            const billsId = this._.map(valuation.bill_id.split(','), this._.toInteger);
-            const chaptersId = this._.map(valuation.chapter_id.split(','), this._.toInteger);
+            const billsId = valuation[valuationField.std_bills]
+                ? this._.map(valuation[valuationField.std_bills].split(','), this._.toInteger)
+                : [-1];
+            const chaptersId = valuation[valuationField.std_xmj]
+                ? this._.map(valuation[valuationField.std_xmj].split(','), this._.toInteger)
+                : [-1];
             const sql = 'SELECT `id`, `name`' +
                 '  From ?? ' +
                 '  WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';

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

@@ -46,7 +46,7 @@
                         <td><a href="/tender/<%- tender.id %>/change/<%- c.cid %>/info"><% if (c.status !== auditConst.status.checked) { %><%- c.code %><% } else { %><%- c.p_code %><% } %></a></td>
                         <td><%- c.name %></td>
                         <td><%- classArray[c.class] %><% c.class %></td>
-                        <td><%- c.total_price %></td>
+                        <td style="text-align: right"><%- c.total_price %></td>
                         <% if (c.auditStatus) { %>
                         <td>
                             <a href="/tender/<%- tender.id %>/change/<%- c.cid %>/info" class="btn <%- auditConst.statusButtonClass[c.status] %> btn-sm">

+ 2 - 2
app/view/setting/user_modal.ejs

@@ -46,7 +46,7 @@
                     <input class="form-control form-control-sm" name="role" value="" type="text">
                 </div>
                 <div class="form-group">
-                    <label>手机<b class="text-danger">*</b></label>
+                    <label>手机</label>
                     <input class="form-control form-control-sm" name="mobile" value="" type="number">
                 </div>
                 <div class="form-group">
@@ -116,7 +116,7 @@
                     <input class="form-control form-control-sm" value="" name="role" type="text">
                 </div>
                 <div class="form-group">
-                    <label>手机<b class="text-danger">*</b></label>
+                    <label>手机</label>
                     <input class="form-control form-control-sm" value="" name="mobile" type="number">
                 </div>
                 <div class="form-group">

+ 2 - 1
app/view/setting/user_permission_modal.ejs

@@ -88,7 +88,8 @@
                 <% } %>
                 <!--需要勾选  创建标段 ,协作办公才能勾选-->
                 <div class="alert alert-secondary">
-                    <p>1.勾选「创建标段」该用户默认具有「新建标段」及标段内「台帐分解」「创建台帐修订」「创建计量期」「创建工程变更」的权限。</p>2.启用「协作办公」,则该用户可以为他创建的标段添加其他用户进行协作办公。
+                    <p>1.勾选「创建标段」该用户默认具有「新建标段」及标段内「台帐分解」「创建台帐修订」「创建计量期」「创建工程变更」的权限。</p>
+                    <!--2.启用「协作办公」,则该用户可以为他创建的标段添加其他用户进行协作办公。-->
                 </div>
             </div>
             <div class="modal-footer">