rpt_main.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /**
  2. * Created by Tony on 2017/6/26.
  3. */
  4. 'use strict'
  5. const PRE_PAGE_OFFSET = 150;
  6. const NEXT_PAGE_OFFSET = 160;
  7. const FIRST_PAGE_OFFSET = 50;
  8. const LAST_PAGE_OFFSET = 60;
  9. const WAIT_TIME_EXPORT = 300000;
  10. let fontSuffixMapObj = {"表标题": "title", "列标题": "column", "正文内容": "content", "合计": "summary", "表眉/表脚": "header_footer"};
  11. let rptTplObj = {
  12. hasInitialized: false,
  13. pdfFont: {'SmartSimsun': [], 'simhei': [], 'simkai': []},
  14. iniPage: function() {
  15. let me = this;
  16. if (!me.hasInitialized) {
  17. zTreeOprObj.getReportTemplateTree();
  18. zTreeOprObj.selectedPrjIDs = [];
  19. me.hasInitialized = true;
  20. zTreeOprObj.canvas = document.getElementById("rptCanvas");
  21. zTreeOprObj.canvas.onclick = canvasOprObj.canvasOnClick;
  22. zTreeOprObj.canvas.onmousemove = canvasOprObj.canvasOnMouseMove;
  23. dynamicLoadJs('/public/jspdf/Arial Narrow-normal.js');
  24. dynamicLoadJs('/public/jspdf/Arial Narrow-bold.js');
  25. dynamicLoadJs('/public/jspdf/Arial Narrow-italic.js');
  26. dynamicLoadJs('/public/jspdf/Arial Narrow-bolditalic.js');
  27. rptControlObj.loadPDFFonts();
  28. indexDbOprObj.iniDb('tmpForPDF', 2);
  29. // dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js');
  30. // dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js', me.pdfFontSimsunCallBack);
  31. }
  32. },
  33. pdfFontSimsunCallBack: function() {
  34. rptTplObj.pdfFont['SmartSimsun'].push('normal');
  35. rptTplObj.pdfFont['SmartSimsun'].push('bold');
  36. },
  37. pdfFontSimkaiCallBack: function() {
  38. rptTplObj.pdfFont['simkai'].push('normal');
  39. rptTplObj.pdfFont['simkai'].push('bold');
  40. },
  41. pdfFontSimheiCallBack: function() {
  42. rptTplObj.pdfFont['simhei'].push('normal');
  43. rptTplObj.pdfFont['simhei'].push('bold');
  44. }
  45. }
  46. let zTreeOprObj = {
  47. treeObj: null,
  48. prjFolderTreeObj: null,
  49. currentNode: null,
  50. checkedRptTplNodes: null,
  51. currentRptPageRst: null,
  52. defReportPageCfg: null,
  53. currentPage: 1,
  54. maxPages: 0,
  55. canvas: null,
  56. selectedPrjIDs: [],
  57. countChkedRptTpl: function () {
  58. let me = zTreeOprObj;
  59. if (me.treeObj) {
  60. me.checkedRptTplNodes = [];
  61. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  62. for (let node of chkNodes) {
  63. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  64. cnt++;
  65. me.checkedRptTplNodes.push(node);
  66. if (me.currentNode === node) hasCurrentNode = true;
  67. }
  68. }
  69. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  70. //这里根据实际需求再做处理
  71. cnt++;
  72. me.checkedRptTplNodes.push(me.currentNode);
  73. }
  74. $("#print_div").find("span").each(function(cIdx,elementSpan){
  75. elementSpan.innerText = cnt;
  76. });
  77. $("#export_div").find("span").each(function(cIdx,elementSpan){
  78. elementSpan.innerText = cnt;
  79. });
  80. // if (cnt) {
  81. // $('#btnBatchArchiveRpt').removeAttr('disabled');
  82. // } else {
  83. // $('#btnBatchArchiveRpt').attr('disabled', '');
  84. // }
  85. }
  86. },
  87. getReportTemplateTree: function() {
  88. let me = zTreeOprObj;
  89. let private_remove_hide_item = function (items, nlv) {
  90. if (items && items.length > 0) {
  91. for (let i = items.length - 1; i >= 0; i--) {
  92. if (!(items[i].released) && items[i].nodeType === 2) {
  93. items.splice(i, 1);
  94. } else {
  95. if (items[i].items && items[i].items.length > 0) {
  96. private_remove_hide_item(items[i].items, nlv + 1);
  97. if (items[i].items.length === 0 && nlv > 0) {
  98. items.splice(i, 1);
  99. }
  100. }
  101. }
  102. }
  103. }
  104. };
  105. let nodeLv = 0;
  106. private_remove_hide_item(TOP_TREE_NODES, nodeLv);
  107. zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_tpl_setting, "rptTplTree", me);
  108. me.treeObj.expandAll(true);
  109. // let topNodes = me.treeObj.getNodes();
  110. // for (let topLvItem of topNodes) {
  111. // me.treeObj.expandNode(topLvItem, true, false, false);
  112. // if (topLvItem.items && topLvItem.items.length > 0) {
  113. // for (let secTopLvItem of topLvItem.items) {
  114. // me.treeObj.expandNode(secTopLvItem, true, false, false);
  115. // }
  116. // }
  117. // }
  118. me.refreshNodes();
  119. },
  120. getCustomerCfg: function() {
  121. let me = zTreeOprObj;
  122. me.defReportPageCfg = {};
  123. Object.assign(me.defReportPageCfg, CUST_CFG);
  124. me.defReportPageCfg.margins = {};
  125. Object.assign(me.defReportPageCfg.margins, CUST_CFG.margins);
  126. me.defReportPageCfg.fonts = [];
  127. for (let fi = 0; fi < CUST_CFG.fonts.length; fi++) {
  128. me.defReportPageCfg.fonts.push({});
  129. Object.assign(me.defReportPageCfg.fonts[fi], CUST_CFG.fonts[fi]);
  130. }
  131. },
  132. iniFontCfgDom: function (cfg) {
  133. for (let font of cfg.fonts) {
  134. let domArrs = [];
  135. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  136. domArrs.push("<div class='row mb-1'>");
  137. //1. label
  138. domArrs.push("<div class='col-3'>" + font.CfgDispName + "</div>");
  139. //2. font name
  140. domArrs.push("<div class='col-3'>");
  141. domArrs.push("<select class='form-control input-sm' id='fontName_" + fontPropSuffix + "' onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"Name\", this)'>");
  142. domArrs.push("<option>宋体</option>");
  143. // <option>楷体</option><option>黑体</option> // 因导出PDF调整到前端输出,字体文件大,支持的字体要谨慎些,不轻易多加字体
  144. domArrs.push("</select>");
  145. domArrs.push("</div>");
  146. //3. font height
  147. domArrs.push("<div class='col-3'>");
  148. domArrs.push("<input class='form-control input-sm' id='fontHeight_" + fontPropSuffix + "' type='number' value='30' step='1' min='6' max='66' " +
  149. "onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)' " +
  150. "onkeyup='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)'>");
  151. domArrs.push("</div>");
  152. //4. font bold italic underline
  153. domArrs.push("<div class='col-3'>");
  154. domArrs.push("<a id='font_bold_" + fontPropSuffix + "' class='btn btn-sm btn-outline-secondary' title='加粗' onclick='rptControlObj.changeFontAdhoc(\"" + font.CfgDispName + "\", \"FontBold\", this)'><i class='fa fa-bold'></i></a>");
  155. domArrs.push("<a id='font_italic_" + fontPropSuffix + "' class='btn btn-sm btn-outline-secondary' title='斜体' onclick='rptControlObj.changeFontAdhoc(\"" + font.CfgDispName + "\", \"FontItalic\", this)'><i class='fa fa-italic'></i></a>");
  156. domArrs.push("<a id='font_underline_" + fontPropSuffix + "' class='btn btn-sm btn-outline-secondary' title='下划线' onclick='rptControlObj.changeFontAdhoc(\"" + font.CfgDispName + "\", \"FontUnderline\", this)'><i class='fa fa-underline'></i></a>");
  157. domArrs.push("</div>");
  158. //
  159. domArrs.push("</div>");
  160. $(domArrs.join("")).insertBefore($("#font_cfg_blank_flag"));
  161. }
  162. },
  163. renderRptCfg: function (cfg) {
  164. this.renderMargin(cfg);
  165. this.renderFormat(cfg);
  166. },
  167. renderMargin: function (cfg) {
  168. $("#elementMargin_Left")[0].value = cfg.margins.Left;
  169. $("#elementMargin_Right")[0].value = cfg.margins.Right;
  170. $("#elementMargin_Top")[0].value = cfg.margins.Top;
  171. $("#elementMargin_Bottom")[0].value = cfg.margins.Bottom;
  172. },
  173. renderFormat: function (cfg) {
  174. for (let font of cfg.fonts) {
  175. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  176. document.getElementById("fontName_" + fontPropSuffix).value = font.Name;
  177. document.getElementById("fontHeight_" + fontPropSuffix).value = font.FontHeight;
  178. document.getElementById("font_bold_" + fontPropSuffix).className = (font.FontBold === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  179. document.getElementById("font_italic_" + fontPropSuffix).className = (font.FontItalic === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  180. document.getElementById("font_underline_" + fontPropSuffix).className = (font.FontUnderline === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  181. }
  182. document.getElementById("cfg_border_thick").value = cfg.borderThick;
  183. document.getElementById("cfg_rpt_vertical_line").checked = cfg.showVerticalLine;
  184. document.getElementById("cfg_rpt_fill_zero").checked = cfg.fillZero;
  185. document.getElementById("cfg_rpt_narrow").checked = cfg.isNarrow;
  186. document.getElementById("cfg_rpt_close_warter_mark").checked = cfg.closeWarterMark;
  187. if (PAGE_SHOW['closeWatermark'] === 0) {
  188. $("#cfg_rpt_close_warter_mark_div")[0].style.display = '';
  189. } else {
  190. $("#cfg_rpt_close_warter_mark_div")[0].style.display = 'none';
  191. }
  192. document.getElementById("cfg_rpt_continuous").checked = cfg.continuousOutput;
  193. },
  194. extractRptCfg: function (cfg) {
  195. cfg.margins.Left = $("#elementMargin_Left")[0].value;
  196. cfg.margins.Right = $("#elementMargin_Right")[0].value;
  197. cfg.margins.Top = $("#elementMargin_Top")[0].value;
  198. cfg.margins.Bottom = $("#elementMargin_Bottom")[0].value;
  199. for (let font of cfg.fonts) {
  200. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  201. font.Name = document.getElementById("fontName_" + fontPropSuffix).value;
  202. font.FontHeight = document.getElementById("fontHeight_" + fontPropSuffix).value;
  203. font.FontBold = (document.getElementById("font_bold_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  204. font.FontItalic = (document.getElementById("font_italic_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  205. font.FontUnderline = (document.getElementById("font_underline_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  206. }
  207. cfg.showVerticalLine = document.getElementById("cfg_rpt_vertical_line").checked;
  208. cfg.isNarrow = document.getElementById("cfg_rpt_narrow").checked;
  209. cfg.fillZero = document.getElementById("cfg_rpt_fill_zero").checked;
  210. cfg.borderThick = document.getElementById("cfg_border_thick").value;
  211. },
  212. refreshNodes: function() {
  213. let me = this;
  214. const _set_archive_icon = function (tplNode) {
  215. let hasArchive = false;
  216. if (PAGE_SHOW['showArchive']) {
  217. for (let aItem of ARCHIVE_LIST) {
  218. if (parseInt(aItem.rpt_id) === parseInt(tplNode.refId)) {
  219. hasArchive = true;
  220. tplNode.icon = "/public/css/ztree/img/diy/10.png";
  221. break;
  222. }
  223. }
  224. }
  225. if (!hasArchive) {
  226. if (!tplNode.isParent) {
  227. tplNode.icon = null;
  228. tplNode.className = "button ico_docu";
  229. }
  230. }
  231. };
  232. let private_setupIsParent = function(node){
  233. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  234. _set_archive_icon(node);
  235. if (node.items && node.items.length) {
  236. for (let i = 0; i < node.items.length; i++) {
  237. private_setupIsParent(node.items[i]);
  238. }
  239. }
  240. };
  241. let topNodes = me.treeObj.getNodes();
  242. for (let i = 0; i < topNodes.length; i++) {
  243. private_setupIsParent(topNodes[i]);
  244. }
  245. me.treeObj.refresh();
  246. },
  247. onCheck: function(event, treeId, treeNode) {
  248. zTreeOprObj.countChkedRptTpl();
  249. rptCustomObj.showMaterialSelect();
  250. if (treeNode.isParent) {
  251. zTreeOprObj.treeObj.expandNode(treeNode, true, true, false);
  252. }
  253. },
  254. onClick: function(event,treeId,treeNode) {
  255. let me = zTreeOprObj;
  256. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  257. window.history.pushState({},0, window.location.pathname + `?rpt_id=${treeNode.refId}`);
  258. me.currentNode = treeNode;
  259. let params = {};
  260. let pageSize = rptControlObj.getCurrentPageSize();
  261. params.pageSize = pageSize;
  262. params.rpt_tpl_id = treeNode.refId;
  263. params.project_id = PROJECT_ID;
  264. params.tender_id = TENDER_ID;
  265. params.stage_id = getStageId();
  266. params.stage_status = getStageStatus();
  267. params.stage_order = getStageOrder();
  268. params.stage_times = getStageTimes();
  269. params.material_order = getMaterialOrder();
  270. params.closeWatermark = getCloseWatermark();
  271. params.custCfg = CUST_CFG;
  272. rptArchiveObj.toggleBtn(false);
  273. const gather_select = customSelects.gather_select.find(function (x) {
  274. return x.id === treeNode.refId;
  275. });
  276. if (gather_select) {
  277. rptCustomObj.init(gather_select.custom_define, customSelects.stageFlow, gather_select);
  278. return;
  279. }
  280. const stage_select = customSelects.stage_select.find(function (x) {
  281. return x.id === treeNode.refId;
  282. });
  283. if (stage_select) {
  284. rptCustomObj.init(stage_select.custom_define, customSelects.stageFlow, stage_select);
  285. return;
  286. }
  287. rptArchiveObj.toggleBtn(true);
  288. me.requestNormalReport(params);
  289. me.countChkedRptTpl();
  290. rptCustomObj.showMaterialSelect();
  291. }
  292. },
  293. changePageSize: function(dom) {
  294. let me = zTreeOprObj,
  295. targetDom = document.getElementById("btnRptPageSize");
  296. let tmpStr = targetDom.innerHTML.trim();
  297. targetDom.innerHTML = dom.innerHTML.trim();
  298. dom.innerHTML = tmpStr;
  299. me.changeCfg();
  300. },
  301. changeOrientation: function(dom) {
  302. let me = zTreeOprObj,
  303. targetDom = document.getElementById("btnRptOrientation");
  304. let tmpStr = targetDom.innerHTML.trim();
  305. targetDom.innerHTML = dom.innerHTML.trim();
  306. dom.innerHTML = tmpStr;
  307. me.changeCfg();
  308. },
  309. changeCfg: function() {
  310. let me = zTreeOprObj;
  311. if (me.currentNode) {
  312. CUST_CFG_ORG = JSON.parse(JSON.stringify(CUST_CFG));
  313. let params = {};
  314. params.pageSize = rptControlObj.getCurrentPageSize();
  315. params.orientation = rptControlObj.getCurrentOrientation();
  316. params.custCfg = CUST_CFG;
  317. params.rpt_tpl_id = me.currentNode.refId;
  318. params.project_id = PROJECT_ID;
  319. params.tender_id = TENDER_ID;
  320. params.stage_id = getStageId();
  321. params.stage_status = getStageStatus();
  322. params.stage_order = getStageOrder();
  323. params.stage_times = getStageTimes();
  324. params.material_order = getMaterialOrder();
  325. params.closeWatermark = getCloseWatermark();
  326. // me.requestNormalReport(params);
  327. localStorage[CUST_NAME + '_custCfg'] = JSON.stringify(CUST_CFG);
  328. const gather_select = customSelects.gather_select.find(function (x) {
  329. return x.id === me.currentNode.refId;
  330. });
  331. if (gather_select) {
  332. rptCustomObj.init(gather_select.custom_define, customSelects.stageFlow, gather_select);
  333. return;
  334. }
  335. const stage_select = customSelects.stage_select.find(function (x) {
  336. return x.id === me.currentNode.refId;
  337. });
  338. if (stage_select) {
  339. rptCustomObj.init(stage_select.custom_define, customSelects.stageFlow, stage_select);
  340. return;
  341. }
  342. me.requestNormalReport(params);
  343. me.countChkedRptTpl();
  344. rptCustomObj.showMaterialSelect();
  345. }
  346. },
  347. resetAfter: function (pageRst) {
  348. let size = pageRst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
  349. if (size[0] > size[1]) {
  350. document.getElementById("btnRptOrientation").innerHTML = "横向";
  351. document.getElementById("hrefRptOrientation").innerHTML = "纵向";
  352. } else {
  353. document.getElementById("btnRptOrientation").innerHTML = "纵向";
  354. document.getElementById("hrefRptOrientation").innerHTML = "横向";
  355. }
  356. },
  357. _parseRoleRelList: function(org_rel_content) {
  358. const rst = JSON.parse(org_rel_content);
  359. for (const role_rel of rst) {
  360. if (role_rel.sign_date !== null && role_rel.sign_date !== undefined && role_rel.sign_date.length >= 8) {
  361. role_rel.sign_date = new Date(role_rel.sign_date);
  362. }
  363. }
  364. return rst;
  365. },
  366. _setupArchive: function() {
  367. //
  368. },
  369. requestNormalReport: function (params) {
  370. let me = zTreeOprObj;
  371. if (COMMON_WATER_MARK_PIC_DATA === null || COMMON_WATER_MARK_PIC_DATA === '') {
  372. params.needWaterMark = true;
  373. } else {
  374. params.needWaterMark = false;
  375. }
  376. $.bootstrapLoading.start();
  377. CommonAjax.postXsrfEx("/tender/report_api/getReport", params, 300000, true, getCookie('csrfToken_j'),
  378. function(result){
  379. $.bootstrapLoading.end();
  380. let pageRst = result.data;
  381. if (params.needWaterMark) COMMON_WATER_MARK_PIC_DATA = result.waterMarkStr;
  382. STAGE_AUDIT = result.stageAudit;
  383. STAGE_AUDIT_ORG = result.stageAuditOrg;
  384. STAGE_FLOW = result.stageFlow;
  385. //stageAuditOrg
  386. if (result.signatureRelInfo && result.signatureRelInfo.length > 0) {
  387. CURRENT_ROLE_REL_ID = result.signatureRelInfo[0].id;
  388. ROLE_REL_LIST = me._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  389. rptSignatureHelper.originalRoleRelList = me._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  390. if (current_stage_status === 3) {
  391. rptSignatureHelper.mergeSignDate(pageRst, ROLE_REL_LIST, true);
  392. rptSignatureHelper.mergeSignature(pageRst, ROLE_REL_LIST);
  393. rptSignatureHelper.mergeSignAudit(pageRst, ROLE_REL_LIST, STAGE_AUDIT);
  394. }
  395. } else {
  396. CURRENT_ROLE_REL_ID = -1;
  397. ROLE_REL_LIST = [];
  398. }
  399. // if (ROLE_REL_LIST)
  400. let canvas = zTreeOprObj.canvas;
  401. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  402. me.resetAfter(pageRst);
  403. me.currentRptPageRst = pageRst;
  404. me.maxPages = pageRst.items.length;
  405. me.currentPage = 1;
  406. me.displayPageValue();
  407. let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
  408. canvas.width = size[0] + 20;
  409. if (size[1] > size[0]) {
  410. canvas.height = size[1] + 100;
  411. } else {
  412. canvas.height = size[1] + 50;
  413. }
  414. // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst);
  415. rptSignatureHelper.buildSelectableAccount();
  416. rptSignatureHelper.buildSelectableAccountUsed();
  417. rptSignatureHelper.buildRoleDom(ROLE_LIST);
  418. me.showPage(1, canvas);
  419. if (PAGE_SHOW.showArchive) {
  420. rptArchiveObj.showArchivedItem(me.currentNode);
  421. }
  422. } else {
  423. //返回了无数据表
  424. JpcCanvasOutput.cleanCanvas(canvas);
  425. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  426. }
  427. rptCustomObj.init(result.customDefine, result.stageFlow, result.customSelect);
  428. try {
  429. if (is_debug && result.debugInfo) {
  430. console.log('含有key的debug信息:');
  431. for (const k in result.debugInfo.key) {
  432. console.log(k + ':', ...result.debugInfo.key[k]);
  433. }
  434. //console.log(result.debugInfo.key);
  435. console.log('其他debug信息:');
  436. for (const di of result.debugInfo.other) {
  437. console.log(...di);
  438. }
  439. }
  440. } catch(err) {
  441. }
  442. }, function(err){
  443. if (me.currentRptPageRst === null) rptArchiveObj.toggleBtn(false);
  444. $.bootstrapLoading.end();
  445. }, function(ex){
  446. if (me.currentRptPageRst === null) rptArchiveObj.toggleBtn(false);
  447. $.bootstrapLoading.end();
  448. }
  449. );
  450. },
  451. scaleReport: function (accScale) {
  452. let me = zTreeOprObj;
  453. let canvas = zTreeOprObj.canvas;
  454. if (accScale !== 0) {
  455. JpcCanvasOutput.scaleFactor += accScale;
  456. if (JpcCanvasOutput.scaleFactor < 0.5) JpcCanvasOutput.scaleFactor = 0.5;
  457. if (JpcCanvasOutput.scaleFactor > 1.5) JpcCanvasOutput.scaleFactor = 1.5;
  458. } else {
  459. JpcCanvasOutput.scaleFactor = 1;
  460. }
  461. document.getElementById("btnNormalScale").innerText = (JpcCanvasOutput.scaleFactor * 100) + '%';
  462. me.showPage(me.currentPage, canvas);
  463. },
  464. requestPrjFolderCommon: function () {
  465. //
  466. },
  467. showPage: function (pageNum, canvas) {
  468. let me = zTreeOprObj;
  469. if (pageNum >= 1 && pageNum <= me.maxPages) {
  470. me.currentPage = pageNum;
  471. JpcCanvasOutput.cleanCanvas(canvas);
  472. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  473. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  474. }
  475. me.displayPageValue();
  476. },
  477. displayPageValue: function() {
  478. let me = zTreeOprObj;
  479. $("#rpt_page_num")[0].value = me.currentPage + "/" + me.maxPages;
  480. $("#rpt_fullscreen_page_num")[0].value = me.currentPage + "/" + me.maxPages;
  481. }
  482. };
  483. let canvasOprObj = {
  484. canvasOnMouseMove: function (event) {
  485. if (zTreeOprObj.currentNode) {
  486. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  487. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  488. if (x < PRE_PAGE_OFFSET) {
  489. canvas.style.cursor = "url(/public/images/PreviousPage.cur), auto";
  490. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  491. canvas.style.cursor = "url(/public/images/NextPage.cur), auto";
  492. } else {
  493. canvas.style.cursor = "";
  494. }
  495. }
  496. },
  497. canvasOnClick: function(event){
  498. if (zTreeOprObj.currentNode) {
  499. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  500. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  501. if (x < PRE_PAGE_OFFSET) {
  502. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  503. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  504. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  505. }
  506. }
  507. },
  508. showFullSreen: function () {
  509. if (zTreeOprObj.currentRptPageRst) {
  510. let orgH = zTreeOprObj.canvas.height;
  511. let orgW = zTreeOprObj.canvas.width;
  512. zTreeOprObj.canvas = document.getElementById("fullScrCanvas");
  513. zTreeOprObj.canvas.height = orgH;
  514. zTreeOprObj.canvas.width = orgW;
  515. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  516. $("#btn_show_full_screen").trigger("click");
  517. $('#fullscreen').on('hide.bs.modal', function () {
  518. zTreeOprObj.canvas = document.getElementById("rptCanvas");
  519. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  520. });
  521. }
  522. }
  523. };
  524. let rptControlObj = {
  525. currentOutputType: "Excel",
  526. currentDownloadUrl: null,
  527. currentDownloadIdx: 0,
  528. isLoading: false,
  529. getCurrentPageSize: function() {
  530. // let rst = "A4";
  531. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  532. //btnRptPageSize
  533. return rst;
  534. },
  535. getCurrentOrientation: function() {
  536. // let rst = "横向";
  537. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  538. return rst;
  539. },
  540. changeType: function(newType) {
  541. let me = rptControlObj;
  542. let excelDom = document.getElementById("EXCEL_TYPE");
  543. let pdfDom = document.getElementById("PDF_TYPE");
  544. if (newType === "Excel") {
  545. excelDom.className = "btn btn-block btn-primary";
  546. pdfDom.className = "btn btn-block btn-outline-secondary";
  547. me.currentOutputType = newType;
  548. } else if (newType === "PDF") {
  549. excelDom.className = "btn btn-block btn-outline-secondary";
  550. pdfDom.className = "btn btn-block btn-primary";
  551. me.currentOutputType = newType;
  552. } else {
  553. //me.currentOutputType = newType;
  554. }
  555. },
  556. getTplIdsCommon: function (refRptTplIds, rpt_names) {
  557. for (let node of zTreeOprObj.checkedRptTplNodes) {
  558. if (node.hasOwnProperty('flags') && node.flags.hasOwnProperty('reportType') && node['flags']['reportType'] !== 'NA') {
  559. // 未来可能会有这些处理,目前空着
  560. } else {
  561. refRptTplIds.push(node.refId);
  562. if (rpt_names) rpt_names.push(node.name);
  563. }
  564. }
  565. },
  566. creatCommonExportParam: function (refRptTplIds) {
  567. let rst = {};
  568. rst.rpt_ids = refRptTplIds;
  569. rst.pageSize = rptControlObj.getCurrentPageSize();
  570. rst.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  571. rst.project_id = PROJECT_ID;
  572. rst.tender_id = TENDER_ID;
  573. rst.stage_id = getStageId();
  574. rst.stage_status = getStageStatus();
  575. rst.stage_order = getStageOrder();
  576. rst.stage_times = getStageTimes();
  577. rst.material_order = getMaterialOrder();
  578. rst.custCfg = CUST_CFG;
  579. rst.closeWatermark = getCloseWatermark();
  580. return rst;
  581. },
  582. getAllInOneBook: async function () {
  583. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  584. let me = rptControlObj;
  585. let refRptTplIds = [], rpt_sheet_names = [];
  586. rptControlObj.getTplIdsCommon(refRptTplIds, rpt_sheet_names);
  587. let params = rptControlObj.creatCommonExportParam(refRptTplIds);
  588. params.closeWatermark = getCloseWatermarkForExcel();
  589. await rptCustomObj.getCustomSelect(params);
  590. params.rpt_names = rpt_sheet_names;
  591. params.rptName = TENDER_NAME;
  592. params.option = getExcelOutputOption();
  593. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  594. if (chkNodes.length > 0) {
  595. delete params.orientation; // 打印时有勾选的话,不需要提供方向
  596. }
  597. $.bootstrapLoading.start();
  598. CommonAjax.postXsrfEx("/tender/report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, getCookie('csrfToken_j'), function(result){
  599. $.bootstrapLoading.end();
  600. if (result) {
  601. let uuIdUrls = [];
  602. let uuIdUrl = "/getFileByUUID/" + result.data[0].uuid + "/" + stringUtil.replaceAll(result.data[0].reportName, "#", "_") + "/xlsx";
  603. uuIdUrls.push(uuIdUrl);
  604. downloadReport(uuIdUrls);
  605. } else {
  606. //
  607. }
  608. },
  609. function(failRst){
  610. // closeWaitingView();
  611. $.bootstrapLoading.end();
  612. console.log(failRst);
  613. },
  614. function(exceptionRst){
  615. // closeWaitingView();
  616. $.bootstrapLoading.end();
  617. console.log(exceptionRst);
  618. }
  619. );
  620. }
  621. },
  622. getAllIndividualExcelBook: async function () {
  623. let me = rptControlObj;
  624. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  625. let refRptTplIds = [];
  626. let rpt_names = [];
  627. rptControlObj.getTplIdsCommon(refRptTplIds, rpt_names);
  628. let params = rptControlObj.creatCommonExportParam(refRptTplIds);
  629. params.closeWatermark = getCloseWatermarkForExcel();
  630. await rptCustomObj.getCustomSelect(params);
  631. params.isOneSheet = true;
  632. params.rpt_names = rpt_names;
  633. params.rptName = 'All';
  634. // 测试连续输出
  635. params.option = getExcelOutputOption();
  636. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  637. if (chkNodes.length > 0) {
  638. delete params.orientation; // 打印时有勾选的话,不需要提供方向
  639. }
  640. $.bootstrapLoading.start();
  641. CommonAjax.postXsrfEx("/tender/report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, getCookie('csrfToken_j'), function(result){
  642. $.bootstrapLoading.end();
  643. if (result) {
  644. let uuIdUrls = [];
  645. for (let uuIdObj of result.data) {
  646. let uuIdUrl = "/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  647. uuIdUrls.push(uuIdUrl);
  648. }
  649. downloadReport(uuIdUrls);
  650. } else {
  651. //
  652. }
  653. },
  654. function(failRst){
  655. // closeWaitingView();
  656. $.bootstrapLoading.end();
  657. console.log(failRst);
  658. },
  659. function(exceptionRst){
  660. // closeWaitingView();
  661. $.bootstrapLoading.end();
  662. console.log(exceptionRst);
  663. }
  664. );
  665. }
  666. },
  667. checkAndGetExcel: function () {
  668. if (zTreeOprObj.treeObj) {
  669. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  670. if (chkNodes.length > 0) {
  671. $("#show_excel_output_cfg").trigger("click");
  672. } else {
  673. rptControlObj.getAllIndividualExcelBook();
  674. }
  675. }
  676. },
  677. getExcel: function () {
  678. let me = rptControlObj;
  679. if ($("#excelExportType_AllInOneBook")[0].checked) {
  680. me.getAllInOneBook();
  681. } else if ($("#excelExportType_IndividualBook")[0].checked) {
  682. me.getAllIndividualExcelBook();
  683. }
  684. },
  685. getPdfFontCallbackLight: function(fontProperty) {
  686. rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
  687. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  688. rptControlObj.isLoading = false;
  689. }
  690. },
  691. getPdfFontCallback: function(fontProperty) {
  692. let me = rptControlObj;
  693. if (rptTplObj.pdfFont['SmartSimsun'].indexOf(fontProperty) < 0) {
  694. rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
  695. }
  696. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  697. $.bootstrapLoading.end();
  698. me.getPDFEx();
  699. }
  700. },
  701. loadPDFFonts: function () {
  702. //这里尝试下异步加载字体文件
  703. let me = rptControlObj;
  704. me.isLoading = true;
  705. // dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js', 'normal', me.getPdfFontCallbackLight);
  706. // dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js', 'bold', me.getPdfFontCallbackLight);
  707. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', me.getPdfFontCallbackLight);
  708. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', me.getPdfFontCallbackLight);
  709. },
  710. getPDFPre: function () {
  711. let me = rptControlObj;
  712. if (me.isLoading) {
  713. $.bootstrapLoading.start();
  714. console.log('fonts are loading...');
  715. setTimeout(me.getPDFPre, 3000); //延时3秒
  716. } else {
  717. $.bootstrapLoading.end(); //根据测试,需要先做一次清理,防止在极端情况下出现阻塞
  718. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  719. me.getPDFEx();
  720. } else {
  721. $.bootstrapLoading.start();
  722. // dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js',"normal", me.getPdfFontCallback);
  723. // dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js',"bold", me.getPdfFontCallback);
  724. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', me.getPdfFontCallback);
  725. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', me.getPdfFontCallback);
  726. }
  727. }
  728. },
  729. getPDFEx: async function () {
  730. let me = rptControlObj;
  731. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0 && PAGE_SHOW['closeExportPdf'] !== 1) {
  732. let refRptTplIds = [];
  733. let rpt_names = [];
  734. rptControlObj.getTplIdsCommon(refRptTplIds, rpt_names);
  735. const signatureRelArr = [];
  736. if (refRptTplIds.length > 0) {
  737. let params = rptControlObj.creatCommonExportParam(refRptTplIds);
  738. // params.getPicFlag = true; //专门针对草图项,只有此项为true,才需要把草图信息带过来,预览及打印动态加载草图 // 纠结:但这样还是解决不了效率问题,得另外想交互方式
  739. await rptCustomObj.getCustomSelect(params);
  740. delete params.orientation; // 打印时有勾选的话,不需要提供方向
  741. $.bootstrapLoading.start();
  742. if (COMMON_WATER_MARK_PIC_DATA === null || COMMON_WATER_MARK_PIC_DATA === '') {
  743. params.needWaterMark = true;
  744. } else {
  745. params.needWaterMark = false;
  746. }
  747. CommonAjax.postXsrfEx("/tender/report_api/getMultiReports", params, WAIT_TIME_EXPORT, true, getCookie('csrfToken_j'),
  748. function(result){
  749. // closeWaitingView();
  750. $.bootstrapLoading.end();
  751. if (params.needWaterMark) COMMON_WATER_MARK_PIC_DATA = result.waterMarkStr;
  752. STAGE_AUDIT = result.stageAudit;
  753. let pageSize = rptControlObj.getCurrentPageSize();
  754. for (const signatureRel of result.signatureRelInfo) {
  755. signatureRelArr.push(JSON.parse(signatureRel.rel_content));
  756. }
  757. downloadPDFReport(result.data, pageSize, rpt_names, signatureRelArr, result.signatureRelInfo, refRptTplIds, STAGE_AUDIT);
  758. /*
  759. for (let idx = 0; idx < result.data.length; idx++) {
  760. let pageData = result.data[idx];
  761. // if (current_stage_status === 3) {
  762. // rptSignatureHelper.mergeSignDate(pageData);
  763. // rptSignatureHelper.mergeSignature(pageData);
  764. // rptSignatureHelper.mergeSignAudit(pageRst, ROLE_REL_LIST, STAGE_AUDIT);
  765. // }
  766. // 备注:因多表的原因,无需merge电子签名,在下面处理
  767. let singleSignatureRelArr = [];
  768. for (let rIdx = 0; rIdx < result.signatureRelInfo.length; rIdx++) {
  769. if (result.signatureRelInfo[rIdx].rpt_id === refRptTplIds[idx]) {
  770. // singleSignatureRelArr.push(signatureRelArr[rIdx]);
  771. singleSignatureRelArr = signatureRelArr[rIdx]; // 有些报表可能没有签名
  772. break;
  773. }
  774. }
  775. // JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[idx], signatureRelArr);
  776. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[idx], singleSignatureRelArr, STAGE_AUDIT); // 精确控制签名
  777. }
  778. //*/
  779. },
  780. function(failRst){
  781. // closeWaitingView();
  782. $.bootstrapLoading.end();
  783. console.log(failRst);
  784. },
  785. function(exceptionRst){
  786. // closeWaitingView();
  787. $.bootstrapLoading.end();
  788. console.log(exceptionRst);
  789. }
  790. );
  791. } else {
  792. //这个分支是为了减少请求,用户已经点过的表,又没有勾选,那么就直接导出成PDF
  793. let pageSize = rptControlObj.getCurrentPageSize();
  794. let pageData = zTreeOprObj.currentRptPageRst;
  795. signatureRelArr.push(ROLE_REL_LIST);
  796. // closeWaitingView();
  797. $.bootstrapLoading.end();
  798. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[0], signatureRelArr);
  799. }
  800. }
  801. },
  802. firstPage: function(dom) {
  803. zTreeOprObj.showPage(1, zTreeOprObj.canvas);
  804. },
  805. prePage: function(dom) {
  806. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, zTreeOprObj.canvas);
  807. },
  808. nextPage: function(dom) {
  809. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, zTreeOprObj.canvas);
  810. },
  811. lastPage: function(dom) {
  812. let me = zTreeOprObj;
  813. zTreeOprObj.showPage(me.maxPages, zTreeOprObj.canvas);
  814. },
  815. onKeydown: function (event, dom) {
  816. let me = zTreeOprObj, keyPressed = null;
  817. if (window.event) {
  818. keyPressed = window.event.keyCode; // IE/Chrome
  819. } else {
  820. keyPressed = event.which; // Firefox
  821. }
  822. if (keyPressed === 13) {
  823. let pageNum = 1;
  824. try {
  825. pageNum = parseInt(dom.value);
  826. } catch (e) {
  827. pageNum = 1;
  828. }
  829. if (pageNum < 1) {
  830. pageNum = 1;
  831. } else if (pageNum > me.maxPages) {
  832. pageNum = me.maxPages;
  833. }
  834. zTreeOprObj.showPage(pageNum, zTreeOprObj.canvas);
  835. return false;
  836. }
  837. },
  838. changeMargin: function(marginPropStr, marginDom) {
  839. CUST_CFG.margins[marginPropStr] = marginDom.value;
  840. },
  841. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  842. for (let font of CUST_CFG.fonts) {
  843. if (font["CfgDispName"] === CfgDispName) {
  844. font[fontProperty] = fontDom.value;
  845. break;
  846. }
  847. }
  848. },
  849. changeBorderWeight: function (dom) {
  850. CUST_CFG.borderThick = dom.value;
  851. },
  852. changeCfgOption: function (optStr, dom) {
  853. CUST_CFG[optStr] = dom.checked;
  854. },
  855. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  856. for (let font of CUST_CFG.fonts) {
  857. if (font["CfgDispName"] === CfgDispName) {
  858. if (font[fontProperty] === 'T') {
  859. font[fontProperty] = 'F';
  860. fontDom.className = "btn btn-sm btn-outline-secondary";
  861. } else {
  862. font[fontProperty] = 'T';
  863. fontDom.className = "btn btn-sm btn-outline-secondary active";
  864. }
  865. break;
  866. }
  867. }
  868. },
  869. restoreMargine: function () {
  870. zTreeOprObj.renderMargin(zTreeOprObj.defReportPageCfg);
  871. zTreeOprObj.extractRptCfg(CUST_CFG);
  872. },
  873. restoreFormat: function () {
  874. zTreeOprObj.renderFormat(zTreeOprObj.defReportPageCfg);
  875. zTreeOprObj.extractRptCfg(CUST_CFG);
  876. },
  877. restoreCustCFG: function () {
  878. let me = this;
  879. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  880. zTreeOprObj.extractRptCfg(CUST_CFG);
  881. // me.saveCustCfg();
  882. },
  883. saveCustCfg: function() {
  884. let params = {};
  885. params.custCfg = CUST_CFG;
  886. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  887. // alert("Save successfully!");
  888. $("#update_msg_response")[0].style.color = "green";
  889. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  890. setTimeout(function(){
  891. $("#update_msg_response")[0].innerHTML = "";
  892. }, 1000);
  893. }, function (failRst) {
  894. $("#update_msg_response")[0].style.color = "red";
  895. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  896. setTimeout(function(){
  897. $("#update_msg_response")[0].innerHTML = "";
  898. }, 1000);
  899. }, null
  900. );
  901. },
  902. confirmCfgChange: function() {
  903. zTreeOprObj.changeCfg();
  904. },
  905. cancelCfgChange: function() {
  906. CUST_CFG = JSON.parse(JSON.stringify(CUST_CFG_ORG));
  907. }
  908. };
  909. function downloadPDFReport(pageDataArr, pageSize, rpt_names, signatureRelArr, signatureRelInfo, refRptTplIds, STAGE_AUDIT) {
  910. rptControlObj.currentDownloadIdx = 0;
  911. const _resetPageDataByBreaks = function(breakAmt, newRptNames) {
  912. let rst = [];
  913. for (let pi = 0; pi < pageDataArr.length; pi++) {
  914. let pageItem = pageDataArr[pi];
  915. let currentRptName = rpt_names[pi];
  916. if (pageItem.items.length > breakAmt) {
  917. let pa = Math.floor(pageItem.items.length / breakAmt);
  918. if (pageItem.items.length % breakAmt > 0) {
  919. pa++;
  920. }
  921. for (let idx = 0; idx < pa; idx++) {
  922. let newPageDataObj = {items: []};
  923. // newPageDataObj[JV.NODE_PAGE_INFO] = JSON.parse(JSON.stringify(pageItem[JV.NODE_PAGE_INFO]));
  924. newPageDataObj[JV.NODE_PAGE_INFO] = pageItem[JV.NODE_PAGE_INFO];
  925. // newPageDataObj[JV.BAND_PROP_MERGE_BAND] = JSON.parse(JSON.stringify(pageItem[JV.BAND_PROP_MERGE_BAND]));
  926. newPageDataObj[JV.BAND_PROP_MERGE_BAND] = pageItem[JV.BAND_PROP_MERGE_BAND];
  927. newPageDataObj[JV.NODE_FONT_COLLECTION] = pageItem[JV.NODE_FONT_COLLECTION];
  928. newPageDataObj[JV.NODE_STYLE_COLLECTION] = pageItem[JV.NODE_STYLE_COLLECTION];
  929. newPageDataObj[JV.NODE_CONTROL_COLLECTION] = pageItem[JV.NODE_CONTROL_COLLECTION];
  930. for ( let dIdx = idx * breakAmt; dIdx < (Math.min( (idx + 1) * breakAmt, pageItem.items.length)); dIdx++) {
  931. // newPageDataObj.items.push(JSON.parse(JSON.stringify( pageItem.items[dIdx] )));
  932. newPageDataObj.items.push(pageItem.items[dIdx]);
  933. }
  934. rst.push(newPageDataObj);
  935. newRptNames.push(currentRptName + '_' + (idx + 1));
  936. }
  937. } else {
  938. rst.push(pageItem);
  939. newRptNames.push(currentRptName);
  940. }
  941. }
  942. return rst;
  943. };
  944. const private_download = function(newPageDataArr, new_rpt_rames) {
  945. if (rptControlObj.currentDownloadIdx < newPageDataArr.length) {
  946. let singleSignatureRelArr = [];
  947. for (let rIdx = 0; rIdx < signatureRelInfo.length; rIdx++) {
  948. // for (const rptId of refRptTplIds) {
  949. // if (signatureRelInfo[rIdx].rpt_id === rptId) {
  950. // singleSignatureRelArr = signatureRelArr[rIdx]; // 有些报表可能没有签名
  951. // break;
  952. // }
  953. // }
  954. let rptId = refRptTplIds[rptControlObj.currentDownloadIdx];
  955. if (signatureRelInfo[rIdx].rpt_id === rptId) {
  956. singleSignatureRelArr = signatureRelArr[rIdx]; // 有些报表可能没有签名
  957. break;
  958. }
  959. // if (signatureRelInfo[rIdx].rpt_id === refRptTplIds[idx]) {
  960. // singleSignatureRelArr = signatureRelArr[rIdx]; // 有些报表可能没有签名
  961. // break;
  962. // }
  963. }
  964. let pageData = newPageDataArr[rptControlObj.currentDownloadIdx];
  965. let rptName = new_rpt_rames[rptControlObj.currentDownloadIdx];
  966. rptControlObj.currentDownloadIdx++;
  967. /*
  968. // 临时代码,为大批量草图PDF下载用(强制分页)
  969. const MAX_PAGES_AMT = 100;
  970. const orgItems = pageData.items;
  971. let ttlSec = parseInt(orgItems.length / MAX_PAGES_AMT);
  972. if (orgItems.length % MAX_PAGES_AMT > 0) {
  973. ttlSec++;
  974. }
  975. for (let idx = 0; idx < ttlSec; idx++) {
  976. let indPages = [];
  977. for (let pi = idx * MAX_PAGES_AMT; pi < Math.min((idx + 1) * MAX_PAGES_AMT, orgItems.length); pi++ ) {
  978. indPages.push(orgItems[pi]);
  979. }
  980. pageData.items = indPages;
  981. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rptName + idx, singleSignatureRelArr, STAGE_AUDIT);
  982. }
  983. pageData.items = orgItems;
  984. //*/
  985. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rptName, singleSignatureRelArr, STAGE_AUDIT); // 精确控制签名
  986. if (rptControlObj.currentDownloadIdx < newPageDataArr.length) setTimeout(private_download(newPageDataArr, new_rpt_rames), 2000);
  987. }
  988. };
  989. /*
  990. // 这里控制导出PDF的页码数量(如果有设置的话)
  991. let newRptNames = []; //这个为导出PDF控制分页用
  992. let newPageDataRst = _resetPageDataByBreaks(10, newRptNames);
  993. private_download(newPageDataRst, newRptNames);
  994. /*/
  995. // 导出PDF真实优化代码
  996. let picPaths = [], dummyPicAmt = 0, dummyCells = [], dupPicPath = [], dupPicCell = [];
  997. // 1. 先找有没有dummy
  998. for (let pageData of pageDataArr) {
  999. for (let page of pageData.items) {
  1000. for (let dCell of page.signature_cells) {
  1001. if (dCell.signature_name === 'dummy_pic') {
  1002. let picIdx = picPaths.indexOf(dCell.path);
  1003. if (picIdx < 0) {
  1004. picPaths.push(dCell.path);
  1005. dummyCells.push(dCell);
  1006. dummyPicAmt++;
  1007. } else {
  1008. let dPicIdx = dupPicPath.indexOf(dCell.path);
  1009. if (dPicIdx < 0) {
  1010. dupPicPath.push(dCell.path);
  1011. dupPicCell.push([]);
  1012. dPicIdx = dupPicPath.length - 1;
  1013. }
  1014. dupPicCell[dPicIdx].push(dCell);
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. if (dummyPicAmt > 0) {
  1021. // 2. 有则一个个请求下载图片,下载完后统一导出PDF
  1022. $.bootstrapLoading.start();
  1023. let handledAmt = 0, exceptionAmt = 0;
  1024. for (let pIdx = 0; pIdx < dummyCells.length; pIdx++) {
  1025. let dCell = dummyCells[pIdx];
  1026. getBlob(dCell.path).then(blob => {
  1027. if (blob === 'not found!') {
  1028. exceptionAmt++;
  1029. if ((handledAmt + exceptionAmt) === dummyPicAmt) {
  1030. $.bootstrapLoading.end();
  1031. private_download(pageDataArr, rpt_names);
  1032. }
  1033. } else {
  1034. let oFileReader = new FileReader();
  1035. oFileReader.onloadend = function (e) {
  1036. let base64 = e.target.result;
  1037. dCell.pic = base64;
  1038. handledAmt++;
  1039. let pPathIdx = dupPicPath.indexOf(dCell.path);
  1040. if (pPathIdx >= 0) {
  1041. for (let dupCell of dupPicCell[pPathIdx]) {
  1042. dupCell.pic = base64;
  1043. }
  1044. }
  1045. // console.log(`已处理草图: ${handledAmt}`);
  1046. if ((handledAmt + exceptionAmt) === dummyPicAmt) {
  1047. $.bootstrapLoading.end();
  1048. private_download(pageDataArr, rpt_names);
  1049. }
  1050. };
  1051. oFileReader.readAsDataURL(blob);
  1052. }
  1053. });
  1054. }
  1055. } else {
  1056. // 3. 无则普通导出
  1057. private_download(pageDataArr, rpt_names);
  1058. }
  1059. //*/
  1060. }
  1061. function downloadReport(urls) {
  1062. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  1063. rptControlObj.currentDownloadUrl = null;
  1064. rptControlObj.currentDownloadIdx = 0;
  1065. const private_download = function() {
  1066. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  1067. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  1068. rptControlObj.currentDownloadIdx++;
  1069. window.location = rptControlObj.currentDownloadUrl;
  1070. if (rptControlObj.currentDownloadIdx < urls.length) setTimeout(private_download, 2000);
  1071. }
  1072. }
  1073. private_download();
  1074. }
  1075. function dynamicLoadJs(url, type, callback) {
  1076. let head = document.getElementsByTagName('head')[0];
  1077. let script = document.createElement('script');
  1078. script.type = 'text/javascript';
  1079. script.src = url;
  1080. if(callback) {
  1081. script.onload = script.onreadystatechange = function (event) {
  1082. callback(type);
  1083. script.onload = script.onreadystatechange = null;
  1084. };
  1085. }
  1086. head.appendChild(script);
  1087. }
  1088. function getStageStatus() {
  1089. return current_stage_status;
  1090. }
  1091. function getStageId() {
  1092. return current_stage_id;
  1093. }
  1094. function getStageOrder() {
  1095. return CUR_ORDER;
  1096. }
  1097. function getMaterialOrder() {
  1098. return parseInt($('#material-select').attr('m-order'));
  1099. }
  1100. function getStageTimes() {
  1101. return current_stage_times;
  1102. }
  1103. function getCloseWatermark() {
  1104. return PAGE_SHOW['closeWatermark'];
  1105. }
  1106. function getCloseWatermarkForExcel() {
  1107. if (PAGE_SHOW['closeWatermark'] === 1 || CUST_CFG.closeWarterMark) {
  1108. return 1;
  1109. } else {
  1110. return 0;
  1111. }
  1112. }
  1113. function getExcelOutputOption() {
  1114. if (CUST_CFG.continuousOutput) {
  1115. return 'infinity'; // 连续输出方式
  1116. } else {
  1117. return 'normal'; // 目前是普通方式
  1118. }
  1119. }