rpt_custom.js 45 KB

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