|
@@ -0,0 +1,563 @@
|
|
|
|
|
+const reportFormatSetupObj = {
|
|
|
|
|
+ treeObj: null,
|
|
|
|
|
+ templateObj: {},
|
|
|
|
|
+ canvas: null,
|
|
|
|
|
+ fieldParamOptions: null,
|
|
|
|
|
+ onCheck: (event, treeId, treeNode) => {
|
|
|
|
|
+ //
|
|
|
|
|
+ },
|
|
|
|
|
+ onClick: (event,treeId,treeNode) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ if (treeNode.nodeType === RT.NodeType.TEMPLATE) {
|
|
|
|
|
+ me.initialize(treeNode);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ onDeleteInfo: (dom) => {
|
|
|
|
|
+ // 删除表眉、表脚项
|
|
|
|
|
+ // console.log(dom.parentElement.parentElement);
|
|
|
|
|
+ $(dom.parentElement.parentElement).remove();
|
|
|
|
|
+ },
|
|
|
|
|
+ onAddInfo: (dom, lv) => {
|
|
|
|
|
+ // 增加表眉、表脚细项
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const domStrs = [];
|
|
|
|
|
+ domStrs.push('<tr class="text-center">');
|
|
|
|
|
+ domStrs.push('<td></td>');
|
|
|
|
|
+ domStrs.push(`<td>${me._createTypeSelection(0)}</td>`);
|
|
|
|
|
+ domStrs.push(`<td class="text-left"><input class="form-control form-control-sm" value="" type="text"></td>`);
|
|
|
|
|
+ domStrs.push(`<td class="text-left"><input class="form-control form-control-sm" value="0" type="text"></td>`);
|
|
|
|
|
+ domStrs.push(`<td class="text-left"><input class="form-control form-control-sm" value="0" type="text"></td>`);
|
|
|
|
|
+ domStrs.push(`<td class="text-left"><input class="form-control form-control-sm" value="" type="text"></td>`);
|
|
|
|
|
+ domStrs.push(`<td class="text-left"><input class="form-control form-control-sm" value="" type="text"></td>`);
|
|
|
|
|
+ domStrs.push('<td><a href="#" onclick="reportFormatSetupObj.onDeleteInfo(this)" class="text-danger mr-2" title="删除">删除</a></td>');
|
|
|
|
|
+ domStrs.push('</tr>');
|
|
|
|
|
+ $(dom.parentElement.parentElement).after(domStrs.join(''));
|
|
|
|
|
+ },
|
|
|
|
|
+ onAddLvInfo: (dom) => {
|
|
|
|
|
+ // 增加表眉、表脚层次项
|
|
|
|
|
+ console.log(dom);
|
|
|
|
|
+ let maxCnt = 0;
|
|
|
|
|
+ for (const td of dom.parentElement.parentElement.nextElementSibling.children[0].children[1].children) {
|
|
|
|
|
+ if (td.cells[0].innerText !== '') {
|
|
|
|
|
+ const lv = parseInt(td.cells[0].innerText) || 0;
|
|
|
|
|
+ if (lv > maxCnt) maxCnt = lv;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // dom.parentElement.parentElement.nextElementSibling.children[0].children[1]
|
|
|
|
|
+ const lvDtl = [];
|
|
|
|
|
+ lvDtl.push('<tr class="text-center">');
|
|
|
|
|
+ lvDtl.push(`<td>${maxCnt + 1}</td>`);
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td><a href="#" onclick="reportFormatSetupObj.onAddInfo(this)" class="text-primary mr-2" title="新增插入子项">新增</a></td>');
|
|
|
|
|
+ lvDtl.push('</tr>');
|
|
|
|
|
+ $(dom.parentElement.parentElement.nextElementSibling.children[0].children[1]).append(lvDtl.join(''));
|
|
|
|
|
+ },
|
|
|
|
|
+ onTypeChange: (dom) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ console.log(dom);
|
|
|
|
|
+ // 根据新选项清理、初始化
|
|
|
|
|
+ if (dom.selectedIndex === 0) {
|
|
|
|
|
+ // 文本
|
|
|
|
|
+ $(dom.parentElement.nextSibling).html('<input class="form-control form-control-sm" value="" type="text">');
|
|
|
|
|
+ dom.parentElement.nextSibling.nextSibling.nextSibling.nextSibling.children[0].value = '';
|
|
|
|
|
+ dom.parentElement.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.children[0].value = '';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 指标
|
|
|
|
|
+ const curNodes = me.treeObj.getSelectedNodes();
|
|
|
|
|
+ if (curNodes.length > 0) {
|
|
|
|
|
+ const rptTemplate = me.templateObj[`${curNodes[0].ID}`];
|
|
|
|
|
+ if (rptTemplate) {
|
|
|
|
|
+ $(dom.parentElement.nextSibling).html(`${me._createSelectionFields(-1, 5010)}`);
|
|
|
|
|
+ dom.parentElement.nextSibling.nextSibling.nextSibling.nextSibling.children[0].value = '';
|
|
|
|
|
+ dom.parentElement.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.children[0].value = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ initialize: (rptNode) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ me.canvas = document.getElementById("rptSetupPreviewCanvas");
|
|
|
|
|
+ // 1. 先清理
|
|
|
|
|
+ me.clearTplProperties();
|
|
|
|
|
+ // 2. 再加表标题、表眉、表脚、电子签名内容
|
|
|
|
|
+ const params = { rpt_tpl_id: rptNode.refId };
|
|
|
|
|
+ const url = '/report_api/getReportTemplate';
|
|
|
|
|
+ $.bootstrapLoading.start();
|
|
|
|
|
+ CommonAjax.postXsrfEx(url, params, 300000, true, getCookie('csrfToken_j'),
|
|
|
|
|
+ async function(result){
|
|
|
|
|
+ console.log(result);
|
|
|
|
|
+ me.templateObj[`${rptNode.refId}`] = result.data;
|
|
|
|
|
+ me.fieldParamOptions = me.initialSelectionFields(result.data);
|
|
|
|
|
+ me.initialTitle(result.data);
|
|
|
|
|
+ me.initialHeader(result.data);
|
|
|
|
|
+ me.initialFooter(result.data);
|
|
|
|
|
+ me.initialSignature(result.data);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }, function(err){
|
|
|
|
|
+ console.log(err);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }, function(ex){
|
|
|
|
|
+ console.log(ex);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ clearTplProperties: () => {
|
|
|
|
|
+ // 表眉
|
|
|
|
|
+ $("#rpt_header_div").empty();
|
|
|
|
|
+ const str1 = '<div>表眉</div><div><a href="#" onclick="reportFormatSetupObj.onAddLvInfo(this)" class="btn btn-sm btn-light text-primary">新增行</a></div>';
|
|
|
|
|
+ $("#rpt_header_div").append(str1);
|
|
|
|
|
+ $("#rpt_header_table_div").empty();
|
|
|
|
|
+ // 表脚
|
|
|
|
|
+ $("#rpt_footer_div").empty();
|
|
|
|
|
+ const str2 = '<div>表脚</div><div><a href="#" onclick="reportFormatSetupObj.onAddLvInfo(this)" class="btn btn-sm btn-light text-primary">新增行</a></div>';
|
|
|
|
|
+ $("#rpt_footer_div").append(str2);
|
|
|
|
|
+ $("#rpt_footer_table_div").empty();
|
|
|
|
|
+ // 表标题
|
|
|
|
|
+ $("#rpt_title_input")[0].value = '';
|
|
|
|
|
+ },
|
|
|
|
|
+ initialHeader: (rptTpl) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const bandInfo = me._getRightBandInfoObj(me._getRightInfoObj(rptTpl), 'HeaderBand');
|
|
|
|
|
+ if (bandInfo) {
|
|
|
|
|
+ const posArr = me._checkLevelInfo(bandInfo);
|
|
|
|
|
+ const html = me._buildHeaderFooterHTML(rptTpl, bandInfo, posArr);
|
|
|
|
|
+ // console.log(html);
|
|
|
|
|
+ // $("#rpt_header_parent_div").empty();
|
|
|
|
|
+ $("#rpt_header_table_div").append(html.join(''));
|
|
|
|
|
+ // rpt_header_div
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ initialFooter: (rptTpl) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const bandInfo = me._getRightBandInfoObj(me._getRightInfoObj(rptTpl), 'FooterBand');
|
|
|
|
|
+ if (bandInfo) {
|
|
|
|
|
+ const posArr = me._checkLevelInfo(bandInfo);
|
|
|
|
|
+ const html = me._buildHeaderFooterHTML(rptTpl, bandInfo, posArr);
|
|
|
|
|
+ console.log(html);
|
|
|
|
|
+ // $("#rpt_header_parent_div").empty();
|
|
|
|
|
+ $("#rpt_footer_table_div").append(html.join(''));
|
|
|
|
|
+ // rpt_header_div
|
|
|
|
|
+ }
|
|
|
|
|
+ //
|
|
|
|
|
+ },
|
|
|
|
|
+ initialTitle: (rptTpl) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ $("#rpt_title_input")[0].value = me._getTitle(rptTpl);
|
|
|
|
|
+ const curNodes = me.treeObj.getSelectedNodes();
|
|
|
|
|
+ if (curNodes.length > 0) {
|
|
|
|
|
+ $("#rename_rpt_confirm")[0].innerText=`确认更新报表模板「${curNodes[0].name}」?`;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ initialSignature: (rptTpl) => {
|
|
|
|
|
+ //
|
|
|
|
|
+ },
|
|
|
|
|
+ _getTitle: (rptTpl) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ let rst = '';
|
|
|
|
|
+ const bandInfo = me._getRightBandInfoObj(me._getRightInfoObj(rptTpl), 'TitleBand');
|
|
|
|
|
+ if (bandInfo && bandInfo.text_s) {
|
|
|
|
|
+ const titleTxt = bandInfo.text_s.find(item => item.font === 'ReportTitle_Main');
|
|
|
|
|
+ if (titleTxt) {
|
|
|
|
|
+ rst = titleTxt.Label;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ rst = bandInfo.text_s[0].Label;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ _setTitle: (rptTpl, newTitle) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const bandInfo = me._getRightBandInfoObj(me._getRightInfoObj(rptTpl), 'TitleBand');
|
|
|
|
|
+ if (bandInfo && bandInfo.text_s) {
|
|
|
|
|
+ const titleTxt = bandInfo.text_s.find(item => item.font === 'ReportTitle_Main');
|
|
|
|
|
+ if (titleTxt) {
|
|
|
|
|
+ titleTxt.Label = newTitle;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ bandInfo.text_s[0].Label = newTitle;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ _getRightInfoObj: (rptTpl) => {
|
|
|
|
|
+ let rst = null;
|
|
|
|
|
+ if (rptTpl) {
|
|
|
|
|
+ if (rptTpl['流水式表_信息']) {
|
|
|
|
|
+ rst = rptTpl['流水式表_信息'];
|
|
|
|
|
+ } else if (rptTpl['账单式表_信息']) {
|
|
|
|
|
+ rst = rptTpl['账单式表_信息'];
|
|
|
|
|
+ } else if (rptTpl['交叉表_信息']) {
|
|
|
|
|
+ rst = rptTpl['交叉表_信息'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ _getRightBandInfoObj: (infoObj, bandName) => {
|
|
|
|
|
+ let rst = null;
|
|
|
|
|
+ if (infoObj) {
|
|
|
|
|
+ for (let info of infoObj['离散信息']) {
|
|
|
|
|
+ if (info['BandName'] === bandName) {
|
|
|
|
|
+ rst = info;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ _checkLevelInfo: (bandInfo) => {
|
|
|
|
|
+ let rst = [];
|
|
|
|
|
+ if (bandInfo) {
|
|
|
|
|
+ if (bandInfo.discrete_field_s) {
|
|
|
|
|
+ for (const field of bandInfo.discrete_field_s) {
|
|
|
|
|
+ const bt = +field.area.Bottom;
|
|
|
|
|
+ if (!rst.includes(bt)) rst.push(bt);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (bandInfo.text_s) {
|
|
|
|
|
+ for (const txt of bandInfo.text_s) {
|
|
|
|
|
+ const bt = +txt.area.Bottom;
|
|
|
|
|
+ if (!rst.includes(bt)) rst.push(bt);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ _createTypeSelection: (dftSelection = 0) => {
|
|
|
|
|
+ const rst = [];
|
|
|
|
|
+ rst.push('<select class="form-control form-control-sm" onchange="reportFormatSetupObj.onTypeChange(this)">');
|
|
|
|
|
+ rst.push(`<option${dftSelection === 0 ? ' selected' : ''}>文本</option>`);
|
|
|
|
|
+ rst.push(`<option${dftSelection !== 0 ? ' selected' : ''}>指标</option>`);
|
|
|
|
|
+ rst.push('</select>');
|
|
|
|
|
+ return rst.join('');
|
|
|
|
|
+ },
|
|
|
|
|
+ initialSelectionFields: (rptTpl) => {
|
|
|
|
|
+ // 这里统一收集可选指标范围(有默认范围 + 报表本身特别的指标)
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const rst = { fields_collection: [], params_collection: [] };
|
|
|
|
|
+ for (const param of rptTpl['离散参数_集合']) {
|
|
|
|
|
+ rst.params_collection.push({ PID: +param.ID, name: param.Name, dftValue: param.Default_Value || '' });
|
|
|
|
|
+ }
|
|
|
|
|
+ for (const fd of rptTpl['指标_数据_映射']['离散指标_集合']) {
|
|
|
|
|
+ rst.fields_collection.push({ FID: +fd.ID, name: fd.Name });
|
|
|
|
|
+ }
|
|
|
|
|
+ const collectAdhocFields = (hfBandInfo) => {
|
|
|
|
|
+ if (hfBandInfo && hfBandInfo.discrete_field_s) {
|
|
|
|
|
+ for (const field of hfBandInfo.discrete_field_s) {
|
|
|
|
|
+ if (!field.ParamID) {
|
|
|
|
|
+ const selField = rst.fields_collection.find(item => item.FID === +field.FieldID);
|
|
|
|
|
+ if (!selField) {
|
|
|
|
|
+ const ahocSelField = me._scanField(rptTpl, field.FieldID);
|
|
|
|
|
+ rst.fields_collection.push({ FID: +ahocSelField.ID, name: ahocSelField.Name });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ const headerBandInfo = me._getRightBandInfoObj(me._getRightInfoObj(rptTpl), 'HeaderBand');
|
|
|
|
|
+ collectAdhocFields(headerBandInfo);
|
|
|
|
|
+ const footerBandInfo = me._getRightBandInfoObj(me._getRightInfoObj(rptTpl), 'FooterBand');
|
|
|
|
|
+ collectAdhocFields(footerBandInfo);
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ _createSelectionFields_BK: (rptTpl, currentFieldID, ParamID) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const rst = [];
|
|
|
|
|
+ let hasSelected = false;
|
|
|
|
|
+ rst.push('<select class="form-control form-control-sm">');
|
|
|
|
|
+ for (const fd of rptTpl['指标_数据_映射']['离散指标_集合']) {
|
|
|
|
|
+ if (!hasSelected) {
|
|
|
|
|
+ hasSelected = fd.ID === currentFieldID;
|
|
|
|
|
+ }
|
|
|
|
|
+ const selectedStr = fd.ID === currentFieldID ? ' selected' : '';
|
|
|
|
|
+ rst.push(`<option${selectedStr} FID="${fd.ID}">${fd.Name}</option>`);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!hasSelected) {
|
|
|
|
|
+ // 如果没有在选项中,那表示是一个额外的指标(可能在: a. '电子签名离散指标_集合' b. '无映射离散指标_集合'中 etc...),需要在模板中全扫描一把
|
|
|
|
|
+ // 有2种情况,一种是离散的指标,另一种是特殊参数(页码)
|
|
|
|
|
+ if (ParamID) {
|
|
|
|
|
+ for (const pd of rptTpl['离散参数_集合']) {
|
|
|
|
|
+ if (`${pd.ID}` === `${ParamID}`) {
|
|
|
|
|
+ rst.push(`<option selected PID="${ParamID}">${pd.Name}</option>`);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const selField = me._scanField(rptTpl, currentFieldID);
|
|
|
|
|
+ if (selField) {
|
|
|
|
|
+ rst.push(`<option selected FID="${currentFieldID}">${selField.Name}</option>`);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ rst.push('</select>');
|
|
|
|
|
+ return rst.join('');
|
|
|
|
|
+ },
|
|
|
|
|
+ _createSelectionFields: (currentFieldID, ParamID) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const rst = [];
|
|
|
|
|
+ let hasSelected = false;
|
|
|
|
|
+ rst.push('<select class="form-control form-control-sm">');
|
|
|
|
|
+ for (const fd of reportFormatSetupObj.fieldParamOptions.fields_collection) {
|
|
|
|
|
+ const selectedStr = `${fd.FID}` === `${currentFieldID}` ? ' selected' : '';
|
|
|
|
|
+ rst.push(`<option${selectedStr} FID="${fd.FID}">${fd.name}</option>`);
|
|
|
|
|
+ }
|
|
|
|
|
+ for (const pd of reportFormatSetupObj.fieldParamOptions.params_collection) {
|
|
|
|
|
+ const selectedStr = `${pd.PID}` === `${ParamID}` ? ' selected' : '';
|
|
|
|
|
+ rst.push(`<option${selectedStr} PID="${pd.PID}">${pd.name}</option>`);
|
|
|
|
|
+ }
|
|
|
|
|
+ rst.push('</select>');
|
|
|
|
|
+ return rst.join('');
|
|
|
|
|
+ },
|
|
|
|
|
+ _scanField: (rptTpl, curFieldId) => {
|
|
|
|
|
+ let rst = null;
|
|
|
|
|
+ rst = rptTpl['无映射离散指标_集合'].find(item => item.ID === curFieldId);
|
|
|
|
|
+ if (!rst) rst = rptTpl['电子签名离散指标_集合'].find(item => `${item.ID}` === `${curFieldId}`);
|
|
|
|
|
+ if (!rst) rst = rptTpl['动态日期离散参数_集合'].find(item => `${item.ID}` === `${curFieldId}`);
|
|
|
|
|
+ if (!rst) rst = rptTpl['电子签名审核意见指标_集合'].find(item => `${item.ID}` === `${curFieldId}`);
|
|
|
|
|
+ if (!rst) rst = rptTpl['指标_数据_映射']['从数据指标_集合'].find(item => `${item.ID}` === `${curFieldId}`);
|
|
|
|
|
+ if (!rst) rst = rptTpl['指标_数据_映射']['主数据指标_集合'].find(item => `${item.ID}` === `${curFieldId}`);
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ _buildHeaderFooterHTML: (rptTpl, hfBandInfo, posArr) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const rst = [];
|
|
|
|
|
+ if (hfBandInfo && posArr.length > 0) {
|
|
|
|
|
+ // 1. 增加一些必要html
|
|
|
|
|
+ rst.push(' <table class="table table-bordered">')
|
|
|
|
|
+ rst.push(' <thead>');
|
|
|
|
|
+ rst.push(' <tr>');
|
|
|
|
|
+ rst.push(' <th width="5%" style="text-align: center;">行号</th>');
|
|
|
|
|
+ rst.push(' <th width="10%" style="text-align: center;">类型</th>');
|
|
|
|
|
+ rst.push(' <th width="20%" style="text-align: center;">值</th>');
|
|
|
|
|
+ rst.push(' <th width="10%" style="text-align: center;">左位置</th>');
|
|
|
|
|
+ rst.push(' <th width="10%" style="text-align: center;">右位置</th>');
|
|
|
|
|
+ rst.push(' <th width="15%" style="text-align: center;">前缀</th>');
|
|
|
|
|
+ rst.push(' <th width="15%" style="text-align: center;">后缀</th>');
|
|
|
|
|
+ rst.push(' <th width="15%" style="text-align: center;">操作</th>');
|
|
|
|
|
+ rst.push(' </tr>');
|
|
|
|
|
+ rst.push(' </thead>');
|
|
|
|
|
+ rst.push(' <tbody>')
|
|
|
|
|
+ // --------
|
|
|
|
|
+ const lvs = [];
|
|
|
|
|
+ for (let idx = 0; idx < posArr.length; idx++) {
|
|
|
|
|
+ const lvDtl = [];
|
|
|
|
|
+ lvDtl.push('<tr class="text-center">');
|
|
|
|
|
+ lvDtl.push(`<td>${idx + 1}</td>`);
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td></td>');
|
|
|
|
|
+ lvDtl.push('<td><a href="#" onclick="reportFormatSetupObj.onAddInfo(this)" class="text-primary mr-2" title="新增插入子项">新增</a></td>');
|
|
|
|
|
+ lvDtl.push('</tr>');
|
|
|
|
|
+ lvs.push(lvDtl);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (hfBandInfo.text_s) {
|
|
|
|
|
+ for (const txt of hfBandInfo.text_s) {
|
|
|
|
|
+ const bt = +txt.area.Bottom;
|
|
|
|
|
+ const btIdx = posArr.indexOf(bt);
|
|
|
|
|
+ if (btIdx >= 0) {
|
|
|
|
|
+ lvs[btIdx].push('<tr class="text-center">');
|
|
|
|
|
+ lvs[btIdx].push('<td></td>');
|
|
|
|
|
+ lvs[btIdx].push(`<td>${me._createTypeSelection(0)}</td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="${txt.Label || ''}" type="text"></td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="${txt.area.Left || '0'}" type="text"></td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="${txt.area.Right || '0'}" type="text"></td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="" type="text"></td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="" type="text"></td>`);
|
|
|
|
|
+ // lvs[btIdx].push('<td></td>');
|
|
|
|
|
+ // lvs[btIdx].push('<td></td>');
|
|
|
|
|
+ lvs[btIdx].push('<td><a href="#" onclick="reportFormatSetupObj.onDeleteInfo(this)" class="text-danger mr-2" title="删除">删除</a></td>');
|
|
|
|
|
+ lvs[btIdx].push('</tr>');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (hfBandInfo.discrete_field_s) {
|
|
|
|
|
+ for (const field of hfBandInfo.discrete_field_s) {
|
|
|
|
|
+ const bt = +field.area.Bottom;
|
|
|
|
|
+ const btIdx = posArr.indexOf(bt);
|
|
|
|
|
+ if (btIdx >= 0) {
|
|
|
|
|
+ lvs[btIdx].push('<tr class="text-center">');
|
|
|
|
|
+ lvs[btIdx].push('<td></td>');
|
|
|
|
|
+ lvs[btIdx].push(`<td>${me._createTypeSelection(1)}</td>`);
|
|
|
|
|
+ // lvs[btIdx].push(`<td>${me._createSelectionFields_BK(rptTpl, field.FieldID, field.ParamID)}</td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td>${me._createSelectionFields(field.FieldID, field.ParamID)}</td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="${field.area.Left || '0'}" type="text"></td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="${field.area.Right || '0'}" type="text"></td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="${field.Prefix || ''}" type="text"></td>`);
|
|
|
|
|
+ lvs[btIdx].push(`<td class="text-left"><input class="form-control form-control-sm" value="${field.Suffix || ''}" type="text"></td>`);
|
|
|
|
|
+ lvs[btIdx].push('<td><a href="#" onclick="reportFormatSetupObj.onDeleteInfo(this)" class="text-danger mr-2" title="删除">删除</a></td>');
|
|
|
|
|
+ lvs[btIdx].push('</tr>');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //...
|
|
|
|
|
+ for (const lv of lvs) {
|
|
|
|
|
+ rst.push(...lv);
|
|
|
|
|
+ }
|
|
|
|
|
+ rst.push(' </tbody>')
|
|
|
|
|
+ rst.push(' </table>')
|
|
|
|
|
+ }
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ updateReportTemplate: () => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const rptTemplate = me._prepareReportTemplate();
|
|
|
|
|
+ if (rptTemplate) {
|
|
|
|
|
+ const params = { tplId: curNodes[0].ID, tplName: curNodes[0].name, tplObj: JSON.stringify(rptTemplate) };
|
|
|
|
|
+ const url = '/report_api/updateReportTemplate';
|
|
|
|
|
+ $.bootstrapLoading.start();
|
|
|
|
|
+ CommonAjax.postXsrfEx(url, params, 300000, true, getCookie('csrfToken_j'),
|
|
|
|
|
+ async function(result){
|
|
|
|
|
+ console.log(result);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }, function(err){
|
|
|
|
|
+ console.log(err);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }, function(ex){
|
|
|
|
|
+ console.log(ex);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ preview: () => {
|
|
|
|
|
+ // alert('hi');
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const rptTemplate = me._prepareReportTemplate();
|
|
|
|
|
+ if (rptTemplate) {
|
|
|
|
|
+ const params = { tplObj: JSON.stringify(rptTemplate) };
|
|
|
|
|
+ const url = '/report_api/getPreviewReport';
|
|
|
|
|
+ $.bootstrapLoading.start();
|
|
|
|
|
+ CommonAjax.postXsrfEx(url, params, 300000, true, getCookie('csrfToken_j'),
|
|
|
|
|
+ async function(result){
|
|
|
|
|
+ // console.log(result);
|
|
|
|
|
+ JpcCanvasOutput.cleanCanvas(me.canvas);
|
|
|
|
|
+ JpcCanvasOutput.drawPageBorder(result.pageRst, me.canvas, getScreenDPI());
|
|
|
|
|
+ JpcCanvasOutput.highlightConflictArea(result.pageRst, 1);
|
|
|
|
|
+ JpcCanvasOutput.drawToCanvas(result.pageRst, me.canvas, 1);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }, function(err){
|
|
|
|
|
+ console.log(err);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }, function(ex){
|
|
|
|
|
+ console.log(ex);
|
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ _prepareReportTemplate: () => {
|
|
|
|
|
+ let rst = null;
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ const curNodes = me.treeObj.getSelectedNodes();
|
|
|
|
|
+ if (curNodes.length > 0) {
|
|
|
|
|
+ const headers = me._createCommonCollctInfo('#rpt_header_table_div');
|
|
|
|
|
+ const footers = me._createCommonCollctInfo('#rpt_footer_table_div');
|
|
|
|
|
+ const rptTemplate = me.templateObj[`${curNodes[0].ID}`];
|
|
|
|
|
+ if (rptTemplate) {
|
|
|
|
|
+ me._setupTemplate(rptTemplate, headers, footers, null);
|
|
|
|
|
+ rst = rptTemplate;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ _createCommonCollctInfo: (containerId) => {
|
|
|
|
|
+ let lvCnt = 0;
|
|
|
|
|
+ const rst = { texts: [], fields: [], levels: 0 };
|
|
|
|
|
+ const createAreaFromDom = (firstDom, lv) => {
|
|
|
|
|
+ const rst = { Top: lv, Left: 0, Right: 0, Bottom: lv + 1, H_CalculationType: "percentage", V_CalculationType: "percentage" };
|
|
|
|
|
+ rst.Left = firstDom.cells[3].childNodes[0].value || 0;
|
|
|
|
|
+ rst.Right = firstDom.cells[4].childNodes[0].value || 0;
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ };
|
|
|
|
|
+ const ParamDftValMap = { '5010': '第 X 页', '5011': '共 X 页' };
|
|
|
|
|
+ const domObj = $(containerId);
|
|
|
|
|
+ for (let idx = 0; idx < domObj[0].childNodes[1].childNodes[3].childNodes.length; idx++) {
|
|
|
|
|
+ const hDom = domObj[0].childNodes[1].childNodes[3].childNodes[idx];
|
|
|
|
|
+ if (hDom.innerText && hDom.innerText.includes('新增')) {
|
|
|
|
|
+ let dtlCnt = 0;
|
|
|
|
|
+ for (let idxN = idx + 1; idxN < domObj[0].childNodes[1].childNodes[3].childNodes.length; idxN++) {
|
|
|
|
|
+ // 开始创建文本对象或指标对象
|
|
|
|
|
+ const hnDom = domObj[0].childNodes[1].childNodes[3].childNodes[idxN];
|
|
|
|
|
+ if (hnDom.innerText && !hnDom.innerText.includes('新增')) {
|
|
|
|
|
+ dtlCnt++;
|
|
|
|
|
+ const areaObj = createAreaFromDom(hnDom, lvCnt);
|
|
|
|
|
+ if (hnDom.cells[1].childNodes[0][0].selected) {
|
|
|
|
|
+ // 创建文本对象
|
|
|
|
|
+ const txtObj = { area: areaObj, font: 'Header', control: 'Header', style: 'Default_None', Label: ''};
|
|
|
|
|
+ txtObj.Label = hnDom.cells[2].childNodes[0].value || '';
|
|
|
|
|
+ rst.texts.push(txtObj);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 创建指标对象
|
|
|
|
|
+ const fieldObj = { area: areaObj, font: 'Header', control: 'Header', style: 'Default_None', Prefix: '', Suffix: ''};
|
|
|
|
|
+ fieldObj.Prefix = hnDom.cells[5].childNodes[0].value || '';
|
|
|
|
|
+ fieldObj.Suffix = hnDom.cells[6].childNodes[0].value || '';
|
|
|
|
|
+ for (const fIdOpt of hnDom.cells[2].childNodes[0]) {
|
|
|
|
|
+ if (fIdOpt.selected) {
|
|
|
|
|
+ if (fIdOpt.attributes['fid']) {
|
|
|
|
|
+ fieldObj.FieldID = +fIdOpt.attributes[fIdOpt.attributes.length - 1].nodeValue;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fieldObj.ParamID = fIdOpt.attributes[fIdOpt.attributes.length - 1].nodeValue;
|
|
|
|
|
+ fieldObj.Default_Value = ParamDftValMap[fieldObj.ParamID] || '';
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ rst.fields.push(fieldObj);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dtlCnt > 0) lvCnt++; // 有子项的才会被统计进来
|
|
|
|
|
+
|
|
|
|
|
+ // lvCnt++; // 不能无条件的统计增加层次
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (lvCnt > 0) {
|
|
|
|
|
+ // 所有rst的text、field的纵坐标都要重新整理一遍
|
|
|
|
|
+ rst.levels = lvCnt;
|
|
|
|
|
+ const lvH = +(100 / lvCnt).toFixed(3);
|
|
|
|
|
+ for (const txt of rst.texts) {
|
|
|
|
|
+ txt.area.Top = lvH * txt.area.Top;
|
|
|
|
|
+ txt.area.Bottom = lvH * txt.area.Bottom;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (const fld of rst.fields) {
|
|
|
|
|
+ fld.area.Top = lvH * fld.area.Top;
|
|
|
|
|
+ fld.area.Bottom = lvH * fld.area.Bottom;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return rst;
|
|
|
|
|
+ },
|
|
|
|
|
+ _setupTemplate: (rptTpl, headersInfo, footersInfo, signatureInfo = null) => {
|
|
|
|
|
+ const me = reportFormatSetupObj;
|
|
|
|
|
+ me._setTitle(rptTpl, $("#rpt_title_input")[0].value);
|
|
|
|
|
+ const headerBandInfo = me._getRightBandInfoObj(me._getRightInfoObj(rptTpl), 'HeaderBand');
|
|
|
|
|
+ if (headerBandInfo) {
|
|
|
|
|
+ const headerBand = rptTpl['布局框_集合'].find(item => item.Name === 'HeaderBand');
|
|
|
|
|
+ // 1. 高度
|
|
|
|
|
+ if (headerBand) {
|
|
|
|
|
+ headerBand.Height = 0.6 * headersInfo.levels;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 2.
|
|
|
|
|
+ headerBandInfo.text_s = headersInfo.texts;
|
|
|
|
|
+ headerBandInfo.discrete_field_s = headersInfo.fields;
|
|
|
|
|
+ }
|
|
|
|
|
+ const footerBandInfo = me._getRightBandInfoObj(me._getRightInfoObj(rptTpl), 'FooterBand');
|
|
|
|
|
+ if (footerBandInfo) {
|
|
|
|
|
+ const footerBand = rptTpl['布局框_集合'].find(item => item.Name === 'FooterBand');
|
|
|
|
|
+ // 1. 高度
|
|
|
|
|
+ if (footerBand) {
|
|
|
|
|
+ footerBand.Height = 0.6 * footersInfo.levels;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 2.
|
|
|
|
|
+ footerBandInfo.text_s = footersInfo.texts;
|
|
|
|
|
+ footerBandInfo.discrete_field_s = footersInfo.fields;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+};
|