stage_im.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const Ledger = require('./ledger');
  10. const imType = require('../const/tender').imType;
  11. class StageIm {
  12. constructor (ctx) {
  13. const self = this;
  14. this.ctx = ctx;
  15. this._ = this.ctx.helper._;
  16. // mainData
  17. this.billsTree = new Ledger.billsTree(this.ctx, {
  18. id: 'ledger_id',
  19. pid: 'ledger_pid',
  20. order: 'order',
  21. level: 'level',
  22. rootId: -1,
  23. keys: ['id', 'tender_id', 'ledger_id'],
  24. stageId: 'id',
  25. calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp'],
  26. calc: function (node) {
  27. if (node.children && node.children.length === 0) {
  28. node.gather_qty = self.ctx.helper.add(node.contract_qty, node.qc_qty);
  29. }
  30. node.gather_tp = self.ctx.helper.add(node.contract_tp, node.qc_tp);
  31. }
  32. });
  33. this.pos = new Ledger.pos({
  34. id: 'id', ledgerId: 'lid',
  35. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  36. calc: function (p) {
  37. p.gather_qty = self.ctx.helper.add(p.contract_qty, p.qc_qty);
  38. }
  39. });
  40. // relaData
  41. this.change = null;
  42. this.details = null;
  43. // result
  44. this.ImData = [];
  45. this.ImBillsData = [];
  46. //
  47. this.imFields = ['uuid', 'doc_code', 'peg', 'bw', 'xm', 'drawing_code', 'calc_memo', 'calc_img'];
  48. this.splitChar = '-';
  49. }
  50. // 加载数据
  51. async _loadMainData () {
  52. const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
  53. if (this.ctx.stage.readOnly) {
  54. const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
  55. this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
  56. this.ctx.helper.assignRelaData(billsData, [
  57. {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
  58. ]);
  59. } else {
  60. const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
  61. this.ctx.helper.assignRelaData(billsData, [
  62. {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
  63. ]);
  64. }
  65. this.billsTree.loadDatas(billsData);
  66. this.billsTree.calculateAll();
  67. const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
  68. if (this.ctx.stage.readOnly) {
  69. const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
  70. this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
  71. this.ctx.helper.assignRelaData(posData, [
  72. {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
  73. ]);
  74. } else {
  75. const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
  76. this.ctx.helper.assignRelaData(posData, [
  77. {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
  78. ]);
  79. }
  80. this.pos.loadDatas(posData);
  81. this.pos.calculateAll();
  82. }
  83. async _loadRelaData () {
  84. if (this.ctx.stage.readOnly) {
  85. this.details = await this.ctx.service.stageDetail.getAuditorStageData(this.ctx.tender.id, this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
  86. } else {
  87. this.details = await this.ctx.service.stageDetail.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
  88. }
  89. if (this.ctx.stage.readOnly) {
  90. this.changes = await this.ctx.service.stageChange.getAuditorAllStageData(this.ctx.tender.id, this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
  91. } else {
  92. this.changes = await this.ctx.service.stageChange.getLastestAllStageData(this.ctx.tender.id, this.ctx.stage.id);
  93. }
  94. }
  95. // 检查汇总节点
  96. async _checkGather() {
  97. const gatherNodes = this.ctx.stage.im_gather_node ? this.ctx.stage.im_gather_node.split(',') : [];
  98. for (const node of this.billsTree.datas) {
  99. node.check = gatherNodes.indexOf(node.id) !== -1;
  100. }
  101. }
  102. // 辅助取值方法
  103. _getNumberFormat(num, length) {
  104. let s = '0000000000';
  105. s = s + num;
  106. return s.substr(s.length - length);
  107. }
  108. _getNodeByLevel(node, level) {
  109. let cur = node;
  110. while (cur && cur.level > level) {
  111. cur = this.billsTree.getParent(cur);
  112. }
  113. return cur;
  114. }
  115. _checkPeg(text) {
  116. const pegReg = /[a-zA-Z]?[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/;
  117. return pegReg.test(text);
  118. }
  119. _getPegStr(text) {
  120. const pegReg1 = /[a-zA-Z]?[kK][0-9]+[++][0-9]{3}([.][0-9]+)?[~~—][a-zA-Z]?[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/;
  121. const result1 = text.match(pegReg1);
  122. if (result1) {
  123. return result1[0];
  124. } else {
  125. const pegReg2 = /[a-zA-Z]?[kK][0-9]+[++][0-9]{3}([.][0-9]+)?-[a-zA-Z]?[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/;
  126. const result2 = text.match(pegReg2);
  127. if (result2) {
  128. return result2[0];
  129. } else {
  130. const pegReg3 = /[a-zA-Z]?[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/;
  131. const result3 = text.match(pegReg3);
  132. return result3 ? result3[0] : '';
  133. }
  134. }
  135. }
  136. _getPegNode (node) {
  137. if (node) {
  138. if (this._checkPeg(node.name)) {
  139. return node;
  140. } else {
  141. const parent = this.billsTree.getParent(node);
  142. return parent ? this._getPegNode(parent) : null;
  143. }
  144. }
  145. }
  146. _getDrawingCode(node) {
  147. if (!node) {
  148. return '';
  149. } else if (node.drawing_code) {
  150. return node.drawing_code;
  151. } else {
  152. const parent = this.billsTree.getParent(node);
  153. return parent ? this._getDrawingCode(parent) : '';
  154. }
  155. }
  156. _getZlNormalBw(node, peg) {
  157. if (peg) {
  158. const subPeg1 = this._getNodeByLevel(node, peg.level + 1);
  159. const subPeg2 = this._getNodeByLevel(node, peg.level + 2);
  160. let result = peg.name;
  161. if (subPeg1 && subPeg1.id !== peg.id && subPeg1.id !== node.id) {
  162. result = result + '-' + subPeg1.name;
  163. if (subPeg2 && subPeg2.id !== subPeg1.id && subPeg2.id !== node.id) {
  164. result = result + '-' + subPeg2.name;
  165. }
  166. }
  167. return result;
  168. } else {
  169. if (node.level === 2 || node.level === 3) {
  170. return node.name;
  171. } else if (node.level >= 4) {
  172. let parent = this.billsTree.getParent(node), result = parent.name;
  173. while (parent.level > 3 && parent) {
  174. parent = this._getNodeByLevel(node, parent.level - 1);
  175. result = parent.name + '-' + result;
  176. }
  177. return result;
  178. } else {
  179. return '';
  180. }
  181. }
  182. }
  183. _getZlGatherBw(node, peg) {
  184. if (peg) {
  185. const subPeg1 = this._getNodeByLevel(node, peg.level + 1);
  186. let result = peg.name;
  187. if (subPeg1 && subPeg1.id !== peg.id) {
  188. result = result + '-' + subPeg1.name;
  189. }
  190. return result;
  191. } else {
  192. if (node.level < 3) {
  193. return node.name;
  194. } else {
  195. let parent = node, result = parent.name;
  196. while (parent.level > 3 && parent) {
  197. parent = this._getNodeByLevel(node, parent.level - 1);
  198. result = parent.name + '-' + result;
  199. }
  200. return result;
  201. }
  202. }
  203. }
  204. _checkCustomDetail(im) {
  205. const self = this;
  206. const cd = this._.find(this.details, function (d) {
  207. return im.lid === d.lid &&
  208. (!im.code || im.code === d.code) &&
  209. (!im.name || im.name === d.name) &&
  210. (!im.unit || im.unit === d.unit) &&
  211. self.ctx.helper.checkZero(self.ctx.helper.sub(im.unit_price, d.unit_price)) &&
  212. (!im.pid || im.pid === d.pid);
  213. });
  214. if (cd) {
  215. this._.assignInWith(im, cd, function (oV, sV, key) {
  216. return self.imFields.indexOf(key) > -1 && sV !== undefined && sV !== null ? sV : oV;
  217. });
  218. }
  219. }
  220. _getCalcMemo(im) {
  221. if (im.calc_memo !== undefined && im.calc_memo !== null && im.calc_memo !== '') return;
  222. if (im.leafXmjs && im.leafXmjs.length > 0) {
  223. const memo = ['本期计量:' + im.jl + ' ' + im.unit];
  224. for (const lx of im.leafXmjs) {
  225. for (const p of lx.pos) {
  226. memo.push(p.name + ':' + p.jl + ' ' + im.unit);
  227. }
  228. }
  229. im.calc_memo = memo.join('\n');
  230. } else if (im.check) {
  231. const memo = [];
  232. for (const [i, b] of im.gclBills.entries()) {
  233. if (b.pos && b.pos.length > 0) {
  234. memo.push('清单' + (i+1) + b.b_code + ' ' + b.name);
  235. for (const p of b.pos) {
  236. memo.push(p.name + ':' + p.jl + ' ' + b.unit);
  237. }
  238. } else {
  239. memo.push('清单' + (i+1) + b.b_code + ' ' + b.name + ':' + b.jl + ' ' + b.unit);
  240. }
  241. }
  242. im.calc_memo = memo.join('\n');
  243. } else {
  244. im.calc_memo = '';
  245. }
  246. }
  247. _getChangeInfo(im) {
  248. if (im.changes && im.changes.length > 0) {
  249. const code = this._.uniq(this._.map(im.changes, 'c_code'));
  250. if (!im.bgl_code || im.bgl_code === '') im.bgl_code = code.join(';');
  251. const new_code = this._.uniq(this._.map(im.changes, 'c_new_code'));
  252. if (!im.bgl_drawing_code || im.bgl_drawing_code === '') im.bgl_drawing_code = new_code.join(';');
  253. }
  254. }
  255. _generateTzPosData(node, gclBills) {
  256. if (!gclBills.pos) {
  257. gclBills.pos = [];
  258. }
  259. const posRange = this.pos.getLedgerPos(node.id);
  260. if (!posRange) { return }
  261. for (const p of posRange) {
  262. if (!p.gather_qty || this.ctx.helper.checkZero(p.gather_qty)) { continue; }
  263. let lp = this._.find(gclBills.pos, {name: p.name});
  264. if (!lp) {
  265. lp = {name: p.name};
  266. gclBills.pos.push(lp);
  267. }
  268. lp.jl = this.ctx.helper.add(lp.jl, p.gather_qty);
  269. lp.contract_jl = this.ctx.helper.add(lp.contract_jl, p.contract_qty);
  270. lp.qc_jl = this.ctx.helper.add(lp.qc_jl, p.qc_qty);
  271. }
  272. }
  273. _generateTzGclBillsData(node, im) {
  274. if (!im.gclBills) {
  275. im.gclBills = [];
  276. }
  277. const posterity = this.billsTree.getPosterity(node);
  278. for (const p of posterity) {
  279. if ((!p.b_code || p.b_code === '') || (p.children && p.children.length > 0)) {
  280. continue;
  281. }
  282. if ((!p.contract_tp || p.contract_tp === 0) && (!p.qc_tp || p.qc_tp === 0)) {
  283. continue;
  284. }
  285. let b = this._.find(im.gclBills, {bid: p.id});
  286. if (!b) {
  287. b = {imid: im.id, bid: p.id, b_code: p.b_code, name: p.name, unit: p.unit};
  288. im.gclBills.push(b);
  289. this.ImBillsData.push(b);
  290. }
  291. b.jl = this.ctx.helper.add(b.jl, p.gather_qty);
  292. b.contract_jl = this.ctx.helper.add(b.contract_jl, p.contract_qty);
  293. b.qc_jl = this.ctx.helper.add(b.qc_jl, p.qc_qty);
  294. this._generateTzPosData(p, b);
  295. }
  296. }
  297. _generateTzChangeData(node, im) {
  298. if (!im.changes) {
  299. im.changes = [];
  300. }
  301. const posterity = this.billsTree.getPosterity(node);
  302. for (const p of posterity) {
  303. if (p.children && p.children.length > 0) {
  304. continue;
  305. }
  306. if ((!p.qc_tp || p.qc_tp === 0)) {
  307. continue;
  308. }
  309. const posRange = this.pos.getLedgerPos(p.id);
  310. if (!posRange) {
  311. for (const c of this.changes) {
  312. if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
  313. im.changes.push(c);
  314. }
  315. }
  316. } else {
  317. for (const pp of posRange) {
  318. if ((!pp.qc_tp || pp.qc_tp === 0)) {
  319. continue;
  320. }
  321. for (const c of this.changes) {
  322. if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
  323. im.changes.push(c);
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. /**
  331. * 生成 0号台账 中间计量数据
  332. * @param {Object} node - 生成中间计量表的节点
  333. */
  334. _generateTzImData (node) {
  335. if (node.gather_tp) {
  336. const peg = this._getPegNode(node);
  337. const im = {
  338. id: this.ImData.length + 1,
  339. lid: node.id, pid: '', code: node.code,
  340. jl: node.gather_tp, contract_jl: node.contract_tp, qc_jl: node.qc_tp,
  341. peg: peg ? this._getPegStr(peg.name) : '', drawing_code: this._getDrawingCode(node),
  342. };
  343. if (this.ctx.stage.im_gather && node.check) {
  344. im.bw = this._getZlGatherBw(node, peg);
  345. im.xm = '';
  346. } else {
  347. im.bw = this._getZlNormalBw(node, peg);
  348. im.xm = node.name;
  349. }
  350. this._checkCustomDetail(im);
  351. im.check = this.ctx.stage.im_gather && node.check;
  352. this._generateTzGclBillsData(node, im);
  353. this.ImData.push(im);
  354. this._generateTzChangeData(node, im);
  355. }
  356. }
  357. _generateZlPosData(node, lx) {
  358. if (!lx.pos) {
  359. lx.pos = [];
  360. }
  361. const posRange = this.pos.getLedgerPos(node.id);
  362. if (!posRange) { return }
  363. for (const p of posRange) {
  364. if (!p.gather_qty || this.ctx.helper.checkZero(p.gather_qty)) { continue; }
  365. let lp = this._.find(lx.pos, {name: p.name});
  366. if (!lp) {
  367. lp = {name: p.name};
  368. lx.pos.push(lp);
  369. }
  370. lp.jl = this.ctx.helper.add(lp.jl, p.gather_qty);
  371. lp.contract_jl = this.ctx.helper.add(lp.contract_jl, p.contract_qty);
  372. lp.qc_jl = this.ctx.helper.add(lp.qc_jl, p.qc_qty);
  373. }
  374. }
  375. _generateZlLeafXmjData(node, im) {
  376. if (!im.leafXmjs) {
  377. im.leafXmjs = [];
  378. }
  379. const leafXmj = this.billsTree.getLeafXmjParent(node);
  380. if (!leafXmj) { return }
  381. let lx = this._.find(im.leafXmjs, {lxid: leafXmj.id});
  382. if (!lx) {
  383. lx = {
  384. lxid: leafXmj.id,
  385. code: leafXmj.code,
  386. name: leafXmj.name
  387. };
  388. im.leafXmjs.push(lx);
  389. }
  390. lx.jl = this.ctx.helper.add(lx.jl, node.gather_qty);
  391. lx.contract_jl = this.ctx.helper.add(lx.contract_jl, node.contract_qty);
  392. lx.qc_jl = this.ctx.helper.add(lx.qc_jl, node.qc_qty);
  393. this._generateZlPosData(node, lx);
  394. }
  395. _generateZlChangeData(node, im) {
  396. if (!im.changes) {
  397. im.changes = [];
  398. }
  399. if ((!node.qc_qty || node.qc_qty === 0)) {
  400. return;
  401. }
  402. const posRange = this.pos.getLedgerPos(node.id);
  403. if (!posRange) {
  404. for (const c of this.changes) {
  405. if (c.lid === node.id && c.pid == -1 && c.qty && c.qty !== 0) {
  406. im.changes.push(c);
  407. }
  408. }
  409. } else {
  410. for (const p of posRange) {
  411. if ((!p.qc_qty || p.qc_qty === 0)) {
  412. continue;
  413. }
  414. for (const c of this.changes) {
  415. if (c.lid === node.id && c.pid === p.id && c.qty && c.qty !== 0) {
  416. im.changes.push(c);
  417. }
  418. }
  419. }
  420. }
  421. }
  422. /**
  423. * 生成 总量控制 中间计量数据
  424. * @param {Object} node - 生成中间计量表的节点
  425. */
  426. _generateZlImData (node) {
  427. const self = this;
  428. const nodeImData = [], posterity = this.billsTree.getPosterity(node);
  429. for (const p of posterity) {
  430. if (p.children && p.children.length > 0 ) { continue; }
  431. if (!p.b_code || p.b_code === '') { continue }
  432. if (this.ctx.helper.checkZero(p.contract_qty) && this.ctx.helper.checkZero(p.qc_qty) ) { continue; }
  433. let im = nodeImData.find(function (d) {
  434. return d.lid === node.id &&
  435. d.code === p.b_code && p.name === d.name && p.unit === d.unit &&
  436. this.ctx.helper.checkZero(self.ctx.helper.sub(p.unit_price, d.unit_price));
  437. });
  438. if (!im) {
  439. const peg = this._getPegNode(node);
  440. im = {
  441. id: this.ImData.length + 1,
  442. lid: node.id, pid: '', code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price,
  443. jl: 0, contract_jl: 0, qc_jl: 0,
  444. peg: peg ? this._getPegStr(peg.name) : ''
  445. };
  446. if (this.ctx.stage.im_gather && node.check) {
  447. im.check = true;
  448. im.bw = this._getZlGatherBw(node, peg);
  449. im.xm = '';
  450. im.drawing_code = this._getDrawingCode(node);
  451. } else {
  452. im.check = false;
  453. im.bw = this._getZlNormalBw(node, peg);
  454. im.xm = node.name;
  455. im.drawing_code = this._getDrawingCode(p);
  456. }
  457. nodeImData.push(im);
  458. this._checkCustomDetail(im);
  459. this.ImData.push(im);
  460. }
  461. if (!this.ctx.stage.im_gather || !node.check) {
  462. this._generateZlLeafXmjData(p, im, 'gather_qty');
  463. }
  464. this._generateZlChangeData(p, im);
  465. im.jl = this.ctx.helper.add(im.jl, p.gather_qty);
  466. im.contract_jl = this.ctx.helper.add(im.contract_jl, p.contract_qty);
  467. im.qc_jl = this.ctx.helper.add(im.qc_jl, p.qc_qty);
  468. }
  469. }
  470. _generateBwImData (node) {
  471. const posterity = this.billsTree.getPosterity(node);
  472. for (const p of posterity) {
  473. if (p.children && p.children.length > 0 ) { continue; }
  474. if (!p.b_code || p.b_code === '') { continue }
  475. const peg = this._getPegNode(node);
  476. const pPos = this.pos.getLedgerPos(p.id);
  477. const bw = this._getZlNormalBw(node, peg);
  478. if (pPos && pPos.length > 0) {
  479. for (const pp of pPos) {
  480. if (this.ctx.helper.checkZero(pp.contract_qty) && this.ctx.helper.checkZero(pp.qc_qty)) { continue }
  481. const im = {
  482. id: this.ImData.length + 1,
  483. lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, pid: pp.id,
  484. jl: pp.gather_qty, contract_jl: pp.contract_qty, qc_jl: pp.qc_qty,
  485. bw: bw,
  486. peg: this._checkPeg(pp.name) ? this._getPegStr(pp.name) : (peg ? this._getPegStr(peg.name) : ''),
  487. xm: pp.name,
  488. drawing_code: pp.drawing_code,
  489. changes: [],
  490. };
  491. im.calc_memo = '本期计量:' + im.jl + ' ' + im.unit;
  492. this._checkCustomDetail(im);
  493. this.ImData.push(im);
  494. if (pp.qc_qty && pp.qc_qty !== 0) {
  495. for (const c of this.changes) {
  496. if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
  497. im.changes.push(c);
  498. }
  499. }
  500. }
  501. }
  502. } else {
  503. if (this.ctx.helper.checkZero(p.contract_qty) && this.ctx.helper.checkZero(p.qc_qty)) { continue }
  504. const im = {
  505. id: this.ImData.length + 1,
  506. lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, pid: '',
  507. jl: p.gather_qty, contract_jl: p.contract_qty, qc_jl: p.qc_qty,
  508. bw: bw,
  509. peg: peg ? this._getPegStr(peg.name) : '',
  510. xm: node.name,
  511. drawing_code: this._getDrawingCode(node),
  512. changes: [],
  513. };
  514. im.calc_memo = '本期计量:' + im.jl + ' ' + im.unit;
  515. this._checkCustomDetail(im);
  516. this.ImData.push(im);
  517. if (p.qc_qty && p.qc_qty !== 0) {
  518. for (const c of this.changes) {
  519. if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
  520. im.changes.push(c);
  521. }
  522. }
  523. }
  524. }
  525. }
  526. }
  527. /**
  528. * 递归 生成中间计量表
  529. * @param {Array} nodes
  530. */
  531. _recursiveBuildImData (nodes) {
  532. if (!nodes || nodes.length === 0) { return; }
  533. for (const node of nodes) {
  534. if (this.billsTree.isLeafXmj(node) || (this.ctx.stage.im_type !== imType.bw.value && this.ctx.stage.im_gather && node.check)) {
  535. if (this.ctx.stage.im_type === imType.tz.value) {
  536. this._generateTzImData(node);
  537. } else if (this.ctx.stage.im_type === imType.zl.value) {
  538. this._generateZlImData(node);
  539. } else if (this.ctx.stage.im_type === imType.bw.value) {
  540. this._generateBwImData(node);
  541. }
  542. } else {
  543. this._recursiveBuildImData(node.children);
  544. }
  545. }
  546. }
  547. // 生成中间计量数据
  548. async buildImData () {
  549. const self = this;
  550. // 初始化
  551. await this._loadMainData();
  552. await this._loadRelaData();
  553. if (this.ctx.stage.im_gather) {
  554. this._checkGather();
  555. }
  556. // 生成数据
  557. this._recursiveBuildImData(this.billsTree.children);
  558. // 排序
  559. if (this.ctx.stage.im_type !== imType.tz.value) {
  560. this.ImData.sort(function (x, y) {
  561. return self.ctx.helper.compareCode(x.code, y.code);
  562. });
  563. }
  564. // 生成数据(需要缓存,并清理缓存)
  565. const pre = (this.ctx.stage.im_pre && this.ctx.stage.im_pre !== '') ? this.ctx.stage.im_pre + splitChar : '';
  566. for (const [i, im] of this.ImData.entries()) {
  567. im.im_code = pre + this._getNumberFormat(this.ctx.stage.order, 2) + this.splitChar + this._getNumberFormat(i + 1, 3);
  568. if (im.gclBills) {
  569. for (const b of im.gclBills) {
  570. b.im_code = im.im_code;
  571. }
  572. }
  573. this._getCalcMemo(im);
  574. delete im.leafXmjs;
  575. delete im.gclBills;
  576. this._getChangeInfo(im);
  577. delete im.changes;
  578. }
  579. }
  580. // 生成中间计量汇总数据
  581. async buildImGatherData () {
  582. this._loadMainData();
  583. if (stage.im_gather) {
  584. this._checkGather();
  585. }
  586. }
  587. }
  588. module.exports = StageIm;