rpt_custom.js 43 KB

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