123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- /**
- * Created by Tony on 2017/6/26.
- */
- 'use strict'
- const PRE_PAGE_OFFSET = 150;
- const NEXT_PAGE_OFFSET = 160;
- const FIRST_PAGE_OFFSET = 50;
- const LAST_PAGE_OFFSET = 60;
- let rptTplObj = {
- hasInitialized: false,
- iniPage: function() {
- let me = this;
- if (!me.hasInitialized) {
- zTreeOprObj.getCustomerCfg();
- zTreeOprObj.getReportTemplateTree();
- me.hasInitialized = true;
- let canvas = document.getElementById("rptCanvas");
- canvas.onclick = canvasOprObj.canvasOnClick;
- canvas.onmousemove = canvasOprObj.canvasOnMouseMove;
- }
- }
- }
- let zTreeOprObj = {
- treeObj: null,
- currentNode: null,
- checkedRptTplNodes: null,
- currentRptPageRst: null,
- reportPageCfg: null,
- currentPage: 1,
- maxPages: 0,
- countChkedRptTpl: function () {
- let me = zTreeOprObj;
- if (me.treeObj) {
- me.checkedRptTplNodes = [];
- let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
- for (let node of chkNodes) {
- if (node.nodeType === TPL_TYPE_TEMPLATE) {
- cnt++;
- me.checkedRptTplNodes.push(node);
- if (me.currentNode === node) hasCurrentNode = true;
- }
- }
- if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
- //这里根据实际需求再做处理
- cnt++;
- me.checkedRptTplNodes.push(me.currentNode);
- }
- $("#export_div").find("span").each(function(cIdx,elementSpan){
- elementSpan.innerText = cnt;
- });
- $("#print_div").find("span").each(function(cIdx,elementSpan){
- elementSpan.innerText = cnt;
- });
- }
- },
- getReportTemplateTree: function() {
- let me = zTreeOprObj, params = {};
- params.engineerId = projectInfoObj.projectInfo.property.engineering;
- CommonAjax.postEx("report_tpl_api/getRptTplTree", params, 20000, true, function(result){
- let private_remove_hide_item = function (items) {
- if (items && items.length > 0) {
- for (let i = items.length - 1; i >= 0; i--) {
- if (!(items[i].released) && items[i].nodeType === 2) {
- items.splice(i, 1);
- } else {
- if (items[i].items && items[i].items.length > 0) {
- private_remove_hide_item(items[i].items);
- }
- }
- }
- }
- }
- private_remove_hide_item(result);
- for (let topNode of result) {
- if (topNode.userId === "-100") {
- topNode.name = topNode.name + " - 标准报表";
- } else {
- topNode.name = topNode.name + " - 定制报表";
- }
- }
- zTreeHelper.createTreeDirectly(result, rpt_tpl_setting, "rptTplTree", me);
- me.refreshNodes();
- }, null, null);
- },
- getCustomerCfg: function() {
- let me = zTreeOprObj, params = {};
- params.engineerId = projectInfoObj.projectInfo.property.engineering;
- CommonAjax.postEx("report_tpl_api/getCustomizeCfg", params, 20000, true, function(result){
- if (result) {
- me.reportPageCfg = result;
- $("#elementMargin_Left").get(0).value = result.margins.Left;
- $("#elementMargin_Right").get(0).value = result.margins.Right;
- $("#elementMargin_Top").get(0).value = result.margins.Top;
- $("#elementMargin_Bottom").get(0).value = result.margins.Bottom;
- for (let font of result.fonts) {
- let fontPropSuffix = "title";
- if (font.CfgDispName === "表标题") {
- fontPropSuffix = "title";
- } else if (font.CfgDispName === "列标题") {
- fontPropSuffix = "column";
- } else if (font.CfgDispName === "正文内容") {
- fontPropSuffix = "content";
- } else if (font.CfgDispName === "合计") {
- fontPropSuffix = "summary";
- } else if (font.CfgDispName === "表眉/表脚") {
- fontPropSuffix = "header_footer";
- }
- document.getElementById("fontName_" + fontPropSuffix).value = font.Name;
- document.getElementById("fontHeight_" + fontPropSuffix).value = font.FontHeight;
- document.getElementById("font_bold_" + fontPropSuffix).className = (font.FontBold === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
- document.getElementById("font_italic_" + fontPropSuffix).className = (font.FontItalic === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
- document.getElementById("font_underline_" + fontPropSuffix).className = (font.FontUnderline === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
- }
- document.getElementById("rpt_vertical_line").checked = result.showVerticalLine;
- document.getElementById("rpt_narrow").checked = result.isNarrow;
- document.getElementById("rpt_fill_zero").checked = result.fillZero;
- } else {
- me.reportPageCfg = null;
- }
- }, null, null
- );
- },
- refreshNodes: function() {
- let me = this;
- let private_setupIsParent = function(node){
- node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
- if (node.items && node.items.length) {
- for (let i = 0; i < node.items.length; i++) {
- private_setupIsParent(node.items[i]);
- }
- }
- };
- let topNodes = me.treeObj.getNodes();
- for (let i = 0; i < topNodes.length; i++) {
- private_setupIsParent(topNodes[i]);
- }
- me.treeObj.refresh();
- },
- onCheck: function(event, treeId, treeNode) {
- zTreeOprObj.countChkedRptTpl();
- },
- onClick: function(event,treeId,treeNode) {
- let me = zTreeOprObj;
- if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
- let params = {};
- let pageSize = rptControlObj.getCurrentPageSize();
- params.pageSize = pageSize;
- params.rpt_tpl_id = treeNode.refId;
- params.prj_id = projectInfoObj.projectInfo.ID;
- params.custCfg = me.reportPageCfg;
- me.currentNode = treeNode;
- me.requestReport(params);
- me.countChkedRptTpl();
- }
- },
- changePageSize: function(dom) {
- let me = zTreeOprObj,
- targetDom = document.getElementById("btnRptPageSize");
- let tmpStr = targetDom.innerHTML.trim();
- targetDom.innerHTML = dom.innerHTML.trim();
- dom.innerHTML = tmpStr;
- me.changeCfg();
- },
- changeOrientation: function(dom) {
- let me = zTreeOprObj,
- targetDom = document.getElementById("btnRptOrientation");
- let tmpStr = targetDom.innerHTML.trim();
- targetDom.innerHTML = dom.innerHTML.trim();
- dom.innerHTML = tmpStr;
- me.changeCfg();
- },
- changeCfg: function() {
- let me = zTreeOprObj;
- let params = {};
- params.pageSize = rptControlObj.getCurrentPageSize();
- params.orientation = rptControlObj.getCurrentOrientation();
- params.rpt_tpl_id = me.currentNode.refId;
- params.prj_id = projectInfoObj.projectInfo.ID;
- params.custCfg = me.reportPageCfg;
- me.requestReport(params);
- },
- resetAfter: function (pageRst) {
- let size = pageRst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
- if (size[0] > size[1]) {
- document.getElementById("btnRptOrientation").innerHTML = "横向";
- document.getElementById("hrefRptOrientation").innerHTML = "纵向";
- } else {
- document.getElementById("btnRptOrientation").innerHTML = "纵向";
- document.getElementById("hrefRptOrientation").innerHTML = "横向";
- }
- },
- requestReport: function (params) {
- let me = zTreeOprObj;
- CommonAjax.postEx("report_api/getReport", params, 5000, true,
- function(result){
- let pageRst = result;
- if (pageRst) {
- me.resetAfter(pageRst);
- let canvas = document.getElementById("rptCanvas");
- me.currentRptPageRst = pageRst;
- me.maxPages = pageRst.items.length;
- me.currentPage = 1;
- me.displayPageValue();
- let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
- canvas.width = size[0] + 20;
- if (size[1] > size[0]) {
- canvas.height = size[1] + 100;
- } else {
- canvas.height = size[1] + 50;
- }
- me.showPage(1, canvas);
- }
- }, null, null
- );
- },
- showPage: function (pageNum, canvas) {
- let me = zTreeOprObj;
- if (pageNum >= 1 && pageNum <= me.maxPages) {
- me.currentPage = pageNum;
- JpcCanvasOutput.cleanCanvas(canvas);
- JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
- JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
- }
- me.displayPageValue();
- },
- displayPageValue: function() {
- let me = zTreeOprObj;
- $("#rpt_page_num").get(0).value = me.currentPage + "/" + me.maxPages;
- }
- };
- let canvasOprObj = {
- canvasOnMouseMove: function (event) {
- if (zTreeOprObj.currentNode) {
- let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
- if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
- if (x < FIRST_PAGE_OFFSET) {
- canvas.style.cursor = "url(/web/building_saas/img/FirstPageSimple.cur), auto";
- } else if (x < PRE_PAGE_OFFSET) {
- canvas.style.cursor = "url(/web/building_saas/img/PreviousPageSimple.cur), auto";
- } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
- canvas.style.cursor = "url(/web/building_saas/img/LastPageSimple.cur), auto";
- } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
- canvas.style.cursor = "url(/web/building_saas/img/NextPageSimple.cur), auto";
- } else {
- canvas.style.cursor = "";
- }
- }
- },
- canvasOnClick: function(event){
- if (zTreeOprObj.currentNode) {
- let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
- if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
- if (x < FIRST_PAGE_OFFSET) {
- zTreeOprObj.showPage(1, canvas);
- } else if (x < PRE_PAGE_OFFSET) {
- zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
- } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
- zTreeOprObj.showPage(zTreeOprObj.maxPages, canvas);
- } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
- zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
- }
- }
- }
- };
- let rptControlObj = {
- currentOutputType: "Excel",
- currentDownloadUrl: null,
- currentDownloadIdx: 0,
- getCurrentPageSize: function() {
- // let rst = "A4";
- let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
- //btnRptPageSize
- return rst;
- },
- getCurrentOrientation: function() {
- // let rst = "横向";
- let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
- return rst;
- },
- getCurrentReportOption: function() {
- //
- },
- changeType: function(newType) {
- let me = rptControlObj;
- let excelDom = document.getElementById("EXCEL_TYPE");
- let pdfDom = document.getElementById("PDF_TYPE");
- if (newType === "Excel") {
- excelDom.className = "btn btn-block btn-primary";
- pdfDom.className = "btn btn-block btn-outline-secondary";
- me.currentOutputType = newType;
- } else if (newType === "PDF") {
- excelDom.className = "btn btn-block btn-outline-secondary";
- pdfDom.className = "btn btn-block btn-primary";
- me.currentOutputType = newType;
- } else {
- //me.currentOutputType = newType;
- }
- },
- outputRpt: function() {
- let me = rptControlObj;
- if (me.currentOutputType === "Excel") {
- me.getExcel();
- } else if (me.currentOutputType === "PDF") {
- me.getPDF();
- } else {
- //other types if needed.
- }
- },
- getAllInOneBook: function () {
- let me = rptControlObj;
- if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
- let orgRptName = zTreeOprObj.checkedRptTplNodes[0].name;
- let refRptTplIds = [];
- for (let node of zTreeOprObj.checkedRptTplNodes) {
- refRptTplIds.push(node.refId);
- }
- let url = "/report_api/getExcelInOneBook/" + projectInfoObj.projectInfo.ID + "/" + refRptTplIds.join(",") + "/" +
- me.getCurrentPageSize() + "/" + orgRptName + "/" + 'normal';
- window.location = url;
- }
- },
- getExcel: function () {
- let me = rptControlObj;
- if ($("#excelExportType_AllInOneBook").get(0).checked) {
- me.getAllInOneBook();
- } else if ($("#excelExportType_IndividualBook").get(0).checked) {
- if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
- let urls = [];
- let orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
- for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
- let orgRptName = tplNode.name;
- let url = "/report_api/getExcel/" + projectInfoObj.projectInfo.ID + "/" + tplNode.refId + "/" +
- me.getCurrentPageSize() + "/" + orientation + "/" + orgRptName + "/" + true + "/" + 'normal';
- urls.push(url);
- }
- downloadReport(urls);
- }
- }
- },
- getPDF: function() {
- let me = rptControlObj;
- if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
- let urls = [];
- let orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
- for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
- let orgRptName = tplNode.name;
- let url = "/report_api/getPDF/" + projectInfoObj.projectInfo.ID + "/" + tplNode.refId + "/" +
- me.getCurrentPageSize() + "/" + orientation + "/" + orgRptName;
- urls.push(url);
- }
- downloadReport(urls);
- }
- },
- firstPage: function(dom) {
- let canvas = document.getElementById("rptCanvas");
- zTreeOprObj.showPage(1, canvas);
- },
- prePage: function(dom) {
- let canvas = document.getElementById("rptCanvas");
- zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
- },
- nextPage: function(dom) {
- let canvas = document.getElementById("rptCanvas");
- zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
- },
- lastPage: function(dom) {
- let me = zTreeOprObj;
- let canvas = document.getElementById("rptCanvas");
- zTreeOprObj.showPage(me.maxPages, canvas);
- },
- onKeydown: function (event, dom) {
- let me = zTreeOprObj, keyPressed = null;
- if (window.event) {
- keyPressed = window.event.keyCode; // IE/Chrome
- } else {
- keyPressed = event.which; // Firefox
- }
- if (keyPressed === 13) {
- let pageNum = 1;
- try {
- pageNum = parseInt(dom.value);
- } catch (e) {
- pageNum = 1;
- }
- let canvas = document.getElementById("rptCanvas");
- if (pageNum < 1) {
- pageNum = 1;
- } else if (pageNum > me.maxPages) {
- pageNum = me.maxPages;
- }
- zTreeOprObj.showPage(pageNum, canvas);
- return false;
- }
- },
- changeMargin: function(marginPropStr, marginDom) {
- zTreeOprObj.reportPageCfg.margins[marginPropStr] = marginDom.value;
- },
- changeFontMain: function(CfgDispName, fontProperty, fontDom) {
- for (let font of zTreeOprObj.reportPageCfg.fonts) {
- if (font["CfgDispName"] === CfgDispName) {
- font[fontProperty] = fontDom.value;
- break;
- }
- }
- },
- changeCfgOption: function (optStr, dom) {
- zTreeOprObj.reportPageCfg[optStr] = dom.checked;
- },
- changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
- for (let font of zTreeOprObj.reportPageCfg.fonts) {
- if (font["CfgDispName"] === CfgDispName) {
- if (font[fontProperty] === 'T') {
- font[fontProperty] = 'F';
- fontDom.className = "btn btn-sm btn-outline-secondary";
- } else {
- font[fontProperty] = 'T';
- fontDom.className = "btn btn-sm btn-outline-secondary active";
- }
- break;
- }
- }
- },
- saveCustCfg: function() {
- let params = {};
- params.custCfg = zTreeOprObj.reportPageCfg;
- CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
- alert("Save successfully!");
- }, null, null
- );
- },
- confirmCfgChange: function() {
- let treeNode = zTreeOprObj.currentNode;
- if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
- let params = {};
- params.pageSize = rptControlObj.getCurrentPageSize();
- params.rpt_tpl_id = treeNode.refId;
- params.prj_id = projectInfoObj.projectInfo.ID;
- params.custCfg = zTreeOprObj.reportPageCfg;
- zTreeOprObj.requestReport(params);
- }
- }
- };
- function downloadReport(urls) {
- //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
- rptControlObj.currentDownloadUrl = null;
- rptControlObj.currentDownloadIdx = 0;
- let private_download = function() {
- if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
- rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
- rptControlObj.currentDownloadIdx++;
- window.location = rptControlObj.currentDownloadUrl;
- setTimeout(private_download, 2000);
- }
- }
- private_download();
- }
|