rpt_custom.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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, ROLE_REL_LIST, 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. data.sp_id = spid;
  493. };
  494. const resetAuditSelect = function () {
  495. const selObj = $('select', '#audit-select-list');
  496. const data = { audit_select: [], closeWatermark: getCloseWatermark() };
  497. getCommonParams(data);
  498. for (const s of selObj) {
  499. const sf = stageFlow[s.selectedIndex];
  500. if (!sf) {
  501. $('#audit-select-hint').html('未选择' + s.attributes['sf-title'].value).show();
  502. return;
  503. }
  504. data.audit_select.push({...sf, sort: sf.audit_order});
  505. }
  506. $('#audit-select-hint').hide();
  507. postData('/report/cDefine', data, function (result) {
  508. reloadReportData(result);
  509. $('#audit-select').modal('hide');
  510. rptArchiveObj.toggleBtn(true);
  511. if (PAGE_SHOW.showArchive) {
  512. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  513. }
  514. });
  515. };
  516. const resetGatherSelect = function (resolve = null) {
  517. const data = {}, hintObj = $('#gather-hint');
  518. if (!resolve) getCommonParams(data);
  519. data[sGatherSelect] = {
  520. tenders: [],
  521. type: gsObj.setting.type,
  522. };
  523. const specCol = gsObj.setting.special ? gsObj.setting.special : [];
  524. for (const sc of specCol) {
  525. sc.sCount = 0;
  526. }
  527. for (const gra of gsObj.grArray) {
  528. const ra = {tid: gra.tid};
  529. for (const sc of specCol) {
  530. if (gra[sc.key]) {
  531. ra[sc.key] = true;
  532. sc.sCount += 1;
  533. }
  534. }
  535. data[sGatherSelect].tenders.push(ra);
  536. }
  537. for (const sc of specCol) {
  538. if (sc.sCount === 0) {
  539. hintObj.html('请选择 ' + sc.title).show();
  540. return;
  541. }
  542. }
  543. if (gsObj.setting.onlySpec) {
  544. if (data[sGatherSelect].tenders.length > specCol.length) {
  545. hintObj.html('请勿选择普通汇总项目').show();
  546. return;
  547. }
  548. } else {
  549. if (data[sGatherSelect].tenders.length <= specCol.length) {
  550. hintObj.html('请至少选择1个普通汇总项目').show();
  551. return;
  552. }
  553. }
  554. if (gsObj.setting.type === 'month' || gsObj.setting.type === 'months') {
  555. data[sGatherSelect].month = $('#gather-month').val();
  556. if (data[sGatherSelect].month === '') {
  557. hintObj.html('请选择 汇总年月').show();
  558. return;
  559. }
  560. } else if (gsObj.setting.type === 'zone') {
  561. data[sGatherSelect].zone = $('#gather-zone').val();
  562. if (data[sGatherSelect].zone === '') {
  563. hintObj.html('请选择 汇总周期').show();
  564. return;
  565. } else if(data[sGatherSelect].zone.indexOf(' - ') < 0) {
  566. hintObj.html('请选择 完整汇总周期').show();
  567. return;
  568. }
  569. } else if (gsObj.setting.type === 'stage') {
  570. data[sGatherSelect].stage = _.toInteger($('#gather-stage').val()) || 0;
  571. const validStage = _.min(_.map(gsObj.grArray, 'stageCount'));
  572. if (!data[sGatherSelect].stage) {
  573. hintObj.html('请选择 汇总期').show();
  574. return;
  575. }
  576. if (data[sGatherSelect].stage > validStage) {
  577. hintObj.html('选择的期无效,请重新选择').show();
  578. return;
  579. }
  580. } else if (gsObj.setting.type === 'stage-zone') {
  581. const stageBegin = _.toInteger($('#gather-stage-begin').val()) || 0;
  582. const stageEnd = _.toInteger($('#gather-stage-end').val()) || 0;
  583. const validStage = _.max(_.map(gsObj.grArray, 'stageCount'));
  584. if (!stageBegin || !stageEnd) {
  585. hintObj.html('请选择 汇总开始期与结束期').show();
  586. return;
  587. }
  588. if (stageEnd <= stageBegin) {
  589. hintObj.html('结束期应大于开始期').show();
  590. return;
  591. }
  592. if (stageEnd > validStage) {
  593. hintObj.html('选择的期无效,请重新选择').show();
  594. return;
  595. }
  596. data[sGatherSelect].stage_zone = stageBegin + ':' + stageEnd;
  597. } else if (gsObj.setting.type === 'custom-zone') {
  598. data[sGatherSelect].custom_zone = $('#gather-custom-zone').val();
  599. if (data[sGatherSelect].custom_zone === '') {
  600. hintObj.html('请选择 汇总周期').show();
  601. return;
  602. } else if(data[sGatherSelect].custom_zone.indexOf(' - ') < 0) {
  603. hintObj.html('请选择 完整汇总周期').show();
  604. return;
  605. }
  606. }
  607. if (data[sGatherSelect].tenders.length > (gsObj.setting.toplimit || 20)) {
  608. hintObj.html('您选择的标段过多,请移除部分').show();
  609. return;
  610. }
  611. hintObj.hide();
  612. if (resolve) {
  613. resolve(data);
  614. rptArchiveObj.toggleBtn(false);
  615. } else {
  616. postData('/report/cDefine', data, function (result) {
  617. reloadReportData(result);
  618. const gather_select = customSelects.gather_select.find(function (x) {
  619. return x.id === zTreeOprObj.currentNode.refId;
  620. });
  621. if (gather_select) {
  622. gather_select.gather_select = data[sGatherSelect];
  623. }
  624. $('#gather-select-count').html(data[sGatherSelect].tenders.length);
  625. $('#gather-select').modal('hide');
  626. rptArchiveObj.toggleBtn(true);
  627. if (PAGE_SHOW.showArchive) {
  628. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  629. }
  630. });
  631. }
  632. };
  633. const resetStageSelect = function (resolve = null) {
  634. const data = {}, hintObj = $('#stage-select-hint');
  635. if (!resolve) getCommonParams(data);
  636. data[sStageSelect] = {
  637. stages: [],
  638. };
  639. for (const sc of $('[name=stage-select-check]:checked')) {
  640. data[sStageSelect].stages.push(parseInt($(sc).attr('stage-order')));
  641. }
  642. if (data[sStageSelect].stages.length < parseInt(hintObj.attr('min-select'))) {
  643. hintObj.html('请至少选择' + hintObj.attr('min-select') + '期数据').show();
  644. return;
  645. } else if (data[sStageSelect].stages.length > parseInt(hintObj.attr('max-select'))) {
  646. hintObj.html('最多只能选择' + hintObj.attr('max-select') + '期数据').show();
  647. return;
  648. }
  649. hintObj.hide();
  650. if (resolve) {
  651. resolve(data);
  652. } else {
  653. postData('/report/cDefine', data, function (result) {
  654. reloadReportData(result);
  655. const stage_select = customSelects.stage_select.find(function (x) {
  656. return x.id === zTreeOprObj.currentNode.refId;
  657. });
  658. if (stage_select) {
  659. stage_select.stage_select = data[sStageSelect];
  660. }
  661. $('#stage-select-count').html(data[sStageSelect].stages.length);
  662. $('#stage-select').modal('hide');
  663. rptArchiveObj.toggleBtn(true);
  664. if (PAGE_SHOW.showArchive) {
  665. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  666. }
  667. });
  668. }
  669. };
  670. const resetMaterialSumSelect = function (resolve = null) {
  671. const data = {}, hintObj = $('#material-sum-select-hint');
  672. if (!resolve) getCommonParams(data);
  673. data[sMaterialSumSelect] = {
  674. materials: [],
  675. };
  676. for (const mc of $('[name=material-sum-select-check]:checked')) {
  677. data[sMaterialSumSelect].materials.push(parseInt($(mc).attr('material-order')));
  678. }
  679. if (data[sMaterialSumSelect].materials.length < parseInt(hintObj.attr('min-select'))) {
  680. hintObj.html('请至少选择' + hintObj.attr('min-select') + '期数据').show();
  681. return;
  682. } else if (data[sMaterialSumSelect].materials.length > parseInt(hintObj.attr('max-select'))) {
  683. hintObj.html('最多只能选择' + hintObj.attr('max-select') + '期数据').show();
  684. return;
  685. }
  686. hintObj.hide();
  687. if (resolve) {
  688. resolve(data);
  689. } else {
  690. postData('/report/cDefine', data, function (result) {
  691. reloadReportData(result);
  692. const material_sum_select = customSelects[sMaterialSumSelect].find(function (x) {
  693. return x.id === zTreeOprObj.currentNode.refId;
  694. });
  695. if (material_sum_select) {
  696. material_sum_select.material_sum_select = data[sMaterialSumSelect];
  697. }
  698. $('#material-sum-select-count').html(data[sMaterialSumSelect].materials.length);
  699. $('#material-sum-select').modal('hide');
  700. rptArchiveObj.toggleBtn(true);
  701. if (PAGE_SHOW.showArchive) {
  702. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  703. }
  704. });
  705. }
  706. };
  707. const resetChangeSelect = function (resolve = null) {
  708. const data = {}, hintObj = $('#change-select-hint');
  709. if (!resolve) getCommonParams(data);
  710. data[sChangeSelect] = [];
  711. for (const sc of $('[name=change-select-check]:checked')) {
  712. data[sChangeSelect].push(sc.value);
  713. }
  714. if (data[sChangeSelect].length === 0) {
  715. hintObj.html('请至少选择一条变更令').show();
  716. return;
  717. } else {
  718. hintObj.hide();
  719. }
  720. if (resolve) {
  721. resolve(data);
  722. } else {
  723. postData('/report/cDefine', data, function (result) {
  724. changeObj.latestSelect = data[sChangeSelect];
  725. reloadReportData(result);
  726. $('#change-select').modal('hide');
  727. rptArchiveObj.toggleBtn(true);
  728. if (PAGE_SHOW.showArchive) {
  729. rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
  730. }
  731. });
  732. }
  733. };
  734. const _createTenderTreeForCross = function (tenders, category, rstItems) {
  735. if (rstItems instanceof Array && rstItems.length === 0) {
  736. //1. 先确定category方式(‘年份’、‘姓名’、‘类型’)及顺序
  737. let ctArr = [];
  738. for (let cat of category) {
  739. if (cat.level) {
  740. ctArr.push(cat);
  741. }
  742. }
  743. ctArr.sort(function (item1, item2) {
  744. return parseInt(item1.level) - parseInt(item2.level);
  745. }); //保证顺序
  746. const _buildDeftNodes = function(startIdx, parentItem) {
  747. if (ctArr.length > startIdx) {
  748. let item = {};
  749. if (parentItem instanceof Array) {
  750. parentItem.push(item);
  751. } else {
  752. parentItem.items.push(item);
  753. }
  754. for (let idx = 0; idx < ctArr[startIdx].value.length; idx++) {
  755. item.name = ctArr[startIdx].value[idx].value;
  756. item.id = ctArr[startIdx].id; //这个相当于类型id,如68:年份 69:类型,105:姓名
  757. item.value_id = ctArr[startIdx].value[idx].id; //每个大类下又有小类,如:2018/2019, 土建/房建, 具体用户姓名...
  758. item.cid = ctArr[startIdx].value[idx].cid; //这个值 = item.id
  759. item.pid = ctArr[startIdx].value[idx].pid; //project id?
  760. item.tenderId = -1;
  761. item.selected = false;
  762. item.isParent = true;
  763. item.last_stage = -1;
  764. item.items = [];
  765. _buildDeftNodes(startIdx + 1, item);
  766. }
  767. }
  768. };
  769. // const _get
  770. //2. 创建基本结构
  771. _buildDeftNodes(0, rstItems);
  772. //3. 挂上标段
  773. const _putupTheTender = function (tender) {
  774. const _findType = function (parentItem) {
  775. for (let cat of tender.category) {
  776. if (cat.cid === parentItem.cid && cat.value === parentItem.value_id) {
  777. if (parentItem.items.length === 0) {
  778. // 到底了,挂上
  779. let lastStage = -1;
  780. if (tender.lastStage) {
  781. lastStage = tender.lastStage.times;
  782. }
  783. let item = {
  784. name: tender.name,
  785. id : -1,
  786. value_id: cat.value,
  787. cid : cat.cid,
  788. pid : -1,
  789. tenderId: tender.id,
  790. selected : false,
  791. isParent: true,
  792. last_stage: lastStage,
  793. items : [],
  794. }
  795. parentItem.items.push(item);
  796. } else {
  797. for (let nodeItem of parentItem.items) {
  798. _findType(tender, nodeItem);
  799. }
  800. }
  801. break;
  802. }
  803. }
  804. };
  805. for (let nodeItem of rstItems) {
  806. _findType(nodeItem);
  807. }
  808. };
  809. for (let tender of tenders) {
  810. _putupTheTender(tender);
  811. }
  812. }
  813. };
  814. const initTenderTreeForCross = function (tenders, category) {
  815. //用户跨标段设置电子签名用
  816. let rstItems = [];
  817. _createTenderTreeForCross(tenders, category, rstItems);
  818. _buildTenderRow('batch_projects_individual', rstItems);
  819. };
  820. const _buildTenderRow = function(tbDomId, topTreeNodes) {
  821. let tbDom = $("#" + tbDomId);
  822. tbDom.empty();
  823. tbDom.append('<tr><th>名称</th><th>计量期</th><th>签名</th><th>选择</th></tr>');
  824. let _pushRptLine = function (nodeItem, level) {
  825. if (nodeItem.isParent) {
  826. 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>')
  827. //<td class="in-1"><i class="fa fa-folder-o"></i>&nbsp;2019</td>
  828. } else {
  829. //
  830. }
  831. };
  832. for (const topItem of topTreeNodes) {
  833. _pushRptLine(topItem, 0);
  834. }
  835. };
  836. const initTenderTree = function (tenders, category) {
  837. const gsSpread = SpreadJsObj.createNewSpread($('#gather-source-spread')[0]);
  838. gsObj.gsSheet = gsSpread.getActiveSheet();
  839. const spreadSetting = {
  840. cols: [
  841. {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox', readOnly: true},
  842. {title: '名称', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true, cellType: 'tree'},
  843. {title: '期数', field: 'phase', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  844. {title: '审批状态', field: 'status', hAlign: 1, width: 60, formatter: '@', readOnly: true}
  845. ],
  846. emptyRows: 0,
  847. headRows: 1,
  848. headRowHeight: [32],
  849. defaultRowHeight: 21,
  850. headerFont: '12px 微软雅黑',
  851. font: '12px 微软雅黑',
  852. headColWidth: [0],
  853. selectedBackColor: '#fffacd',
  854. };
  855. SpreadJsObj.initSheet(gsObj.gsSheet, spreadSetting);
  856. gsObj.tenderSourceTree = Tender2Tree.convert(category, tenders, ledgerAuditConst, auditConst);
  857. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  858. gsSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.gsButtonClicked);
  859. const grSpread = SpreadJsObj.createNewSpread($('#gather-result-spread')[0]);
  860. gsObj.grSheet = grSpread.getActiveSheet();
  861. grSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.grButtonClicked);
  862. $('#gather-hint').hide();
  863. $('#gather-select').bind('shown.bs.modal', function () {
  864. if (gsSpread) gsSpread.refresh();
  865. if (grSpread) grSpread.refresh();
  866. });
  867. $('.datepicker-here').datepicker({
  868. autoClose: true,
  869. });
  870. };
  871. const comfirmSelectPromise = function (rptName, gather_select) {
  872. const promise = new Promise(function (resolve, reject) {
  873. init(gather_select.custom_define, customSelects.stageFlow, gather_select, rptName, resolve, reject);
  874. });
  875. return promise;
  876. };
  877. const getCustomSelect = async function (params) {
  878. if (!params.rpt_ids || params.rpt_ids.length === 0) return;
  879. const currentRptId = zTreeOprObj.currentNode ? zTreeOprObj.currentNode.refId : -1;
  880. params.customSelect = [];
  881. const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  882. for (const rptId of params.rpt_ids) {
  883. const gather_select = customSelects.gather_select.find(function (x) {
  884. return x.id === rptId;
  885. });
  886. const stage_select = customSelects.stage_select.find(function (x) {
  887. return x.id === rptId;
  888. });
  889. const change_select = customSelects.change_select.find(function (x) {
  890. return x.id === rptId;
  891. });
  892. const material_sum_select = customSelects.material_sum_select.find(function (x) {
  893. return x.id === rptId;
  894. });
  895. if (gather_select && gather_select.custom_define && gather_select.custom_define[sGatherSelect].enable) {
  896. if (rptId === currentRptId) {
  897. const data = {};
  898. data[sGatherSelect] = gather_select[sGatherSelect];
  899. params.customSelect.push(data);
  900. } else {
  901. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  902. const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', gather_select);
  903. params.customSelect.push(select);
  904. $('#gather-select').modal('hide');
  905. }
  906. } else if (stage_select && stage_select.custom_define && stage_select.custom_define[sStageSelect].enable) {
  907. if (rptId === currentRptId) {
  908. const data = {};
  909. data[sStageSelect] = stage_select[sStageSelect];
  910. params.customSelect.push(data);
  911. } else {
  912. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  913. const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', stage_select);
  914. params.customSelect.push(select);
  915. $('#stage-select').modal('hide');
  916. }
  917. } else if (change_select && change_select.custom_define && change_select.custom_define[sChangeSelect].enable ) {
  918. if (rptId === currentRptId && changeObj.latestPush) {
  919. const data = {};
  920. data[sChangeSelect] = changeObj.latestSelect;
  921. params.customSelect.push(data);
  922. } else {
  923. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  924. const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', change_select);
  925. params.customSelect.push(select);
  926. $('#change-select').modal('hide');
  927. }
  928. } else if (material_sum_select && material_sum_select.custom_define && material_sum_select.custom_define[sMaterialSumSelect].enable) {
  929. if (rptId === currentRptId) {
  930. const data = {};
  931. data[sMaterialSumSelect] = material_sum_select[sMaterialSumSelect];
  932. params.customSelect.push(data);
  933. } else {
  934. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  935. const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', material_sum_select);
  936. params.customSelect.push(select);
  937. $('#material-sum-select').modal('hide');
  938. }
  939. } else {
  940. params.customSelect.push(null);
  941. }
  942. }
  943. };
  944. const showMaterialSelect = function () {
  945. const needShow = function () {
  946. if (zTreeOprObj.currentNode) {
  947. const ms = dataSelects.material_select.find(function (x) { return x.id === zTreeOprObj.currentNode.refId});
  948. if (ms) return true;
  949. }
  950. const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  951. for (const node of chkNodes) {
  952. const ms = dataSelects.material_select.find(function (x) { return x.id === node.refId});
  953. if (ms) return true;
  954. }
  955. return false;
  956. };
  957. if (needShow()) {
  958. $('#material').show();
  959. } else {
  960. $('#material').hide();
  961. }
  962. };
  963. const postReportData = function (url, params, successCallback, errorCallBack, showWaiting = true) {
  964. if (showWaiting) showWaitingView();
  965. $.ajax({
  966. type:"POST",
  967. url: url,
  968. data: {'params': JSON.stringify(params)},
  969. dataType: 'json',
  970. cache: false,
  971. timeout: 300000,
  972. beforeSend: function(xhr) {
  973. let csrfToken = Cookies.get('csrfToken_j');
  974. xhr.setRequestHeader('x-csrf-token', csrfToken);
  975. },
  976. success: function(result){
  977. successCallback(result);
  978. if (showWaiting) closeWaitingView();
  979. },
  980. error: function(jqXHR, textStatus, errorThrown){
  981. toastr.error('error: ' + textStatus + " " + errorThrown);
  982. if (errorCallBack) {
  983. errorCallBack();
  984. }
  985. if (showWaiting) closeWaitingView();
  986. }
  987. });
  988. };
  989. const changeMaterial = function (obj) {
  990. $('#material-select').attr('m-order', $(obj).attr('m-order')).html(obj.innerText);
  991. const data = {};
  992. getCommonParams(data);
  993. postReportData('/tender/report_api/getReport', data, reloadReportData);
  994. };
  995. return {
  996. init,
  997. resetAuditSelect, resetGatherSelect, resetStageSelect, resetChangeSelect, resetMaterialSumSelect,
  998. initTenderTree,
  999. initTenderTreeForCross,
  1000. getCustomSelect,
  1001. showMaterialSelect, changeMaterial,
  1002. };
  1003. })();