rpt_custom.js 39 KB

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