Browse Source

中间计量,第二次提交

MaiXinRong 5 years ago
parent
commit
0963faa8c2

+ 11 - 3
app/controller/stage_controller.js

@@ -251,15 +251,23 @@ module.exports = app => {
                 return await ctx.service.stageDetail.getLastestStageData(ctx.tender.id, ctx.stage.id);
             }
         }
+        async _getStageChangeData(ctx) {
+            if (ctx.stage.readOnly) {
+                return await ctx.service.stageChange.getAuditorAllStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
+            } else {
+                return await ctx.service.stageChange.getLastestAllStageData(ctx.tender.id, ctx.stage.id);
+            }
+        }
 
         async getStageData(ctx) {
             try {
                 const ledgerData = await this._getStageLedgerData(ctx);
                 const posData = await this._getStagePosData(ctx);
                 const detailData = await this._getStageDetailData(ctx);
+                const changeData = await this._getStageChangeData(ctx);
 
                 ctx.body = {err: 0, msg: '', data: {
-                    ledgerData, posData, detailData
+                    ledgerData, posData, detailData, changeData,
                 }};
             } catch (err) {
                 this.log(err);
@@ -478,7 +486,6 @@ module.exports = app => {
                         this.ctx.helper.assignRelaData(result.pos, [
                             {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
                         ]);
-                        result.stageDetail = await ctx.service.stageDetail.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
                     } else {
                         const curStage = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, ctx.stage.id);
                         this.ctx.helper.assignRelaData(result.ledger, [
@@ -488,8 +495,9 @@ module.exports = app => {
                         this.ctx.helper.assignRelaData(result.pos, [
                             {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
                         ]);
-                        result.stageDetail = await ctx.service.stageDetail.getLastestStageData(ctx.tender.id, ctx.stage.id);
                     }
+                    result.stageDetail = await this._getStageDetailData(ctx);
+                    result.changeData = await this._getStageChangeData(ctx);
                     ctx.body = { err: 0, msg: '', data: result };
                 }
             } catch (err) {

+ 12 - 14
app/public/js/stage.js

@@ -1321,7 +1321,7 @@ $(document).ready(() => {
         SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
         // 加载中间计量
         stageIm.init(stage, imType);
-        stageIm.loadData(result.ledgerData, result.posData, result.detailData);
+        stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
     }, null, true);
     spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
     spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
@@ -2230,26 +2230,20 @@ $(document).ready(() => {
                     updateData.unit_price = data.unit_price;
                 }
                 updateData.bgl_code = $('#bgl-code').val();
+                updateData.bgl_drawing_code = $('#bgl-drawing-code').val();
                 updateData.bw = $('#bw-name').val();
-                updateData.start_peg = $('#start-peg').val();
-                updateData.end_peg = $('#end-peg').val();
-                updateData.jldy = $('#unit-name').val();
+                updateData.peg = $('#peg').val();
+                updateData.xm = $('#xm-name').val();
                 updateData.drawing_code = $('#drawing-code').val();
                 updateData.calc_memo = $('#calc-memo').val();
                 postData(window.location.pathname + '/detail/save', updateData, function (result) {
                     _.assign(data, result);
-                    $('#edit-detail').show();
-                    $('#save-detail').hide();
-                    $('#cancel-detail').hide();
                     self.reLoadDetailData();
                     needCheckDetail();
                 });
             });
             // 取消
             $('#cancel-detail').click(() => {
-                $('#edit-detail').show();
-                $('#cancel-detail').hide();
-                $('#save-detail').hide();
                 self.reLoadDetailData();
             });
         }
@@ -2449,6 +2443,10 @@ $(document).ready(() => {
             $('#show-bgl-code').text(bglCode);
             $('#bgl-code').val(bglCode);
 
+            const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
+            $('#show-bgl-drawing-code').text(bglDrawingCode);
+            $('#bgl-drawing-code').val(bglDrawingCode);
+
             const bwName = data && data.bw ? data.bw : '';
             $('#show-bw-name').text(bwName);
             $('#bw-name').val(bwName);
@@ -2457,16 +2455,16 @@ $(document).ready(() => {
             $('#show-peg').text(peg);
             $('#peg').val(peg);
 
-            const xmjName = data && data.leaf_xmj_name ? data.leaf_xmj_name: '';
-            $('#show-xmj-name').text(xmjName);
-            $('#xmj-name').val(xmjName);
+            const xmName = data && data.xm ? data.xm: '';
+            $('#show-xm-name').text(xmName);
+            $('#xm-name').val(xmName);
 
             const drawingCode = data && data.drawing_code ? data.drawing_code: '';
             $('#show-drawing-code').text(drawingCode);
             $('#drawing-code').val(drawingCode);
 
             const calcMemo = data && data.calc_memo ? data.calc_memo: '';
-            $('#show-calc-memo').html(calcMemo.replace('\n', '<br/>'));
+            $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
             $('#calc-memo').val(calcMemo);
 
             const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';

+ 16 - 34
app/public/js/stage_detail.js

@@ -71,7 +71,7 @@ $(document).ready(() => {
         loadPosData: function () {
             const data = SpreadJsObj.getSelectObject(detailSpread.getActiveSheet());
             const html = [];
-            if (data) {
+            if (data && data.leafXmjs) {
                 const rowIndex = parseInt($('#leaf-xmj-list').attr('rowIndex'));
                 const leafXmj = data.leafXmjs[rowIndex];
                 if (leafXmj) {
@@ -123,16 +123,18 @@ $(document).ready(() => {
             $('#save-detail').hide();
             $('#cancel-detail').hide();
             $('#bgl-code').val(data && data.bgl_code ? data.bgl_code : '').attr('readonly', '');
+            $('#bgl-drawing-code').val(data && data.bgl_drawing_code ? data.bgl_drawing_code : '').attr('readonly', '');
             $('#bw-name').val(data && data.bw ? data.bw : '').attr('readonly', '');
-            $('#start-peg').val(data && data.start_peg ? data.start_peg : '').attr('readonly', '');
-            $('#end-peg').val(data && data.end_peg ? data.end_peg : '').attr('readonly', '');
-            $('#unit-name').val(data && data.jldy ? data.jldy : '').attr('readonly', '');
+            $('#peg').val(data && data.peg ? data.peg : '').attr('readonly', '');
+            $('#xm-name').val(data && data.xm ? data.xm : '').attr('readonly', '');
             $('#drawing-code').val(data && data.drawing_code ? data.drawing_code : '').attr('readonly', '');
             $('#calc-memo').val(data && data.calc_memo ? data.calc_memo : '').attr('readonly', '');
             if (data && data.calc_img) {
-                $('#calc-img').html('<img src="/' + data.calc_img + '" class="d-100" width="100%">');
+                $('#calc-img').attr('src', '/' + data.calc_img );
+                $('#view-calc-img').attr('src', '/' + data.calc_img );
             } else {
-                $('#calc-img').html('');
+                $('#calc-img').attr('');
+                $('#view-calc-img').attr('');
             }
         },
         selectionChanged: function (e, info) {
@@ -305,8 +307,7 @@ $(document).ready(() => {
     console.time('loadDetailRela');
     postData(window.location.pathname + '/load', { loadType: 'all' }, function (data) {
         console.timeEnd('loadDetailRela');
-        //stageIm.loadData(data.ledger, data.curStage, data.pos, data.curPosStage, data.stageDetail);
-        stageIm.loadData(data.ledger, data.pos, data.stageDetail);
+        stageIm.loadData(data.ledger, data.pos, data.stageDetail, data.changeData);
         reBuildImData();
     });
 
@@ -536,10 +537,10 @@ $(document).ready(() => {
         $('#save-detail').show();
         $('#cancel-detail').show();
         $('#bgl-code').removeAttr('readonly');
+        $('#bgl-drawing-code').removeAttr('readonly');
         $('#bw-name').removeAttr('readonly');
-        $('#start-peg').removeAttr('readonly');
-        $('#end-peg').removeAttr('readonly');
-        $('#unit-name').removeAttr('readonly');
+        $('#peg').removeAttr('readonly');
+        $('#xm-name').removeAttr('readonly');
         $('#drawing-code').removeAttr('readonly');
         $('#calc-memo').removeAttr('readonly');
     });
@@ -567,10 +568,10 @@ $(document).ready(() => {
             updateData.unit_price = data.unit_price;
         }
         updateData.bgl_code = $('#bgl-code').val();
+        updateData.bgl_drawing_code = $('#bgl-drawing-code').val();
         updateData.bw = $('#bw-name').val();
-        updateData.start_peg = $('#start-peg').val();
-        updateData.end_peg = $('#end-peg').val();
-        updateData.jldy = $('#unit-name').val();
+        updateData.peg = $('#peg').val();
+        updateData.xm = $('#xm-name').val();
         updateData.drawing_code = $('#drawing-code').val();
         updateData.calc_memo = $('#calc-memo').val();
         //check('bgl_code', $('#bgl-code'), data, updateData);
@@ -582,31 +583,12 @@ $(document).ready(() => {
         //check('calc_memo', $('#calc-memo'), data, updateData);
         postData(window.location.pathname + '/save', updateData, function (result) {
             _.assign(data, result);
-            $('#edit-detail').show();
-            $('#save-detail').hide();
-            $('#cancel-detail').hide();
-            $('#bgl-code').attr('readonly', '');
-            $('#bw-name').attr('readonly', '');
-            $('#start-peg').attr('readonly', '');
-            $('#end-peg').attr('readonly', '');
-            $('#unit-name').attr('readonly', '');
-            $('#drawing-code').attr('readonly', '');
-            $('#calc-memo').attr('readonly', '');
+            detailOperationObj.reLoadDetailData();
             needCheckDetail();
         });
     });
     // 取消
     $('#cancel-detail').click(() => {
-        $('#edit-detail').show();
-        $('#cancel-detail').hide();
-        $('#save-detail').hide();
-        $('#bgl-code').attr('readonly', '');
-        $('#bw-name').attr('readonly', '');
-        $('#start-peg').attr('readonly', '');
-        $('#end-peg').attr('readonly', '');
-        $('#unit-name').attr('readonly', '');
-        $('#drawing-code').attr('readonly', '');
-        $('#calc-memo').attr('readonly', '');
         detailOperationObj.reLoadDetailData();
     });
 

+ 307 - 75
app/public/js/stage_im.js

@@ -9,9 +9,9 @@
  */
 
 const stageIm = (function () {
-    const imFields = ['uuid', 'doc_code', 'bgl_code', 'start_peg', 'end_peg', 'bw', 'jldy', 'drawing_code', 'calc_memo', 'calc_img'];
+    const imFields = ['uuid', 'doc_code', 'bgl_code', 'bgl_drawing_code', 'peg', 'bw', 'xm', 'drawing_code', 'calc_memo', 'calc_img'];
     const splitChar = '-';
-    let stage, imType, details, ImData, pre;
+    let stage, imType, details, changes, ImData, pre;
     const gsTreeSetting = {
         id: 'ledger_id',
         pid: 'ledger_pid',
@@ -57,14 +57,14 @@ const stageIm = (function () {
     }
 
     function initCheck () {
-        const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(','), _.toNumber) : [];
+        const gatherNodes = stage.im_gather_node ? stage.im_gather_node.split(',') : [];
         for (const node of gsTree.datas) {
             node.check = gatherNodes.indexOf(node.id) !== -1;
         }
 
     }
 
-    function loadData (ledger, pos, stageDetail) {
+    function loadData (ledger, pos, stageDetail, stageChange) {
         gsTree.loadDatas(ledger);
         treeCalc.calculateAll(gsTree);
 
@@ -73,6 +73,8 @@ const stageIm = (function () {
 
         initCheck();
         details = stageDetail;
+
+        changes = stageChange;
     }
 
     // function loadData (ledger, curStage, pos, curPosStage, stageDetail) {
@@ -161,13 +163,64 @@ const stageIm = (function () {
         }
     }
 
+    function getZlNormalBw(node, peg) {
+        if (peg) {
+            const subPeg1 = getNodeByLevel(node, peg.level + 1);
+            const subPeg2 = getNodeByLevel(node, peg.level + 2);
+            let result = peg.name;
+            if (subPeg1 && subPeg1.id !== peg.id) {
+                result = result + '-' + subPeg1.name;
+                if (subPeg2 && subPeg2.id !== subPeg1.id) {
+                    result = result + '-' + subPeg2.name;
+                }
+            }
+            return result;
+        } else {
+            if (node.level === 2) {
+                return node.name;
+            } else if (node.level >= 3) {
+                let parent = node, result = parent.name;
+                while (parent.level > 3 && parent) {
+                    parent = getNodeByLevel(node, parent.level - 1);
+                    result = parent.name + '-' + result;
+                }
+                return result;
+            } else {
+                return '';
+            }
+        }
+    }
+
+    function getZlGatherBw(node, peg) {
+        if (peg) {
+            const subPeg1 = getNodeByLevel(node, peg.level + 1);
+            let result = peg.name;
+            if (subPeg1 && subPeg1.id !== peg.id) {
+                result = result + '-' + subPeg1.name;
+            }
+            return result;
+        } else {
+            if (node.level < 3) {
+                return node.name;
+            } else {
+                let parent = node, result = parent.name;
+                while (parent.level > 3 && parent) {
+                    parent = getNodeByLevel(node, parent.level - 1);
+                    result = parent.name + '-' + result;
+                }
+                return result;
+            }
+        }
+    }
+
     function checkCustomDetail(im) {
         const cd = _.find(details, function (d) {
             return im.lid === d.lid &&
                 (!im.code || im.code === d.code) &&
                 (!im.name || im.name === d.name) &&
                 (!im.unit || im.unit === d.unit) &&
-                checkZero(ZhCalc.sub(im.unit_price, d.unit_price));
+                checkZero(ZhCalc.sub(im.unit_price, d.unit_price)) &&
+                (!im.pid || im.pid === d.pid);
         });
         if (cd) {
             _.assignInWith(im, cd, function (oV, sV, key) {
@@ -176,58 +229,117 @@ const stageIm = (function () {
         }
     }
 
-    function generatePosData(node, lx) {
-        if (!lx.pos) {
-            lx.pos = [];
+    function getCalcMemo(im) {
+        if (im.calc_memo !== undefined && im.calc_memo !== null && im.calc_memo !== '') return;
+
+        if (im.leafXmjs && im.leafXmjs.length > 0) {
+            const memo = ['本期计量:' + im.jl + ' ' + im.unit];
+            for (const lx of im.leafXmjs) {
+                for (const p of lx.pos) {
+                    memo.push(p.name + ':' + p.jl + ' ' + im.unit);
+                }
+            }
+            im.calc_memo = memo.join('\n');
+        } else if (im.gclBills && im.gclBills.length > 0) {
+            const memo = [];
+            for (const [i, b] of im.gclBills.entries()) {
+                if (b.pos && b.pos.length > 0) {
+                    memo.push('清单' + (i+1) + b.b_code + ' ' + b.name);
+                    for (const p of b.pos) {
+                        memo.push(p.name + ':' + p.jl + ' ' + b.unit);
+                    }
+                } else {
+                    memo.push('清单' + (i+1) + b.b_code + ' ' + b.name + ':' + b.jl + ' ' + b.unit);
+                }
+            }
+            im.calc_memo = memo.join('\n');
+        } else {
+            im.calc_memo =  '';
+        }
+    }
+    function getChangeInfo(im) {
+        if (im.changes && im.changes.length > 0) {
+            const code = _.uniq(_.map(im.changes, 'c_code'));
+            if (!im.bgl_code || im.bgl_code === '') im.bgl_code = code.join(';');
+            const new_code = _.uniq(_.map(im.changes, 'c_new_code'));
+            if (!im.bgl_drawing_code || im.bgl_drawing_code === '') im.bgl_drawing_code = new_code.join(';');
+        }
+    }
+
+    function generateTzPosData(node, gclBills) {
+        if (!gclBills.pos) {
+            gclBills.pos = [];
         }
         const posRange = gsPos.getLedgerPos(node.id);
         if (!posRange) { return }
         for (const p of posRange) {
             if (!p.gather_qty || checkZero(p.gather_qty)) { continue; }
-            let lp = _.find(lx.pos, {name: p.name});
+            let lp = _.find(gclBills.pos, {name: p.name});
             if (!lp) {
-                lp = {name: p.name, qty: p.gather_qty};
-                lx.pos.push(lp);
+                lp = {name: p.name};
+                gclBills.pos.push(lp);
             }
             lp.jl = ZhCalc.add(lp.jl, p.gather_qty);
+            lp.contract_jl = ZhCalc.add(lp.contract_jl, p.contract_qty);
+            lp.qc_jl = ZhCalc.add(lp.qc_jl, p.qc_qty);
         }
     }
-
-    /**
-     * 生成所属项目节数据(取最底层项目节)
-     * @param node - 生成数据基于的台账节点
-     * @param im - 中间计量数据
-     */
-    function generateLeafXmjData(node, im, jlField) {
-        if (!im.leafXmjs) {
-            im.leafXmjs = [];
+    function generateTzGclBillsData(node, im) {
+        if (!im.gclBills) {
+            im.gclBills = [];
         }
-        const leafXmj = gsTree.getLeafXmjParent(node);
-        if (!leafXmj) { return }
-        let lx = _.find(im.leafXmjs, {lxid: leafXmj.id});
-        if (!lx) {
-            lx = {
-                lxid: leafXmj.id,
-                code: leafXmj.code,
-                name: leafXmj.name
-            };
-            im.leafXmjs.push(lx);
+        const posterity = gsTree.getPosterity(node);
+        for (const p of posterity) {
+            if (p.children && p.children.length > 0) {
+                continue;
+            }
+            if ((!p.contract_tp || p.contract_tp === 0) && (!p.qc_tp || p.qc_tp === 0)) {
+                continue;
+            }
+            let b = _.find(im.gclBills, {bid: p.id});
+            if (!b) {
+                b = {bid: p.id, b_code: p.b_code, name: p.name, unit: p.unit};
+                im.gclBills.push(b);
+            }
+            b.jl = ZhCalc.add(b.jl, p.gather_qty);
+            b.contract_jl = ZhCalc.add(b.contract_jl, p.contract_qty);
+            b.qc_jl = ZhCalc.add(b.qc_jl, p.qc_qty);
+            generateTzPosData(p, b);
         }
-        lx.jl = ZhCalc.add(lx.jl, node[jlField]);
-        generatePosData(node, lx);
     }
-
-    function getCalcMemo(im) {
-        if (im.calc_memo !== undefined && im.calc_memo !== null && im.calc_memo !== '') return;
-        const memo = ['本期计量:' + im.jl + ' ' + im.unit];
-        for (const lx of im.leafXmjs) {
-            for (const p of lx.pos) {
-                memo.push(p.name + ':' + p.qty + ' ' + im.unit);
+    function generateTzChangeData(node, im) {
+        if (!im.changes) {
+            im.changes = [];
+        }
+        const posterity = gsTree.getPosterity(node);
+        for (const p of posterity) {
+            if (p.children && p.children.length > 0) {
+                continue;
+            }
+            if ((!p.qc_tp || p.qc_tp === 0)) {
+                continue;
+            }
+            const posRange = gsPos.getLedgerPos(p.id);
+            if (!posRange) {
+                for (const c of changes) {
+                    if (c.lid === p.id && c.pid == -1) {
+                        im.changes.push(c);
+                    }
+                }
+            } else {
+                for (const pp of posRange) {
+                    if ((!pp.qc_tp || pp.qc_tp === 0)) {
+                        continue;
+                    }
+                    for (const c of changes) {
+                        if (c.lid === p.id && c.pid === pp.id) {
+                            im.changes.push(c);
+                        }
+                    }
+                }
             }
         }
-        return memo.join('\n');
     }
-
     /**
      * 生成 0号台账 中间计量数据
      * @param {Object} node - 生成中间计量表的节点
@@ -236,28 +348,92 @@ const stageIm = (function () {
         if (node.gather_tp) {
             const peg = getPegNode(node);
             const im = {
-                lid: node.id,
-                code: node.code,
-                jl: node.gather_tp,
-                contract_jl: node.contract_tp,
-                qc_jl: node.qc_tp,
+                lid: node.id, code: node.code,
+                jl: node.gather_tp, contract_jl: node.contract_tp, qc_jl: node.qc_tp,
                 im_code: getNewImCode(),
-                fbfx: getFbfx(node, peg),
-                peg: peg ? peg.name : '',
-                drawing_code: getDrawingCode(node),
+                peg: peg ? peg.name : '', drawing_code: getDrawingCode(node),
             };
             if (stage.im_gather && node.check) {
-                im.bw = node.name;
+                im.bw = getZlGatherBw(node, peg);
+                im.xm = '';
             } else {
-                im.jldy = node.name;
-                im.bw = node.name
+                im.bw = getZlNormalBw(node, peg);
+                im.xm = node.name;
             }
             checkCustomDetail(im);
-            generateLeafXmjData(node, im, 'gather_tp');
+            if (!stage.im_gather || !node.check) {
+                generateTzGclBillsData(node, im);
+            }
             ImData.push(im);
+            generateTzChangeData(node, im);
         }
     }
 
+    function generateZlPosData(node, lx) {
+        if (!lx.pos) {
+            lx.pos = [];
+        }
+        const posRange = gsPos.getLedgerPos(node.id);
+        if (!posRange) { return }
+        for (const p of posRange) {
+            if (!p.gather_qty || checkZero(p.gather_qty)) { continue; }
+            let lp = _.find(lx.pos, {name: p.name});
+            if (!lp) {
+                lp = {name: p.name};
+                lx.pos.push(lp);
+            }
+            lp.jl = ZhCalc.add(lp.jl, p.gather_qty);
+            lp.contract_jl = ZhCalc.add(lp.contract_jl, p.contract_qty);
+            lp.qc_jl = ZhCalc.add(lp.qc_jl, p.qc_qty);
+        }
+    }
+    function generateZlLeafXmjData(node, im) {
+        if (!im.leafXmjs) {
+            im.leafXmjs = [];
+        }
+        const leafXmj = gsTree.getLeafXmjParent(node);
+        if (!leafXmj) { return }
+        let lx = _.find(im.leafXmjs, {lxid: leafXmj.id});
+        if (!lx) {
+            lx = {
+                lxid: leafXmj.id,
+                code: leafXmj.code,
+                name: leafXmj.name
+            };
+            im.leafXmjs.push(lx);
+        }
+        lx.jl = ZhCalc.add(lx.jl, node.gather_qty);
+        lx.contract_jl = ZhCalc.add(lx.contract_jl, node.contract_qty);
+        lx.qc_jl = ZhCalc.add(lx.qc_jl, node.qc_qty);
+        generateZlPosData(node, lx);
+    }
+    function generateZlChangeData(node, im) {
+        if (!im.changes) {
+            im.changes = [];
+        }
+        if ((!node.qc_tp || node.qc_tp === 0)) {
+            return;
+        }
+        const posRange = gsPos.getLedgerPos(node.id);
+        if (!posRange) {
+            for (const c of changes) {
+                if (c.lid === node.id && c.pid == -1) {
+                    im.changes.push(c);
+                }
+            }
+        } else {
+            for (const p of posRange) {
+                if ((!p.qc_tp || p.qc_tp === 0)) {
+                    continue;
+                }
+                for (const c of changes) {
+                    if (c.lid === node.id && c.pid === p.id) {
+                        im.changes.push(c);
+                    }
+                }
+            }
+        }
+    }
     /**
      * 生成 总量控制 中间计量数据
      * @param {Object} node - 生成中间计量表的节点
@@ -269,41 +445,97 @@ const stageIm = (function () {
             if (!p.b_code || p.b_code === '') { continue }
             if (!p.gather_qty || p.gather_qty === 0 ) { continue; }
             let im = nodeImData.find(function (d) {
-                return d.code === p.b_code && p.name === d.name && p.unit === d.unit && checkZero(ZhCalc.sub(p.unit_price, d.unit_price));
+                return d.lid === node.id &&
+                    d.code === p.b_code && p.name === d.name && p.unit === d.unit && checkZero(ZhCalc.sub(p.unit_price, d.unit_price));
             });
             if (!im) {
                 const peg = getPegNode(node);
                 im = {
-                    lid: node.id,
-                    code: p.b_code,
-                    name: p.name,
-                    unit: p.unit,
-                    unit_price: p.unit_price,
-                    jl: 0,
-                    contract_jl: 0,
-                    qc_jl: 0,
+                    lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price,
+                    jl: 0, contract_jl: 0, qc_jl: 0,
                     im_code: getNewImCode(),
-                    fbfx: getFbfx(node, peg),
-                    peg: peg ? peg.name : '',
-                    drawing_code: getDrawingCode(node),
-                    bw: node.name,
+                    peg: peg ? peg.name : '', drawing_code: getDrawingCode(node),
                 };
                 if (stage.im_gather && node.check) {
-
+                    im.bw = getZlGatherBw(node, peg);
+                    im.xm = '';
                 } else {
-                    im.jldy = p.name;
+                    im.bw = getZlNormalBw(node, peg);
+                    im.xm = node.name;
                 }
                 nodeImData.push(im);
                 checkCustomDetail(im);
                 ImData.push(im);
             }
-            generateLeafXmjData(p, im, 'gather_qty');
+            if (!stage.im_gather || !node.check) {
+                generateZlLeafXmjData(p, im, 'gather_qty');
+            }
+            generateZlChangeData(p, im);
             im.jl = ZhCalc.add(im.jl, p.gather_qty);
             im.contract_jl = ZhCalc.add(im.contract_jl, p.contract_qty);
             im.qc_jl = ZhCalc.add(im.qc_jl, p.qc_qty);
         }
     }
 
+    function generateBwImData (node) {
+        const posterity = gsTree.getPosterity(node);
+        for (const p of posterity) {
+            if (p.children && p.children.length > 0 ) { continue; }
+            if (!p.b_code || p.b_code === '') { continue }
+            const peg = getPegNode(node);
+            const pPos = gsPos.getLedgerPos(p.id);
+            const bw = getZlNormalBw(node, peg);
+            if (pPos && pPos.length > 0) {
+                for (const pp of pPos) {
+                    if ((!pp.contract_qty || pp.contract_qty === 0) && (!pp.qc_qty || pp.qc_qty === 0)) { continue }
+                    const im = {
+                        lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, pid: pp.id,
+                        jl: pp.gather_qty, contract_jl: pp.contract_qty, qc_jl: pp.qc_qty,
+                        im_code: getNewImCode(),
+                        bw: bw,
+                        peg: CheckPeg(pp.name) ? pp.name : (peg ? peg.name : ''),
+                        xm: pp.name,
+                        drawing_code: pp.drawing_code,
+                        changes: [],
+                    };
+                    im.calc_memo = '本期计量:' + im.jl + ' ' + im.unit;
+                    checkCustomDetail(im);
+                    ImData.push(im);
+                    if (pp.qc_qty && pp.qc_qty !== 0) {
+                        for (const c of changes) {
+                            if (c.lid === p.id && c.pid === pp.id) {
+                                im.changes.push(c);
+                            }
+                        }
+                    }
+                }
+            } else {
+                if ((!p.contract_qty || p.contract_qty === 0) && (!p.qc_qty || p.qc_qty === 0)) { continue }
+
+                const im = {
+                    lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, pid: '',
+                    jl: p.gather_qty, contract_jl: p.contract_qty, qc_jl: p.qc_qty,
+                    im_code: getNewImCode(),
+                    bw: bw,
+                    peg: peg ? peg.name : '',
+                    xm: node.name,
+                    drawing_code: getDrawingCode(node),
+                    changes: [],
+                };
+                im.calc_memo = '本期计量:' + im.jl + ' ' + im.unit;
+                checkCustomDetail(im);
+                ImData.push(im);
+                if (p.qc_qty && p.qc_qty !== 0) {
+                    for (const c of changes) {
+                        if (c.lid === p.id && c.pid == -1) {
+                            im.changes.push(c);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
     /**
      * 递归 生成中间计量表
      * @param {Array} nodes
@@ -311,11 +543,13 @@ const stageIm = (function () {
     function recursiveBuildImData (nodes) {
         if (!nodes || nodes.length === 0) { return; }
         for (const node of nodes) {
-            if (gsTree.isLeafXmj(node) || (stage.im_gather && node.check)) {
+            if (gsTree.isLeafXmj(node) || (stage.im_type !== imType.bw.value && stage.im_gather && node.check)) {
                 if (stage.im_type === imType.tz.value) {
                     generateTzImData(node);
-                } else {
+                } else if (stage.im_type === imType.zl.value) {
                     generateZlImData(node);
+                } else if (stage.im_type === imType.bw.value) {
+                    generateBwImData(node);
                 }
             } else {
                 recursiveBuildImData(node.children);
@@ -337,10 +571,8 @@ const stageIm = (function () {
         // 生成数据
         recursiveBuildImData(gsTree.children);
         for (const im of ImData) {
-            im.calc_memo = getCalcMemo(im);
-            if (im.leafXmjs && im.leafXmjs.length === 1) {
-                im.leaf_xmj_name = im.leafXmjs[0].name;
-            }
+            getCalcMemo(im);
+            getChangeInfo(im);
         }
         return ImData;
     }

+ 34 - 2
app/service/stage_change.js

@@ -58,17 +58,49 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditorStageData(tid, sid, times, order, lid, pid) {
-            const sql = 'SELECT c.* FROM ' + this.tableName + ' As c ' +
+            const sql = 'SELECT c.*' +
+                '  oc.code As c_code, oc.new_code As c_new_code' +
+                '  FROM ' + this.tableName + ' As c ' +
                 '  INNER JOIN ( ' +
                 '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
                 '      WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) And lid = ? And pid = ?' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`';
+                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`'
+            '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
+            '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid, times, times, order, lid, pid ? pid : -1];
             return await this.db.query(sql, sqlParam);
         }
 
+        async getLastestAllStageData(tid, sid) {
+            const sql = 'SELECT c.*,' +
+                '  oc.code As c_code, oc.new_code As c_new_code' +
+                '  FROM ' + this.tableName + ' As c ' +
+                '  INNER JOIN ( ' +
+                '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
+                '      WHERE tid = ? And sid = ?' +
+                '      GROUP By `lid`, `pid`' +
+                '  ) As m ' +
+                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid`' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
+                '  ON c.cid = oc.cid';
+            const sqlParam = [tid, sid];
+            return await this.db.query(sql, sqlParam);
+        }
+
+        async getAuditorAllStageData(tid, sid, times, order) {
+            const sql = 'SELECT c.* FROM ' + this.tableName + ' As c ' +
+                '  INNER JOIN ( ' +
+                '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
+                '      WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
+                '      GROUP By `lid`, `pid`' +
+                '  ) As m ' +
+                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid`';
+            const sqlParam = [tid, sid, times, times, order];
+            return await this.db.query(sql, sqlParam);
+        }
+
         /**
          * 台账,调用变更令
          *

+ 13 - 11
app/view/stage/detail.ejs

@@ -55,24 +55,24 @@
                                 <input class="form-control form-control-sm" type="text" readonly="" id="bgl-code">
                             </div>
                             <div class="form-group">
-                                <label>部位:</label>
-                                <input class="form-control form-control-sm" type="text" readonly="" value="" id="bw-name">
+                                <label>变更图号:</label>
+                                <input class="form-control  form-control-sm" type="text" readonly="" id="bgl-drawing-code">
                             </div>
                             <div class="form-group">
-                                <label>起始桩号:</label>
-                                <input class="form-control form-control-sm" type="text" readonly="" value="" id="start-peg">
+                                <label>部位:</label>
+                                <input class="form-control form-control-sm" type="text" readonly="" id="bw-name">
                             </div>
                             <div class="form-group">
-                                <label>止桩号:</label>
-                                <input class="form-control form-control-sm" type="text" readonly="" value="" id="end-peg">
+                                <label>止桩号:</label>
+                                <input class="form-control form-control-sm" type="text" readonly="" id="peg">
                             </div>
                             <div class="form-group">
-                                <label>计量单元:</label>
-                                <input class="form-control form-control-sm" type="text" readonly="" value="" id="unit-name">
+                                <label>细目:</label>
+                                <input class="form-control form-control-sm" type="text" readonly="" id="xm-name">
                             </div>
                             <div class="form-group">
-                                <label>图号:</label>
-                                <input class="form-control form-control-sm" type="text" readonly="" value="" id="drawing-code">
+                                <label>图:</label>
+                                <input class="form-control form-control-sm" type="text" readonly="" id="drawing-code">
                             </div>
                             <div class="form-group">
                                 <label>计算式说明:</label>
@@ -85,7 +85,9 @@
                                     <a href="#edit-img" data-toggle="modal" data-target="#edit-img" id="modify-img" style="display: none;">添加草图</a>
                                     <% } %>
                                 </div>
-                                <p id="calc-img"><img src="" class="d-100" width="100%"></p>
+                                <p>
+                                    <a href="#imgview" data-toggle="modal" data-target="#imgview"><img src="" class="d-100" width="100%" id="calc-img"></a>
+                                </p>
                             </div>
                         </div>
                     </div>

+ 17 - 1
app/view/stage/detail_modal.ejs

@@ -11,7 +11,7 @@
                     <div class="row" id="im-type">
                         <% for (const i in imType) { %>
                         <% console.log(ctx.stage.im_type === imType[i].value); %>
-                        <div class="col-6">
+                        <div class="col-4">
                             <div class="card border-primary" name="im-type" im-type="<%- imType[i].value %>" <% if (ctx.stage.im_type !== imType[i].value) { %>style="cursor:pointer;"<% } %>>
                                 <div class="card-body<% if (ctx.stage.im_type === imType[i].value) { %> text-primary<% } %>">
                                     <h5 class="card-title mb-0" im-type="<%- imType[i].value %>">
@@ -144,4 +144,20 @@
         </div>
     </div>
 </div>
+<!--草图预览-->
+<div class="modal fade" id="imgview" data-backdrop="static">
+    <div class="modal-dialog modal-lgx" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">查看草图</h5>
+            </div>
+            <div class="modal-body">
+                <img src="" id="view-calc-img">
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
+            </div>
+        </div>
+    </div>
+</div>
 <% include ./audit_modal.ejs %>

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

@@ -125,7 +125,7 @@
                                 <tr><th>变更图号</th><td id="show-bgl-drawing-code"></td></tr>
                                 <tr><th>部位</th><td id="show-bw-name"></td></tr>
                                 <tr><th>起止桩号</th><td id="show-peg"></td></tr>
-                                <tr><th>细目</th><td id="show-xmj-name"></td></tr>
+                                <tr><th>细目</th><td id="show-xm-name"></td></tr>
                                 <tr><th>图册号</th><td id="show-drawing-code"></td></tr>
                                 <tr><th colspan="2">计算式说明</th></tr>
                                 <tr><td colspan="2" id="show-calc-memo" style="word-wrap:break-word"></td></tr>
@@ -175,7 +175,7 @@
                                     <div class="input-group-prepend">
                                         <span class="input-group-text">细目</span>
                                     </div>
-                                    <input type="text" class="form-control" value="" id="xmj-name">
+                                    <input type="text" class="form-control" value="" id="xm-name">
                                 </div>
                                 <div class="input-group input-group-sm mb-2">
                                     <div class="input-group-prepend">

+ 2 - 3
app/view/stage/modal.ejs

@@ -207,7 +207,7 @@
             <div class="modal-body">
                 <div class="form-group">
                     <label for="formGroupExampleInput">大小限制:10MB,支持<span data-toggle="tooltip" data-placement="bottom" title="" data-original-title="doc,docx,xls,xlsx,ppt,pptx,pdf">office等文档格式</span>、<span data-toggle="tooltip" data-placement="bottom" title="" data-original-title="jpg,png,bmp">图片格式</span>、<span data-toggle="tooltip" data-placement="bottom" title="" data-original-title="rar,zip">压缩包格式</span></label>
-                    <input type="file" class="form-control form-control-sm" id="upload-file" multiple>
+                    <input type="file" class="" id="upload-file" multiple>
                 </div>
             </div>
             <div class="modal-footer">
@@ -248,8 +248,7 @@
                     <label>中间计量模式 <a href="/public/images/example/jiliangmoshi.png" target="_blank" data-toggle="tooltip" data-placement="bottom" data-original-title="点击查看相关报表"><i class="fa fa-question-circle-o"></i></a></label>
                     <div class="row" id="im-type">
                         <% for (const i in imType) { %>
-                        <% console.log(ctx.stage.im_type === imType[i].value); %>
-                        <div class="col-6">
+                        <div class="col-4">
                             <div class="card border-primary" name="im-type" im-type="<%- imType[i].value %>" <% if (ctx.stage.im_type !== imType[i].value) { %>style="cursor:pointer;"<% } %>>
                                 <div class="card-body<% if (ctx.stage.im_type === imType[i].value) { %> text-primary<% } %>">
                                     <h5 class="card-title mb-0" im-type="<%- imType[i].value %>">

+ 1 - 1
app/view/tender/tender_sub_menu.ejs

@@ -21,7 +21,7 @@
             </ul>
         </div>
         <div class="nav-box">
-            <h3><i class="fa fa-calendar-check-o"></i> 计量台帐</h3>
+            <h3><i class="fa fa-calendar-check-o"></i> 计量支付</h3>
             <ul class="nav-list list-unstyled sub-list">
                 <li <% if (ctx.url === '/tender/' + ctx.tender.id + '/measure/stage') { %>class="active"<% } %>><a href="/tender/<%- ctx.tender.id %>/measure/stage"><span>期列表</span></a></li>
                 <li <% if (ctx.url === '/tender/' + ctx.tender.id + '/measure/compare') { %>class="active"<% } %>><a href="/tender/<%- ctx.tender.id %>/measure/compare"><span>多期比较</span></a></li>

+ 1 - 1
app/view/tender/tender_sub_mini_menu.ejs

@@ -18,7 +18,7 @@
             </ul>
         </div>
         <div class="nav-box">
-            <h3><i class="fa fa-calendar-check-o"></i> 计量台帐</h3>
+            <h3><i class="fa fa-calendar-check-o"></i> 计量支付</h3>
             <ul class="nav-list list-unstyled sub-list">
                 <li <% if (ctx.url === '/tender/' + ctx.tender.id + '/measure/stage') { %>class="active"<% } %>><a href="/tender/<%- ctx.tender.id %>/measure/stage"><span>期列表</span></a></li>
                 <li <% if (ctx.url === '/tender/' + ctx.tender.id + '/measure/compare') { %>class="active"<% } %>><a href="/tender/<%- ctx.tender.id %>/measure/compare"><span>多期比较</span></a></li>