rpt_custom.js 17 KB

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