rpt_custom.js 31 KB

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