rpt_custom.js 17 KB

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