'use strict'; /** * * * @author Mai * @date * @version */ const rptCustomObj = (function () { // 审批人选择 const sAuditSelect = 'audit_select'; let stageFlow = []; // 汇总表 const sGatherSelect = 'gather_select'; let gsObj = { setting: null, gsSheet: null, grSheet: null, tenderSourceTree: null, grArray: [], orgSelect: null, }; const grSpreadSetting = { baseCols: [ {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true}, ], extraCols: [ {title: '%s', colSpan: '1', rowSpan: '1', field: '%s', hAlign: 1, vAlign: '1', width: 60, cellType: 'checkbox', readOnly: true}, ], emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', headColWidth: [] }; const gatherSelectSpreadObj = { _addTender: function (tender) { const gr = gsObj.grArray.find(function (x) { return x.tid === tender.tid; }); const t = {tid: tender.tid, name: tender.name} if (!gr) gsObj.grArray.push(t); return t; }, _removeTender: function (tender) { const gri = gsObj.grArray.findIndex(function (x, i, arr) { return x.tid === tender.tid; }); if (gri >= 0) gsObj.grArray.splice(gri, 1); }, reloadResultData: function () { SpreadJsObj.reLoadSheetData(gsObj.grSheet); }, gsButtonClicked: function (e, info) { if (!info.sheet.zh_setting) return; const col = info.sheet.zh_setting.cols[info.col]; if (col.field !== 'selected') return; const node = SpreadJsObj.getSelectObject(info.sheet); node.selected = !node.selected; if (node.children && node.children.length > 0) { const posterity = gsObj.tenderSourceTree.getPosterity(node); for (const p of posterity) { p.selected = node.selected; if (!p.children || p.children.length === 0){ if (p.selected) { gatherSelectSpreadObj._addTender(p); } else { gatherSelectSpreadObj._removeTender(p); } } } SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1); } else { if (node.selected) { gatherSelectSpreadObj._addTender(node); } else { gatherSelectSpreadObj._removeTender(node); } SpreadJsObj.reLoadRowData(info.sheet, info.row, 1); } gatherSelectSpreadObj.reloadResultData(); }, grButtonClicked: function (e, info) { if (!info.sheet.zh_setting) return; const col = info.sheet.zh_setting.cols[info.col]; if (col.field === 'name') return; const node = SpreadJsObj.getSelectObject(info.sheet); const refreshRows = [info.row]; node[col.field] = !node[col.field]; for (const rCol of info.sheet.zh_setting.cols) { if (rCol.field !== 'name' && rCol.field !== col.field) { node[rCol.field] = false; } } if (node[col.field]) { for (const [i, gra] of gsObj.grArray.entries()) { if (gra[col.field] && gra.tid !== node.tid) { gra[col.field] = false; refreshRows.push(i); } } } SpreadJsObj.reLoadRowsData(info.sheet, refreshRows); }, initSelectTenders: function (tenders) { if (!tenders) return; const specCol = gsObj.setting.special ? gsObj.setting.special : []; const select = []; for (const node of gsObj.tenderSourceTree.nodes) { node.selected = false; } for (const t of tenders) { const tender = gsObj.tenderSourceTree.nodes.find(function (x) { return x.tid === t.tid}); tender.selected = true; select.push(tender); const st = this._addTender(tender); for (const sc of specCol) { st[sc.key] = t[sc.key]; } } SpreadJsObj.reLoadColsData(gsObj.gsSheet, [0]); if (select.length > 0) SpreadJsObj.locateTreeNode(gsObj.gsSheet, select[0].tmt_id); this.reloadResultData(); }, }; const getStageFlowSelectHtml = function (select, id) { const html = []; html.push(''); return html.join(''); }; const checkAsSelectValid = function (validFlow, asSelect) { for (const s of asSelect) { const f = validFlow.find(function (x) { return x.aid === s.aid && x.order === s.order; }); if (!f) { $('#audit-select-hint').html('本期审批流程发生变动,原审批人选择不适配,需重新选择').show(); return false; } } $('#audit-select-hint').hide(); return true; }; const initAuditSelect = function (asSetting, asSelect) { const setting = JSON.parse(asSetting), select = asSelect; $('#audit-select-title').html(setting.title); const html = []; for (const [i, s] of setting.select.entries()) { html.push(''); html.push('', s.title, ''); html.push('', getStageFlowSelectHtml(s, 'sf-' + i), ''); html.push(''); } $('#audit-select-list').html(html.join('')); for (const [i, s] of setting.select.entries()) { const obj = $('#sf-' + i); const s = select[i]; const sf = s ? stageFlow.find(function (x) { return x.order === s.order && x.aid === s.aid; }) : null; obj[0].selectedIndex = sf ? sf.order : -1; } if (asSelect.length === 0 || !checkAsSelectValid(stageFlow, asSelect)) { $('#audit-select').modal('show'); } }; const initGrSpreadSetting = function (gsSetting) { grSpreadSetting.cols = []; for (const bc of grSpreadSetting.baseCols) { grSpreadSetting.cols.push(bc); if (bc.field === 'name') bc.width = gsSetting.nameColWidth ? gsSetting.nameColWidth : 180; } if (gsSetting.special) { for (const s of gsSetting.special) { for (const ec of grSpreadSetting.extraCols) { const c = {}; c.title = ec.title.replace('%s', s.title); c.colSpan = ec.colSpan; c.field = ec.field.replace('%s', s.key); c.hAlign = ec.hAlign; c.width = s.width ? s.width : ec.width; c.cellType = ec.cellType; c.readOnly = ec.readOnly; grSpreadSetting.cols.push(c); } } } }; const initGatherSelect = function (gsSetting, gsSelect, rptName, resolve = null) { gsObj.grArray = []; gsObj.setting = JSON.parse(gsSetting); gsObj.orgSelect = gsSelect; $('#gather-select-count').html(gsSelect ? gsSelect.tenders.length : 0); $('#gather-select-title').html(gsObj.setting.title + (rptName ? '-' + rptName : '')); initGrSpreadSetting(gsObj.setting); SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting); if (gsObj.setting.type === 'month') { $('#gather-by-month').show(); $('#gather-by-zone').hide(); } else if (gsObj.setting.type === 'zone') { $('#gather-by-month').hide(); $('#gather-by-zone').show(); } else { $('#gather-by-month').hide(); $('#gather-by-zone').hide(); } SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray); // 初始化选择结果 if (gsSelect) { if (gsSelect.zone) { $('#gather-zone').val(gsSelect.zone ? gsSelect.zone : ''); } else if (gsSelect.month) { $('#gather-month').val(gsSelect.month ? gsSelect.month: ''); } } gatherSelectSpreadObj.initSelectTenders(gsSelect ? gsSelect.tenders : []); // 初始化 $("#gather-select").modal('show'); $('#gather-select-ok').unbind('click'); $('#gather-select-ok').bind('click', () => {rptCustomObj.resetGatherSelect(resolve);}); }; const init = function (cDefine, sfData, cSelect, rptName, resolve = null) { stageFlow = sfData; if (cDefine && cDefine[sAuditSelect] && cDefine[sAuditSelect].enable && cDefine[sAuditSelect].setting) { $('#pnl_audit_select').show(); initAuditSelect(cDefine[sAuditSelect].setting, cSelect ? cSelect[sAuditSelect] : []); } else { $('#pnl_audit_select').hide(); } if (cDefine && cDefine[sGatherSelect] && cDefine[sGatherSelect].enable && cDefine[sGatherSelect].setting) { $('#pnl_gather_select').show(); initGatherSelect(cDefine[sGatherSelect].setting, cSelect ? cSelect[sGatherSelect] : null, rptName, resolve); } else { $('#pnl_gather_select').hide(); } }; const reloadReportData = function (result) { // hintBox.unWaitBox(); let pageRst = result.data; if (result.signatureRelInfo && result.signatureRelInfo.length > 0) { CURRENT_ROLE_REL_ID = result.signatureRelInfo[0].id; ROLE_REL_LIST = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content); STAGE_AUDIT = result.stageAudit; rptSignatureHelper.originalRoleRelList = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content); if (current_stage_status === 3) { rptSignatureHelper.mergeSignDate(pageRst, ROLE_REL_LIST, true); rptSignatureHelper.mergeSignature(pageRst, ROLE_REL_LIST); rptSignatureHelper.mergeSignAudit(pageRst, ROLE_REL_LIST, STAGE_AUDIT); } } else { CURRENT_ROLE_REL_ID = -1; ROLE_REL_LIST = []; } // if (ROLE_REL_LIST) let canvas = zTreeOprObj.canvas; if (pageRst && pageRst.items && pageRst.items.length > 0) { zTreeOprObj.resetAfter(pageRst); zTreeOprObj.currentRptPageRst = pageRst; zTreeOprObj.maxPages = pageRst.items.length; zTreeOprObj.currentPage = 1; zTreeOprObj.displayPageValue(); let size = JpcCanvasOutput.getReportSizeInPixel(zTreeOprObj.currentRptPageRst, getScreenDPI()); canvas.width = size[0] + 20; if (size[1] > size[0]) { canvas.height = size[1] + 100; } else { canvas.height = size[1] + 50; } // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst); rptSignatureHelper.buildSelectableAccount(); rptSignatureHelper.buildSelectableAccountUsed(); rptSignatureHelper.buildRoleDom(ROLE_LIST); zTreeOprObj.showPage(1, canvas); } else { //返回了无数据表 JpcCanvasOutput.cleanCanvas(canvas); JpcCanvasOutput.drawPageBorder(zTreeOprObj.currentRptPageRst, canvas, getScreenDPI()); } rptCustomObj.init(result.customDefine, result.stageFlow, result.customSelect); try { if (is_debug && result.debugInfo) { console.log('含有key的debug信息:'); for (const k in result.debugInfo.key) { console.log(k + ':', ...result.debugInfo.key[k]); } //console.log(result.debugInfo.key); console.log('其他debug信息:'); for (const di of result.debugInfo.other) { console.log(...di); } } } catch(err) { } zTreeOprObj.countChkedRptTpl(); }; const getCommonParams = function (data) { data.pageSize = rptControlObj.getCurrentPageSize(); data.rpt_tpl_id = zTreeOprObj.currentNode.refId; data.custCfg = CUST_CFG; data.project_id = PROJECT_ID; data.tender_id = TENDER_ID; data.stage_id = getStageId(); data.stage_status = getStageStatus(); data.stage_order = getStageOrder(); data.stage_times = getStageTimes(); data.material_order = getMaterialOrder(); }; const resetAuditSelect = function () { const selObj = $('select', '#audit-select-list'); const data = { audit_select: [] }; getCommonParams(data); for (const s of selObj) { const sf = stageFlow[s.selectedIndex]; if (!sf) { $('#audit-select-hint').html('未选择' + s.attributes['sf-title'].value).show(); return; } data.audit_select.push(sf); } $('#audit-select-hint').hide(); postData('/report/cDefine', data, function (result) { reloadReportData(result); $('#audit-select').modal('hide'); }); }; const resetGatherSelect = function (resolve = null) { const data = {}, hintObj = $('#gather-hint'); if (!resolve) getCommonParams(data); data[sGatherSelect] = { tenders: [], type: gsObj.setting.type, }; const specCol = gsObj.setting.special ? gsObj.setting.special : []; for (const sc of specCol) { sc.sCount = 0; } for (const gra of gsObj.grArray) { const ra = {tid: gra.tid}; for (const sc of specCol) { if (gra[sc.key]) { ra[sc.key] = true; sc.sCount += 1; } } data[sGatherSelect].tenders.push(ra); } for (const sc of specCol) { if (sc.sCount === 0) { hintObj.html('请选择 ' + sc.title).show(); return; } } if (data[sGatherSelect].tenders.length <= specCol.length) { hintObj.html('请至少选择1个普通汇总项目').show(); return; } if (gsObj.setting.type === 'month') { data[sGatherSelect].month = $('#gather-month').val(); if (data[sGatherSelect].month === '') { hintObj.html('请选择 汇总年月').show(); return; } } else if (gsObj.setting.type === 'zone') { data[sGatherSelect].zone = $('#gather-zone').val(); if (data[sGatherSelect].zone === '') { hintObj.html('请选择 汇总周期').show(); return; } else if(data[sGatherSelect].zone.indexOf(' - ') < 0) { hintObj.html('请选择 完整汇总周期').show(); return; } } hintObj.hide(); if (resolve) { resolve(data); } else { postData('/report/cDefine', data, function (result) { reloadReportData(result); const gather_select = customSelects.gather_select.find(function (x) { return x.id === zTreeOprObj.currentNode.refId; }); if (gather_select) { gather_select.gather_select = data[sGatherSelect]; } $('#gather-select-count').html(data[sGatherSelect].tenders.length); $('#gather-select').modal('hide'); }); } }; const initTenderTree = function (tenders, category) { const gsSpread = SpreadJsObj.createNewSpread($('#gather-source-spread')[0]); gsObj.gsSheet = gsSpread.getActiveSheet(); const spreadSetting = { cols: [ {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox', readOnly: true}, {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true, cellType: 'tree'}, {title: '期数', field: 'phase', hAlign: 1, width: 60, formatter: '@', readOnly: true}, {title: '审批状态', field: 'status', hAlign: 1, width: 60, formatter: '@', readOnly: true} ], emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', headColWidth: [0], selectedBackColor: '#fffacd', }; SpreadJsObj.initSheet(gsObj.gsSheet, spreadSetting); gsObj.tenderSourceTree = Tender2Tree.convert(category, tenders); SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree); gsSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.gsButtonClicked); const grSpread = SpreadJsObj.createNewSpread($('#gather-result-spread')[0]); gsObj.grSheet = grSpread.getActiveSheet(); grSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.grButtonClicked); $('#gather-hint').hide(); $('#gather-select').bind('shown.bs.modal', function () { if (gsSpread) gsSpread.refresh(); if (grSpread) grSpread.refresh(); }); $('.datepicker-here').datepicker({ autoClose: true, }); }; const comfirmSelectPromise = function (rptName, gather_select) { const promise = new Promise(function (resolve, reject) { init(gather_select.custom_define, customSelects.stageFlow, gather_select, rptName, resolve, reject); }); return promise; }; const getCustomSelect = async function (params) { if (!params.rpt_ids || params.rpt_ids.length === 0) return; const currentRptId = zTreeOprObj.currentNode ? zTreeOprObj.currentNode.refId : -1; params.customSelect = []; const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true); for (const rptId of params.rpt_ids) { const gather_select = customSelects.gather_select.find(function (x) { return x.id === rptId; }); if (gather_select && gather_select.custom_define && gather_select.custom_define[sGatherSelect].enable) { if (rptId === currentRptId) { params.customSelect.push(gather_select[sGatherSelect]); } else { const chkNode = chkNodes.find(function (x) { return x.refId === rptId}); params.customSelect.push(await comfirmSelectPromise(chkNode ? chkNode.name : '', gather_select)); } } else { params.customSelect.push(null); } } $('#gather-select').modal('hide'); }; const showMaterialSelect = function () { const needShow = function () { if (zTreeOprObj.currentNode) { const ms = dataSelects.material_select.find(function (x) { return x.id === zTreeOprObj.currentNode.refId}); if (ms) return true; } const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true); for (const node of chkNodes) { const ms = dataSelects.material_select.find(function (x) { return x.id === node.refId}); if (ms) return true; } return false; }; if (needShow()) { $('#material').show(); } else { $('#material').hide(); } }; const changeMaterial = function (obj) { $('#material-select').attr('m-order', $(obj).attr('m-order')).html(obj.innerText); }; return { init, resetAuditSelect, resetGatherSelect, initTenderTree, getCustomSelect, showMaterialSelect, changeMaterial }; })();