rpt_custom.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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: 180, 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. tender.selected = true;
  137. select.push(tender);
  138. const st = this._addTender(tender);
  139. for (const sc of specCol) {
  140. st[sc.key] = t[sc.key];
  141. }
  142. }
  143. SpreadJsObj.reLoadColsData(gsObj.gsSheet, [0]);
  144. if (select.length > 0) SpreadJsObj.locateTreeNode(gsObj.gsSheet, select[0].tmt_id);
  145. this.reloadResultData();
  146. },
  147. };
  148. const getStageFlowSelectHtml = function (select, id) {
  149. const html = [];
  150. html.push('<select style="width: 80%" id="' + id + '" sf-title="' + select.title + '">');
  151. for (const sf of stageFlow) {
  152. html.push('<option>' + sf.name + '-' + sf.role +'</option>');
  153. }
  154. html.push('</select>');
  155. return html.join('');
  156. };
  157. const checkAsSelectValid = function (validFlow, asSelect) {
  158. for (const s of asSelect) {
  159. const f = validFlow.find(function (x) {
  160. return x.aid === s.aid && x.order === s.order;
  161. });
  162. if (!f) {
  163. $('#audit-select-hint').html('本期审批流程发生变动,原审批人选择不适配,需重新选择').show();
  164. return false;
  165. }
  166. }
  167. $('#audit-select-hint').hide();
  168. return true;
  169. };
  170. const initAuditSelect = function (asSetting, asSelect) {
  171. const setting = JSON.parse(asSetting), select = asSelect;
  172. $('#audit-select-title').html(setting.title);
  173. if (setting.hideSign) {
  174. $('#pnl_eSignature').hide();
  175. } else {
  176. $('#pnl_eSignature').show();
  177. }
  178. const html = [];
  179. for (const [i, s] of setting.select.entries()) {
  180. html.push('<tr>');
  181. html.push('<td>', s.title, '</td>');
  182. html.push('<td>', getStageFlowSelectHtml(s, 'sf-' + i), '</td>');
  183. html.push('</tr>');
  184. }
  185. $('#audit-select-list').html(html.join(''));
  186. for (const [i, s] of setting.select.entries()) {
  187. const obj = $('#sf-' + i);
  188. const s = select[i];
  189. const sf = s ? stageFlow.find(function (x) {
  190. return x.order === s.order && x.aid === s.aid;
  191. }) : null;
  192. obj[0].selectedIndex = sf ? sf.order : -1;
  193. }
  194. if (asSelect.length === 0 || !checkAsSelectValid(stageFlow, asSelect)) {
  195. $('#audit-select').modal('show');
  196. }
  197. };
  198. const initGrSpreadSetting = function (gsSetting) {
  199. grSpreadSetting.cols = [];
  200. for (const bc of grSpreadSetting.baseCols) {
  201. grSpreadSetting.cols.push(bc);
  202. if (bc.field === 'name') bc.width = gsSetting.nameColWidth ? gsSetting.nameColWidth : 180;
  203. }
  204. if (gsSetting.special) {
  205. for (const s of gsSetting.special) {
  206. for (const ec of grSpreadSetting.extraCols) {
  207. const c = {};
  208. c.title = ec.title.replace('%s', s.title);
  209. c.colSpan = ec.colSpan;
  210. c.field = ec.field.replace('%s', s.key);
  211. c.hAlign = ec.hAlign;
  212. c.width = s.width ? s.width : ec.width;
  213. c.cellType = ec.cellType;
  214. c.readOnly = ec.readOnly;
  215. grSpreadSetting.cols.push(c);
  216. }
  217. }
  218. }
  219. };
  220. const initGatherSelect = function (gsSetting, gsSelect, rptName, resolve = null) {
  221. gsObj.grArray = [];
  222. gsObj.setting = JSON.parse(gsSetting);
  223. gsObj.orgSelect = gsSelect;
  224. $('#gather-select-count').html(gsSelect ? gsSelect.tenders.length : 0);
  225. $('#gather-select-title').html(gsObj.setting.title + (rptName ? '-' + rptName : ''));
  226. initGrSpreadSetting(gsObj.setting);
  227. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  228. // 初始化选择结果
  229. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  230. gatherSelectSpreadObj.initSelectTenders(gsSelect ? gsSelect.tenders : []);
  231. $('[name=gather-type]').hide();
  232. if (gsObj.setting.type === 'month') $('#gather-by-month').show();
  233. if (gsObj.setting.type === 'zone') $('#gather-by-zone').show();
  234. if (gsObj.setting.type === 'stage') $('#gather-by-stage').show();
  235. if (gsObj.setting.type === 'stage-zone') $('#gather-by-stage-zone').show();
  236. if (gsSelect) {
  237. if (gsSelect.zone) {
  238. $('#gather-zone').val(gsSelect.zone ? gsSelect.zone : '');
  239. } else if (gsSelect.month) {
  240. $('#gather-month').val(gsSelect.month ? gsSelect.month: '');
  241. } else if (gsSelect.stage) {
  242. $('#gather-stage').val(gsSelect.stage || '');
  243. } else if (gsSelect.stage_zone) {
  244. const [stageBegin, stageEnd] = gsSelect.stage_zone ? gsSelect.stage_zone.split(':') : ['', ''];
  245. $('#gather-stage-begin').val(stageBegin);
  246. $('#gather-stage-end').val(stageEnd);
  247. }
  248. }
  249. // 初始化
  250. $("#gather-select").modal('show');
  251. $('#gather-select-ok').unbind('click');
  252. $('#gather-select-ok').bind('click', () => {rptCustomObj.resetGatherSelect(resolve);});
  253. };
  254. const initStageSelect = function (gsSetting, gsSelect, rptName, resolve = null) {
  255. const setting = JSON.parse(gsSetting);
  256. $('#stage-select-count').html(gsSelect && gsSelect.stages ? gsSelect.stages.length : 0);
  257. $('#stage-select-title').html(setting.title + (rptName ? '-' + rptName : ''));
  258. // 初始化选择结果
  259. $('#stage-select-hint').attr('min-select', setting.min).attr('max-select', setting.max).hide();
  260. for (const sc of $('[name=stage-select-check]')) {
  261. sc.checked = false;
  262. }
  263. if (gsSelect && gsSelect.stages) {
  264. for (const s of gsSelect.stages) {
  265. $('#stage-select-' + s)[0].checked = true;
  266. }
  267. }
  268. $("#stage-select").modal('show');
  269. $('#stage-select-ok').unbind('click');
  270. $('#stage-select-ok').bind('click', () => {rptCustomObj.resetStageSelect(resolve);});
  271. };
  272. const init = function (cDefine, sfData, cSelect, rptName, resolve = null) {
  273. stageFlow = sfData;
  274. if (cDefine && cDefine[sAuditSelect] && cDefine[sAuditSelect].enable && cDefine[sAuditSelect].setting) {
  275. $('#pnl_audit_select').show();
  276. initAuditSelect(cDefine[sAuditSelect].setting, cSelect ? cSelect[sAuditSelect] : []);
  277. } else {
  278. $('#pnl_eSignature').show();
  279. $('#pnl_audit_select').hide();
  280. }
  281. if (cDefine && cDefine[sGatherSelect] && cDefine[sGatherSelect].enable && cDefine[sGatherSelect].setting) {
  282. $('#pnl_gather_select').show();
  283. initGatherSelect(cDefine[sGatherSelect].setting, cSelect ? cSelect[sGatherSelect] : null, rptName, resolve);
  284. } else {
  285. $('#pnl_gather_select').hide();
  286. }
  287. if (cDefine && cDefine[sStageSelect] && cDefine[sStageSelect].enable && cDefine[sStageSelect].setting) {
  288. $('#pnl_stage_select').show();
  289. initStageSelect(cDefine[sStageSelect].setting, cSelect ? cSelect[sStageSelect] : null, rptName, resolve);
  290. } else {
  291. $('#pnl_stage_select').hide();
  292. }
  293. };
  294. const reloadReportData = function (result) {
  295. // hintBox.unWaitBox();
  296. let pageRst = result.data;
  297. if (result.signatureRelInfo && result.signatureRelInfo.length > 0) {
  298. CURRENT_ROLE_REL_ID = result.signatureRelInfo[0].id;
  299. ROLE_REL_LIST = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  300. STAGE_AUDIT = result.stageAudit;
  301. rptSignatureHelper.originalRoleRelList = zTreeOprObj._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  302. if (current_stage_status === 3) {
  303. rptSignatureHelper.mergeSignDate(pageRst, ROLE_REL_LIST, true);
  304. rptSignatureHelper.mergeSignature(pageRst, ROLE_REL_LIST);
  305. rptSignatureHelper.mergeSignAudit(pageRst, ROLE_REL_LIST, STAGE_AUDIT);
  306. }
  307. } else {
  308. CURRENT_ROLE_REL_ID = -1;
  309. ROLE_REL_LIST = [];
  310. }
  311. // if (ROLE_REL_LIST)
  312. let canvas = zTreeOprObj.canvas;
  313. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  314. zTreeOprObj.resetAfter(pageRst);
  315. zTreeOprObj.currentRptPageRst = pageRst;
  316. zTreeOprObj.maxPages = pageRst.items.length;
  317. zTreeOprObj.currentPage = 1;
  318. zTreeOprObj.displayPageValue();
  319. let size = JpcCanvasOutput.getReportSizeInPixel(zTreeOprObj.currentRptPageRst, getScreenDPI());
  320. canvas.width = size[0] + 20;
  321. if (size[1] > size[0]) {
  322. canvas.height = size[1] + 100;
  323. } else {
  324. canvas.height = size[1] + 50;
  325. }
  326. // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst);
  327. rptSignatureHelper.buildSelectableAccount();
  328. rptSignatureHelper.buildSelectableAccountUsed();
  329. rptSignatureHelper.buildRoleDom(ROLE_LIST);
  330. zTreeOprObj.showPage(1, canvas);
  331. } else {
  332. //返回了无数据表
  333. JpcCanvasOutput.cleanCanvas(canvas);
  334. JpcCanvasOutput.drawPageBorder(zTreeOprObj.currentRptPageRst, canvas, getScreenDPI());
  335. }
  336. rptCustomObj.init(result.customDefine, result.stageFlow, result.customSelect);
  337. try {
  338. if (is_debug && result.debugInfo) {
  339. console.log('含有key的debug信息:');
  340. for (const k in result.debugInfo.key) {
  341. console.log(k + ':', ...result.debugInfo.key[k]);
  342. }
  343. //console.log(result.debugInfo.key);
  344. console.log('其他debug信息:');
  345. for (const di of result.debugInfo.other) {
  346. console.log(...di);
  347. }
  348. }
  349. } catch(err) {
  350. }
  351. zTreeOprObj.countChkedRptTpl();
  352. };
  353. const getCommonParams = function (data) {
  354. data.pageSize = rptControlObj.getCurrentPageSize();
  355. data.rpt_tpl_id = zTreeOprObj.currentNode.refId;
  356. data.custCfg = CUST_CFG;
  357. data.project_id = PROJECT_ID;
  358. data.tender_id = TENDER_ID;
  359. data.stage_id = getStageId();
  360. data.stage_status = getStageStatus();
  361. data.stage_order = getStageOrder();
  362. data.stage_times = getStageTimes();
  363. data.material_order = getMaterialOrder();
  364. };
  365. const resetAuditSelect = function () {
  366. const selObj = $('select', '#audit-select-list');
  367. const data = { audit_select: [], closeWatermark: getCloseWatermark() };
  368. getCommonParams(data);
  369. for (const s of selObj) {
  370. const sf = stageFlow[s.selectedIndex];
  371. if (!sf) {
  372. $('#audit-select-hint').html('未选择' + s.attributes['sf-title'].value).show();
  373. return;
  374. }
  375. data.audit_select.push(sf);
  376. }
  377. $('#audit-select-hint').hide();
  378. postData('/report/cDefine', data, function (result) {
  379. reloadReportData(result);
  380. $('#audit-select').modal('hide');
  381. });
  382. };
  383. const resetGatherSelect = function (resolve = null) {
  384. const data = {}, hintObj = $('#gather-hint');
  385. if (!resolve) getCommonParams(data);
  386. data[sGatherSelect] = {
  387. tenders: [],
  388. type: gsObj.setting.type,
  389. };
  390. const specCol = gsObj.setting.special ? gsObj.setting.special : [];
  391. for (const sc of specCol) {
  392. sc.sCount = 0;
  393. }
  394. for (const gra of gsObj.grArray) {
  395. const ra = {tid: gra.tid};
  396. for (const sc of specCol) {
  397. if (gra[sc.key]) {
  398. ra[sc.key] = true;
  399. sc.sCount += 1;
  400. }
  401. }
  402. data[sGatherSelect].tenders.push(ra);
  403. }
  404. for (const sc of specCol) {
  405. if (sc.sCount === 0) {
  406. hintObj.html('请选择 ' + sc.title).show();
  407. return;
  408. }
  409. }
  410. if (data[sGatherSelect].tenders.length <= specCol.length) {
  411. hintObj.html('请至少选择1个普通汇总项目').show();
  412. return;
  413. }
  414. if (gsObj.setting.type === 'month') {
  415. data[sGatherSelect].month = $('#gather-month').val();
  416. if (data[sGatherSelect].month === '') {
  417. hintObj.html('请选择 汇总年月').show();
  418. return;
  419. }
  420. } else if (gsObj.setting.type === 'zone') {
  421. data[sGatherSelect].zone = $('#gather-zone').val();
  422. if (data[sGatherSelect].zone === '') {
  423. hintObj.html('请选择 汇总周期').show();
  424. return;
  425. } else if(data[sGatherSelect].zone.indexOf(' - ') < 0) {
  426. hintObj.html('请选择 完整汇总周期').show();
  427. return;
  428. }
  429. } else if (gsObj.setting.type === 'stage') {
  430. data[sGatherSelect].stage = _.toInteger($('#gather-stage').val()) || 0;
  431. const validStage = _.min(_.map(gsObj.grArray, 'stageCount'));
  432. if (!data[sGatherSelect].stage) {
  433. hintObj.html('请选择 汇总期').show();
  434. return;
  435. }
  436. if (data[sGatherSelect].stage > validStage) {
  437. hintObj.html('选择的期无效,请重新选择').show();
  438. return;
  439. }
  440. } else if (gsObj.setting.type === 'stage-zone') {
  441. const stageBegin = _.toInteger($('#gather-stage-begin').val()) || 0;
  442. const stageEnd = _.toInteger($('#gather-stage-end').val()) || 0;
  443. const validStage = _.max(_.map(gsObj.grArray, 'stageCount'));
  444. if (!stageBegin || !stageEnd) {
  445. hintObj.html('请选择 汇总开始期与结束期').show();
  446. return;
  447. }
  448. if (stageEnd <= stageBegin) {
  449. hintObj.html('结束期应大于开始期').show();
  450. return;
  451. }
  452. if (stageEnd > validStage) {
  453. hintObj.html('选择的期无效,请重新选择').show();
  454. return;
  455. }
  456. data[sGatherSelect].stage_zone = stageBegin + ':' + stageEnd;
  457. }
  458. hintObj.hide();
  459. if (resolve) {
  460. resolve(data);
  461. } else {
  462. postData('/report/cDefine', data, function (result) {
  463. reloadReportData(result);
  464. const gather_select = customSelects.gather_select.find(function (x) {
  465. return x.id === zTreeOprObj.currentNode.refId;
  466. });
  467. if (gather_select) {
  468. gather_select.gather_select = data[sGatherSelect];
  469. }
  470. $('#gather-select-count').html(data[sGatherSelect].tenders.length);
  471. $('#gather-select').modal('hide');
  472. });
  473. }
  474. };
  475. const resetStageSelect = function (resolve = null) {
  476. const data = {}, hintObj = $('#stage-select-hint');
  477. if (!resolve) getCommonParams(data);
  478. data[sStageSelect] = {
  479. stages: [],
  480. };
  481. for (const sc of $('[name=stage-select-check]:checked')) {
  482. data[sStageSelect].stages.push(parseInt($(sc).attr('stage-order')));
  483. }
  484. if (data[sStageSelect].stages.length < parseInt(hintObj.attr('min-select'))) {
  485. hintObj.html('请至少选择' + hintObj.attr('min-select') + '期数据').show();
  486. return;
  487. } else if (data[sStageSelect].stages.length > parseInt(hintObj.attr('max-select'))) {
  488. hintObj.html('最多只能选择' + hintObj.attr('max-select') + '期数据').show();
  489. return;
  490. }
  491. hintObj.hide();
  492. if (resolve) {
  493. resolve(data);
  494. } else {
  495. postData('/report/cDefine', data, function (result) {
  496. reloadReportData(result);
  497. const stage_select = customSelects.stage_select.find(function (x) {
  498. return x.id === zTreeOprObj.currentNode.refId;
  499. });
  500. if (stage_select) {
  501. stage_select.stage_select = data[sStageSelect];
  502. }
  503. $('#stage-select-count').html(data[sStageSelect].stages.length);
  504. $('#stage-select').modal('hide');
  505. });
  506. }
  507. };
  508. const _createTenderTreeForCross = function (tenders, category, rstItems) {
  509. if (rstItems instanceof Array && rstItems.length === 0) {
  510. //1. 先确定category方式(‘年份’、‘姓名’、‘类型’)及顺序
  511. let ctArr = [];
  512. for (let cat of category) {
  513. if (cat.level) {
  514. ctArr.push(cat);
  515. }
  516. }
  517. ctArr.sort(function (item1, item2) {
  518. return parseInt(item1.level) - parseInt(item2.level);
  519. }); //保证顺序
  520. const _buildDeftNodes = function(startIdx, parentItem) {
  521. if (ctArr.length > startIdx) {
  522. let item = {};
  523. if (parentItem instanceof Array) {
  524. parentItem.push(item);
  525. } else {
  526. parentItem.items.push(item);
  527. }
  528. for (let idx = 0; idx < ctArr[startIdx].value.length; idx++) {
  529. item.name = ctArr[startIdx].value[idx].value;
  530. item.id = ctArr[startIdx].id; //这个相当于类型id,如68:年份 69:类型,105:姓名
  531. item.value_id = ctArr[startIdx].value[idx].id; //每个大类下又有小类,如:2018/2019, 土建/房建, 具体用户姓名...
  532. item.cid = ctArr[startIdx].value[idx].cid; //这个值 = item.id
  533. item.pid = ctArr[startIdx].value[idx].pid; //project id?
  534. item.tenderId = -1;
  535. item.selected = false;
  536. item.isParent = true;
  537. item.last_stage = -1;
  538. item.items = [];
  539. _buildDeftNodes(startIdx + 1, item);
  540. }
  541. }
  542. };
  543. // const _get
  544. //2. 创建基本结构
  545. _buildDeftNodes(0, rstItems);
  546. //3. 挂上标段
  547. const _putupTheTender = function (tender) {
  548. const _findType = function (parentItem) {
  549. for (let cat of tender.category) {
  550. if (cat.cid === parentItem.cid && cat.value === parentItem.value_id) {
  551. if (parentItem.items.length === 0) {
  552. // 到底了,挂上
  553. let lastStage = -1;
  554. if (tender.lastStage) {
  555. lastStage = tender.lastStage.times;
  556. }
  557. let item = {
  558. name: tender.name,
  559. id : -1,
  560. value_id: cat.value,
  561. cid : cat.cid,
  562. pid : -1,
  563. tenderId: tender.id,
  564. selected : false,
  565. isParent: true,
  566. last_stage: lastStage,
  567. items : [],
  568. }
  569. parentItem.items.push(item);
  570. } else {
  571. for (let nodeItem of parentItem.items) {
  572. _findType(tender, nodeItem);
  573. }
  574. }
  575. break;
  576. }
  577. }
  578. };
  579. for (let nodeItem of rstItems) {
  580. _findType(nodeItem);
  581. }
  582. };
  583. for (let tender of tenders) {
  584. _putupTheTender(tender);
  585. }
  586. }
  587. };
  588. const initTenderTreeForCross = function (tenders, category) {
  589. //用户跨标段设置电子签名用
  590. let rstItems = [];
  591. _createTenderTreeForCross(tenders, category, rstItems);
  592. _buildTenderRow('batch_projects_individual', rstItems);
  593. };
  594. const _buildTenderRow = function(tbDomId, topTreeNodes) {
  595. let tbDom = $("#" + tbDomId);
  596. tbDom.empty();
  597. tbDom.append('<tr><th>名称</th><th>计量期</th><th>签名</th><th>选择</th></tr>');
  598. let _pushRptLine = function (nodeItem, level) {
  599. if (nodeItem.isParent) {
  600. 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>')
  601. //<td class="in-1"><i class="fa fa-folder-o"></i>&nbsp;2019</td>
  602. } else {
  603. //
  604. }
  605. };
  606. for (const topItem of topTreeNodes) {
  607. _pushRptLine(topItem, 0);
  608. }
  609. }
  610. const initTenderTree = function (tenders, category) {
  611. const gsSpread = SpreadJsObj.createNewSpread($('#gather-source-spread')[0]);
  612. gsObj.gsSheet = gsSpread.getActiveSheet();
  613. const spreadSetting = {
  614. cols: [
  615. {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox', readOnly: true},
  616. {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true, cellType: 'tree'},
  617. {title: '期数', field: 'phase', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  618. {title: '审批状态', field: 'status', hAlign: 1, width: 60, formatter: '@', readOnly: true}
  619. ],
  620. emptyRows: 0,
  621. headRows: 1,
  622. headRowHeight: [32],
  623. defaultRowHeight: 21,
  624. headerFont: '12px 微软雅黑',
  625. font: '12px 微软雅黑',
  626. headColWidth: [0],
  627. selectedBackColor: '#fffacd',
  628. };
  629. SpreadJsObj.initSheet(gsObj.gsSheet, spreadSetting);
  630. gsObj.tenderSourceTree = Tender2Tree.convert(category, tenders, ledgerAuditConst, auditConst);
  631. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  632. gsSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.gsButtonClicked);
  633. const grSpread = SpreadJsObj.createNewSpread($('#gather-result-spread')[0]);
  634. gsObj.grSheet = grSpread.getActiveSheet();
  635. grSpread.bind(spreadNS.Events.ButtonClicked, gatherSelectSpreadObj.grButtonClicked);
  636. $('#gather-hint').hide();
  637. $('#gather-select').bind('shown.bs.modal', function () {
  638. if (gsSpread) gsSpread.refresh();
  639. if (grSpread) grSpread.refresh();
  640. });
  641. $('.datepicker-here').datepicker({
  642. autoClose: true,
  643. });
  644. };
  645. const comfirmSelectPromise = function (rptName, gather_select) {
  646. const promise = new Promise(function (resolve, reject) {
  647. init(gather_select.custom_define, customSelects.stageFlow, gather_select, rptName, resolve, reject);
  648. });
  649. return promise;
  650. };
  651. const getCustomSelect = async function (params) {
  652. if (!params.rpt_ids || params.rpt_ids.length === 0) return;
  653. const currentRptId = zTreeOprObj.currentNode ? zTreeOprObj.currentNode.refId : -1;
  654. params.customSelect = [];
  655. const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  656. for (const rptId of params.rpt_ids) {
  657. const gather_select = customSelects.gather_select.find(function (x) {
  658. return x.id === rptId;
  659. });
  660. const stage_select = customSelects.stage_select.find(function (x) {
  661. return x.id === rptId;
  662. });
  663. if (gather_select && gather_select.custom_define && gather_select.custom_define[sGatherSelect].enable) {
  664. if (rptId === currentRptId) {
  665. const data = {};
  666. data[sGatherSelect] = gather_select[sGatherSelect];
  667. params.customSelect.push(data);
  668. } else {
  669. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  670. params.customSelect.push(await comfirmSelectPromise(chkNode ? chkNode.name : '', gather_select));
  671. }
  672. $('#gather-select').modal('hide');
  673. } else if (stage_select && stage_select.custom_define && stage_select.custom_define[sStageSelect].enable) {
  674. if (rptId === currentRptId) {
  675. const data = {};
  676. data[sStageSelect] = stage_select[sStageSelect];
  677. params.customSelect.push(data);
  678. } else {
  679. const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
  680. params.customSelect.push(await comfirmSelectPromise(chkNode ? chkNode.name : '', stage_select));
  681. }
  682. $('#stage-select').modal('hide');
  683. } else {
  684. params.customSelect.push(null);
  685. }
  686. }
  687. };
  688. const showMaterialSelect = function () {
  689. const needShow = function () {
  690. if (zTreeOprObj.currentNode) {
  691. const ms = dataSelects.material_select.find(function (x) { return x.id === zTreeOprObj.currentNode.refId});
  692. if (ms) return true;
  693. }
  694. const chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  695. for (const node of chkNodes) {
  696. const ms = dataSelects.material_select.find(function (x) { return x.id === node.refId});
  697. if (ms) return true;
  698. }
  699. return false;
  700. };
  701. if (needShow()) {
  702. $('#material').show();
  703. } else {
  704. $('#material').hide();
  705. }
  706. };
  707. const changeMaterial = function (obj) {
  708. $('#material-select').attr('m-order', $(obj).attr('m-order')).html(obj.innerText);
  709. };
  710. return {
  711. init,
  712. resetAuditSelect, resetGatherSelect, resetStageSelect,
  713. initTenderTree,
  714. initTenderTreeForCross,
  715. getCustomSelect,
  716. showMaterialSelect, changeMaterial,
  717. };
  718. })();