rpt_custom.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const rptCustomObj = (function () {
  10. // 审批人选择
  11. const sAuditSelect = 'audit_select';
  12. let stageFlow = [];
  13. // 汇总表
  14. const sGatherSelect = 'gather_select';
  15. let gsObj = {
  16. setting: null,
  17. gsSheet: null,
  18. grSheet: null,
  19. tenderSourceTree: null,
  20. grArray: [],
  21. orgSelect: null,
  22. };
  23. // 期选择
  24. const sStageSelect = 'stage_select';
  25. const grSpreadSetting = {
  26. baseCols: [
  27. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 240, formatter: '@', readOnly: true},
  28. ],
  29. extraCols: [
  30. {title: '%s', colSpan: '1', rowSpan: '1', field: '%s', hAlign: 1, vAlign: '1', width: 60, cellType: 'checkbox', readOnly: true},
  31. ],
  32. emptyRows: 0,
  33. headRows: 1,
  34. headRowHeight: [32],
  35. defaultRowHeight: 21,
  36. headerFont: '12px 微软雅黑',
  37. font: '12px 微软雅黑',
  38. headColWidth: []
  39. };
  40. const gatherSelectSpreadObj = {
  41. _getStageSelectHtml: function (valid) {
  42. const html = [];
  43. for (let i = 1; i <= valid; i++) {
  44. html.push(`<option value="${i}">第${i}期</option>`);
  45. }
  46. return html.join('');
  47. },
  48. _rebuildStageSelect: function () {
  49. if (gsObj.setting.type === 'stage') {
  50. const validStage = _.min(_.map(gsObj.grArray, 'stageCount'));
  51. $('#gather-stage').html(this._getStageSelectHtml(validStage));
  52. } else if (gsObj.setting.type === 'stage-zone') {
  53. const validStage = _.max(_.map(gsObj.grArray, 'stageCount'));
  54. $('#gather-stage-begin').html(this._getStageSelectHtml(validStage));
  55. $('#gather-stage-end').html(this._getStageSelectHtml(validStage));
  56. }
  57. },
  58. _addTender: function (tender) {
  59. const gr = gsObj.grArray.find(function (x) {
  60. return x.tid === tender.tid;
  61. });
  62. const t = {tid: tender.tid, name: tender.name, stageCount: tender.stageCount};
  63. if (!gr) gsObj.grArray.push(t);
  64. return t;
  65. },
  66. _removeTender: function (tender) {
  67. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  68. return x.tid === tender.tid;
  69. });
  70. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  71. },
  72. reloadResultData: function () {
  73. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  74. this._rebuildStageSelect();
  75. },
  76. gsButtonClicked: function (e, info) {
  77. if (!info.sheet.zh_setting) return;
  78. const col = info.sheet.zh_setting.cols[info.col];
  79. if (col.field !== 'selected') return;
  80. const node = SpreadJsObj.getSelectObject(info.sheet);
  81. node.selected = !node.selected;
  82. if (node.children && node.children.length > 0) {
  83. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  84. for (const p of posterity) {
  85. p.selected = node.selected;
  86. if (!p.children || p.children.length === 0){
  87. if (p.selected) {
  88. gatherSelectSpreadObj._addTender(p);
  89. } else {
  90. gatherSelectSpreadObj._removeTender(p);
  91. }
  92. }
  93. }
  94. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  95. } else {
  96. if (node.selected) {
  97. gatherSelectSpreadObj._addTender(node);
  98. } else {
  99. gatherSelectSpreadObj._removeTender(node);
  100. }
  101. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  102. }
  103. gatherSelectSpreadObj.reloadResultData();
  104. },
  105. grButtonClicked: function (e, info) {
  106. if (!info.sheet.zh_setting) return;
  107. const col = info.sheet.zh_setting.cols[info.col];
  108. if (col.field === 'name') return;
  109. const node = SpreadJsObj.getSelectObject(info.sheet);
  110. const refreshRows = [info.row];
  111. node[col.field] = !node[col.field];
  112. for (const rCol of info.sheet.zh_setting.cols) {
  113. if (rCol.field !== 'name' && rCol.field !== col.field) {
  114. node[rCol.field] = false;
  115. }
  116. }
  117. if (node[col.field]) {
  118. for (const [i, gra] of gsObj.grArray.entries()) {
  119. if (gra[col.field] && gra.tid !== node.tid) {
  120. gra[col.field] = false;
  121. refreshRows.push(i);
  122. }
  123. }
  124. }
  125. SpreadJsObj.reLoadRowsData(info.sheet, refreshRows);
  126. },
  127. initSelectTenders: function (tenders) {
  128. if (!tenders) return;
  129. const specCol = gsObj.setting.special ? gsObj.setting.special : [];
  130. const select = [];
  131. for (const node of gsObj.tenderSourceTree.nodes) {
  132. node.selected = false;
  133. }
  134. for (const t of tenders) {
  135. const tender = gsObj.tenderSourceTree.nodes.find(function (x) { return x.tid === t.tid});
  136. if (!tender) continue;
  137. tender.selected = true;
  138. select.push(tender);
  139. const st = this._addTender(tender);
  140. for (const sc of specCol) {
  141. st[sc.key] = t[sc.key];
  142. }
  143. }
  144. SpreadJsObj.reLoadColsData(gsObj.gsSheet, [0]);
  145. if (select.length > 0) SpreadJsObj.locateTreeNode(gsObj.gsSheet, select[0].tmt_id);
  146. this.reloadResultData();
  147. },
  148. };
  149. // 材差 - 期选择
  150. const sMaterialSumSelect = 'material_sum_select';
  151. // 变更令选择
  152. const sChangeSelect = 'change_select';
  153. const changeObj = {
  154. changes: null,
  155. latestPush: null,
  156. loadChanges: async function () {
  157. const self = this;
  158. const result = await postDataAsync(`/tender/${window.location.pathname.split('/')[2]}/load`, { filter: 'change'});
  159. this.changes = result.change;
  160. const html = [];
  161. for (const c of this.changes) {
  162. html.push('<tr>', `<td class="text-center"><input type="checkbox" name="change-select-check" value="${c.cid}"></td>`, `<td>${c.code}</td>`, `<td>${c.name}</td>`, '</tr>');
  163. }
  164. $('#change-select-list').html(html.join(''));
  165. $('[name=change-select-check]').click(function () {
  166. const selectChange = $('[name=change-select-check]:checked');
  167. const selectHtml = [];
  168. for (const sc of selectChange) {
  169. const c = self.changes.find(x => { return x.cid === sc.value });
  170. selectHtml.push(`<tr><td class="text-center">${selectHtml.length + 1}</td><td>${c.code}</td><td>${c.name}</td></tr>`);
  171. }
  172. $('#change-select-result').html(selectHtml.join(''));
  173. });
  174. $('#change-select-all').click(function () {
  175. const change = $('[name=change-select-check]');
  176. const selectHtml = [];
  177. for (const sc of change) {
  178. sc.checked = this.checked;
  179. if (this.checked) {
  180. const c = self.changes.find(x => { return x.cid === sc.value });
  181. selectHtml.push(`<tr><td class="text-center">${selectHtml.length + 1}</td><td>${c.code}</td><td>${c.name}</td></tr>`);
  182. }
  183. }
  184. $('#change-select-result').html(selectHtml.join(''));
  185. });
  186. },
  187. show: async function (title, resolve) {
  188. this.latestPush = null;
  189. $('#change-select-title').html(title);
  190. if (!this.changes) {
  191. await this.loadChanges();
  192. }
  193. if (resolve) {
  194. setTimeout(() => { $("#change-select").modal('show'); }, 1000);
  195. } else {
  196. $('#change-select').modal('show');
  197. }
  198. $('#change-select-ok').unbind('click');
  199. $('#change-select-ok').bind('click', () => {
  200. rptCustomObj.resetChangeSelect(resolve);
  201. });
  202. }
  203. };
  204. const getStageFlowSelectHtml = function (select, id) {
  205. const html = [];
  206. html.push('<select style="width: 80%" id="' + id + '" sf-title="' + select.title + '">');
  207. for (const sf of stageFlow) {
  208. html.push(`<option ${sf.visible ? '' : 'style="display: none"'}>${sf.name}-${sf.role}</option>`);
  209. }
  210. html.push('</select>');
  211. return html.join('');
  212. };
  213. const checkAsSelectValid = function (validFlow, asSelect) {
  214. for (const s of asSelect) {
  215. const f = validFlow.find(function (x) {
  216. return x.aid === s.aid && x.order === s.order;
  217. });
  218. if (!f) {
  219. $('#audit-select-hint').html('本期审批流程发生变动,原审批人选择不适配,需重新选择').show();
  220. return false;
  221. }
  222. }
  223. $('#audit-select-hint').hide();
  224. return true;
  225. };
  226. const initAuditSelect = function (asSetting, asSelect) {
  227. const setting = JSON.parse(asSetting), select = asSelect;
  228. $('#audit-select-title').html(setting.title);
  229. if (setting.hideSign) {
  230. $('#pnl_eSignature').hide();
  231. } else {
  232. $('#pnl_eSignature').show();
  233. }
  234. $('#pnl_audit_select div button').html('<i class="fa fa-pencil"></i><br>' + (setting.caption || '审批人选择'));
  235. const html = [];
  236. for (const [i, s] of setting.select.entries()) {
  237. html.push('<tr>');
  238. html.push('<td>', s.title, '</td>');
  239. html.push('<td>', getStageFlowSelectHtml(s, 'sf-' + i), '</td>');
  240. html.push('</tr>');
  241. }
  242. $('#audit-select-list').html(html.join(''));
  243. for (const [i, s] of setting.select.entries()) {
  244. const obj = $('#sf-' + i);
  245. const s = select[i];
  246. obj[0].selectedIndex = s ? stageFlow.findIndex(function (x) {
  247. return x.order === s.order && x.aid === s.aid;
  248. }) : -1;
  249. }
  250. if (asSelect.length === 0 || !checkAsSelectValid(stageFlow, asSelect)) {
  251. $('#audit-select').modal('show');
  252. }
  253. };
  254. const initGrSpreadSetting = function (gsSetting) {
  255. grSpreadSetting.cols = [];
  256. for (const bc of grSpreadSetting.baseCols) {
  257. grSpreadSetting.cols.push(bc);
  258. if (bc.field === 'name') bc.width = gsSetting.nameColWidth ? gsSetting.nameColWidth : 240;
  259. }
  260. if (gsSetting.special) {
  261. for (const s of gsSetting.special) {
  262. for (const ec of grSpreadSetting.extraCols) {
  263. const c = {};
  264. c.title = ec.title.replace('%s', s.title);
  265. c.colSpan = ec.colSpan;
  266. c.field = ec.field.replace('%s', s.key);
  267. c.hAlign = ec.hAlign;
  268. c.width = s.width ? s.width : ec.width;
  269. c.cellType = ec.cellType;
  270. c.readOnly = ec.readOnly;
  271. grSpreadSetting.cols.push(c);
  272. }
  273. }
  274. }
  275. };
  276. const initGatherSelect = function (gsSetting, gsSelect, rptName, resolve = null) {
  277. gsObj.grArray = [];
  278. gsObj.setting = JSON.parse(gsSetting);
  279. gsObj.orgSelect = gsSelect;
  280. $('#gather-select-count').html(gsSelect ? gsSelect.tenders.length : 0);
  281. $('#gather-select-title').html(gsObj.setting.title + (rptName ? '-' + rptName : ''));
  282. initGrSpreadSetting(gsObj.setting);
  283. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  284. // 初始化选择结果
  285. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  286. gatherSelectSpreadObj.initSelectTenders(gsSelect ? gsSelect.tenders : []);
  287. $('[name=gather-type]').hide();
  288. if (gsObj.setting.type === 'month' || gsObj.setting.type === 'months') $('#gather-by-month').show();
  289. if (gsObj.setting.type === 'zone') $('#gather-by-zone').show();
  290. if (gsObj.setting.type === 'stage') $('#gather-by-stage').show();
  291. if (gsObj.setting.type === 'stage-zone') $('#gather-by-stage-zone').show();
  292. if (gsObj.setting.type === 'checked-zone') $('#gather-by-checked-zone').show();
  293. if (gsSelect) {
  294. if (gsSelect.zone) {
  295. $('#gather-zone').val(gsSelect.zone ? gsSelect.zone : '');
  296. } else if (gsSelect.checked_zone) {
  297. $('#gather-checked-zone').val(gsSelect.checked_zone ? gsSelect.checked_zone : '');
  298. } else if (gsSelect.month) {
  299. $('#gather-month').val(gsSelect.month ? gsSelect.month: '');
  300. } else if (gsSelect.stage) {
  301. $('#gather-stage').val(gsSelect.stage || '');
  302. } else if (gsSelect.stage_zone) {
  303. const [stageBegin, stageEnd] = gsSelect.stage_zone ? gsSelect.stage_zone.split(':') : ['', ''];
  304. $('#gather-stage-begin').val(stageBegin);
  305. $('#gather-stage-end').val(stageEnd);
  306. }
  307. }
  308. // 初始化
  309. if (resolve) {
  310. setTimeout(() => { $("#gather-select").modal('show'); }, 1000);
  311. } else {
  312. $("#gather-select").modal('show');
  313. }
  314. $('#gather-select-ok').unbind('click');
  315. $('#gather-select-ok').bind('click', () => {
  316. rptCustomObj.resetGatherSelect(resolve);
  317. // $("#gather-select").modal('hide');
  318. });
  319. };
  320. const initStageSelect = function (gsSetting, gsSelect, rptName, resolve = null) {
  321. const setting = JSON.parse(gsSetting);
  322. $('#stage-select-count').html(gsSelect && gsSelect.stages ? gsSelect.stages.length : 0);
  323. $('#stage-select-title').html(setting.title + (rptName ? '-' + rptName : ''));
  324. // 初始化选择结果
  325. $('#stage-select-hint').attr('min-select', setting.min).attr('max-select', setting.max).hide();
  326. for (const sc of $('[name=stage-select-check]')) {
  327. sc.checked = false;
  328. }
  329. if (gsSelect && gsSelect.stages) {
  330. for (const s of gsSelect.stages) {
  331. $('#stage-select-' + s)[0].checked = true;
  332. }
  333. }
  334. if (resolve) {
  335. setTimeout(() => { $("#stage-select").modal('show'); }, 1000);
  336. } else {
  337. $("#stage-select").modal('show');
  338. }
  339. $('#stage-select-ok').unbind('click');
  340. $('#stage-select-ok').bind('click', () => {
  341. rptCustomObj.resetStageSelect(resolve);
  342. // $("#stage-select").modal('hide');
  343. });
  344. $('#stage-select-all').unbind('click');
  345. $('#stage-select-all').bind('click', function () {
  346. const material = $('[name=stage-select-check]');
  347. for (const m of material) {
  348. m.checked = this.checked;
  349. }
  350. });
  351. };
  352. const initChangeSelect = function (gsSetting, rptName, resolve = null) {
  353. changeObj.show('选择工程变更' + (rptName ? '-' + rptName : ''), resolve);
  354. };
  355. const initMaterialSumSelect = function (gsSetting, gsSelect, rptName, resolve = null) {
  356. const setting = JSON.parse(gsSetting);
  357. $('#material-sum-select-count').html(gsSelect && gsSelect.materials ? gsSelect.materials.length : 0);
  358. $('#material-sum-select-title').html((setting.title || '请选择材差期') + (rptName ? '-' + rptName : ''));
  359. // 初始化选择结果
  360. $('#material-sum-select-hint').attr('min-select', setting.min).attr('max-select', setting.max).hide();
  361. for (const sc of $('[name=material-sum-select-check]')) {
  362. sc.checked = false;
  363. }
  364. if (gsSelect && gsSelect.materials) {
  365. for (const s of gsSelect.materials) {
  366. $('#material-sum-select-' + s)[0].checked = true;
  367. }
  368. }
  369. if (resolve) {
  370. setTimeout(() => { $("#material-sum-select").modal('show'); }, 1000);
  371. } else {
  372. $("#material-sum-select").modal('show');
  373. }
  374. $('#material-sum-select-ok').unbind('click');
  375. $('#material-sum-select-ok').bind('click', () => {
  376. rptCustomObj.resetMaterialSumSelect(resolve);
  377. // $("#stage-select").modal('hide');
  378. });
  379. $('#material-sum-select-all').unbind('click');
  380. $('#material-sum-select-all').bind('click', function () {
  381. const material = $('[name=material-sum-select-check]');
  382. for (const m of material) {
  383. m.checked = this.checked;
  384. }
  385. });
  386. };
  387. const init = function (cDefine, sfData, cSelect, rptName, resolve = null) {
  388. stageFlow = sfData;
  389. if (cDefine && cDefine[sAuditSelect] && cDefine[sAuditSelect].enable && cDefine[sAuditSelect].setting) {
  390. $('#pnl_audit_select').show();
  391. initAuditSelect(cDefine[sAuditSelect].setting, cSelect ? cSelect[sAuditSelect] : []);
  392. } else {
  393. $('#pnl_eSignature').show();
  394. $('#pnl_audit_select').hide();
  395. }
  396. if (cDefine && cDefine[sGatherSelect] && cDefine[sGatherSelect].enable && cDefine[sGatherSelect].setting) {
  397. $('#pnl_gather_select').show();
  398. initGatherSelect(cDefine[sGatherSelect].setting, cSelect ? cSelect[sGatherSelect] : null, rptName, resolve);
  399. } else {
  400. $('#pnl_gather_select').hide();
  401. }
  402. if (cDefine && cDefine[sStageSelect] && cDefine[sStageSelect].enable && cDefine[sStageSelect].setting) {
  403. $('#pnl_stage_select').show();
  404. initStageSelect(cDefine[sStageSelect].setting, cSelect ? cSelect[sStageSelect] : null, rptName, resolve);
  405. } else {
  406. $('#pnl_stage_select').hide();
  407. }
  408. if (cDefine && cDefine[sMaterialSumSelect] && cDefine[sMaterialSumSelect].enable && cDefine[sMaterialSumSelect].setting) {
  409. $('#pnl_material_sum_select').show();
  410. initMaterialSumSelect(cDefine[sMaterialSumSelect].setting, cSelect ? cSelect[sMaterialSumSelect] : null, rptName, resolve);
  411. } else {
  412. $('#pnl_material_sum_select').hide();
  413. }
  414. if (cDefine && cDefine[sChangeSelect] && cDefine[sChangeSelect].enable) {
  415. initChangeSelect(cDefine[sChangeSelect].setting, rptName, resolve);
  416. }
  417. };
  418. const reloadReportData = async function (result) {
  419. let pageRst = result.data;
  420. if (result.signatureRelInfo && result.signatureRelInfo.length > 0) {
  421. CURRENT_ROLE_REL_ID = result.signatureRelInfo[0].id;
  422. ROLE_REL_LIST = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  423. STAGE_AUDIT = result.stageAudit;
  424. rptSignatureHelper.originalRoleRelList = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  425. rptSignatureHelper.mergeSignDate(pageRst, ROLE_REL_LIST, true, getStageStatus() !== 3);
  426. rptSignatureHelper.mergeSignature(pageRst, ROLE_REL_LIST, true, getStageStatus() !== 3);
  427. await rptSignatureHelper.resetDummySignature(pageRst, ROLE_REL_LIST, getStageStatus() !== 3); // 这里重新整理签章坐标信息(因签章大小在后台暂时获取不到,挪到前端处理)
  428. rptSignatureHelper.mergeSignAudit(pageRst, ROLE_REL_LIST, STAGE_AUDIT, getStageStatus() !== 3);
  429. if (PAGE_SHOW.isTextSignature) {
  430. resetTextSignature(pageRst, getStageStatus() !== 3);
  431. }
  432. } else {
  433. CURRENT_ROLE_REL_ID = -1;
  434. ROLE_REL_LIST = [];
  435. }
  436. let canvas = zTreeOprObj.canvas;
  437. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  438. zTreeOprObj.resetAfter(pageRst);
  439. zTreeOprObj.currentRptPageRst = pageRst;
  440. zTreeOprObj.maxPages = pageRst.items.length;
  441. zTreeOprObj.currentPage = 1;
  442. zTreeOprObj.displayPageValue();
  443. let size = JpcCanvasOutput.getReportSizeInPixel(zTreeOprObj.currentRptPageRst, getScreenDPI());
  444. canvas.width = size[0] + 20;
  445. if (size[1] > size[0]) {
  446. canvas.height = size[1] + 100;
  447. } else {
  448. canvas.height = size[1] + 50;
  449. }
  450. // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst);
  451. rptSignatureHelper.buildSelectableAccount();
  452. rptSignatureHelper.buildSelectableAccountUsed();
  453. rptSignatureHelper.buildRoleDom(ROLE_LIST);
  454. zTreeOprObj.showPage(1, canvas);
  455. } else {
  456. //返回了无数据表
  457. JpcCanvasOutput.cleanCanvas(canvas);
  458. JpcCanvasOutput.drawPageBorder(zTreeOprObj.currentRptPageRst, canvas, getScreenDPI());
  459. }
  460. rptCustomObj.init(result.customDefine, result.stageFlow, result.customSelect);
  461. try {
  462. if (is_debug && result.debugInfo) {
  463. console.log('含有key的debug信息:');
  464. for (const k in result.debugInfo.key) {
  465. console.log(k + ':', ...result.debugInfo.key[k]);
  466. }
  467. console.log('其他debug信息:');
  468. for (const di of result.debugInfo.other) {
  469. console.log(...di);
  470. }
  471. }
  472. } catch(err) {
  473. }
  474. zTreeOprObj.countChkedRptTpl();
  475. };
  476. const getCommonParams = function (data) {
  477. data.pageSize = rptControlObj.getCurrentPageSize();
  478. data.rpt_tpl_id = zTreeOprObj.currentNode.refId;
  479. data.custCfg = CUST_CFG;
  480. data.project_id = PROJECT_ID;
  481. data.tender_id = TENDER_ID;
  482. data.stage_id = getStageId();
  483. data.stage_status = getStageStatus();
  484. data.stage_order = getStageOrder();
  485. data.stage_times = getStageTimes();
  486. data.material_order = getMaterialOrder();
  487. };
  488. const resetAuditSelect = function () {
  489. const selObj = $('select', '#audit-select-list');
  490. const data = { audit_select: [], closeWatermark: getCloseWatermark() };
  491. getCommonParams(data);
  492. for (const s of selObj) {
  493. const sf = stageFlow[s.selectedIndex];
  494. if (!sf) {
  495. $('#audit-select-hint').html('未选择' + s.attributes['sf-title'].value).show();
  496. return;
  497. }
  498. data.audit_select.push({...sf, sort: s.selectedIndex});
  499. }
  500. $('#audit-select-hint').hide();
  501. postData('/report/cDefine', data, function (result) {
  502. reloadReportData(result);
  503. $('#audit-select').modal('hide');
  504. rptArchiveObj.toggleBtn(true);
  505. if (PAGE_SHOW.showArchive) {
  506. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  507. }
  508. });
  509. };
  510. const resetGatherSelect = function (resolve = null) {
  511. const data = {}, hintObj = $('#gather-hint');
  512. if (!resolve) getCommonParams(data);
  513. data[sGatherSelect] = {
  514. tenders: [],
  515. type: gsObj.setting.type,
  516. };
  517. const specCol = gsObj.setting.special ? gsObj.setting.special : [];
  518. for (const sc of specCol) {
  519. sc.sCount = 0;
  520. }
  521. for (const gra of gsObj.grArray) {
  522. const ra = {tid: gra.tid};
  523. for (const sc of specCol) {
  524. if (gra[sc.key]) {
  525. ra[sc.key] = true;
  526. sc.sCount += 1;
  527. }
  528. }
  529. data[sGatherSelect].tenders.push(ra);
  530. }
  531. for (const sc of specCol) {
  532. if (sc.sCount === 0) {
  533. hintObj.html('请选择 ' + sc.title).show();
  534. return;
  535. }
  536. }
  537. if (gsObj.setting.onlySpec) {
  538. if (data[sGatherSelect].tenders.length > specCol.length) {
  539. hintObj.html('请勿选择普通汇总项目').show();
  540. return;
  541. }
  542. } else {
  543. if (data[sGatherSelect].tenders.length <= specCol.length) {
  544. hintObj.html('请至少选择1个普通汇总项目').show();
  545. return;
  546. }
  547. }
  548. if (gsObj.setting.type === 'month' || gsObj.setting.type === 'months') {
  549. data[sGatherSelect].month = $('#gather-month').val();
  550. if (data[sGatherSelect].month === '') {
  551. hintObj.html('请选择 汇总年月').show();
  552. return;
  553. }
  554. } else if (gsObj.setting.type === 'zone') {
  555. data[sGatherSelect].zone = $('#gather-zone').val();
  556. if (data[sGatherSelect].zone === '') {
  557. hintObj.html('请选择 汇总周期').show();
  558. return;
  559. } else if(data[sGatherSelect].zone.indexOf(' - ') < 0) {
  560. hintObj.html('请选择 完整汇总周期').show();
  561. return;
  562. }
  563. } else if (gsObj.setting.type === 'stage') {
  564. data[sGatherSelect].stage = _.toInteger($('#gather-stage').val()) || 0;
  565. const validStage = _.min(_.map(gsObj.grArray, 'stageCount'));
  566. if (!data[sGatherSelect].stage) {
  567. hintObj.html('请选择 汇总期').show();
  568. return;
  569. }
  570. if (data[sGatherSelect].stage > validStage) {
  571. hintObj.html('选择的期无效,请重新选择').show();
  572. return;
  573. }
  574. } else if (gsObj.setting.type === 'stage-zone') {
  575. const stageBegin = _.toInteger($('#gather-stage-begin').val()) || 0;
  576. const stageEnd = _.toInteger($('#gather-stage-end').val()) || 0;
  577. const validStage = _.max(_.map(gsObj.grArray, 'stageCount'));
  578. if (!stageBegin || !stageEnd) {
  579. hintObj.html('请选择 汇总开始期与结束期').show();
  580. return;
  581. }
  582. if (stageEnd <= stageBegin) {
  583. hintObj.html('结束期应大于开始期').show();
  584. return;
  585. }
  586. if (stageEnd > validStage) {
  587. hintObj.html('选择的期无效,请重新选择').show();
  588. return;
  589. }
  590. data[sGatherSelect].stage_zone = stageBegin + ':' + stageEnd;
  591. } else if (gsObj.setting.type === 'checked-zone') {
  592. data[sGatherSelect].checked_zone = $('#gather-checked-zone').val();
  593. if (data[sGatherSelect].checked_zone === '') {
  594. hintObj.html('请选择 汇总周期').show();
  595. return;
  596. } else if(data[sGatherSelect].checked_zone.indexOf(' - ') < 0) {
  597. hintObj.html('请选择 完整汇总周期').show();
  598. return;
  599. }
  600. }
  601. hintObj.hide();
  602. if (resolve) {
  603. resolve(data);
  604. rptArchiveObj.toggleBtn(false);
  605. } else {
  606. postData('/report/cDefine', data, function (result) {
  607. reloadReportData(result);
  608. const gather_select = customSelects.gather_select.find(function (x) {
  609. return x.id === zTreeOprObj.currentNode.refId;
  610. });
  611. if (gather_select) {
  612. gather_select.gather_select = data[sGatherSelect];
  613. }
  614. $('#gather-select-count').html(data[sGatherSelect].tenders.length);
  615. $('#gather-select').modal('hide');
  616. rptArchiveObj.toggleBtn(true);
  617. if (PAGE_SHOW.showArchive) {
  618. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  619. }
  620. });
  621. }
  622. };
  623. const resetStageSelect = function (resolve = null) {
  624. const data = {}, hintObj = $('#stage-select-hint');
  625. if (!resolve) getCommonParams(data);
  626. data[sStageSelect] = {
  627. stages: [],
  628. };
  629. for (const sc of $('[name=stage-select-check]:checked')) {
  630. data[sStageSelect].stages.push(parseInt($(sc).attr('stage-order')));
  631. }
  632. if (data[sStageSelect].stages.length < parseInt(hintObj.attr('min-select'))) {
  633. hintObj.html('请至少选择' + hintObj.attr('min-select') + '期数据').show();
  634. return;
  635. } else if (data[sStageSelect].stages.length > parseInt(hintObj.attr('max-select'))) {
  636. hintObj.html('最多只能选择' + hintObj.attr('max-select') + '期数据').show();
  637. return;
  638. }
  639. hintObj.hide();
  640. if (resolve) {
  641. resolve(data);
  642. } else {
  643. postData('/report/cDefine', data, function (result) {
  644. reloadReportData(result);
  645. const stage_select = customSelects.stage_select.find(function (x) {
  646. return x.id === zTreeOprObj.currentNode.refId;
  647. });
  648. if (stage_select) {
  649. stage_select.stage_select = data[sStageSelect];
  650. }
  651. $('#stage-select-count').html(data[sStageSelect].stages.length);
  652. $('#stage-select').modal('hide');
  653. rptArchiveObj.toggleBtn(true);
  654. if (PAGE_SHOW.showArchive) {
  655. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  656. }
  657. });
  658. }
  659. };
  660. const resetMaterialSumSelect = function (resolve = null) {
  661. const data = {}, hintObj = $('#material-sum-select-hint');
  662. if (!resolve) getCommonParams(data);
  663. data[sMaterialSumSelect] = {
  664. materials: [],
  665. };
  666. for (const mc of $('[name=material-sum-select-check]:checked')) {
  667. data[sMaterialSumSelect].materials.push(parseInt($(mc).attr('material-order')));
  668. }
  669. if (data[sMaterialSumSelect].materials.length < parseInt(hintObj.attr('min-select'))) {
  670. hintObj.html('请至少选择' + hintObj.attr('min-select') + '期数据').show();
  671. return;
  672. } else if (data[sMaterialSumSelect].materials.length > parseInt(hintObj.attr('max-select'))) {
  673. hintObj.html('最多只能选择' + hintObj.attr('max-select') + '期数据').show();
  674. return;
  675. }
  676. hintObj.hide();
  677. if (resolve) {
  678. resolve(data);
  679. } else {
  680. postData('/report/cDefine', data, function (result) {
  681. reloadReportData(result);
  682. const material_sum_select = customSelects[sMaterialSumSelect].find(function (x) {
  683. return x.id === zTreeOprObj.currentNode.refId;
  684. });
  685. if (material_sum_select) {
  686. material_sum_select.material_sum_select = data[sMaterialSumSelect];
  687. }
  688. $('#material-sum-select-count').html(data[sMaterialSumSelect].materials.length);
  689. $('#material-sum-select').modal('hide');
  690. rptArchiveObj.toggleBtn(true);
  691. if (PAGE_SHOW.showArchive) {
  692. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  693. }
  694. });
  695. }
  696. };
  697. const resetChangeSelect = function (resolve = null) {
  698. const data = {}, hintObj = $('#change-select-hint');
  699. if (!resolve) getCommonParams(data);
  700. data[sChangeSelect] = [];
  701. for (const sc of $('[name=change-select-check]:checked')) {
  702. data[sChangeSelect].push(sc.value);
  703. }
  704. if (data[sChangeSelect].length === 0) {
  705. hintObj.html('请至少选择一条变更令').show();
  706. return;
  707. } else {
  708. hintObj.hide();
  709. }
  710. if (resolve) {
  711. resolve(data);
  712. } else {
  713. postData('/report/cDefine', data, function (result) {
  714. changeObj.latestSelect = data[sChangeSelect];
  715. reloadReportData(result);
  716. $('#change-select').modal('hide');
  717. rptArchiveObj.toggleBtn(true);
  718. if (PAGE_SHOW.showArchive) {
  719. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  720. }
  721. });
  722. }
  723. };
  724. const _createTenderTreeForCross = function (tenders, category, rstItems) {
  725. if (rstItems instanceof Array && rstItems.length === 0) {
  726. //1. 先确定category方式(‘年份’、‘姓名’、‘类型’)及顺序
  727. let ctArr = [];
  728. for (let cat of category) {
  729. if (cat.level) {
  730. ctArr.push(cat);
  731. }
  732. }
  733. ctArr.sort(function (item1, item2) {
  734. return parseInt(item1.level) - parseInt(item2.level);
  735. }); //保证顺序
  736. const _buildDeftNodes = function(startIdx, parentItem) {
  737. if (ctArr.length > startIdx) {
  738. let item = {};
  739. if (parentItem instanceof Array) {
  740. parentItem.push(item);
  741. } else {
  742. parentItem.items.push(item);
  743. }
  744. for (let idx = 0; idx < ctArr[startIdx].value.length; idx++) {
  745. item.name = ctArr[startIdx].value[idx].value;
  746. item.id = ctArr[startIdx].id; //这个相当于类型id,如68:年份 69:类型,105:姓名
  747. item.value_id = ctArr[startIdx].value[idx].id; //每个大类下又有小类,如:2018/2019, 土建/房建, 具体用户姓名...
  748. item.cid = ctArr[startIdx].value[idx].cid; //这个值 = item.id
  749. item.pid = ctArr[startIdx].value[idx].pid; //project id?
  750. item.tenderId = -1;
  751. item.selected = false;
  752. item.isParent = true;
  753. item.last_stage = -1;
  754. item.items = [];
  755. _buildDeftNodes(startIdx + 1, item);
  756. }
  757. }
  758. };
  759. // const _get
  760. //2. 创建基本结构
  761. _buildDeftNodes(0, rstItems);
  762. //3. 挂上标段
  763. const _putupTheTender = function (tender) {
  764. const _findType = function (parentItem) {
  765. for (let cat of tender.category) {
  766. if (cat.cid === parentItem.cid && cat.value === parentItem.value_id) {
  767. if (parentItem.items.length === 0) {
  768. // 到底了,挂上
  769. let lastStage = -1;
  770. if (tender.lastStage) {
  771. lastStage = tender.lastStage.times;
  772. }
  773. let item = {
  774. name: tender.name,
  775. id : -1,
  776. value_id: cat.value,
  777. cid : cat.cid,
  778. pid : -1,
  779. tenderId: tender.id,
  780. selected : false,
  781. isParent: true,
  782. last_stage: lastStage,
  783. items : [],
  784. }
  785. parentItem.items.push(item);
  786. } else {
  787. for (let nodeItem of parentItem.items) {
  788. _findType(tender, nodeItem);
  789. }
  790. }
  791. break;
  792. }
  793. }
  794. };
  795. for (let nodeItem of rstItems) {
  796. _findType(nodeItem);
  797. }
  798. };
  799. for (let tender of tenders) {
  800. _putupTheTender(tender);
  801. }
  802. }
  803. };
  804. const initTenderTreeForCross = function (tenders, category) {
  805. //用户跨标段设置电子签名用
  806. let rstItems = [];
  807. _createTenderTreeForCross(tenders, category, rstItems);
  808. _buildTenderRow('batch_projects_individual', rstItems);
  809. };
  810. const _buildTenderRow = function(tbDomId, topTreeNodes) {
  811. let tbDom = $("#" + tbDomId);
  812. tbDom.empty();
  813. tbDom.append('<tr><th>名称</th><th>计量期</th><th>签名</th><th>选择</th></tr>');
  814. let _pushRptLine = function (nodeItem, level) {
  815. if (nodeItem.isParent) {
  816. tbDom.append('<tr><td class="in-'+ (level + 1) + '"><i class="fa fa-folder-o"></i>&nbsp;' + nodeItem.name + '</td><td></td><td></td><td></td></tr>')
  817. //<td class="in-1"><i class="fa fa-folder-o"></i>&nbsp;2019</td>
  818. } else {
  819. //
  820. }
  821. };
  822. for (const topItem of topTreeNodes) {
  823. _pushRptLine(topItem, 0);
  824. }
  825. };
  826. const initTenderTree = function (tenders, category) {
  827. const gsSpread = SpreadJsObj.createNewSpread($('#gather-source-spread')[0]);
  828. gsObj.gsSheet = gsSpread.getActiveSheet();
  829. const spreadSetting = {
  830. cols: [
  831. {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox', readOnly: true},
  832. {title: '名称', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true, cellType: 'tree'},
  833. {title: '期数', field: 'phase', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  834. {title: '审批状态', field: 'status', hAlign: 1, width: 60, formatter: '@', readOnly: true}
  835. ],
  836. emptyRows: 0,
  837. headRows: 1,
  838. headRowHeight: [32],
  839. defaultRowHeight: 21,
  840. headerFont: '12px 微软雅黑',
  841. font: '12px 微软雅黑',
  842. headColWidth: [0],
  843. selectedBackColor: '#fffacd',
  844. };
  845. SpreadJsObj.initSheet(gsObj.gsSheet, spreadSetting);
  846. gsObj.tenderSourceTree = Tender2Tree.convert(category, tenders, ledgerAuditConst, auditConst);
  847. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  848. gsSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.gsButtonClicked);
  849. const grSpread = SpreadJsObj.createNewSpread($('#gather-result-spread')[0]);
  850. gsObj.grSheet = grSpread.getActiveSheet();
  851. grSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.grButtonClicked);
  852. $('#gather-hint').hide();
  853. $('#gather-select').bind('shown.bs.modal', function () {
  854. if (gsSpread) gsSpread.refresh();
  855. if (grSpread) grSpread.refresh();
  856. });
  857. $('.datepicker-here').datepicker({
  858. autoClose: true,
  859. });
  860. };
  861. const comfirmSelectPromise = function (rptName, gather_select) {
  862. const promise = new Promise(function (resolve, reject) {
  863. init(gather_select.custom_define, customSelects.stageFlow, gather_select, rptName, resolve, reject);
  864. });
  865. return promise;
  866. };
  867. const getCustomSelect = async function (params) {
  868. if (!params.rpt_ids || params.rpt_ids.length === 0) return;
  869. const currentRptId = zTreeOprObj.currentNode ? zTreeOprObj.currentNode.refId : -1;
  870. params.customSelect = [];
  871. const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  872. for (const rptId of params.rpt_ids) {
  873. const gather_select = customSelects.gather_select.find(function (x) {
  874. return x.id === rptId;
  875. });
  876. const stage_select = customSelects.stage_select.find(function (x) {
  877. return x.id === rptId;
  878. });
  879. const change_select = customSelects.change_select.find(function (x) {
  880. return x.id === rptId;
  881. });
  882. const material_sum_select = customSelects.material_sum_select.find(function (x) {
  883. return x.id === rptId;
  884. });
  885. if (gather_select && gather_select.custom_define && gather_select.custom_define[sGatherSelect].enable) {
  886. if (rptId === currentRptId) {
  887. const data = {};
  888. data[sGatherSelect] = gather_select[sGatherSelect];
  889. params.customSelect.push(data);
  890. } else {
  891. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  892. const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', gather_select);
  893. params.customSelect.push(select);
  894. $('#gather-select').modal('hide');
  895. }
  896. } else if (stage_select && stage_select.custom_define && stage_select.custom_define[sStageSelect].enable) {
  897. if (rptId === currentRptId) {
  898. const data = {};
  899. data[sStageSelect] = stage_select[sStageSelect];
  900. params.customSelect.push(data);
  901. } else {
  902. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  903. const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', stage_select);
  904. params.customSelect.push(select);
  905. $('#stage-select').modal('hide');
  906. }
  907. } else if (change_select && change_select.custom_define && change_select.custom_define[sChangeSelect].enable ) {
  908. if (rptId === currentRptId && changeObj.latestPush) {
  909. const data = {};
  910. data[sChangeSelect] = changeObj.latestSelect;
  911. params.customSelect.push(data);
  912. } else {
  913. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  914. const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', change_select);
  915. params.customSelect.push(select);
  916. $('#change-select').modal('hide');
  917. }
  918. } else if (material_sum_select && material_sum_select.custom_define && material_sum_select.custom_define[sMaterialSumSelect].enable) {
  919. if (rptId === currentRptId) {
  920. const data = {};
  921. data[sMaterialSumSelect] = material_sum_select[sMaterialSumSelect];
  922. params.customSelect.push(data);
  923. } else {
  924. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  925. const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', material_sum_select);
  926. params.customSelect.push(select);
  927. $('#material-sum-select').modal('hide');
  928. }
  929. } else {
  930. params.customSelect.push(null);
  931. }
  932. }
  933. };
  934. const showMaterialSelect = function () {
  935. const needShow = function () {
  936. if (zTreeOprObj.currentNode) {
  937. const ms = dataSelects.material_select.find(function (x) { return x.id === zTreeOprObj.currentNode.refId});
  938. if (ms) return true;
  939. }
  940. const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  941. for (const node of chkNodes) {
  942. const ms = dataSelects.material_select.find(function (x) { return x.id === node.refId});
  943. if (ms) return true;
  944. }
  945. return false;
  946. };
  947. if (needShow()) {
  948. $('#material').show();
  949. } else {
  950. $('#material').hide();
  951. }
  952. };
  953. const postReportData = function (url, params, successCallback, errorCallBack, showWaiting = true) {
  954. if (showWaiting) showWaitingView();
  955. $.ajax({
  956. type:"POST",
  957. url: url,
  958. data: {'params': JSON.stringify(params)},
  959. dataType: 'json',
  960. cache: false,
  961. timeout: 300000,
  962. beforeSend: function(xhr) {
  963. let csrfToken = Cookies.get('csrfToken_j');
  964. xhr.setRequestHeader('x-csrf-token', csrfToken);
  965. },
  966. success: function(result){
  967. successCallback(result);
  968. if (showWaiting) closeWaitingView();
  969. },
  970. error: function(jqXHR, textStatus, errorThrown){
  971. toastr.error('error: ' + textStatus + " " + errorThrown);
  972. if (errorCallBack) {
  973. errorCallBack();
  974. }
  975. if (showWaiting) closeWaitingView();
  976. }
  977. });
  978. };
  979. const changeMaterial = function (obj) {
  980. $('#material-select').attr('m-order', $(obj).attr('m-order')).html(obj.innerText);
  981. const data = {};
  982. getCommonParams(data);
  983. postReportData('/tender/report_api/getReport', data, reloadReportData);
  984. };
  985. return {
  986. init,
  987. resetAuditSelect, resetGatherSelect, resetStageSelect, resetChangeSelect, resetMaterialSumSelect,
  988. initTenderTree,
  989. initTenderTreeForCross,
  990. getCustomSelect,
  991. showMaterialSelect, changeMaterial,
  992. };
  993. })();