Browse Source

报表签章改进

Tony Kang 3 years ago
parent
commit
efccf9a0f5
1 changed files with 161 additions and 89 deletions
  1. 161 89
      app/public/report/js/rpt_signature.js

+ 161 - 89
app/public/report/js/rpt_signature.js

@@ -479,7 +479,7 @@ let rptSignatureHelper = {
         return rst;
     },
 
-    setupAfterSelectSignature: function (signatureDivId) {
+    setupAfterSelectSignature: async function (signatureDivId) {
         //0. 签名日期
         let me = rptSignatureHelper;
         rptSignatureHelper.resetSignDate(signatureDivId);
@@ -501,6 +501,9 @@ let rptSignatureHelper = {
                     }
                 }
             }
+            if (hasStamp) {
+                resetStampSignature(zTreeOprObj.currentRptPageRst, ROLE_REL_LIST);
+            }
             if (PAGE_SHOW.isTextSignature) {
                 resetTextSignature(zTreeOprObj.currentRptPageRst);
             }
@@ -517,7 +520,7 @@ let rptSignatureHelper = {
         // rptSignatureHelper.originalRoleRelList = rptSignatureHelper.originalRoleRelList.concat(ROLE_REL_LIST);
         rptSignatureHelper.originalRoleRelList = JSON.parse(JSON.stringify(ROLE_REL_LIST));
         CommonAjax.postXsrfEx("/tender/report_api/updateRoleRelationship", params, 10000, true, getCookie('csrfToken_j'),
-            function(result){
+            async function(result){
                 // console.log(result);
                 if (result.data && result.data.insertId > 0) {
                     CURRENT_ROLE_REL_ID = result.data.insertId;
@@ -538,6 +541,7 @@ let rptSignatureHelper = {
                     if (current_stage_status === 3) {
                         rptSignatureHelper.mergeSignDate(zTreeOprObj.currentRptPageRst, ROLE_REL_LIST, true);
                         rptSignatureHelper.mergeSignature(zTreeOprObj.currentRptPageRst, ROLE_REL_LIST);
+                        await rptSignatureHelper.resetDummySignature(zTreeOprObj.currentRptPageRst, ROLE_REL_LIST); // 这里重新整理签章坐标信息(因签章大小在后台暂时获取不到,挪到前端处理)
                         rptSignatureHelper.mergeSignAudit(zTreeOprObj.currentRptPageRst, ROLE_REL_LIST, STAGE_AUDIT);
                         zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
                     }
@@ -695,66 +699,6 @@ let rptSignatureHelper = {
         // 备注:计算草图等其他图形需要额外做些处理
         let dummySignIdx = 0;
         const stampPicKeys = [], stampPicFeatures = [];
-        const _resetStampArea = function(stampCell, roleRelItem) {
-            const ctrl = pageData[JV.NODE_CONTROL_COLLECTION][stampCell[JV.PROP_CONTROL]];
-            let pLeft = stampCell.orgArea.Left,
-                pTop = stampCell.orgArea.Top;
-            let std_stamp_size_width = STD_STAMP_SIZE_WIDTH, std_stamp_size_height = STD_STAMP_SIZE_HEIGHT;
-            if (roleRelItem.stampFeature) {
-                std_stamp_size_width = parseFloat(roleRelItem.stampFeature.ImageWidth.value);
-                std_stamp_size_height = parseFloat(roleRelItem.stampFeature.ImageHeight.value);
-            }
-            switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
-                case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
-                    pLeft = stampCell.orgArea.Left;
-                    break;
-                case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
-                    pLeft = (stampCell.orgArea.Left + stampCell.orgArea.Right - std_stamp_size_width) / 2;
-                    break;
-                case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
-                    pLeft = stampCell.orgArea.Right - std_stamp_size_width;
-                    break;
-                default:break;
-            }
-            switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
-                case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
-                    pTop = stampCell.orgArea.Top;
-                    break;
-                case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
-                    pTop = (stampCell.orgArea.Top + stampCell.orgArea.Bottom - std_stamp_size_height) / 2;
-                    break;
-                case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
-                    pTop = stampCell.orgArea.Bottom - std_stamp_size_height;
-                    break;
-                default:break;
-            }
-            stampCell.area.Left = pLeft;
-            stampCell.area.Top = pTop;
-            stampCell.area.Right = pLeft + std_stamp_size_width;
-            stampCell.area.Bottom = pTop + std_stamp_size_height;
-            // 最后一步,如超过报表范围,则要调整坐标
-            const maxRect = stampCell.maxRect;
-            if (stampCell.area.Left < maxRect[0]) {
-                const width = maxRect[0] - stampCell.area.Left;
-                stampCell.area.Left += width;
-                stampCell.area.Right += width;
-            }
-            if (stampCell.area.Top < maxRect[1]) {
-                const height = maxRect[1] - stampCell.area.Top;
-                stampCell.area.Top += height;
-                stampCell.area.Bottom += height;
-            }
-            if (stampCell.area.Right > maxRect[2]) {
-                const width = maxRect[2] - stampCell.area.Right; // 负
-                stampCell.area.Left += width;
-                stampCell.area.Right += width;
-            }
-            if (stampCell.area.Bottom > maxRect[3]) {
-                const height = maxRect[3] - stampCell.area.Bottom;
-                stampCell.area.Top += height;
-                stampCell.area.Bottom += height;
-            }
-        };
         for (let pageIdx = 0; pageIdx < pageData.items.length; pageIdx++) {
             const page = pageData.items[pageIdx];
             if (page[JV.PROP_SIGNATURE_CELLS] && page[JV.PROP_SIGNATURE_CELLS].length > 0) {
@@ -776,7 +720,7 @@ let rptSignatureHelper = {
                             // { "FileSize": {"value": "2514"}, "Format": {"value": "png"}, "ImageHeight": {"value": "94"}, "ImageWidth": {"value": "94"} }
                             roleRelItem.stampFeature = stampPicFeatures[stmpIdx];
                             // 重新处理cell坐标
-                            _resetStampArea(signatureCell, roleRelItem);
+                            _resetStampArea(pageData[JV.NODE_CONTROL_COLLECTION][signatureCell[JV.PROP_CONTROL]], signatureCell, roleRelItem);
                         }
                         if (ifPushRoleRel) roleRel.push(roleRelItem);
                     }
@@ -1005,38 +949,106 @@ function _createDummyCell() {
     return rst;
 }
 
-function resetTextSignature(pageData) {
+function resetStampSignature(pageData, roleRelList) {
+    const dupPicPaths = [];
+    const _getMaxRect = function(page) {
+        const rect = [100000000, 100000000, 0, 0];
+        for (const cell of page.cells) {
+            if (rect[0] > cell.area.Left) {
+                rect[0] = cell.area.Left;
+            }
+            if (rect[1] > cell.area.Top) {
+                rect[1] = cell.area.Top;
+            }
+            if (rect[2] < cell.area.Right) {
+                rect[2] = cell.area.Right;
+            }
+            if (rect[3] < cell.area.Bottom) {
+                rect[3] = cell.area.Bottom;
+            }
+        }
+        return rect;
+    };
+
     for (const page of pageData.items) {
-        for (let sCell of page.signature_cells) {
-            let fitCell = null;
-            for (let idx = page.cells.length - 1; idx >= 0; idx--) {
-                const cell = page.cells[idx];
-                if (sCell.area.Left === cell.area.Left && sCell.area.Right === cell.area.Right && sCell.area.Top === cell.area.Top && sCell.area.Bottom === cell.area.Bottom) {
-                    fitCell = cell;
-                    break;
+        const maxRect = _getMaxRect(page);
+        if (page.signature_cells) {
+            const newStampCells = [];
+            for (let scIdx = 0; scIdx < page.signature_cells.length; scIdx++) {
+                const sCell = page.signature_cells[scIdx];
+                for (const role_rel of roleRelList) {
+                    if (sCell.signature_name === role_rel.signature_name) {
+                        if (Array.isArray(role_rel.sign_output) && role_rel.sign_output.length > 0) {
+                            for (const signType of role_rel.sign_output) {
+                                switch (signType) {
+                                    case COMPANY_SIGN_STR:
+                                    case PRIVATE_SIGN_STR:
+                                        // 创建一个新的cell
+                                        let stampPath = (signType === COMPANY_SIGN_STR) ? role_rel.company_stamp_path : role_rel.private_stamp_path;
+                                        stampPath = OSS_PATH + stampPath;
+                                        if (dupPicPaths.indexOf(stampPath) < 0) {
+                                            dupPicPaths.push(stampPath);
+                                        }
+                                        const newStampCell = {
+                                            signature_name: JV.SIGNATURE_NAME_DUMMY,
+                                            control: sCell.control,
+                                            style: sCell.style,
+                                            path: stampPath,
+                                            isStamp: true,
+                                            maxRect,
+                                            orgArea: sCell.area,
+                                            area: {Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom},
+                                        };
+                                        newStampCells.push(newStampCell);
+                                        break;
+                                    default: break;
+                                }
+                            }
+                        }
+                    }
                 }
             }
-            if (fitCell) {
-                fitCell.Value = '';
-                for (let role of ROLE_REL_LIST) {
-                    if (sCell.signature_name === role.signature_name) {
-                        fitCell.Value = role.user_name;
+            if (newStampCells.length > 0) {
+                page.signature_cells = page.signature_cells.concat(newStampCells);
+            }
+        }
+    }
+}
+
+function resetTextSignature(pageData) {
+    for (const page of pageData.items) {
+        for (let sCell of page.signature_cells) {
+            if (!sCell.isStamp) {
+                let fitCell = null;
+                for (let idx = page.cells.length - 1; idx >= 0; idx--) {
+                    const cell = page.cells[idx];
+                    if (sCell.area.Left === cell.area.Left && sCell.area.Right === cell.area.Right && sCell.area.Top === cell.area.Top && sCell.area.Bottom === cell.area.Bottom) {
+                        fitCell = cell;
                         break;
                     }
                 }
-            } else {
-                // 要创建新的文本签名cell
-                for (let role of ROLE_REL_LIST) {
-                    if (sCell.signature_name === role.signature_name) {
-                        const newCell = {
-                            font: 'Footer',
-                            control: sCell.control,
-                            style: sCell.style,
-                            Value: role.user_name,
-                            area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
-                        };
-                        page.cells.push(newCell);
-                        break;
+                if (fitCell) {
+                    fitCell.Value = '';
+                    for (let role of ROLE_REL_LIST) {
+                        if (sCell.signature_name === role.signature_name) {
+                            fitCell.Value = role.user_name;
+                            break;
+                        }
+                    }
+                } else {
+                    // 要创建新的文本签名cell
+                    for (let role of ROLE_REL_LIST) {
+                        if (sCell.signature_name === role.signature_name) {
+                            const newCell = {
+                                font: 'Footer',
+                                control: sCell.control,
+                                style: sCell.style,
+                                Value: role.user_name,
+                                area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
+                            };
+                            page.cells.push(newCell);
+                            break;
+                        }
                     }
                 }
             }
@@ -1044,6 +1056,66 @@ function resetTextSignature(pageData) {
     }
 }
 
+function _resetStampArea(ctrl, stampCell, roleRelItem) {
+    let pLeft = stampCell.orgArea.Left,
+        pTop = stampCell.orgArea.Top;
+    let std_stamp_size_width = STD_STAMP_SIZE_WIDTH, std_stamp_size_height = STD_STAMP_SIZE_HEIGHT;
+    if (roleRelItem.stampFeature) {
+        std_stamp_size_width = parseFloat(roleRelItem.stampFeature.ImageWidth.value);
+        std_stamp_size_height = parseFloat(roleRelItem.stampFeature.ImageHeight.value);
+    }
+    switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
+        case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
+            pLeft = stampCell.orgArea.Left;
+            break;
+        case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
+            pLeft = (stampCell.orgArea.Left + stampCell.orgArea.Right - std_stamp_size_width) / 2;
+            break;
+        case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
+            pLeft = stampCell.orgArea.Right - std_stamp_size_width;
+            break;
+        default:break;
+    }
+    switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
+        case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
+            pTop = stampCell.orgArea.Top;
+            break;
+        case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
+            pTop = (stampCell.orgArea.Top + stampCell.orgArea.Bottom - std_stamp_size_height) / 2;
+            break;
+        case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
+            pTop = stampCell.orgArea.Bottom - std_stamp_size_height;
+            break;
+        default:break;
+    }
+    stampCell.area.Left = pLeft;
+    stampCell.area.Top = pTop;
+    stampCell.area.Right = pLeft + std_stamp_size_width;
+    stampCell.area.Bottom = pTop + std_stamp_size_height;
+    // 最后一步,如超过报表范围,则要调整坐标
+    const maxRect = stampCell.maxRect;
+    if (stampCell.area.Left < maxRect[0]) {
+        const width = maxRect[0] - stampCell.area.Left;
+        stampCell.area.Left += width;
+        stampCell.area.Right += width;
+    }
+    if (stampCell.area.Top < maxRect[1]) {
+        const height = maxRect[1] - stampCell.area.Top;
+        stampCell.area.Top += height;
+        stampCell.area.Bottom += height;
+    }
+    if (stampCell.area.Right > maxRect[2]) {
+        const width = maxRect[2] - stampCell.area.Right; // 负
+        stampCell.area.Left += width;
+        stampCell.area.Right += width;
+    }
+    if (stampCell.area.Bottom > maxRect[3]) {
+        const height = maxRect[3] - stampCell.area.Bottom;
+        stampCell.area.Top += height;
+        stampCell.area.Bottom += height;
+    }
+}
+
 function getHttpBlobText(url) {
     return new Promise(resolve => {
         const xhr = new XMLHttpRequest();