rpt_main.js 63 KB

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