rpt_custom.js 34 KB

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