浏览代码

计量台账,检查计算相关

MaiXinRong 5 年之前
父节点
当前提交
eb556efcbb

+ 2 - 3
app/controller/stage_controller.js

@@ -999,11 +999,10 @@ module.exports = app => {
 
                 await ctx.service.stageAudit.start(ctx.stage.id, ctx.stage.times);
 
-                ctx.redirect(ctx.request.header.referer);
+                ctx.body = {err: 0, msg: '', data: []};
             } catch (err) {
                 this.log(err);
-                ctx.session.postError = err.toString();
-                ctx.redirect(ctx.request.header.referer);
+                ctx.body = this.ajaxErrorBody(err, '上报失败');
             }
         }
         /**

+ 4 - 1
app/public/js/shares/cs_tools.js

@@ -108,6 +108,9 @@ const showSideTools = function (show) {
             }
             $(setting.tabSelector).show();
         };
+        const clearErrorData = function () {
+            if (setting.storeKey) removeLocalCache(setting.storeKey);
+        };
         if (setting.storeKey) {
             const storeStr = getLocalCache(setting.storeKey);
             const storeData = storeStr ? JSON.parse(storeStr) : [];
@@ -123,7 +126,7 @@ const showSideTools = function (show) {
             spread.refresh();
             if (setting.afterShow) setting.afterShow();
         };
-        return {spread: spread, loadErrorData: loadErrorData, show: showErrorList};
+        return {spread: spread, loadErrorData: loadErrorData, clearErrorData: clearErrorData, show: showErrorList};
     };
 
     $.posSearch = function (setting) {

+ 76 - 1
app/public/js/stage.js

@@ -508,6 +508,20 @@ $(document).ready(() => {
     };
     SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
 
+    const errorList = $.cs_errorList({
+        tabSelector: '#error-list-tab',
+        selector: '#error-list',
+        relaSpread: slSpread,
+        storeKey: 'stage-error-' + stage.id,
+        afterLocated:  function () {
+            stagePosSpreadObj.loadCurPosData();
+        },
+        afterShow: function () {
+            slSpread.refresh();
+            if (spSpread) spSpread.refresh();
+        },
+    });
+
     const stageTreeSpreadObj = {
         loadExprToInput(sheet) {
             const sel = sheet.getSelections()[0];
@@ -2543,7 +2557,7 @@ $(document).ready(() => {
             $('.tab-content .tab-select-show').removeClass('active');
             tab.addClass('active');
             tabPanel.addClass('active');
-            showTools(tab.hasClass('active'));
+            showSideTools(tab.hasClass('active'));
             if (tab.attr('content') === '#search' && !searchLedger) {
                 searchLedger = $.billsSearch({
                     selector: '#search',
@@ -2622,6 +2636,9 @@ $(document).ready(() => {
                     checkedChanges.refresh();
                 }
             }
+            if (tab.attr('content') === '#error-list') {
+                errorList.spread.refresh();
+            }
         } else {
             tab.removeClass('active');
             tabPanel.removeClass('active');
@@ -2871,4 +2888,62 @@ $(document).ready(() => {
             }
         });
     })('a[name=showLevel]', slSpread.getActiveSheet());
+
+    const dataChecker = DataChecker({
+        loadUrl: window.location.pathname + '/load',
+        loadData: { filter: 'ledger;pos' },
+        checkFun: function (data, progress) {
+            const checkFields = ['contract_qty', 'qc_qty'], result = [];
+            const differBills = [], differPos = [];
+            const iLen = data.ledgerData.length;
+            for (const [i, b] of data.ledgerData.entries()) {
+                const pr = _.filter(data.posData, {lid: b.id});
+                if (pr && pr.length > 0) {
+                    const checkData = {}, calcData = {};
+                    for (const field of checkFields) {
+                        checkData[field] = b[field] ? b[field] : 0;
+                    }
+                    for (const p of pr) {
+                        for (const field of checkFields) {
+                            calcData[field] = ZhCalc.add(calcData[field], p[field]);
+                        }
+                    }
+                    for (const field of checkFields) {
+                        calcData[field] = calcData[field] ? calcData[field] : 0;
+                    }
+                    if (!_.isMatch(checkData, calcData)) {
+                        result.push({
+                            ledger_id: b.ledger_id,
+                            b_code: b.b_code,
+                            name: b.name,
+                            serialNo: stageTree.getNodeIndex(stageTree.getItems(b.ledger_id)) + 1,
+                            error: {checkData: checkData, calcData: calcData}
+                        });
+                        differBills.push(b);
+                        for (const p of pr) {
+                            differPos.push(p);
+                        }
+                    }
+                    progress(parseInt((i+1)/iLen*90));
+                }
+            }
+
+            stagePos.updateDatas({update: differPos});
+            const refreshData = stageTree.loadPostStageData({bills: differBills});
+            progress(95);
+            stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
+            stagePosSpreadObj.loadCurPosData();
+            return result;
+        },
+        errorList: errorList,
+    });
+    $('[name=stage-start]').submit(function (e) {
+        if (checkAuditorFrom()) {
+            $(this).parent().parent().parent().modal('hide');
+            const formData = new FormData();
+            dataChecker.checkAndPost(this.action, formData);
+            $('#hide-all').hide();
+        }
+        return false;
+    });
 });

+ 1 - 0
app/public/js/stage_audit.js

@@ -160,6 +160,7 @@ function checkAuditorFrom () {
         return false;
     }
     $('#hide-all').show();
+    return true;
 }
 // texterea换行
 function auditCheck(i) {

+ 48 - 5
app/view/shares/check_data_modal.ejs

@@ -44,6 +44,7 @@
      * }
      */
     const DataChecker = function (setting) {
+        let progressInterval;
         $('#show-error-list').click(function () {
             $('#check').modal('hide');
             setting.errorList.show();
@@ -59,17 +60,58 @@
         const progress = function (percent) {
             $('.progress-bar').attr('aria-valuenow', percent).width(percent + '%').html(percent + '%');
         }
+        const fakeProgresTo = function (percent) {
+            const processObj = $('.progress-bar');
+            let count = 0;
+            progressInterval = setInterval(function () {
+                const pos = parseInt(processObj.attr('aria-valuenow'));
+                if (pos < 10) {                                       // 1
+                    processObj.attr('aria-valuenow', pos + 2);
+                    processObj.width((pos + 2) + '%');
+                } else if (pos < 20) {                                // 2
+                    processObj.attr('aria-valuenow', pos + 1);
+                    processObj.width((pos + 1) + '%');
+                } else if (pos < 30) {                         // 4
+                    count += 1;
+                    if (count % 2 === 0) {
+                        processObj.attr('aria-valuenow', pos + 1);
+                        processObj.width((pos + 1) + '%');
+                    }
+                } else if (pos < 40) {                         // 10
+                    count += 1;
+                    if (count % 5 === 0) {
+                        processObj.attr('aria-valuenow', pos + 1);
+                        processObj.width((pos + 1) + '%');
+                    }
+                } else if (pos < 45) {                        // 15
+                    count += 1;
+                    if (count % 15 === 0) {
+                        processObj.attr('aria-valuenow', pos + 1);
+                        processObj.width((pos + 1) + '%');
+                    }
+                }  else if (pos < 50) {                       // 20
+                    count += 1;
+                    if (count % 40 === 0) {
+                        processObj.attr('aria-valuenow', pos + 1);
+                        processObj.width((pos + 1) + '%');
+                    }
+                }
+            }, 100);
+        }
+        const stopFakeProgress = function (percent) {
+            clearInterval(progressInterval);
+            progress(percent);
+        }
         const addProgress = function (percent) {
-            if (percent % 2 === 0) {
-                const oldPercent = parseInt($('.progress-bar').attr('aria-valuenow'));
-                progress(oldPercent + percent/2);
-            }
+            const oldPercent = parseInt($('.progress-bar').attr('aria-valuenow'));
+            progress(oldPercent + parseInt(percent/2));
         }
         const checkAndPost = async function (postUrl, postForm) {
             progress(0);
             $('#check').modal('show');
+            fakeProgresTo(50);
             const lastestData = await loadCheckData();
-            progress(50);
+            stopFakeProgress(50);
             const result = setting.checkFun(lastestData, addProgress);
             progress(100);
             setTimeout(function () {
@@ -77,6 +119,7 @@
                     $('#check-error-hint').modal('show');
                     setting.errorList.loadErrorData(result);
                 } else {
+                    setting.errorList.clearErrorData();
                     postDataWithFile(postUrl, postForm, function () {
                         window.location.reload();
                     });

+ 2 - 2
app/view/stage/audit_modal.ejs

@@ -65,7 +65,7 @@
                             </div>
                         </div>
                     </div>
-                    <form class="modal-footer" method="post" action="<%- preUrl %>/audit/start" onsubmit="return checkAuditorFrom()">
+                    <form class="modal-footer" method="post" action="<%- preUrl %>/audit/start" name="stage-start">
                         <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
                         <input type="hidden" name="_csrf" value="<%= ctx.csrf %>">
                         <button class="btn btn-primary btn-sm" type="submit">确认上报</button>
@@ -937,7 +937,7 @@
                             </div>
                         </div>
                     </div>
-                    <form class="modal-footer" method="post" action="<%- preUrl %>/audit/start" onsubmit="return checkAuditorFrom()">
+                    <form class="modal-footer" method="post" action="<%- preUrl %>/audit/start" name="stage-start">
                         <input type="hidden" name="_csrf" value="<%= ctx.csrf %>">
                         <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
                         <button class="btn btn-primary btn-sm" type="submit">确认上报</button>

+ 8 - 3
app/view/stage/index.ejs

@@ -41,7 +41,7 @@
         <div class="c-header p-0">
         </div>
         <div class="row w-100 sub-content">
-            <div id="main-view" class="c-body" style="width: 100%">
+            <div id="left-view" class="c-body" style="width: 100%">
                 <!--上部分-->
                 <div class="sjs-height-1" id="stage-ledger">
                 </div>
@@ -99,8 +99,8 @@
                     </div>
                 </div>
             </div>
-            <div id="tools-view" class="c-body" style="display: none; width: 33%;">
-                <div class="resize-x" id="right-spr" r-Type="width" div1="#main-view" div2="#tools-view" title="调整大小" a-type="percent"><!--调整左右高度条--></div>
+            <div id="right-view" class="c-body" style="display: none; width: 33%;">
+                <div class="resize-x" id="right-spr" r-Type="width" div1="#left-view" div2="#right-view" title="调整大小" a-type="percent"><!--调整左右高度条--></div>
                 <div class="tab-content">
                     <!--中间计量-->
                     <div id="zhongjian" class="tab-pane tab-select-show">
@@ -500,6 +500,8 @@
                         <div class="sjs-bottom" id="ccb-spread">
                         </div>
                     </div>
+                    <div id="error-list" class="tab-pane">
+                    </div>
                 </div>
             </div>
         </div>
@@ -521,6 +523,9 @@
                 <li class="nav-item">
                     <a class="nav-link" content="#checked-change" href="javascript: void(0);">变更令</a>
                 </li>
+                <li class="nav-item">
+                    <a class="nav-link" content="#error-list" id="error-list-tab" href="javascript: void(0);" style="display: none;">错误列表</a>
+                </li>
             </ul>
         </div>
     </div>

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

@@ -383,3 +383,4 @@
 </div>
 <% include ./audit_modal.ejs %>
 <% include ../shares/merge_peg_modal.ejs %>
+<% include ../shares/check_data_modal.ejs %>