Browse Source

定位至中间计量

MaiXinRong 5 years ago
parent
commit
a388a84c23
3 changed files with 133 additions and 32 deletions
  1. 24 32
      app/public/js/spreadjs_rela/spreadjs_zh.js
  2. 41 0
      app/public/js/stage.js
  3. 68 0
      app/public/js/stage_im.js

+ 24 - 32
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -865,6 +865,15 @@ const SpreadJsObj = {
         sheet.getParent().focus();
         sheet.showRow(index, spreadNS.VerticalPosition.center);
     },
+    locateData: function (sheet, data) {
+        if (!sheet.zh_data) { return }
+        const index = sheet.zh_data.indexOf(data);
+        const sels = sheet.getSelections();
+        sheet.setSelection(index, sels[0].col, 1, 1);
+        SpreadJsObj.reloadRowsBackColor(sheet, [index, sels[0].row]);
+        sheet.getParent().focus();
+        sheet.showRow(index, spreadNS.VerticalPosition.center);
+    },
     saveTopAndSelect: function (sheet, cacheKey) {
         const sel = sheet.getSelections()[0];
         const top = sheet.getViewportTopRow(1);
@@ -1693,16 +1702,20 @@ const SpreadJsObj = {
                 }
 
             };
-            proto.paint = function (canvas, value, x, y, w, h, style, options) {
-                const col = options.sheet.zh_setting.cols[options.col];
+            proto.getActiveImage = function(sheet, iRow, iCol) {
+                const col = sheet.zh_setting.cols[iCol];
 
-                const sortData = SpreadJsObj.getSortData(options.sheet);
-                const data = sortData ? sortData[options.row] : null;
+                const sortData = SpreadJsObj.getSortData(sheet);
+                const data = sortData ? sortData[iRow] : null;
                 let showImage = true;
                 if (col.showImage && Object.prototype.toString.apply(col.showImage) === "[object Function]") {
                     showImage = col.showImage(data);
                 }
-                const img = showImage ? this.getImage(options.sheet, options.row, options.col) : null;
+                const img = showImage ? this.getImage(sheet, iRow, iCol) : null;
+                return [col, img];
+            };
+            proto.paint = function (canvas, value, x, y, w, h, style, options) {
+                const [col, img] = this.getActiveImage(options.sheet, options.row, options.col);
 
                 const indent = col.indent ? col.indent : 10;
                 if (style.hAlign === spreadNS.HorizontalAlign.right) {
@@ -1802,15 +1815,8 @@ const SpreadJsObj = {
              注释部分以进入鼠标进入图片,点击图片为基准更新图片,鼠标快速移动时,可能失效
               */
             proto.processMouseDown = function (hitinfo) {
-                const col = options.sheet.zh_setting.cols[hitinfo.col];
-
-                const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
-                const data = sortData ? sortData[hitinfo.row] : null;
-                let showImage = true;
-                if (col.showImage && Object.prototype.toString.apply(col.showImage) === "[object Function]") {
-                    showImage = col.showImage(data);
-                }
-                const img = showImage ? this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col) : null;
+                const [col, img] = this.getActiveImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
+                if (!img) return;
 
                 const halfX = img.width / 2, halfY = img.height / 2;
                 const indent = col.indent ? col.indent : 10;
@@ -1826,15 +1832,8 @@ const SpreadJsObj = {
                 }
             };
             proto.processMouseUp = function (hitinfo) {
-                const col = options.sheet.zh_setting.cols[hitinfo.col];
-
-                const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
-                const data = sortData ? sortData[hitinfo.row] : null;
-                let showImage = true;
-                if (col.showImage && Object.prototype.toString.apply(col.showImage) === "[object Function]") {
-                    showImage = col.showImage(data);
-                }
-                const img = showImage ? this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col) : null;
+                const [col, img] = this.getActiveImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
+                if (!img) return;
 
                 const halfX = img.width / 2, halfY = img.height / 2;
                 const indent = col.indent ? col.indent : 10;
@@ -1856,15 +1855,8 @@ const SpreadJsObj = {
                 }
             };
             proto.processMouseMove = function (hitinfo) {
-                const col = options.sheet.zh_setting.cols[hitinfo.col];
-
-                const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
-                const data = sortData ? sortData[hitinfo.row] : null;
-                let showImage = true;
-                if (col.showImage && Object.prototype.toString.apply(col.showImage) === "[object Function]") {
-                    showImage = col.showImage(data);
-                }
-                const img = showImage ? this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col) : null;
+                const [col, img] = this.getActiveImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
+                if (!img) return;
 
                 const halfX = img.width / 2, halfY = img.height / 2;
                 const indent = col.indent ? col.indent : 10;

+ 41 - 0
app/public/js/stage.js

@@ -1044,6 +1044,47 @@ $(document).ready(() => {
         });
     }
     stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
+    $.contextMenu({
+        selector: '#stage-ledger',
+        build: function ($trigger, e) {
+            const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
+            return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
+        },
+        items: {
+            'locateZjjl': {
+                name: '定位至中间计量',
+                icon: 'fa-sign-in',
+                callback: function (key, opt) {
+                    if (!detail) {
+                        detail = new Detail($('#detail-spread'));
+                    }
+                    const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
+                    const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
+                    if (leafUsedBills) {
+                        if (!$('#zhongjian').hasClass('active')) {
+                            const tab = $('#zhongjian'), tabPanel = $(tab.attr('content'));
+                            $('a', '.side-menu').removeClass('active');
+                            $('.tab-content .tab-select-show').removeClass('active');
+                            tab.addClass('active');
+                            tabPanel.addClass('active');
+                            showSideTools(tab.hasClass('active'));
+                            slSpread.refresh();
+                            spSpread.refresh();
+                        }
+                        const relaXmj = stageIm.getRelaXmj(leafUsedBills);
+                        const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
+                        SpreadJsObj.locateData(detail.sheet, im);
+                        detail.spread.refresh();
+                        $('#zhongjian .sjs-bottom').height('400px');
+                        $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
+                        detail.reLoadDetailData();
+                    } else {
+                        toastr.error('无可定位中间计量');
+                    }
+                },
+            },
+        }
+    });
 
     const stagePosSpreadObj = {
         loadExprToInput(sheet) {

+ 68 - 0
app/public/js/stage_im.js

@@ -445,6 +445,28 @@ const stageIm = (function () {
         }
     }
 
+    function getFirstUsedPos(node) {
+        const pPos = gsPos.getLedgerPos(node.id);
+        if (!pPos || pPos.length === 0) return null;
+        for (const pp of pPos) {
+            if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty)) return pp;
+        }
+    }
+
+    function getFirstUsed(node) {
+        if (node.children && node.children.length > 0) {
+            const posterity = gsTree.getPosterity(node);
+            for (const p of posterity) {
+                if (p.children && p.children.length > 0) continue;
+                if (checkUsed(p)) return [p, getFirstUsedPos(p)]
+            }
+        } else if (checkUsed(node)) {
+            return [node, getFirstUsedPos(node)];
+        } else {
+            return [null, null]
+        }
+    }
+
     /**
      * 生成 0号台账 中间计量数据
      * @param {Object} node - 生成中间计量表的节点
@@ -907,6 +929,49 @@ const stageIm = (function () {
         return buildImData();
     }
 
+    function getParentCheckNode(node) {
+        let parent = node;
+        while (parent) {
+            if (parent.check) {
+                return parent;
+            } else {
+                parent = this.getParent(parent);
+            }
+        }
+        return null;
+    }
+    function getRelaXmj(node) {
+        if (checkUsed(node)) {
+            if (stage.im_gather) {
+                const checkedParent = getParentCheckNode(node);
+                return checkedParent ? checkedParent : gsTree.getLeafXmjParent(node);
+            } else {
+                return gsTree.getLeafXmjParent(node);
+            }
+        } else {
+            return null;
+        }
+    }
+    function getRelaImData(relaXmj, bills, pos) {
+        if (stage.im_type === imType.tz.value) {
+            return _.find(ImData, {lid: relaXmj.id});
+        } else if (stage.im_type === imType.zl.value) {
+            return _.find(ImData, {lid: relaXmj.id, code: bills.b_code, name: bills.name, unit: bills.unit, unit_price: bills.unit_price});
+        } else if (stage.im_type === imType.bw.value) {
+            if (pos) {
+                return _.find(ImData, {lid: relaXmj.id, code: bills.b_code, name: bills.name, unit: bills.unit, unit_price: bills.unit_price, pid: pos.id});
+            } else {
+                return _.find(ImData, {lid: relaXmj.id, code: bills.b_code, name: bills.name, unit: bills.unit, unit_price: bills.unit_price, pid: ''});
+            }
+        } else if (stage.im_type === imType.bb.value) {
+            if (pos) {
+                return _.find(ImData, {lid: relaXmj.id, pos_name: pos.name});
+            } else {
+                return _.find(ImData, {lid: relaXmj.id, pos_name: ''});
+            }
+        }
+    }
+
     return {
         init,
         initCheck,
@@ -922,5 +987,8 @@ const stageIm = (function () {
         getImData: function () {
             return ImData;
         },
+        getFirstUsed: getFirstUsed,
+        getRelaXmj: getRelaXmj,
+        getRelaImData: getRelaImData,
     }
 })();