rpt_custom.js 45 KB

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