settle_select.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. function getGxbyText(data) {
  2. const def = thirdParty.gxby.find(function (x) {
  3. return x.value === data.gxby_status;
  4. });
  5. return def ? def.name : '';
  6. }
  7. function getDaglText(data) {
  8. const def = thirdParty.dagl.find(function (x) {
  9. return x.value === data.dagl_status;
  10. });
  11. return def ? def.name : '';
  12. }
  13. const ckBillsSpread = window.location.pathname + '-billsSelect';
  14. $(document).ready(() => {
  15. autoFlashHeight();
  16. let searchLedger;
  17. const settleTreeSetting = {
  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. autoExpand: 3,
  26. markExpandKey: 'settle-select-expand',
  27. markExpandSubKey: window.location.pathname.split('/')[2],
  28. calcFields: ['total_price', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'],
  29. calcFun: function(node) {
  30. if (!node.children || node.children.length === 0) {
  31. node.end_gather_qty = ZhCalc.add(node.end_contract_qty, node.end_qc_qty);
  32. if (node.end_contract_qty) {
  33. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  34. } else {
  35. node.end_correct_tp = node.end_gather_tp;
  36. }
  37. }
  38. node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
  39. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  40. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  41. }
  42. };
  43. const settleTree = createNewPathTree('stage', settleTreeSetting);
  44. const settlePosSetting = {
  45. id: 'id', ledgerId: 'lid',
  46. calcFun: function(pos) {
  47. pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty);
  48. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  49. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  50. }
  51. };
  52. const settlePos = new StagePosData(settlePosSetting);
  53. const slSpread = SpreadJsObj.createNewSpread($('#settle-bills')[0]);
  54. const slSheet = slSpread.getActiveSheet();
  55. slSheet.frozenColumnCount(billsSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
  56. slSheet.options.frozenlineColor = '#93b5e4';
  57. const ratioCol = billsSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
  58. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
  59. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  60. if (!data) return defaultColor;
  61. if (data.children && data.children.length > 0) return defaultColor;
  62. if (col.field === 'gxby') {
  63. const def = thirdParty.gxby.find(function (x) {
  64. return x.value === data.gxby_status;
  65. });
  66. if (def && def.color) return def.color;
  67. } else if (col.field === 'dagl') {
  68. const def = thirdParty.dagl.find(function (x) {
  69. return x.value === data.dagl_status;
  70. });
  71. if (def && def.color) return def.color;
  72. }
  73. };
  74. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  75. sjsSettingObj.set3FCols(billsSpreadSetting.cols, [
  76. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  77. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  78. ]);
  79. SpreadJsObj.initSheet(slSheet, billsSpreadSetting);
  80. const spSpread = SpreadJsObj.createNewSpread($('#settle-pos')[0]);
  81. const spSheet = spSpread.getActiveSheet();
  82. spSheet.frozenColumnCount(posSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
  83. spSheet.options.frozenlineColor = '#93b5e4';
  84. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  85. if (!data) return defaultColor;
  86. if (col.field === 'gxby') {
  87. const def = thirdParty.gxby.find(function (x) {
  88. return x.value === data.gxby_status;
  89. });
  90. if (def && def.color) return def.color;
  91. } else if (col.field === 'dagl') {
  92. const def = thirdParty.dagl.find(function (x) {
  93. return x.value === data.dagl_status;
  94. });
  95. if (def && def.color) return def.color;
  96. }
  97. };
  98. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  99. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  100. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  101. ]);
  102. SpreadJsObj.initSheet(spSheet, posSpreadSetting);
  103. const settleCheck = {
  104. _analysisPos(pos) {
  105. pos.undoneDeal = pos.quantity ? !checkZero(ZhCalc.sub(pos.end_contract_qty, pos.quantity)) : false;
  106. pos.undone = !!pos.undoneDeal || !!pos.undoneChange;
  107. },
  108. _analysisNode(node) {
  109. if (node.undoneDeal === undefined) node.undoneDeal = false;
  110. if (node.undoneChange === undefined) node.undoneChange = false;
  111. if (node.children && node.children.length > 0) {
  112. for (const child of node.children) {
  113. this._analysisNode(child);
  114. if (child.undoneDeal) node.undoneDeal = true;
  115. if (child.undoneChange) node.undoneChange = true;
  116. }
  117. node.undone = !!node.undoneDeal || !!node.undoneChange;
  118. } else {
  119. const posRange = settlePos.getLedgerPos(node.id);
  120. if (posRange && posRange.length > 0) {
  121. for (const pos of posRange) {
  122. this._analysisPos(pos);
  123. if (pos.undoneDeal) node.undoneDeal = true;
  124. if (pos.undoneChange) node.undoneChange = true;
  125. }
  126. node.undone = !!node.undoneDeal || !!node.undoneChange;
  127. } else {
  128. node.undoneDeal = node.end_contract_qty
  129. ? !checkZero(ZhCalc.sub(node.end_contract_qty, node.quantity))
  130. : !checkZero(ZhCalc.sub(node.end_contract_tp, node.total_price));
  131. node.undone = !!node.undoneDeal || !!node.undoneChange;
  132. }
  133. }
  134. },
  135. init() {
  136. for (const node of settleTree.children) {
  137. this._analysisNode(node);
  138. }
  139. }
  140. };
  141. const settleBillsObj = {
  142. loadRelaData: function() {
  143. SpreadJsObj.saveTopAndSelect(slSheet, ckBillsSpread);
  144. SpreadJsObj.resetTopAndSelect(spSheet);
  145. settlePosObj.loadCurPosData();
  146. },
  147. selectionChanged: function(e, info) {
  148. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  149. settleBillsObj.loadRelaData();
  150. }
  151. },
  152. topRowChanged(e, info) {
  153. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  154. },
  155. buttonClicked: function(e, info) {
  156. if (!info.sheet.zh_setting) return;
  157. const col = info.sheet.zh_setting.cols[info.col];
  158. if (col.field !== 'selected') return;
  159. const node = SpreadJsObj.getSelectObject(info.sheet);
  160. if (node.undone && !node.selected) {
  161. let msg = '选择的节点不可结算';
  162. if (node.undoneDeal) msg = msg + ',合同未计量完';
  163. if (node.undoneChange) msg = msg + ',变更令未调用完';
  164. toastr.warning(msg);
  165. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  166. return;
  167. }
  168. if (!node.selected) {
  169. const parents = settleTree.getAllParents(node);
  170. for (const p of parents) {
  171. if (p.selected) {
  172. toastr.warning(`父项${p.code || ''}以勾选,勿需重复勾选子项`);
  173. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  174. return;
  175. }
  176. }
  177. }
  178. const update = {};
  179. if (!node.selected) {
  180. update.add = [{ lid: node.id }];
  181. const posterity = settleTree.getPosterity(node);
  182. for (const p of posterity) {
  183. if (p.selected) {
  184. if (!update.del) update.del = [];
  185. update.del.push({ lid: node.id });
  186. }
  187. if (!p.children || p.children.length === 0) {
  188. const posRange = settlePos.getLedgerPos(p.id);
  189. if (posRange && posRange.length > 0) {
  190. for (const p of posRange) {
  191. if (p.selected) {
  192. if (!update.del) update.del = [];
  193. update.del.push({ pid: p.id });
  194. }
  195. }
  196. }
  197. }
  198. }
  199. } else {
  200. update.del = [{ lid: node.id }];
  201. }
  202. postData(window.location.pathname + '/update', update, result => {
  203. node.selected = !node.selected;
  204. if (result.del) {
  205. let refreshRow = [], refreshPos = false;
  206. for (const d of result.del) {
  207. if (d.lid) {
  208. const sbi = settleTree.nodes.findIndex(x => { return x.id === d.lid; });
  209. settleTree.nodes[sbi].selected = false;
  210. refreshRow.push(sbi);
  211. } else if (d.pid) {
  212. const sp = settlePos.getPos(d.pid);
  213. if (sp) {
  214. sp.selected = false;
  215. if (sp.lid === node.id) refreshPos = false;
  216. }
  217. }
  218. }
  219. if (refreshRow.length > 0) SpreadJsObj.reLoadRowsData(info.sheet, refreshRow);
  220. if (refreshPos) settlePosObj.loadCurPosData();
  221. }
  222. }, () => {
  223. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  224. });
  225. },
  226. };
  227. slSpread.bind(spreadNS.Events.SelectionChanged, settleBillsObj.selectionChanged);
  228. slSpread.bind(spreadNS.Events.TopRowChanged, settleBillsObj.topRowChanged);
  229. if (!readOnly) {
  230. slSpread.bind(spreadNS.Events.ButtonClicked, settleBillsObj.buttonClicked);
  231. }
  232. const settlePosObj = {
  233. loadCurPosData: function() {
  234. const billsNode = SpreadJsObj.getSelectObject(slSheet);
  235. if (billsNode) {
  236. spSheet.zh_setting.readOnly = readOnly;
  237. const posRange = settlePos.getLedgerPos(billsNode.id) || [];
  238. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly);
  239. if (posRange.length > 0) SpreadJsObj.locateData(spSheet, posRange[0]);
  240. } else {
  241. spSheet.zh_setting.readOnly = true;
  242. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, [], true);
  243. }
  244. },
  245. buttonClicked: function(e, info) {
  246. if (!info.sheet.zh_setting) return;
  247. const col = info.sheet.zh_setting.cols[info.col];
  248. if (col.field !== 'selected') return;
  249. const node = SpreadJsObj.getSelectObject(info.sheet);
  250. if (node.undone && !node.selected) {
  251. let msg = '选择的节点不可结算';
  252. if (node.undoneDeal) msg = msg + ',合同未计量完';
  253. if (node.undoneChange) msg = msg + ',变更令未调用完';
  254. toastr.warning(msg);
  255. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  256. return;
  257. }
  258. if (!node.selected) {
  259. const billsNode = settleTree.nodes.find(x => { return x.id === node.lid });
  260. const parents = settleTree.getAllParents(billsNode);
  261. for (const p of parents) {
  262. if (p.selected) {
  263. toastr.warning(`所属清单的父项${p.code || ''}以勾选,勿需重复勾选计量单元`);
  264. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  265. return;
  266. }
  267. }
  268. }
  269. const update = {};
  270. if (!node.selected) {
  271. update.add = [{ pid: node.id }];
  272. } else {
  273. update.del = [{ pid: node.id }];
  274. }
  275. postData(window.location.pathname + '/update', update, result => {
  276. node.selected = !node.selected;
  277. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  278. }, () => {
  279. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  280. });
  281. },
  282. };
  283. if (!readOnly) {
  284. spSpread.bind(spreadNS.Events.ButtonClicked, settlePosObj.buttonClicked);
  285. }
  286. postData('load', {filter: 'stageBills;stagePos;settleSelect;tag;settleChange'}, function(result) {
  287. for (const select of result.settleSelect) {
  288. if (select.pid) {
  289. const sp = result.stagePos.find(x => { return x.id === select.pid });
  290. if (sp) sp.selected = true;
  291. } else {
  292. const sb = result.stageBills.find(x => { return x.id === select.lid });
  293. if (sb) sb.selected = true;
  294. }
  295. }
  296. for (const change of result.settleChange) {
  297. const sb = result.stageBills.find(x => { return x.id === change.gcl_id });
  298. if (sb) sb.undoneChange = true;
  299. if (change.mx_id) {
  300. const sp = result.stagePos.find(x => { return x.id === change.mx_id });
  301. if (sp) sp.undoneChange = true;
  302. }
  303. }
  304. settleTree.loadDatas(result.stageBills);
  305. treeCalc.calculateAll(settleTree);
  306. settlePos.loadDatas(result.stagePos);
  307. settlePos.calculateAll();
  308. settleCheck.init();
  309. SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree);
  310. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  311. settlePosObj.loadCurPosData();
  312. });
  313. // 展开收起工具栏
  314. $('a', '.right-nav').bind('click', function () {
  315. const tab = $(this), tabPanel = $(tab.attr('content'));
  316. if (!tab.hasClass('active')) {
  317. $('a', '.side-menu').removeClass('active');
  318. $('.tab-content .tab-select-show').removeClass('active');
  319. tab.addClass('active');
  320. tabPanel.addClass('active');
  321. showSideTools(tab.hasClass('active'));
  322. if (tab.attr('content') === '#search' && !searchLedger) {
  323. searchLedger = $.billsSearch({
  324. selector: '#search',
  325. searchSpread: slSpread,
  326. searchOver: true,
  327. searchEmpty: true,
  328. resultSpreadSetting: {
  329. cols: [
  330. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  331. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  332. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  333. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  334. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  335. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  336. ],
  337. emptyRows: 0,
  338. headRows: 1,
  339. headRowHeight: [32],
  340. headColWidth: [30],
  341. defaultRowHeight: 21,
  342. headerFont: '12px 微软雅黑',
  343. font: '12px 微软雅黑',
  344. selectedBackColor: '#fffacd',
  345. readOnly: true,
  346. },
  347. afterLocated: function () {
  348. settlePosObj.loadCurPosData();
  349. },
  350. });
  351. searchLedger.spread.refresh();
  352. }
  353. } else {
  354. tab.removeClass('active');
  355. tabPanel.removeClass('active');
  356. showSideTools(tab.hasClass('active'));
  357. }
  358. slSpread.refresh();
  359. spSpread.refresh();
  360. });
  361. $.subMenu({
  362. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  363. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  364. key: 'menu.1.0.0',
  365. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  366. callback: function (info) {
  367. if (info.mini) {
  368. $('.panel-title').addClass('fluid');
  369. $('#sub-menu').removeClass('panel-sidebar');
  370. } else {
  371. $('.panel-title').removeClass('fluid');
  372. $('#sub-menu').addClass('panel-sidebar');
  373. }
  374. autoFlashHeight();
  375. }
  376. });
  377. // 加载上下窗口resizer
  378. $.divResizer({
  379. select: '#main-resize',
  380. callback: function () {
  381. slSpread.refresh();
  382. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  383. $(".sp-wrap").height(bcontent-30);
  384. spSpread.refresh();
  385. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  386. }
  387. });
  388. // 工具栏resizer
  389. $.divResizer({
  390. select: '#right-spr',
  391. callback: function () {
  392. slSpread.refresh();
  393. spSpread.refresh();
  394. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  395. }
  396. });
  397. // 显示层次
  398. (function (select, sheet) {
  399. $(select).click(function () {
  400. const tag = $(this).attr('tag');
  401. const tree = sheet.zh_tree;
  402. if (!tree) return;
  403. setTimeout(() => {
  404. showWaitingView();
  405. switch (tag) {
  406. case "1":
  407. case "2":
  408. case "3":
  409. case "4":
  410. case "5":
  411. tree.expandByLevel(parseInt(tag));
  412. SpreadJsObj.refreshTreeRowVisible(sheet);
  413. break;
  414. case "last":
  415. tree.expandByCustom(() => { return true; });
  416. SpreadJsObj.refreshTreeRowVisible(sheet);
  417. break;
  418. }
  419. closeWaitingView();
  420. }, 100);
  421. });
  422. })('a[name=showLevel]', slSheet);
  423. });