rpt_custom.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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) {
  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);
  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. };
  226. const init = function (cDefine, sfData, cSelect) {
  227. stageFlow = sfData;
  228. if (cDefine && cDefine[sAuditSelect] && cDefine[sAuditSelect].enable && cDefine[sAuditSelect].setting) {
  229. $('#pnl_audit_select').show();
  230. initAuditSelect(cDefine[sAuditSelect].setting, cSelect ? cSelect[sAuditSelect] : []);
  231. } else {
  232. $('#pnl_audit_select').hide();
  233. }
  234. if (cDefine && cDefine[sGatherSelect] && cDefine[sGatherSelect].enable && cDefine[sGatherSelect].setting) {
  235. $('#pnl_gather_select').show();
  236. initGatherSelect(cDefine[sGatherSelect].setting, cSelect ? cSelect[sGatherSelect] : null);
  237. } else {
  238. $('#pnl_gather_select').hide();
  239. }
  240. };
  241. const reloadReportData = function (result) {
  242. // hintBox.unWaitBox();
  243. let pageRst = result.data;
  244. if (result.signatureRelInfo && result.signatureRelInfo.length > 0) {
  245. CURRENT_ROLE_REL_ID = result.signatureRelInfo[0].id;
  246. ROLE_REL_LIST = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  247. STAGE_AUDIT = result.stageAudit;
  248. rptSignatureHelper.originalRoleRelList = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  249. if (current_stage_status === 3) {
  250. rptSignatureHelper.mergeSignDate(pageRst, ROLE_REL_LIST);
  251. rptSignatureHelper.mergeSignature(pageRst, ROLE_REL_LIST);
  252. }
  253. } else {
  254. CURRENT_ROLE_REL_ID = -1;
  255. ROLE_REL_LIST = [];
  256. }
  257. // if (ROLE_REL_LIST)
  258. let canvas = zTreeOprObj.canvas;
  259. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  260. zTreeOprObj.resetAfter(pageRst);
  261. zTreeOprObj.currentRptPageRst = pageRst;
  262. zTreeOprObj.maxPages = pageRst.items.length;
  263. zTreeOprObj.currentPage = 1;
  264. zTreeOprObj.displayPageValue();
  265. let size = JpcCanvasOutput.getReportSizeInPixel(zTreeOprObj.currentRptPageRst, getScreenDPI());
  266. canvas.width = size[0] + 20;
  267. if (size[1] > size[0]) {
  268. canvas.height = size[1] + 100;
  269. } else {
  270. canvas.height = size[1] + 50;
  271. }
  272. // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst);
  273. rptSignatureHelper.buildSelectableAccount();
  274. rptSignatureHelper.buildSelectableAccountUsed();
  275. rptSignatureHelper.buildRoleDom(ROLE_LIST);
  276. zTreeOprObj.showPage(1, canvas);
  277. } else {
  278. //返回了无数据表
  279. JpcCanvasOutput.cleanCanvas(canvas);
  280. JpcCanvasOutput.drawPageBorder(zTreeOprObj.currentRptPageRst, canvas, getScreenDPI());
  281. }
  282. rptCustomObj.init(result.customDefine, result.stageFlow, result.customSelect);
  283. try {
  284. if (is_debug && result.debugInfo) {
  285. console.log('含有key的debug信息:');
  286. for (const k in result.debugInfo.key) {
  287. console.log(k + ':', ...result.debugInfo.key[k]);
  288. }
  289. //console.log(result.debugInfo.key);
  290. console.log('其他debug信息:');
  291. for (const di of result.debugInfo.other) {
  292. console.log(...di);
  293. }
  294. }
  295. } catch(err) {
  296. }
  297. };
  298. const getCommonParams = function (data) {
  299. data.pageSize = rptControlObj.getCurrentPageSize();
  300. data.orientation = rptControlObj.getCurrentOrientation();
  301. data.rpt_tpl_id = zTreeOprObj.currentNode.refId;
  302. data.custCfg = CUST_CFG;
  303. data.project_id = PROJECT_ID;
  304. data.tender_id = TENDER_ID;
  305. data.stage_id = getStageId();
  306. data.stage_status = getStageStatus();
  307. data.stage_order = getStageOrder();
  308. data.stage_times = getStageTimes();
  309. };
  310. const resetAuditSelect = function () {
  311. const selObj = $('select', '#audit-select-list');
  312. const data = { audit_select: [] };
  313. getCommonParams(data);
  314. for (const s of selObj) {
  315. const sf = stageFlow[s.selectedIndex];
  316. if (!sf) {
  317. $('#audit-select-hint').html('未选择' + s.attributes['sf-title'].value).show();
  318. return;
  319. }
  320. data.audit_select.push(sf);
  321. }
  322. $('#audit-select-hint').hide();
  323. postData('/report/cDefine', data, function (result) {
  324. reloadReportData(result);
  325. $('#audit-select').modal('hide');
  326. });
  327. };
  328. const resetGatherSelect = function () {
  329. const data = {}, hintObj = $('#gather-hint');
  330. getCommonParams(data);
  331. data[sGatherSelect] = {
  332. tenders: [],
  333. type: gsObj.setting.type,
  334. };
  335. const specCol = gsObj.setting.special ? gsObj.setting.special : [];
  336. for (const gra of gsObj.grArray) {
  337. const ra = {tid: gra.tid};
  338. for (const sc of specCol) {
  339. if (gra[sc.key]) {
  340. ra[sc.key] = true;
  341. sc.sCount += 1;
  342. }
  343. }
  344. data[sGatherSelect].tenders.push(ra);
  345. }
  346. for (const sc of specCol) {
  347. if (sc.sCount === 0) {
  348. hintObj.html('请选择 ' + sc.title).show();
  349. return;
  350. }
  351. }
  352. if (data[sGatherSelect].tenders.length <= specCol.length) {
  353. hintObj.html('请至少选择1个普通汇总项目').show();
  354. return;
  355. }
  356. if (gsObj.setting.type === 'month') {
  357. data[sGatherSelect].month = $('#gather-month').val();
  358. if (data[sGatherSelect].month === '') {
  359. hintObj.html('请选择 汇总年月').show();
  360. return;
  361. }
  362. } else if (gsObj.setting.type === 'zone') {
  363. data[sGatherSelect].zone = $('#gather-zone').val();
  364. if (data[sGatherSelect].zone === '') {
  365. hintObj.html('请选择 汇总周期').show();
  366. return;
  367. } else if(data[sGatherSelect].zone.indexOf(' - ') < 0) {
  368. hintObj.html('请选择 完整汇总周期').show();
  369. return;
  370. }
  371. }
  372. hintObj.hide();
  373. postData('/report/cDefine', data, function (result) {
  374. reloadReportData(result);
  375. $('#gather-select-count').html(data[sGatherSelect].tenders.length);
  376. $('#gather-select').modal('hide');
  377. });
  378. };
  379. const initTenderTree = function (tenders, category) {
  380. const gsSpread = SpreadJsObj.createNewSpread($('#gather-source-spread')[0]);
  381. gsObj.gsSheet = gsSpread.getActiveSheet();
  382. const spreadSetting = {
  383. cols: [
  384. {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox', readOnly: true},
  385. {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true, cellType: 'tree'},
  386. {title: '期数', field: 'phase', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  387. {title: '审批状态', field: 'status', hAlign: 1, width: 60, formatter: '@', readOnly: true}
  388. ],
  389. emptyRows: 0,
  390. headRows: 1,
  391. headRowHeight: [32],
  392. defaultRowHeight: 21,
  393. headerFont: '12px 微软雅黑',
  394. font: '12px 微软雅黑',
  395. headColWidth: [0],
  396. selectedBackColor: '#fffacd',
  397. };
  398. SpreadJsObj.initSheet(gsObj.gsSheet, spreadSetting);
  399. gsObj.tenderSourceTree = Tender2Tree.convert(category, tenders);
  400. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  401. gsSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.gsButtonClicked);
  402. const grSpread = SpreadJsObj.createNewSpread($('#gather-result-spread')[0]);
  403. gsObj.grSheet = grSpread.getActiveSheet();
  404. grSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.grButtonClicked);
  405. $('#gather-hint').hide();
  406. $('#gather-select').bind('shown.bs.modal', function () {
  407. if (gsSpread) gsSpread.refresh();
  408. if (grSpread) grSpread.refresh();
  409. });
  410. $('.datepicker-here').datepicker({
  411. autoClose: true,
  412. });
  413. };
  414. return {init, resetAuditSelect, resetGatherSelect, initTenderTree};
  415. })();