rpt_custom.js 38 KB

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