/** * Created by Tony on 2019/9/25. */ 'use strict' const DFT_ROLE_NAME = ''; const NORMAL_SIGN_STR = 'normal_sign'; const COMPANY_SIGN_STR = 'company_stamp'; const PRIVATE_SIGN_STR = 'private_stamp'; const STD_STAMP_SIZE_WIDTH = 4.2 * 96 / 2.54; // 公章大小:宽度(4.2CM) const STD_STAMP_SIZE_HEIGHT = 4.2 * 96 / 2.54; // 公章大小:高度(4.2CM) let rptSignatureHelper = { currentSelectedESignAccDom: null, currentSelectedESignAccIdx: -1, currentSelectedESignAccName: null, currentSelectedESignParentDivId: '', originalRoleRelList: [], buildSelectableAccount: function () { //PRJ_ACCOUNT_LIST //1. 清理所有选择项 // $("#project_account_select_div").empty(); let accDiv = $('#project_account_select_div'); let accSelect = $('#project_account_select_dom'); //绑定成员 let searchInput = $('#search_account').val(); accDiv.empty(); accSelect.empty(); //2. 一个个加可选用户项 const prj_accounts = []; const prj_sel_option_accounts = []; const acc_role_keys = []; for (let accIdx = 0; accIdx < PRJ_ACCOUNT_LIST.length; accIdx++) { const prjAccount = PRJ_ACCOUNT_LIST[accIdx]; if (searchInput === '' || (searchInput !== '' && prjAccount.name.indexOf(searchInput) !== -1)) { let companyKey = prjAccount.account_group; let roleKey = prjAccount.role; if (companyKey === '') { companyKey = '其他单位'; } if (roleKey === '') { roleKey = DFT_ROLE_NAME; } let keyIdx = acc_role_keys.indexOf(companyKey); if (keyIdx < 0) { acc_role_keys.push(companyKey); prj_accounts.push([]); prj_sel_option_accounts.push([]); keyIdx = prj_accounts.length - 1; //这里先push一些 html prefix,在后面统一在push html suffix prj_accounts[keyIdx].push('
' + userName + '-' + ((userRole === '')?DFT_ROLE_NAME:userRole) + '
'); }, pushDomElementByRole: function (elementsStrArr, roleName, userName) { elementsStrArr.push('' + roleName + '-' + userName + '
'); }, pushDatePickerDom: function (elementsStrArr, userAcc, role_rel, seq = 0) { // let idSuffixStr = 'dtp_' + rptSignatureHelper.currentSelectedESignAccName + '_' + rptSignatureHelper.currentSelectedESignParentDivId; let milliSec = (new Date()).getMilliseconds(); const idSuffixStr = `dtp_${seq}_${milliSec}_${rptSignatureHelper.currentSelectedESignParentDivId}`; elementsStrArr.push('' + selectedAcc.name + '-' + roleName + '
'); $('#existed_roles_ul').append(domArr.join(' ')); }, function(err){ // hintBox.unWaitBox(); }, function(ex){ // hintBox.unWaitBox(); } ); } else { alert('请输入合适的名称!'); } }, buildRoleDom: function (roleList) { const ulDom = $('#existed_roles_ul'); ulDom.empty(); for (let domIdx = 0; domIdx < roleList.length; domIdx++) { const role = roleList[domIdx]; const domArr = []; domArr.push('' + acc.name + '-' + ((acc.role === '')?DFT_ROLE_NAME:acc.role) + '
'); ulDom.append(domArr.join(' ')); } }, getUserAccount: function (accId) { let rst = null; for (const acc of PRJ_ACCOUNT_LIST) { if (acc.id === accId) { rst = acc; break; } } return rst; }, _getCompanySign: function(companyName) { let rst = ''; for (const cUnit of CONSTRUCT_UNIT_LIST) { if (cUnit.name === companyName) { rst = cUnit.sign_path; break; } } return rst; }, mergeSignature: function (pageData, currRoleRelList, setPic = false) { for (const page of pageData.items) { if (page.signature_cells) { const adHocScells = []; for (const sCell of page.signature_cells) { if (sCell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) < 0) { sCell.path = null; sCell.pre_path = null; sCell.pic = null; } for (const role_rel of currRoleRelList) { if (role_rel.signature_name === sCell.signature_name) { // 处理签章 if (!Array.isArray(role_rel.sign_output)) { role_rel.sign_output = []; role_rel.sign_output.push(NORMAL_SIGN_STR); } for (const signType of role_rel.sign_output) { switch (signType) { case NORMAL_SIGN_STR: sCell.path = role_rel.sign_path; sCell.pre_path = role_rel.sign_path; if (setPic) { sCell.pic = role_rel.sign_pic; // 有些场景(如:批量归档)需要直接设置签名数据 } break; case COMPANY_SIGN_STR: case PRIVATE_SIGN_STR: /* const stampPath = (signType === COMPANY_SIGN_STR) ? role_rel.company_stamp_path : role_rel.private_stamp_path; // 生成一个新的dummy cell(类似草图) const newStampCell = _createDummyCell(); newStampCell.signature_name = JV.SIGNATURE_NAME_DUMMY; newStampCell.path = OSS_PATH + stampPath; newStampCell.control = sCell.control; newStampCell.style = sCell.style; newStampCell.isStamp = true; // 这个标记纯属为了刷新用,其他sign cell是没有的 // 设置坐标 rptSignatureHelper._resetStampPos(sCell, newStampCell, pageData[JV.NODE_CONTROL_COLLECTION]); // 加到cells去 adHocScells.push(newStampCell); //*/ break; default: break; } } break; } } } page.signature_cells = page.signature_cells.concat(adHocScells); } } }, resetDummySignature: async function(pageData, roleRel, ifPushRoleRel = false) { // 备注:计算草图等其他图形需要额外做些处理 let dummySignIdx = 0; const stampPicKeys = [], stampPicFeatures = []; 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) { for (const signatureCell of page[JV.PROP_SIGNATURE_CELLS]) { if (signatureCell.signature_name.indexOf(JV.SIGNATURE_NAME_DUMMY) >= 0) { // 表示这是一个其他类型的非原生电子签名图,只是借用signature的处理机制,每个图都是唯一的,所以需要重新给个唯一的新signature_name // signatureCell.signature_name = signatureCell.signature_name + '_' + pageIdx + '_' + dummySignIdx; signatureCell.signature_name = signatureCell.signature_name + '_' + page.page_seq + '_' + dummySignIdx; // page_seq在分页后都不会变动 dummySignIdx++; const roleRelItem = { type: '用户', sign_path: signatureCell.path, signature_name: signatureCell.signature_name }; if (signatureCell.isStamp) { let stmpIdx = stampPicKeys.indexOf(signatureCell.path); if (stampPicKeys.indexOf(signatureCell.path) < 0) { stampPicKeys.push(signatureCell.path); stmpIdx = stampPicKeys.length - 1; const picRes = await getHttpBlobText(signatureCell.path + '?x-oss-process=image/info'); stampPicFeatures.push(picRes); } // { "FileSize": {"value": "2514"}, "Format": {"value": "png"}, "ImageHeight": {"value": "94"}, "ImageWidth": {"value": "94"} } roleRelItem.stampFeature = stampPicFeatures[stmpIdx]; // 重新处理cell坐标 _resetStampArea(pageData[JV.NODE_CONTROL_COLLECTION][signatureCell[JV.PROP_CONTROL]], signatureCell, roleRelItem); } if (ifPushRoleRel) roleRel.push(roleRelItem); } } } } }, mergeSignAudit: function (pageData, currRoleRelList, currAuditList) { for (const page of pageData.items) { if (page.signature_audit_cells) { for (const sCell of page.signature_audit_cells) { sCell.Value = ''; // 这里要先清除原有信息 for (const role_rel of currRoleRelList) { if (sCell.signature_name === role_rel.signature_name + '_审核意见') { let preDate = ''; sCell.Value = '同意'; // 只有选择了签名的,才需要初始化一个默认的意见(之前的逻辑在有多个签名,哪怕只选择了一个,其他的意见都会有默认意见) for (const audit_rel of currAuditList) { if (role_rel.acc_id === audit_rel.aid) { if (audit_rel.end_time > preDate && audit_rel.status === 3) { sCell.Value = audit_rel.opinion; preDate = audit_rel.end_time; } //不能break,实际会有多个审核意见,以最后一个为准 } } break; } } } } } }, mergeSignDate: function (pageData, currRoleRelList, isMergeOrgAlso) { if (currRoleRelList && currRoleRelList.length > 0 && STAGE_AUDIT && STAGE_AUDIT.length > 0) { for (let rridx = 0; rridx < currRoleRelList.length; rridx++) { const role_rel = currRoleRelList[rridx]; if (role_rel.sign_date === undefined || role_rel.sign_date === null || role_rel.sign_date === '') { //* let dftDate = _getSignDateByAllScenarios(role_rel.acc_id); role_rel.sign_date = dftDate; if (isMergeOrgAlso) { rptSignatureHelper.originalRoleRelList[rridx].sign_date = dftDate; //备注:在多选导出的情况下,originalRoleRelList不需要merge } /*/ let hasAudit = false; for (const stg_audit of STAGE_AUDIT) { if (role_rel.acc_id === stg_audit.aid) { hasAudit = true; if (stg_audit.status === 3) { role_rel.sign_date = stg_audit.end_time; rptSignatureHelper.originalRoleRelList[rridx].sign_date = stg_audit.end_time; } else { role_rel.sign_date = ''; rptSignatureHelper.originalRoleRelList[rridx].sign_date = ''; } // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准 } } let isOrgRpt = false; for (const stg of STAGE_LIST) { if (stg.id === current_stage_id) { if (stg.user_id === role_rel.acc_id) { isOrgRpt = true; } break; } } if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) { if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) { role_rel.sign_date = STAGE_AUDIT_ORG[0].begin_time; rptSignatureHelper.originalRoleRelList[rridx].sign_date = STAGE_AUDIT_ORG[0].begin_time; } } if (!isOrgRpt && !hasAudit) { //非审批流程人员以及非原报,则显示期截至时间 for (const stg of STAGE_LIST) { if (stg.id === current_stage_id && stg.period) { const period = stg.period.split(' ~ '); if (period.length === 2) { role_rel.sign_date = period[1]; rptSignatureHelper.originalRoleRelList[rridx].sign_date = period[1]; } } } } //*/ } } } for (const page of pageData.items) { if (page.signature_date_cells) { for (const sCell of page.signature_date_cells) { if (sCell.Value === undefined || sCell.Value === null && sCell.Value === '') { sCell.Value = _getSignDateDftName(); } for (const role_rel of currRoleRelList) { if (sCell.signature_name === role_rel.signature_name + '_签字日期') { if (role_rel.sign_date !== '') { if (typeof role_rel.sign_date === 'string') { role_rel.sign_date = new Date(role_rel.sign_date); } sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format); } break; } } } } } }, _changeSignType: function(dom, signature_name, chkStr) { for (const roleRel of ROLE_REL_LIST) { if (roleRel.signature_name === signature_name) { if (dom.checked) { if (roleRel.sign_output.indexOf(chkStr) < 0) { roleRel.sign_output.push(chkStr); } } else { let idx = roleRel.sign_output.indexOf(chkStr); if (idx >= 0) { roleRel.sign_output.splice(idx, 1); } } break; } } }, _resetStampPos: function(orgCell, targetCell, controls) { const ctrl = controls[orgCell.control]; let pLeft = orgCell.area.Left, pTop = orgCell.area.Top; switch(ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) { case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]: pLeft = orgCell.area.Left; break; case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]: pLeft = (orgCell.area.Left + orgCell.area.Right - STD_STAMP_SIZE_WIDTH) / 2 ; break; case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]: pLeft = orgCell.area.Right - STD_STAMP_SIZE_WIDTH; break; } switch(ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) { case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]: pTop = orgCell.area.Top; break; case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]: pTop = (orgCell.area.Top + orgCell.area.Bottom - STD_STAMP_SIZE_HEIGHT) / 2 ; break; case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]: pTop = orgCell.area.Bottom - STD_STAMP_SIZE_HEIGHT; break; } targetCell.area.Left = pLeft; targetCell.area.Top = pTop; targetCell.area.Right = pLeft + STD_STAMP_SIZE_WIDTH; targetCell.area.Bottom = pTop + STD_STAMP_SIZE_HEIGHT; }, } function _getSignDateByAllScenarios(userAccId) { let rst = ''; let hasAudit = false; for (const stg_audit of STAGE_AUDIT) { if (stg_audit.aid === userAccId) { hasAudit = true; if (stg_audit.status === 3) { rst = stg_audit.end_time; } else { rst = ''; } // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准 } } let isOrgRpt = false; for (const stg of STAGE_LIST) { if (stg.id === current_stage_id) { if (stg.user_id === userAccId) { isOrgRpt = true; } break; } } if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) { if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) { rst = STAGE_AUDIT_ORG[0].begin_time; } } if (!isOrgRpt && !hasAudit) { //非审批流程人员以及非原报,则显示期截至时间 for (const stg of STAGE_LIST) { if (stg.id === current_stage_id && stg.period) { const period = stg.period.split(' ~ '); if (period.length === 2) { rst = period[1]; } } } } return rst; } function _getSignDateDftName() { return ' 年 月 日'; } function _createDummyCell() { const rst = { font: 'Footer', control: 'Footer', style: 'Default_None', Value: '', area: { Left: 0, Right: 0, Top: 0, Bottom: 0 }, }; return rst; } 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) { 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 (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; } } if (fitCell) { fitCell.Value = ''; for (let role of ROLE_REL_LIST) { if (sCell.signature_name === role.signature_name) { if (role.sign_output && role.sign_output.indexOf(NORMAL_SIGN_STR) >= 0) { fitCell.Value = role.user_name; } else { fitCell.Value = ''; } break; } } } else { // 要创建新的文本签名cell for (let role of ROLE_REL_LIST) { if (sCell.signature_name === role.signature_name && role.sign_output && role.sign_output.indexOf(NORMAL_SIGN_STR) >= 0) { 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; } } } } } } } function _resetStampArea(ctrl, stampCell, roleRelItem) { let pLeft = stampCell.orgArea.Left, pTop = stampCell.orgArea.Top; if (roleRelItem.stampFeature !== 'not found!') { let std_stamp_size_width = STD_STAMP_SIZE_WIDTH, std_stamp_size_height = STD_STAMP_SIZE_HEIGHT; let widthRate = 1, heightRate = 1; if (roleRelItem.stampFeature) { std_stamp_size_width = parseFloat(roleRelItem.stampFeature.ImageWidth.value); std_stamp_size_height = parseFloat(roleRelItem.stampFeature.ImageHeight.value); if (roleRelItem.stampFeature.ImageWidth.value !== roleRelItem.stampFeature.ImageHeight.value) { //设置比例 if (std_stamp_size_width > std_stamp_size_height) { heightRate = std_stamp_size_height / std_stamp_size_width; } else { widthRate = std_stamp_size_width / std_stamp_size_height; } } if (std_stamp_size_width > STD_STAMP_SIZE_WIDTH || std_stamp_size_height > STD_STAMP_SIZE_HEIGHT) { std_stamp_size_width = Math.min(std_stamp_size_width, STD_STAMP_SIZE_WIDTH); std_stamp_size_height = Math.min(std_stamp_size_height, STD_STAMP_SIZE_HEIGHT); if (widthRate === 1) { std_stamp_size_height = std_stamp_size_height * heightRate; } else { std_stamp_size_width = std_stamp_size_width * widthRate; } } } 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(); // let fullUrl = url + '?x-oss-process=image/info'; xhr.open('GET', url, true); xhr.responseType = 'json'; xhr.onload = () => { if (xhr.status === 200) { resolve(xhr.response); } else { resolve('not found!'); } }; xhr.send(); }); }