exponent_modal.ejs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <% if (!ctx.material.readOnly) { %>
  2. <!--新增分项价格指数-->
  3. <div class="modal fade" id="choose2" data-backdrop="static">
  4. <div class="modal-dialog modal-lg" role="document">
  5. <div class="modal-content">
  6. <div class="modal-header">
  7. <h5 class="modal-title">新增分项价格指数</h5>
  8. </div>
  9. <div class="modal-body">
  10. <!-- <div class="custom-control custom-checkbox mb-2">-->
  11. <!-- <input type="checkbox" class="custom-control-input" id="im-gather-check">-->
  12. <!-- <label class="custom-control-label" for="im-gather-check">汇总计量节点</label>-->
  13. <!-- </div>-->
  14. <div class="d-inline-block mb-2">
  15. <div class="dropdown">
  16. <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  17. <i class="fa fa-list-ol"></i> 显示层级
  18. </button>
  19. <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
  20. <a class="dropdown-item" name="showLevel" tag="1" href="javascript: void(0);">第一层</a>
  21. <a class="dropdown-item" name="showLevel" tag="2" href="javascript: void(0);">第二层</a>
  22. <a class="dropdown-item" name="showLevel" tag="3" href="javascript: void(0);">第三层</a>
  23. <a class="dropdown-item" name="showLevel" tag="4" href="javascript: void(0);">第四层</a>
  24. <a class="dropdown-item" name="showLevel" tag="5" href="javascript: void(0);">第五层</a>
  25. <a class="dropdown-item" name="showLevel" tag="last" href="javascript: void(0);">最底层</a>
  26. <a class="dropdown-item" name="showLevel" tag="leafXmj" href="javascript: void(0);">只显示项目节</a>
  27. </div>
  28. </div>
  29. </div>
  30. <div class="modal-height-500" id="gather-spread">
  31. </div>
  32. <div class="popover bs-popover-right" role="tooltip" id="gather-confirm" style="display: none">
  33. <div class="arrow" style="top:30px"></div>
  34. <div class="popover-body">
  35. <p id="gather-confirm-hint">父项已勾选,继续将取消父项勾选。</p>
  36. <p class="mb-0 d-flex justify-content-end" id="gather-confirm-btn">
  37. <button class="btn btn-sm btn-secondary" id="gather-confirm-cancel">取消</button>&nbsp;<button class="btn btn-sm btn-success" id="gather-confirm-ok">继续</button>
  38. </p>
  39. </div>
  40. </div>
  41. <div class="popover bs-popover-right" role="tooltip" id="gather-tip" style="display: none">
  42. <style>
  43. #gather-tip>.arrow::after {
  44. border-right-color: #ffc107;
  45. }
  46. </style>
  47. <div class="arrow" style="top:6px"></div>
  48. <div class="popover-body bg-warning">
  49. <span id="gather-tip-hint">父项已勾选,继续将取消父项勾选。</span>
  50. </div>
  51. </div>
  52. </div>
  53. <div class="modal-footer">
  54. <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
  55. <% if (!ctx.material.readOnly && ctx.material.user_id === ctx.session.sessionUser.accountId) { %>
  56. <button type="button" class="btn btn-primary btn-sm" id="choose2-ok">确定</button>
  57. <% } %>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <script>
  63. const pre_nodes = JSON.parse(unescape('<%- escape(JSON.stringify(ctx.material.pre_exponent_node)) %>'));
  64. $(function () {
  65. const gatherConfirmPopover = {
  66. reBind: function (obj, eventName, fun) {
  67. obj.unbind(eventName);
  68. obj.bind(eventName, fun);
  69. },
  70. check: function (pos, hint, okCallback) {
  71. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  72. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  73. this.reBind(cancelObj, 'click', function () {
  74. confirmObj.hide();
  75. });
  76. this.reBind(okObj, 'click', function () {
  77. okCallback();
  78. confirmObj.hide();
  79. });
  80. hintObj.text(hint);
  81. confirmObj.css("top", pos.y).css("left", pos.x).show();
  82. },
  83. showTip: function (pos, hint) {
  84. const confirmObj = $('#gather-tip'), hintObj = $('#gather-tip-hint');
  85. hintObj.text(hint);
  86. confirmObj.css("top", pos.y).css("left", pos.x).show();
  87. setTimeout(function () {
  88. confirmObj.hide();
  89. }, 2000);
  90. }
  91. };
  92. let gsSpread = null;
  93. const gsTreeSetting = {
  94. id: 'ledger_id',
  95. pid: 'ledger_pid',
  96. order: 'order',
  97. level: 'level',
  98. rootId: -1,
  99. keys: ['id', 'tender_id', 'ledger_id'],
  100. stageId: 'id',
  101. };
  102. gsTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty'];
  103. gsTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp'];
  104. // gsTreeSetting.updateFields = [];
  105. // gsTreeSetting.calcFields = [];
  106. if (isStageSelf) {
  107. for (const ms of materialStageData) {
  108. gsTreeSetting.updateFields.push(ms.sid + '_contract_qty', ms.sid + '_contract_tp',
  109. ms.sid + '_qc_qty', ms.sid + '_qc_tp', ms.sid + '_qc_minus_qty');
  110. gsTreeSetting.calcFields.push(ms.sid + '_deal_tp', ms.sid + '_total_price', ms.sid + '_contract_tp',
  111. ms.sid + '_qc_tp', ms.sid + '_gather_tp',
  112. ms.sid + '_contract_pc_tp', ms.sid + '_qc_pc_tp', ms.sid + '_pc_tp');
  113. }
  114. }
  115. // else {
  116. // gsTreeSetting.updateFields.push(materialSids + '_contract_qty', materialSids + '_contract_tp',
  117. // materialSids + '_qc_qty', materialSids + '_qc_tp', materialSids + '_qc_minus_qty');
  118. // gsTreeSetting.calcFields.push(materialSids + '_deal_tp', materialSids + '_total_price', materialSids + '_contract_tp',
  119. // materialSids + '_qc_tp', materialSids + '_gather_tp',
  120. // materialSids + '_contract_pc_tp', materialSids + '_qc_pc_tp', materialSids + '_pc_tp');
  121. // }
  122. gsTreeSetting.calcFun = function (node) {
  123. if (node.children && node.children.length === 0) {
  124. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  125. if (isStageSelf) {
  126. for (const ms of materialStageData) {
  127. node[ms.sid + '_gather_qty'] = ZhCalc.add(node[ms.sid + '_contract_qty'], node[ms.sid + '_qc_qty']);
  128. }
  129. }
  130. }
  131. node.gather_tp = ZhCalc.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
  132. if (isStageSelf) {
  133. for (const ms of materialStageData) {
  134. node[ms.sid + '_gather_tp'] = ZhCalc.sum([node[ms.sid + '_contract_tp'], node[ms.sid + '_qc_tp'], node[ms.sid + '_pc_tp']]);
  135. }
  136. }
  137. };
  138. const gsTree = createNewPathTree('stage', gsTreeSetting);
  139. // 显示树结构信息
  140. $('#choose2').on('shown.bs.modal', function () {
  141. if (!gsSpread) {
  142. postData(window.location.pathname + '/save', {type: 'load', filter: 'ledger'}, function (result) {
  143. gsTree.loadDatas(result.ledgerData);
  144. treeCalc.calculateAll(gsTree);
  145. gsSpread = SpreadJsObj.createNewSpread($('#gather-spread')[0]);
  146. const setting = {
  147. cols: [
  148. {title: '', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  149. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  150. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  151. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  152. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  153. ],
  154. headRows: 1,
  155. emptyRows: 0,
  156. headRowHeight: [32],
  157. defaultRowHeight: 21,
  158. headerFont: '12px 微软雅黑',
  159. font: '12px 微软雅黑',
  160. };
  161. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  162. SpreadJsObj.initSheet(gsSpread.getActiveSheet(), setting);
  163. gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  164. function checkParent(node, field = 'check') {
  165. const parent = gsTree.getParent(node);
  166. if (parent) {
  167. return parent[field] ? parent[field] : checkParent(parent, field);
  168. } else {
  169. return false;
  170. }
  171. }
  172. function checkChildren(node, field = 'check') {
  173. for (const child of node.children) {
  174. if (child[field]) {
  175. return true;
  176. } else if (checkChildren(child, field)) {
  177. return true;
  178. }
  179. }
  180. return false;
  181. }
  182. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  183. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  184. if (sheet.isEditing()) {
  185. sheet.endEdit(true);
  186. }
  187. }
  188. if (info.sheet.zh_setting) {
  189. const col = info.sheet.zh_setting.cols[info.col];
  190. if (col.field !== 'check') {
  191. return;
  192. }
  193. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  194. const node = sortData[info.row];
  195. if (!node.check) {
  196. if (checkParent(node, 'pre_check')) {
  197. const rect = info.sheet.getCellRect(info.row, info.col);
  198. gatherConfirmPopover.showTip({
  199. x: rect.x + rect.width / 2 + 25,
  200. y: rect.y + rect.height / 2 + 27,
  201. }, '该项的父项上期已勾选调用,无法勾选该项。');
  202. SpreadJsObj.reLoadRowsData(info.sheet, [gsTree.nodes.indexOf(node)]);
  203. return;
  204. }
  205. if (checkChildren(node, 'pre_check')) {
  206. const rect = info.sheet.getCellRect(info.row, info.col);
  207. gatherConfirmPopover.showTip({
  208. x: rect.x + rect.width / 2 + 25,
  209. y: rect.y + rect.height / 2 + 27,
  210. }, '该项的子项上期已勾选调用,无法勾选该项。');
  211. SpreadJsObj.reLoadRowsData(info.sheet, [gsTree.nodes.indexOf(node)]);
  212. return;
  213. }
  214. if (checkParent(node)) {
  215. const rect = info.sheet.getCellRect(info.row, info.col);
  216. gatherConfirmPopover.check({
  217. x: rect.x + rect.width / 2 + 25,
  218. y: rect.y + rect.height / 2 + 3,
  219. }, '父项已勾选,继续将取消父项勾选。', function () {
  220. node.check = true;
  221. const parents = gsTree.getFullPathNodes(gsTree.getParent(node).full_path);
  222. const rows = [gsTree.nodes.indexOf(node)];
  223. for (const p of parents) {
  224. if (p.check) {
  225. p.check = false;
  226. rows.push(gsTree.nodes.indexOf(p));
  227. }
  228. }
  229. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  230. });
  231. } else if (checkChildren(node)) {
  232. const rect = info.sheet.getCellRect(info.row, info.col);
  233. gatherConfirmPopover.check({
  234. x: rect.x + rect.width / 2 + 25,
  235. y: rect.y + rect.height / 2 + 3,
  236. }, '子项已勾选,继续将取消子项勾选。', function () {
  237. node.check = true;
  238. const posterity = gsTree.getPosterity(node);
  239. const rows = [gsTree.nodes.indexOf(node)];
  240. for (const p of posterity) {
  241. if (p.check) {
  242. rows.push(gsTree.nodes.indexOf(p));
  243. p.check = false;
  244. }
  245. }
  246. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  247. });
  248. } else {
  249. node.check = true;
  250. SpreadJsObj.reLoadRowsData(info.sheet, [gsTree.nodes.indexOf(node)]);
  251. }
  252. } else {
  253. if (node.pre_check) {
  254. const rect = info.sheet.getCellRect(info.row, info.col);
  255. gatherConfirmPopover.showTip({
  256. x: rect.x + rect.width / 2 + 25,
  257. y: rect.y + rect.height / 2 + 27,
  258. }, '该项上期已勾选调用,无法去除勾选。');
  259. SpreadJsObj.reLoadRowsData(info.sheet, [gsTree.nodes.indexOf(node)]);
  260. return;
  261. }
  262. node.check = false;
  263. SpreadJsObj.reLoadRowsData(info.sheet, [gsTree.nodes.indexOf(node)]);
  264. }
  265. }
  266. });
  267. const pre_gatherNodes = pre_nodes ? _.map(pre_nodes.split(',')) : [];
  268. const gatherNodes = exponent_nodes ? _.map(exponent_nodes.split(',')) : [];
  269. for (const node of gsTree.datas) {
  270. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  271. node.pre_check = pre_gatherNodes.indexOf(node.id + '') !== -1;
  272. }
  273. SpreadJsObj.loadSheetData(gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, gsTree);
  274. console.log(gsTree);
  275. gsTree.expandByLevel(4);
  276. SpreadJsObj.refreshTreeRowVisible(gsSpread.getActiveSheet());
  277. // SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  278. (function (select, sheet) {
  279. $(select).click(function () {
  280. if (!sheet.zh_tree) return;
  281. const tag = $(this).attr('tag');
  282. const tree = sheet.zh_tree;
  283. setTimeout(() => {
  284. showWaitingView();
  285. switch (tag) {
  286. case "1":
  287. case "2":
  288. case "3":
  289. case "4":
  290. case "5":
  291. tree.expandByLevel(parseInt(tag));
  292. SpreadJsObj.refreshTreeRowVisible(sheet);
  293. break;
  294. case "last":
  295. tree.expandByCustom(() => { return true; });
  296. SpreadJsObj.refreshTreeRowVisible(sheet);
  297. break;
  298. case "leafXmj":
  299. tree.expandToLeafXmj();
  300. SpreadJsObj.refreshTreeRowVisible(sheet);
  301. break;
  302. }
  303. closeWaitingView();
  304. }, 100);
  305. });
  306. })('a[name=showLevel]', gsSpread.getActiveSheet());
  307. });
  308. } else {
  309. const gatherNodes = exponent_nodes ? _.map(exponent_nodes.split(',')) : [];
  310. const pre_gatherNodes = pre_nodes ? _.map(pre_nodes.split(',')) : [];
  311. for (const node of gsTree.datas) {
  312. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  313. node.pre_check = pre_gatherNodes.indexOf(node.id + '') !== -1;
  314. }
  315. SpreadJsObj.reLoadColsData(gsSpread.getActiveSheet(), [0]);
  316. }
  317. });
  318. // 提交 高级设置
  319. $('#choose2-ok').click(() => {
  320. if (!gsTree) { return; }
  321. const nodes = [];
  322. for (const node of gsTree.nodes) {
  323. if (node.check) {
  324. nodes.push(node);
  325. }
  326. }
  327. // 和exponent_nodes对比新增和移除,新增的告诉后台,比得出最新标段(不含新增分项)这条数据的调差基数
  328. const nodeData = [];
  329. const tpData = {};
  330. if (showStageExponent) {
  331. for (const ms of materialStageData) {
  332. tpData[ms.sid + '_tp'] = {
  333. contract_tp: 0,
  334. qc_tp: 0,
  335. gather_tp: 0,
  336. };
  337. }
  338. } else {
  339. tpData['all'] = {
  340. contract_tp: 0,
  341. qc_tp: 0,
  342. gather_tp: 0,
  343. };
  344. }
  345. const gatherNodes = exponent_nodes ? _.map(exponent_nodes.split(',')) : [];
  346. const pre_gatherNodes = pre_nodes ? _.map(pre_nodes.split(',')) : [];
  347. const newNodes = _.map(nodes, 'id');
  348. console.log(gatherNodes, newNodes);
  349. if (_.isEqual(_.sortBy(gatherNodes), _.sortBy(newNodes))) {
  350. toastr.warning('未做任何修改');
  351. return;
  352. }
  353. // 比较nodes和gatherNodes得出新增和移除的
  354. const delNodes = _.difference(gatherNodes, newNodes);
  355. const addNodes = _.difference(newNodes, gatherNodes);
  356. for (const node of nodes) {
  357. const isAdd = addNodes.indexOf(node.id + '') !== -1;
  358. if (showStageExponent) {
  359. for (const ms of materialStageData) {
  360. const key = ms.sid + '_tp';
  361. tpData[key].contract_tp = ZhCalc.add(tpData[key].contract_tp, node[ms.sid + '_contract_tp'] || 0);
  362. tpData[key].qc_tp = ZhCalc.add(tpData[key].qc_tp, node[ms.sid + '_qc_tp'] || 0);
  363. tpData[key].gather_tp = ZhCalc.add(tpData[key].gather_tp, node[ms.sid + '_gather_tp'] || 0);
  364. if (isAdd) {
  365. nodeData.push({
  366. code: node.code || node.b_code,
  367. node: node.id,
  368. name: node.name,
  369. ms_id: ms.id,
  370. contract_tp: node[ms.sid + '_contract_tp'] || 0,
  371. qc_tp: node[ms.sid + '_qc_tp'] || 0,
  372. gather_tp: node[ms.sid + '_gather_tp'] || 0,
  373. ex_calc: setExCalc(exponent_nodes ? null : _.find(ex_calcList, {ms_id: ms.id}).ex_calc, node[ms.sid + '_contract_tp'], node[ms.sid + '_qc_tp'], node[ms.sid + '_gather_tp']),
  374. });
  375. }
  376. }
  377. } else {
  378. const key = 'all';
  379. tpData[key].contract_tp = ZhCalc.add(tpData[key].contract_tp, node.contract_tp || 0);
  380. tpData[key].qc_tp = ZhCalc.add(tpData[key].qc_tp, node.qc_tp || 0);
  381. tpData[key].gather_tp = ZhCalc.add(tpData[key].gather_tp, node.gather_tp || 0);
  382. if (isAdd) {
  383. nodeData.push({
  384. code: node.code || node.b_code,
  385. node: node.id,
  386. name: node.name,
  387. ms_id: null,
  388. contract_tp: node.contract_tp || 0,
  389. qc_tp: node.qc_tp || 0,
  390. gather_tp: node.gather_tp || 0,
  391. ex_calc: setExCalc(exponent_nodes ? null : ex_calc, node.contract_tp, node.qc_tp, node.gather_tp),
  392. });
  393. }
  394. }
  395. }
  396. // 标段(不含新增分项)调差基数数据更新或新增
  397. const baseNodes = _.filter(materialExponentNodeData, { name: '标段', node: '-1' });
  398. // 总金额 - tpData 里金额就是不含新增分项金额,先获取总金额
  399. const totalTp = {};
  400. for (const node of gsTree.children) {
  401. if (showStageExponent) {
  402. for (const ms of materialStageData) {
  403. const key = ms.sid + '_tp';
  404. if (!totalTp[key]) {
  405. totalTp[key] = {
  406. contract_tp: 0,
  407. qc_tp: 0,
  408. gather_tp: 0,
  409. };
  410. }
  411. totalTp[key].contract_tp = ZhCalc.add(totalTp[key].contract_tp, node[ms.sid + '_contract_tp'] || 0);
  412. totalTp[key].qc_tp = ZhCalc.add(totalTp[key].qc_tp, node[ms.sid + '_qc_tp'] || 0);
  413. totalTp[key].gather_tp = ZhCalc.add(totalTp[key].gather_tp, node[ms.sid + '_gather_tp'] || 0);
  414. }
  415. } else {
  416. const key = 'all';
  417. if (!totalTp[key]) {
  418. totalTp[key] = {
  419. contract_tp: 0,
  420. qc_tp: 0,
  421. gather_tp: 0,
  422. };
  423. }
  424. totalTp[key].contract_tp = ZhCalc.add(totalTp[key].contract_tp, node.contract_tp || 0);
  425. totalTp[key].qc_tp = ZhCalc.add(totalTp[key].qc_tp, node.qc_tp || 0);
  426. totalTp[key].gather_tp = ZhCalc.add(totalTp[key].gather_tp, node.gather_tp || 0);
  427. }
  428. }
  429. if (showStageExponent) {
  430. for (const ms of materialStageData) {
  431. const node_tp = newNodes.length > 0 ? tpData[ms.sid + '_tp'] : { contract_tp: 0, qc_tp: 0, gather_tp: 0 };
  432. const total_tp = totalTp[ms.sid + '_tp'];
  433. const contract_tp = ZhCalc.sub(total_tp.contract_tp, node_tp.contract_tp);
  434. const qc_tp = ZhCalc.sub(total_tp.qc_tp, node_tp.qc_tp);
  435. const gather_tp = ZhCalc.sub(total_tp.gather_tp, node_tp.gather_tp);
  436. const baseSid = _.find(baseNodes, { ms_id: ms.id });
  437. if (baseSid) {
  438. let ex_calc = null;
  439. if (exponent_nodes) {
  440. ex_calc = _.find(ex_calcList, { ms_id: ms.id, mn_id: baseSid.id }).ex_calc;
  441. } else {
  442. ex_calc = _.find(ex_calcList, { ms_id: ms.id }).ex_calc;
  443. }
  444. baseSid.contract_tp = contract_tp;
  445. baseSid.qc_tp = qc_tp;
  446. baseSid.gather_tp = gather_tp;
  447. baseSid.ex_calc = setExCalc(ex_calc, contract_tp, qc_tp, gather_tp);
  448. } else {
  449. baseNodes.push({
  450. code: '不含新增分项',
  451. name: '标段',
  452. node: '-1',
  453. ms_id: ms.id,
  454. ex_calc: setExCalc(exponent_nodes ? null : _.find(ex_calcList, { ms_id: ms.id }).ex_calc, contract_tp, qc_tp, gather_tp),
  455. contract_tp,
  456. qc_tp,
  457. gather_tp,
  458. });
  459. }
  460. }
  461. } else {
  462. const node_tp = newNodes.length > 0 ? tpData['all'] : { contract_tp: 0, qc_tp: 0, gather_tp: 0 };
  463. const total_tp = totalTp['all'];
  464. const contract_tp = ZhCalc.sub(total_tp.contract_tp, node_tp.contract_tp);
  465. const qc_tp = ZhCalc.sub(total_tp.qc_tp, node_tp.qc_tp);
  466. const gather_tp = ZhCalc.sub(total_tp.gather_tp, node_tp.gather_tp);
  467. if (baseNodes.length > 0) {
  468. baseNodes[0].contract_tp = contract_tp;
  469. baseNodes[0].qc_tp = qc_tp;
  470. baseNodes[0].gather_tp = gather_tp;
  471. baseNodes[0].ex_calc = setExCalc(baseNodes[0].ex_calc, contract_tp, qc_tp, gather_tp);
  472. } else {
  473. baseNodes.push({
  474. code: '不含新增分项',
  475. name: '标段',
  476. node: '-1',
  477. ms_id: null,
  478. ex_calc: setExCalc(ex_calc, contract_tp, qc_tp, gather_tp),
  479. contract_tp,
  480. qc_tp,
  481. gather_tp,
  482. });
  483. }
  484. }
  485. console.log(baseNodes, nodeData);
  486. postData(window.location.pathname + '/save', { type:'update_node', updateData: { baseNodes, addNodes: nodeData, delNodes, exponent_node: newNodes } }, function (result) {
  487. window.location.reload();
  488. });
  489. });
  490. function setExCalc(old_ex_calc, contract_tp, qc_tp, gather_tp) {
  491. const insert_ex_calc = [
  492. {
  493. code: 'bqht',
  494. text: '所选分项合同计量金额',
  495. value: contract_tp || 0,
  496. select: false,
  497. },
  498. {
  499. code: 'bqbg',
  500. text: '所选分项变更计量金额',
  501. value: qc_tp || 0,
  502. select: false,
  503. },
  504. {
  505. code: 'bqwc',
  506. text: '所选分项完成计量金额',
  507. value: gather_tp || 0,
  508. select: true,
  509. },
  510. {
  511. code: 'zdy',
  512. text: '自定义金额',
  513. value: gather_tp || 0,
  514. result: '',
  515. select: false,
  516. },
  517. ];
  518. const gatherNodes = exponent_nodes ? _.map(exponent_nodes.split(',')) : [];
  519. if (gatherNodes.length !== 0) {
  520. // 判断是否更新new_ex_calc的select为true值
  521. const selectItem = _.find(old_ex_calc, { select: true });
  522. if (selectItem) {
  523. const set_selectItem = _.find(insert_ex_calc, { code: selectItem.code });
  524. if (set_selectItem && !set_selectItem.select) {
  525. const oldSelectItem = _.find(insert_ex_calc, { select: true });
  526. if (oldSelectItem) {
  527. oldSelectItem.select = false;
  528. }
  529. set_selectItem.select = true;
  530. }
  531. }
  532. // 自定义金额要赋值
  533. if (old_ex_calc) {
  534. const zdyItem = _.find(old_ex_calc, { code: 'zdy' });
  535. if (zdyItem) {
  536. const insertZdyItem = _.find(insert_ex_calc, { code: 'zdy' });
  537. if (zdyItem.result) {
  538. insertZdyItem.result = zdyItem.result;
  539. insertZdyItem.value = zdyItem.value;
  540. }
  541. }
  542. }
  543. }
  544. return insert_ex_calc;
  545. }
  546. });
  547. </script>
  548. <% } %>
  549. <% include ./audit_modal.ejs %>