Преглед изворни кода

调用变更令窗口,删除、复制粘贴本期计量,已用提示,超计提示

MaiXinRong пре 6 година
родитељ
комит
ebe8298648

+ 26 - 0
app/controller/stage_controller.js

@@ -613,6 +613,32 @@ module.exports = app => {
                 ctx.body = {err: 1, msg: err.toString(), data: null};
             }
         }
+
+        /**
+         * 调用变更令 (Ajax-Post)
+         * @param ctx
+         * @returns {Promise<void>}
+         */
+        async useChange(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data.target || (!data.target.bills && !data.target.pos) || !data.change) {
+                    throw '调用变更令数据错误'
+                }
+                let result;
+                if (data.target.bills) {
+                    result = await ctx.service.stageBills.useChange(data.target.bills, data.change);
+                } else {
+                    result = await ctx.service.stageBills.userChange(data.target.pos, data.change);
+                }
+                ctx.body = {err: 0, msg: '', data: result};
+            } catch(err) {
+                this.log(err);
+                ctx.body = {err: 1, msg: err.toString(), data: null};
+            }
+        }
+
+
         // 审批相关
         /**
          * 添加审批人

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

@@ -248,7 +248,7 @@ function getQueryVariable(variable) {
 
 const zeroRange = 0.00000001;
 function checkZero(value) {
-    return _.isNumber(value) && value !== Math.abs(value) < zeroRange;
+    return _.isNumber(value) && Math.abs(value) < zeroRange;
 }
 
 /**

+ 5 - 1
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -299,7 +299,11 @@ const SpreadJsObj = {
                 cell.font(col.font);
             }
             if (col.foreColor) {
-                cell.foreColor(col.foreColor);
+                if (Object.prototype.toString.apply(col.foreColor) === "[object Function]") {
+                    cell.foreColor(col.foreColor(data, sheet.getDefaultStyle().foreColor));
+                } else {
+                    cell.foreColor(col.foreColor);
+                }
             }
             if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object Function]") {
                 cell.locked(col.readOnly(data) || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);

+ 57 - 11
app/public/js/stage.js

@@ -141,23 +141,34 @@ $(document).ready(() => {
             // 初始化 清单编号窗口 参数
             this.spreadSetting = {
                 cols: [
-                    {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14},
+                    {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
+                        if (data.uamount && !checkZero(data.uamount)) {
+                            return $('#icon-ok')[0];
+                        } else {
+                            return null;
+                        }
+                    }},
                     {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
                     {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
                     {title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
                     {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, },
-                    {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, },
+                    {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
                 ],
                 emptyRows: 0,
                 headRows: 1,
                 headRowHeight: [40],
-            };
-            this.spreadSetting.cols[0].img = function (data) {
-                //return $('#icon-ok')[0];
-                if (data.uamount && !checkZero(data.uamount)) {
-                    return $('#icon-ok')[0];
-                } else {
-                    return null;
+                getColor: function (data, col, defaultColor) {
+                    if (col.field === 'uamount') {
+                        if (!data.vamount) {
+                            return data.uamount ? '#ff6f5c' : defaultColor;
+                        } else if (data.uamount) {
+                            return data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
+                        } else {
+                            return defaultColor;
+                        }
+                    } else {
+                        return defaultColor;
+                    }
                 }
             };
             this.curChangeId = '';
@@ -183,8 +194,8 @@ $(document).ready(() => {
                     const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
                     const node = sortData[info.row];
                     node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
-                    // 刷新已用提示
-                    info.sheet.repaint(info.sheet.getCellRect(info.row, 0));
+                    // 刷新界面
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
                 }
             });
             this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
@@ -218,6 +229,7 @@ $(document).ready(() => {
             $('#customCheckDisabled').click(function () {
                 self._filterEmptyChange(!this.checked);
             });
+            // 展开收起 变更令详细信息
             $('#show-bgl-detail').bind('click', function () {
                 const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
                 if (detail.hasClass('col-4')) {
@@ -234,6 +246,39 @@ $(document).ready(() => {
                     self.spread.refresh();
                 }
             });
+            // 添加调用变更令
+            $('#usg-bg-ok').click(function () {
+                const data = { target: self.callData, change: [] };
+                for (const c of self.changes) {
+                    if (c.uamount) {
+                        if (!c.vamount || checkZero(c.vamount)) {
+                            toast('变更令:' + c.code + ' 当前不可使用', 'error');
+                            return;
+                        } else {
+                            if (c.uamount > c.vamount) {
+                                toast('变更令:' + c.code + ' 超计,请修改本期计量后,再提交', 'error');
+                                return;
+                            }
+                        }
+                    }
+                }
+                self.obj.modal('hide');
+                // 提交数据到后端
+                // postData(window.location.pathname + 'use-change', data, function(result) {
+                //     if (result.pos) {
+                //         stagePos.loadCurStageData(result.pos.curStageData);
+                //     }
+                //     const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
+                //     stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
+                //     stagePosSpreadObj.loadCurPosData();
+                //     self.obj.modal('hide');
+                // });
+            })
+        }
+        _calculateValidAmount() {
+            for (const c of this.changes) {
+                c.vamount = c.b_amount;
+            }
         }
         _loadChangeDetail(change) {
             if (change) {
@@ -310,6 +355,7 @@ $(document).ready(() => {
             $('#b-code-hint').text('当前变更清单:' + code);
             postData(window.location.pathname + '/valid-change', data, function (result) {
                 self.changes = result;
+                self._calculateValidAmount();
                 self._viewChanges();
                 self.obj.modal('show');
             });

+ 1 - 0
app/router.js

@@ -128,6 +128,7 @@ module.exports = app => {
     app.post('/tender/:id/measure/stage/:order/pos', sessionAuth, tenderCheck, 'stageController.getStagePosData');
     app.post('/tender/:id/measure/stage/:order/update', sessionAuth, tenderCheck, 'stageController.updateStageData');
     app.post('/tender/:id/measure/stage/:order/valid-change', sessionAuth, tenderCheck, 'stageController.searchValidChange');
+    app.post('/tender/:id/measure/stage/:order/use-change',sessionAuth, tenderCheck, 'stageController.useChange');
     // 中间计量
     app.get('/tender/:id/measure/stage/:order/detail', sessionAuth, tenderCheck, 'stageController.detail');
     app.post('/tender/:id/measure/stage/:order/detail/build', sessionAuth, tenderCheck, 'stageController.buildDetailData');

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

@@ -184,7 +184,7 @@
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
-                <button type="button" class="btn btn-primary">添加</button>
+                <button type="button" class="btn btn-primary" id="usg-bg-ok">添加</button>
             </div>
         </div>
     </div>