rpt_custom.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. const grSpreadSetting = {
  24. baseCols: [
  25. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true},
  26. ],
  27. extraCols: [
  28. {title: '%s', colSpan: '1', rowSpan: '1', field: '%s', hAlign: 1, vAlign: '1', width: 60, cellType: 'checkbox', readOnly: true},
  29. ],
  30. emptyRows: 0,
  31. headRows: 1,
  32. headRowHeight: [32],
  33. defaultRowHeight: 21,
  34. headerFont: '12px 微软雅黑',
  35. font: '12px 微软雅黑',
  36. headColWidth: []
  37. };
  38. const gatherSelectSpreadObj = {
  39. _addTender: function (tender) {
  40. const gr = gsObj.grArray.find(function (x) {
  41. return x.tid === tender.tid;
  42. });
  43. const t = {tid: tender.tid, name: tender.name}
  44. if (!gr) gsObj.grArray.push(t);
  45. return t;
  46. },
  47. _removeTender: function (tender) {
  48. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  49. return x.tid === tender.tid;
  50. });
  51. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  52. },
  53. reloadResultData: function () {
  54. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  55. },
  56. gsButtonClicked: function (e, info) {
  57. if (!info.sheet.zh_setting) return;
  58. const col = info.sheet.zh_setting.cols[info.col];
  59. if (col.field !== 'selected') return;
  60. const node = SpreadJsObj.getSelectObject(info.sheet);
  61. node.selected = !node.selected;
  62. if (node.children && node.children.length > 0) {
  63. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  64. for (const p of posterity) {
  65. p.selected = node.selected;
  66. if (!p.children || p.children.length === 0){
  67. if (p.selected) {
  68. gatherSelectSpreadObj._addTender(p);
  69. } else {
  70. gatherSelectSpreadObj._removeTender(p);
  71. }
  72. }
  73. }
  74. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  75. } else {
  76. if (node.selected) {
  77. gatherSelectSpreadObj._addTender(node);
  78. } else {
  79. gatherSelectSpreadObj._removeTender(node);
  80. }
  81. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  82. }
  83. gatherSelectSpreadObj.reloadResultData();
  84. },
  85. grButtonClicked: function (e, info) {
  86. if (!info.sheet.zh_setting) return;
  87. const col = info.sheet.zh_setting.cols[info.col];
  88. if (col.field === 'name') return;
  89. const node = SpreadJsObj.getSelectObject(info.sheet);
  90. const refreshRows = [info.row];
  91. node[col.field] = !node[col.field];
  92. for (const rCol of info.sheet.zh_setting.cols) {
  93. if (rCol.field !== 'name' && rCol.field !== col.field) {
  94. node[rCol.field] = false;
  95. }
  96. }
  97. if (node[col.field]) {
  98. for (const [i, gra] of gsObj.grArray.entries()) {
  99. if (gra[col.field] && gra.tid !== node.tid) {
  100. gra[col.field] = false;
  101. refreshRows.push(i);
  102. }
  103. }
  104. }
  105. SpreadJsObj.reLoadRowsData(info.sheet, refreshRows);
  106. },
  107. initSelectTenders: function (tenders) {
  108. if (!tenders) return;
  109. const specCol = gsObj.setting.special ? gsObj.setting.special : [];
  110. const select = [];
  111. for (const node of gsObj.tenderSourceTree.nodes) {
  112. node.selected = false;
  113. }
  114. for (const t of tenders) {
  115. const tender = gsObj.tenderSourceTree.nodes.find(function (x) { return x.tid === t.tid});
  116. tender.selected = true;
  117. select.push(tender);
  118. const st = this._addTender(tender);
  119. for (const sc of specCol) {
  120. st[sc.key] = t[sc.key];
  121. }
  122. }
  123. SpreadJsObj.reLoadColsData(gsObj.gsSheet, [0]);
  124. if (select.length > 0) SpreadJsObj.locateTreeNode(gsObj.gsSheet, select[0].tmt_id);
  125. this.reloadResultData();
  126. },
  127. };
  128. const getStageFlowSelectHtml = function (select, id) {
  129. const html = [];
  130. html.push('<select style="width: 80%" id="' + id + '" sf-title="' + select.title + '">');
  131. for (const sf of stageFlow) {
  132. html.push('<option>' + sf.name + '-' + sf.role +'</option>');
  133. }
  134. html.push('</select>');
  135. return html.join('');
  136. };
  137. const checkAsSelectValid = function (validFlow, asSelect) {
  138. for (const s of asSelect) {
  139. const f = validFlow.find(function (x) {
  140. return x.aid === s.aid && x.order === s.order;
  141. });
  142. if (!f) {
  143. $('#audit-select-hint').html('本期审批流程发生变动,原审批人选择不适配,需重新选择').show();
  144. return false;
  145. }
  146. }
  147. $('#audit-select-hint').hide();
  148. return true;
  149. };
  150. const initAuditSelect = function (asSetting, asSelect) {
  151. const setting = JSON.parse(asSetting), select = asSelect;
  152. $('#audit-select-title').html(setting.title);
  153. const html = [];
  154. for (const [i, s] of setting.select.entries()) {
  155. html.push('<tr>');
  156. html.push('<td>', s.title, '</td>');
  157. html.push('<td>', getStageFlowSelectHtml(s, 'sf-' + i), '</td>');
  158. html.push('</tr>');
  159. }
  160. $('#audit-select-list').html(html.join(''));
  161. for (const [i, s] of setting.select.entries()) {
  162. const obj = $('#sf-' + i);
  163. const s = select[i];
  164. const sf = s ? stageFlow.find(function (x) {
  165. return x.order === s.order && x.aid === s.aid;
  166. }) : null;
  167. obj[0].selectedIndex = sf ? sf.order : -1;
  168. }
  169. if (asSelect.length === 0 || !checkAsSelectValid(stageFlow, asSelect)) {
  170. $('#audit-select').modal('show');
  171. }
  172. };
  173. const initGrSpreadSetting = function (gsSetting) {
  174. grSpreadSetting.cols = [];
  175. for (const bc of grSpreadSetting.baseCols) {
  176. grSpreadSetting.cols.push(bc);
  177. if (bc.field === 'name') bc.width = gsSetting.nameColWidth ? gsSetting.nameColWidth : 180;
  178. }
  179. if (gsSetting.special) {
  180. for (const s of gsSetting.special) {
  181. for (const ec of grSpreadSetting.extraCols) {
  182. const c = {};
  183. c.title = ec.title.replace('%s', s.title);
  184. c.colSpan = ec.colSpan;
  185. c.field = ec.field.replace('%s', s.key);
  186. c.hAlign = ec.hAlign;
  187. c.width = s.width ? s.width : ec.width;
  188. c.cellType = ec.cellType;
  189. c.readOnly = ec.readOnly;
  190. grSpreadSetting.cols.push(c);
  191. }
  192. }
  193. }
  194. };
  195. const initGatherSelect = function (gsSetting, gsSelect, rptName, resolve = null) {
  196. gsObj.grArray = [];
  197. gsObj.setting = JSON.parse(gsSetting);
  198. gsObj.orgSelect = gsSelect;
  199. $('#gather-select-count').html(gsSelect ? gsSelect.tenders.length : 0);
  200. $('#gather-select-title').html(gsObj.setting.title + (rptName ? '-' + rptName : ''));
  201. initGrSpreadSetting(gsObj.setting);
  202. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  203. if (gsObj.setting.type === 'month') {
  204. $('#gather-by-month').show();
  205. $('#gather-by-zone').hide();
  206. } else if (gsObj.setting.type === 'zone') {
  207. $('#gather-by-month').hide();
  208. $('#gather-by-zone').show();
  209. } else {
  210. $('#gather-by-month').hide();
  211. $('#gather-by-zone').hide();
  212. }
  213. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  214. // 初始化选择结果
  215. if (gsSelect) {
  216. if (gsSelect.zone) {
  217. $('#gather-zone').val(gsSelect.zone ? gsSelect.zone : '');
  218. } else if (gsSelect.month) {
  219. $('#gather-month').val(gsSelect.month ? gsSelect.month: '');
  220. }
  221. }
  222. gatherSelectSpreadObj.initSelectTenders(gsSelect ? gsSelect.tenders : []);
  223. // 初始化
  224. $("#gather-select").modal('show');
  225. $('#gather-select-ok').unbind('click');
  226. $('#gather-select-ok').bind('click', () => {rptCustomObj.resetGatherSelect(resolve);});
  227. };
  228. const init = function (cDefine, sfData, cSelect, rptName, resolve = null) {
  229. stageFlow = sfData;
  230. if (cDefine && cDefine[sAuditSelect] && cDefine[sAuditSelect].enable && cDefine[sAuditSelect].setting) {
  231. $('#pnl_audit_select').show();
  232. initAuditSelect(cDefine[sAuditSelect].setting, cSelect ? cSelect[sAuditSelect] : []);
  233. } else {
  234. $('#pnl_audit_select').hide();
  235. }
  236. if (cDefine && cDefine[sGatherSelect] && cDefine[sGatherSelect].enable && cDefine[sGatherSelect].setting) {
  237. $('#pnl_gather_select').show();
  238. initGatherSelect(cDefine[sGatherSelect].setting, cSelect ? cSelect[sGatherSelect] : null, rptName, resolve);
  239. } else {
  240. $('#pnl_gather_select').hide();
  241. }
  242. };
  243. const reloadReportData = function (result) {
  244. // hintBox.unWaitBox();
  245. let pageRst = result.data;
  246. if (result.signatureRelInfo && result.signatureRelInfo.length > 0) {
  247. CURRENT_ROLE_REL_ID = result.signatureRelInfo[0].id;
  248. ROLE_REL_LIST = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  249. STAGE_AUDIT = result.stageAudit;
  250. rptSignatureHelper.originalRoleRelList = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  251. if (current_stage_status === 3) {
  252. rptSignatureHelper.mergeSignDate(pageRst, ROLE_REL_LIST, true);
  253. rptSignatureHelper.mergeSignature(pageRst, ROLE_REL_LIST);
  254. rptSignatureHelper.mergeSignAudit(pageRst, ROLE_REL_LIST, STAGE_AUDIT);
  255. }
  256. } else {
  257. CURRENT_ROLE_REL_ID = -1;
  258. ROLE_REL_LIST = [];
  259. }
  260. // if (ROLE_REL_LIST)
  261. let canvas = zTreeOprObj.canvas;
  262. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  263. zTreeOprObj.resetAfter(pageRst);
  264. zTreeOprObj.currentRptPageRst = pageRst;
  265. zTreeOprObj.maxPages = pageRst.items.length;
  266. zTreeOprObj.currentPage = 1;
  267. zTreeOprObj.displayPageValue();
  268. let size = JpcCanvasOutput.getReportSizeInPixel(zTreeOprObj.currentRptPageRst, getScreenDPI());
  269. canvas.width = size[0] + 20;
  270. if (size[1] > size[0]) {
  271. canvas.height = size[1] + 100;
  272. } else {
  273. canvas.height = size[1] + 50;
  274. }
  275. // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst);
  276. rptSignatureHelper.buildSelectableAccount();
  277. rptSignatureHelper.buildSelectableAccountUsed();
  278. rptSignatureHelper.buildRoleDom(ROLE_LIST);
  279. zTreeOprObj.showPage(1, canvas);
  280. } else {
  281. //返回了无数据表
  282. JpcCanvasOutput.cleanCanvas(canvas);
  283. JpcCanvasOutput.drawPageBorder(zTreeOprObj.currentRptPageRst, canvas, getScreenDPI());
  284. }
  285. rptCustomObj.init(result.customDefine, result.stageFlow, result.customSelect);
  286. try {
  287. if (is_debug && result.debugInfo) {
  288. console.log('含有key的debug信息:');
  289. for (const k in result.debugInfo.key) {
  290. console.log(k + ':', ...result.debugInfo.key[k]);
  291. }
  292. //console.log(result.debugInfo.key);
  293. console.log('其他debug信息:');
  294. for (const di of result.debugInfo.other) {
  295. console.log(...di);
  296. }
  297. }
  298. } catch(err) {
  299. }
  300. zTreeOprObj.countChkedRptTpl();
  301. };
  302. const getCommonParams = function (data) {
  303. data.pageSize = rptControlObj.getCurrentPageSize();
  304. data.rpt_tpl_id = zTreeOprObj.currentNode.refId;
  305. data.custCfg = CUST_CFG;
  306. data.project_id = PROJECT_ID;
  307. data.tender_id = TENDER_ID;
  308. data.stage_id = getStageId();
  309. data.stage_status = getStageStatus();
  310. data.stage_order = getStageOrder();
  311. data.stage_times = getStageTimes();
  312. data.material_order = getMaterialOrder();
  313. };
  314. const resetAuditSelect = function () {
  315. const selObj = $('select', '#audit-select-list');
  316. const data = { audit_select: [] };
  317. getCommonParams(data);
  318. for (const s of selObj) {
  319. const sf = stageFlow[s.selectedIndex];
  320. if (!sf) {
  321. $('#audit-select-hint').html('未选择' + s.attributes['sf-title'].value).show();
  322. return;
  323. }
  324. data.audit_select.push(sf);
  325. }
  326. $('#audit-select-hint').hide();
  327. postData('/report/cDefine', data, function (result) {
  328. reloadReportData(result);
  329. $('#audit-select').modal('hide');
  330. });
  331. };
  332. const resetGatherSelect = function (resolve = null) {
  333. const data = {}, hintObj = $('#gather-hint');
  334. if (!resolve) getCommonParams(data);
  335. data[sGatherSelect] = {
  336. tenders: [],
  337. type: gsObj.setting.type,
  338. };
  339. const specCol = gsObj.setting.special ? gsObj.setting.special : [];
  340. for (const sc of specCol) {
  341. sc.sCount = 0;
  342. }
  343. for (const gra of gsObj.grArray) {
  344. const ra = {tid: gra.tid};
  345. for (const sc of specCol) {
  346. if (gra[sc.key]) {
  347. ra[sc.key] = true;
  348. sc.sCount += 1;
  349. }
  350. }
  351. data[sGatherSelect].tenders.push(ra);
  352. }
  353. for (const sc of specCol) {
  354. if (sc.sCount === 0) {
  355. hintObj.html('请选择 ' + sc.title).show();
  356. return;
  357. }
  358. }
  359. if (data[sGatherSelect].tenders.length <= specCol.length) {
  360. hintObj.html('请至少选择1个普通汇总项目').show();
  361. return;
  362. }
  363. if (gsObj.setting.type === 'month') {
  364. data[sGatherSelect].month = $('#gather-month').val();
  365. if (data[sGatherSelect].month === '') {
  366. hintObj.html('请选择 汇总年月').show();
  367. return;
  368. }
  369. } else if (gsObj.setting.type === 'zone') {
  370. data[sGatherSelect].zone = $('#gather-zone').val();
  371. if (data[sGatherSelect].zone === '') {
  372. hintObj.html('请选择 汇总周期').show();
  373. return;
  374. } else if(data[sGatherSelect].zone.indexOf(' - ') < 0) {
  375. hintObj.html('请选择 完整汇总周期').show();
  376. return;
  377. }
  378. }
  379. hintObj.hide();
  380. if (resolve) {
  381. resolve(data);
  382. } else {
  383. postData('/report/cDefine', data, function (result) {
  384. reloadReportData(result);
  385. const gather_select = customSelects.gather_select.find(function (x) {
  386. return x.id === zTreeOprObj.currentNode.refId;
  387. });
  388. if (gather_select) {
  389. gather_select.gather_select = data[sGatherSelect];
  390. }
  391. $('#gather-select-count').html(data[sGatherSelect].tenders.length);
  392. $('#gather-select').modal('hide');
  393. });
  394. }
  395. };
  396. const initTenderTree = function (tenders, category) {
  397. const gsSpread = SpreadJsObj.createNewSpread($('#gather-source-spread')[0]);
  398. gsObj.gsSheet = gsSpread.getActiveSheet();
  399. const spreadSetting = {
  400. cols: [
  401. {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox', readOnly: true},
  402. {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true, cellType: 'tree'},
  403. {title: '期数', field: 'phase', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  404. {title: '审批状态', field: 'status', hAlign: 1, width: 60, formatter: '@', readOnly: true}
  405. ],
  406. emptyRows: 0,
  407. headRows: 1,
  408. headRowHeight: [32],
  409. defaultRowHeight: 21,
  410. headerFont: '12px 微软雅黑',
  411. font: '12px 微软雅黑',
  412. headColWidth: [0],
  413. selectedBackColor: '#fffacd',
  414. };
  415. SpreadJsObj.initSheet(gsObj.gsSheet, spreadSetting);
  416. gsObj.tenderSourceTree = Tender2Tree.convert(category, tenders);
  417. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  418. gsSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.gsButtonClicked);
  419. const grSpread = SpreadJsObj.createNewSpread($('#gather-result-spread')[0]);
  420. gsObj.grSheet = grSpread.getActiveSheet();
  421. grSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.grButtonClicked);
  422. $('#gather-hint').hide();
  423. $('#gather-select').bind('shown.bs.modal', function () {
  424. if (gsSpread) gsSpread.refresh();
  425. if (grSpread) grSpread.refresh();
  426. });
  427. $('.datepicker-here').datepicker({
  428. autoClose: true,
  429. });
  430. };
  431. const comfirmSelectPromise = function (rptName, gather_select) {
  432. const promise = new Promise(function (resolve, reject) {
  433. init(gather_select.custom_define, customSelects.stageFlow, gather_select, rptName, resolve, reject);
  434. });
  435. return promise;
  436. };
  437. const getCustomSelect = async function (params) {
  438. if (!params.rpt_ids || params.rpt_ids.length === 0) return;
  439. const currentRptId = zTreeOprObj.currentNode ? zTreeOprObj.currentNode.refId : -1;
  440. params.customSelect = [];
  441. const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  442. for (const rptId of params.rpt_ids) {
  443. const gather_select = customSelects.gather_select.find(function (x) {
  444. return x.id === rptId;
  445. });
  446. if (gather_select && gather_select.custom_define && gather_select.custom_define[sGatherSelect].enable) {
  447. if (rptId === currentRptId) {
  448. params.customSelect.push(gather_select[sGatherSelect]);
  449. } else {
  450. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  451. params.customSelect.push(await comfirmSelectPromise(chkNode ? chkNode.name : '', gather_select));
  452. }
  453. } else {
  454. params.customSelect.push(null);
  455. }
  456. }
  457. $('#gather-select').modal('hide');
  458. };
  459. const showMaterialSelect = function () {
  460. const needShow = function () {
  461. if (zTreeOprObj.currentNode) {
  462. const ms = dataSelects.material_select.find(function (x) { return x.id === zTreeOprObj.currentNode.refId});
  463. if (ms) return true;
  464. }
  465. const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  466. for (const node of chkNodes) {
  467. const ms = dataSelects.material_select.find(function (x) { return x.id === node.refId});
  468. if (ms) return true;
  469. }
  470. return false;
  471. };
  472. if (needShow()) {
  473. $('#material').show();
  474. } else {
  475. $('#material').hide();
  476. }
  477. };
  478. const changeMaterial = function (obj) {
  479. $('#material-select').attr('m-order', $(obj).attr('m-order')).html(obj.innerText);
  480. };
  481. return {
  482. init,
  483. resetAuditSelect, resetGatherSelect,
  484. initTenderTree,
  485. getCustomSelect,
  486. showMaterialSelect, changeMaterial
  487. };
  488. })();