瀏覽代碼

工料readOnly设置

laiguoran 5 年之前
父節點
當前提交
a9d8d3ef15

+ 0 - 32
app/const/spread.js

@@ -415,37 +415,6 @@ measure.compare.pos = {
     defaultRowHeight: 21,
 };
 
-// 材料调差 - 调差工料
-const material = {
-    bill: {
-        cols: [
-            {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.t_type', cellType: 'select'},
-            {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.code'},
-            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 1, width: 180, formatter: '@', readOnly: 'readOnly.name'},
-            {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 2, width: 60, formatter: '@', readOnly: 'readOnly.unit'},
-            {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 2, width: 230, formatter: '@', readOnly: 'readOnly.spec'},
-            {title: '工料分类', colSpan: '1', rowSpan: '2', field: 'm_type', hAlign: 2, width: 60, readOnly: 'readOnly.m_type', cellType: 'select'},
-            {title: '本期应耗数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.quantity'},
-            {title: '基准价', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.basic_price'},
-            {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 2, width: 60, formatter: '@', readOnly: 'readOnly.basic_times'},
-            {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
-            {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 2, width: 60, formatter: '@', readOnly: 'readOnly.msg_times'},
-            {title: '|价差', colSpan: '1', rowSpan: '1|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true},
-            {title: '本期材料调差|风险幅度(%)', colSpan: '3|1', rowSpan: '1|1', field: 'm_risk', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.m_risk'},
-            {title: '|有效价差', colSpan: '|1', rowSpan: '|1', field: 'm_spread', hAlign: 2, width: 80, type: 'Number', readOnly: true},
-            {title: '|调整金额', colSpan: '|1', rowSpan: '1|1', field: 'm_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true},
-            {title: '截止上期调差金额', colSpan: '1', rowSpan: '2', field: 'pre_tp', hAlign: 2, width: 120, type: 'Number', readOnly: true},
-            {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 2, width: 60, formatter: '@', readOnly: 'readOnly.remark'},
-        ],
-        emptyRows: 0,
-        headRows: 2,
-        headRowHeight: [32, 32],
-        defaultRowHeight: 21,
-        headerFont: '10pt 微软雅黑',
-        font: '10pt 微软雅黑',
-    },
-}
-
 
 module.exports = {
     withCl,
@@ -457,5 +426,4 @@ module.exports = {
     stageCompare,
     filterCols: { tzWithoutCols, dgnCols, clCols, stageDgnCols},
     measure,
-    material,
 };

+ 4 - 16
app/controller/material_controller.js

@@ -11,7 +11,6 @@
 const moment = require('moment');
 const auditConst = require('../const/audit').material;
 const auditStageConst = require('../const/audit').stage;
-const spreadConst = require('../const/spread');
 const tenderConst = require('../const/tender');
 const measureType = tenderConst.measureType;
 const accountGroup = require('../const/account_group').group;
@@ -189,19 +188,6 @@ module.exports = app => {
         }
 
         /**
-         * 获取SpreadSetting
-         * @private
-         */
-        _getSpreadSetting() {
-            const billsSetting = spreadConst.material;
-            const ledger = JSON.parse(JSON.stringify(billsSetting.bill));
-            if (this.ctx.material.readOnly) {
-                ledger.readOnly = true;
-            }
-            return [ledger];
-        }
-
-        /**
          * 获取审批界面所需的 原报、审批人数据等
          * @param ctx
          * @returns {Promise<void>}
@@ -232,8 +218,10 @@ module.exports = app => {
             try {
                 await this._getMaterialAuditViewData(ctx);
                 const renderData = await this._getDefaultRenderData(ctx);
-                // [renderData.billsSpread] = this._getSpreadSetting();
-                renderData.materialBillsData = await ctx.service.materialBills.getAllDataByCondition({ where: { mid: ctx.material.id } });
+                // 取所有工料表
+                renderData.materialBillsData = await ctx.service.materialBills.getAllDataByCondition({ where: { tid: ctx.tender.id } });
+                // 取所有已被调用的工料清单表
+                renderData.materialListData = await ctx.service.materialList.getAllDataByCondition({ where: { tid: ctx.tender.id } });
                 renderData.materialType = JSON.stringify(materialConst);
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.material.info);
                 await this.layout('material/info.ejs', renderData, 'material/info_modal.ejs');

+ 9 - 7
app/middleware/material_check.js

@@ -52,11 +52,11 @@ module.exports = options => {
             // todo 校验权限 (标段参与人、分享)
             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;
-                } else {
-                    material.readOnly = material.status !== status.uncheck && material.status !== status.checkNo;
-                }
+                // if (material.curAuditor) {
+                //     material.readOnly = material.status === status.checking && material.curAuditor.user_id === accountId;
+                // } else {
+                //     material.readOnly = material.status !== status.uncheck && material.status !== status.checkNo;
+                // }
                 material.curTimes = material.times;
                 if (material.status === status.uncheck || material.status === status.checkNo) {
                     material.curOrder = 0;
@@ -69,7 +69,7 @@ module.exports = options => {
                 if (material.status === status.uncheck) {
                     throw '您无权查看该数据';
                 }
-                material.readOnly = material.status !== status.checking || accountId !== material.curAuditor.aid;
+                // material.readOnly = material.status !== status.checking || accountId !== material.curAuditor.aid;
                 material.curTimes = material.status === status.checkNo ? material.times - 1 : material.times;
                 if (material.status === status.checked) {
                     material.curOrder = _.max(_.map(material.auditors, 'order'));
@@ -85,7 +85,7 @@ module.exports = options => {
                 if (material.status === status.uncheck) {
                     throw '您无权查看该数据';
                 }
-                material.readOnly = true;
+                // material.readOnly = true;
                 material.curTimes = material.status === status.checkNo ? material.times - 1 : material.times;
                 material.curOrder = material.status === status.checked ? _.max(_.map(material.auditors, 'order')) : material.curAuditor.order - 1;
             } else { // 其他不可见
@@ -96,6 +96,8 @@ module.exports = options => {
             material.highOrder = yield this.service.material.count({
                 tid: this.tender.id,
             });
+            // 调差的readOnly 指表格和页面只能看不能改,和审批无关
+            material.readOnly = !((material.status === status.uncheck || material.status === status.checkNo) && accountId === material.user_id);
             this.material = material;
             yield next;
         } catch (err) {

+ 30 - 54
app/public/js/material.js

@@ -22,22 +22,21 @@ function loadUpdateMaterials(newMaterial, fields) {
 $(document).ready(() => {
     autoFlashHeight();
     const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
-    console.log(materialType);
     const materialSpreadSetting = {
         cols: [
-            {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.t_type', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
-            {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.code'},
-            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: 'readOnly.name'},
-            {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.unit'},
-            {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 230, formatter: '@', readOnly: 'readOnly.spec'},
-            {title: '工料分类', colSpan: '1', rowSpan: '2', field: 'm_type', hAlign: 0, width: 60, readOnly: 'readOnly.m_type', cellType: 'customizeCombo', comboItems: materialType.m_type, cellTypeKey: 2},
-            {title: '本期应耗数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.quantity'},
-            {title: '基准价', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.basic_price'},
-            {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.basic_times'},
-            {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
-            {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.msg_times'},
+            {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
+            {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 230, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '工料分类', colSpan: '1', rowSpan: '2', field: 'm_type', hAlign: 0, width: 60, readOnly: 'readOnly.isEdit', cellType: 'customizeCombo', comboItems: materialType.m_type, cellTypeKey: 2},
+            {title: '本期应耗数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.isEdit'},
+            {title: '基准价', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit'},
+            {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit'},
+            {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
             {title: '|价差', colSpan: '1', rowSpan: '1|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true},
-            {title: '本期材料调差|风险幅度(%)', colSpan: '3|1', rowSpan: '1|1', field: 'm_risk', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.m_risk'},
+            {title: '本期材料调差|风险幅度(%)', colSpan: '3|1', rowSpan: '1|1', field: 'm_risk', hAlign: 2, width: 100, type: 'Number', readOnly: 'readOnly.isEdit'},
             {title: '|有效价差', colSpan: '|1', rowSpan: '|1', field: 'm_spread', hAlign: 2, width: 80, type: 'Number', readOnly: true},
             {title: '|调整金额', colSpan: '|1', rowSpan: '1|1', field: 'm_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true},
             {title: '截止上期调差金额', colSpan: '1', rowSpan: '2', field: 'pre_tp', hAlign: 2, width: 120, type: 'Number', readOnly: true},
@@ -52,46 +51,21 @@ $(document).ready(() => {
         font: '10pt 微软雅黑',
     };
 
+    const materialBase = {
+        isEdit: function (data) {
+            return materialListData.find(function (item) {
+                return item.mbid === data.id;
+            });
+        }
+    }
+
     const materialCol = {
         readOnly: {
-            t_type: function (data) {
-                return false;
-            },
-            code: function (data) {
-                return false;
-            },
-            name: function (data) {
-                return false;
-            },
-            unit: function (data) {
-                return false;
-            },
-            spec: function (data) {
-                return false;
-            },
-            m_type: function (data) {
-                return false;
-            },
-            quantity: function (data) {
-                return false;
-            },
-            basic_price: function (data) {
-                return false;
-            },
-            basic_times: function (data) {
-                return false;
-            },
-            msg_tp: function (data) {
-                return false;
-            },
-            msg_times: function (data) {
-                return false;
-            },
-            m_risk: function (data) {
-                return false;
+            isEdit: function (data) {
+                return !(readOnly || materialBase.isEdit(data) === undefined);
             },
-            remark: function (data) {
-                return false;
+            remark: function () {
+                return readOnly;
             },
         },
     };
@@ -110,7 +84,8 @@ $(document).ready(() => {
             };
             const sheet = materialSpread.getActiveSheet();
             const select = SpreadJsObj.getSelectObject(sheet);
-            setObjEnable($('#del'), !readOnly && select);
+            // 还需判断是否已被调差清单调用
+            setObjEnable($('#del'), !readOnly && select && materialBase.isEdit(select) === undefined);
         },
         add: function () {
             const sheet = materialSpread.getActiveSheet();
@@ -199,9 +174,10 @@ $(document).ready(() => {
                     },
                     disabled: function (key, opt) {
                         const sheet = materialSpread.getActiveSheet();
-                        if (sheet.zh_data.length > 0) {
-                            const selection = sheet.getSelections();
-                            return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
+                        const select = SpreadJsObj.getSelectObject(sheet);
+                        materialSpreadObj.refreshActn();
+                        if (!readOnly && select && materialBase.isEdit(select) === undefined) {
+                            return false;
                         } else {
                             return true;
                         }

+ 5 - 0
app/public/js/measure_stage.js

@@ -79,3 +79,8 @@ $('a[data-target="#sp-list" ]').on('click', function () {
        $('#auditor-list2').html(righthtml.join(''));
    })
 });
+
+function checkValidForm() {
+    $('#add-stage-btn').attr('disabled', true);
+    return true;
+}

+ 77 - 0
app/service/material_list.js

@@ -0,0 +1,77 @@
+'use strict';
+
+/**
+ * 期计量 数据模型
+ *
+ * @author Mai
+ * @date 2018/8/13
+ * @version
+ */
+
+const auditConst = require('../const/audit').material;
+
+module.exports = app => {
+    class MaterialList extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'material_list';
+        }
+
+        /**
+         * 添加工料
+         * @return {void}
+         */
+        async add() {
+            if (!this.ctx.tender || !this.ctx.material) {
+                throw '数据错误';
+            }
+            const newBills = {
+                tid: this.ctx.tender.id,
+                mid: this.ctx.material.id,
+                in_time: new Date(),
+            };
+
+            // 新增工料
+            const result = await this.db.insert(this.tableName, newBills);
+            if (result.affectedRows !== 1) {
+                throw '新增工料数据失败';
+            }
+            return await this.getDataById(result.insertId);
+        }
+
+        /**
+         * 删除工料
+         * @param {int} id 工料id
+         * @return {void}
+         */
+        async del(id) {
+            if (!this.ctx.tender || !this.ctx.material) {
+                throw '数据错误';
+            }
+            // 判断是否可删
+            return await this.deleteById(id);
+        }
+
+        /**
+         * 修改工料信息
+         * @param {Object} data 工料内容
+         * @return {void}
+         */
+        async save(data) {
+            if (!this.ctx.tender || !this.ctx.material) {
+                throw '数据错误';
+            }
+            delete data.in_time;
+            // 判断是否可修改
+            return await this.db.update(this.tableName, data);
+        }
+    }
+
+    return MaterialList;
+};

+ 5 - 2
app/view/material/info.ejs

@@ -50,11 +50,14 @@
         </div>
     </div>
 </div>
-<% if (ctx.material.status === auditConst.status.uncheck && ctx.session.sessionUser.accountId === ctx.material.user_id) {%>
+<% if ((ctx.material.status === auditConst.status.uncheck || ctx.material.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === ctx.material.user_id) {%>
 <script>
     const accountList = JSON.parse('<%- JSON.stringify(accountList) %>');
+</script>
+<% } %>
+<script>
     const materialType = JSON.parse('<%- materialType %>');
     const materialBillsData = JSON.parse('<%- JSON.stringify(materialBillsData) %>');
+    const materialListData = JSON.parse('<%- JSON.stringify(materialListData) %>');
     const readOnly = <%- material.readOnly %>;
 </script>
-<% } %>

+ 2 - 2
app/view/measure/stage_modal.ejs

@@ -3,7 +3,7 @@
 <!--弹出添加期-->
 <div class="modal fade" id="add-qi" data-backdrop="static">
     <div class="modal-dialog" role="document">
-        <form class="modal-content" action="<%- preUrl + '/measure/add' %>" method="post">
+        <form class="modal-content" action="<%- preUrl + '/measure/add' %>" method="post" onsubmit="return checkValidForm();">
             <div class="modal-header">
                 <h5 class="modal-title">添加新一期</h5>
             </div>
@@ -24,7 +24,7 @@
             <div class="modal-footer">
                 <input type="hidden" name="_csrf" value="<%= ctx.csrf %>" />
                 <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
-                <button type="submit" class="btn btn-primary">确定添加</button>
+                <button type="submit" class="btn btn-primary" id="add-stage-btn">确定添加</button>
             </div>
         </form>
     </div>