settle_select.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. // 0: 可结算,1: 合同未完成,2:
  104. const settleCheck = {
  105. _analysisPos(pos) {
  106. pos.undoneDeal = pos.quantity ? !checkZero(ZhCalc.div(pos.end_contract_qty, pos.quantity)) : false;
  107. pos.undone = pos.undoneDeal || pos.undoneChange;
  108. },
  109. _analysisNode(node) {
  110. if (node.undoneDeal === undefined) node.undoneDeal = false;
  111. if (node.undoneChange === undefined) node.undoneChange = false;
  112. if (node.children && node.children.length > 0) {
  113. for (const child of node.children) {
  114. this._analysisNode(child);
  115. if (child.undoneDeal) node.undoneDeal = true;
  116. if (child.undoneChange) node.undoneChange = true;
  117. }
  118. node.undone = !!node.undoneDeal || !!node.undoneChange;
  119. } else {
  120. const posRange = settlePos.getLedgerPos(node.id);
  121. if (posRange && posRange.length > 0) {
  122. for (const pos of posRange) {
  123. this._analysisPos(pos);
  124. if (pos.undoneDeal) node.undoneDeal = true;
  125. if (pos.undoneChange) node.undoneChange = true;
  126. }
  127. } else {
  128. node.undoneDeal = node.end_contract_qty ? !checkZero(ZhCalc.div(node.end_contract_qty, node.quantity)) : false;
  129. node.undone = !!node.undoneDeal || !!node.undoneChange;
  130. }
  131. }
  132. },
  133. init() {
  134. for (const node of settleTree.children) {
  135. this._analysisNode(node);
  136. }
  137. }
  138. };
  139. const settleBillsObj = {
  140. loadRelaData: function() {
  141. SpreadJsObj.saveTopAndSelect(slSheet, ckBillsSpread);
  142. SpreadJsObj.resetTopAndSelect(spSheet);
  143. settlePosObj.loadCurPosData();
  144. },
  145. selectionChanged: function(e, info) {
  146. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  147. settleBillsObj.loadRelaData();
  148. }
  149. },
  150. topRowChanged(e, info) {
  151. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  152. },
  153. buttonClicked: function(e, info) {
  154. if (!info.sheet.zh_setting) return;
  155. const col = info.sheet.zh_setting.cols[info.col];
  156. if (col.field !== 'selected') return;
  157. const node = SpreadJsObj.getSelectObject(info.sheet);
  158. if (node.undone && !node.selected) {
  159. let msg = '选择的节点不可结算';
  160. if (node.undoneDeal) msg = msg + ',合同未计量完';
  161. if (node.undoneChange) msg = msg + ',变更令未调用完';
  162. toastr.warning(msg);
  163. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  164. return;
  165. }
  166. if (!node.selected) {
  167. const parents = settleTree.getAllParents(node);
  168. for (const p of parents) {
  169. if (p.selected) {
  170. toastr.warning(`父项${p.code || ''}以勾选,勿需重复勾选子项`);
  171. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  172. return;
  173. }
  174. }
  175. }
  176. const update = {};
  177. if (!node.selected) {
  178. update.add = [{ lid: node.id }];
  179. const posterity = settleTree.getPosterity(node);
  180. for (const p of posterity) {
  181. if (p.selected) {
  182. if (!update.del) update.del = [];
  183. update.del.push({ lid: node.id });
  184. }
  185. if (!p.children || p.children.length === 0) {
  186. const posRange = settlePos.getLedgerPos(p.id);
  187. for (const p of posRange) {
  188. if (p.selected) {
  189. if (!update.del) update.del = [];
  190. update.del.push({ pid: p.id });
  191. }
  192. }
  193. }
  194. }
  195. } else {
  196. update.del = [{ lid: node.id }];
  197. }
  198. postData(window.location.pathname + '/update', update, result => {
  199. node.selected = !node.selected;
  200. if (result.del) {
  201. let refreshRow = [], refreshPos = false;
  202. for (const d of result.del) {
  203. if (d.lid) {
  204. const sbi = settleTree.nodes.findIndex(x => { return x.id === d.lid; });
  205. settleTree.nodes[sbi].selected = false;
  206. refreshRow.push(sbi);
  207. } else if (d.pid) {
  208. const sp = settlePos.getPos(d.pid);
  209. if (sp) {
  210. sp.selected = false;
  211. if (sp.lid === node.id) refreshPos = false;
  212. }
  213. }
  214. }
  215. if (refreshRow.length > 0) SpreadJsObj.reLoadRowsData(info.sheet, refreshRow);
  216. if (refreshPos) settlePosObj.loadCurPosData();
  217. }
  218. }, () => {
  219. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  220. });
  221. },
  222. };
  223. slSpread.bind(spreadNS.Events.SelectionChanged, settleBillsObj.selectionChanged);
  224. slSpread.bind(spreadNS.Events.TopRowChanged, settleBillsObj.topRowChanged);
  225. if (!readOnly) {
  226. slSpread.bind(spreadNS.Events.ButtonClicked, settleBillsObj.buttonClicked);
  227. }
  228. const settlePosObj = {
  229. loadCurPosData: function() {
  230. const billsNode = SpreadJsObj.getSelectObject(slSheet);
  231. if (billsNode) {
  232. spSheet.zh_setting.readOnly = readOnly;
  233. const posRange = settlePos.getLedgerPos(billsNode.id) || [];
  234. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly);
  235. if (posRange.length > 0) SpreadJsObj.locateData(spSheet, posRange[0]);
  236. } else {
  237. spSheet.zh_setting.readOnly = true;
  238. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, [], true);
  239. }
  240. },
  241. buttonClicked: function(e, info) {
  242. if (!info.sheet.zh_setting) return;
  243. const col = info.sheet.zh_setting.cols[info.col];
  244. if (col.field !== 'selected') return;
  245. const node = SpreadJsObj.getSelectObject(info.sheet);
  246. if (node.undone && !node.selected) {
  247. let msg = '选择的节点不可结算';
  248. if (node.undoneDeal) msg = msg + ',合同未计量完';
  249. if (node.undoneChange) msg = msg + ',变更令未调用完';
  250. toastr.warning(msg);
  251. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  252. return;
  253. }
  254. if (!node.selected) {
  255. const billsNode = settleTree.nodes.find(x => { return x.id === node.lid });
  256. const parents = settleTree.getAllParents(billsNode);
  257. for (const p of parents) {
  258. if (p.selected) {
  259. toastr.warning(`所属清单的父项${p.code || ''}以勾选,勿需重复勾选计量单元`);
  260. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  261. return;
  262. }
  263. }
  264. }
  265. const update = {};
  266. if (!node.selected) {
  267. update.add = [{ lid: node.id }];
  268. } else {
  269. update.del = [{ lid: node.id }];
  270. }
  271. postData(window.location.pathname + '/update', update, result => {
  272. node.selected = !node.selected;
  273. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  274. }, () => {
  275. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  276. });
  277. },
  278. };
  279. if (!readOnly) {
  280. spSpread.bind(spreadNS.Events.ButtonClicked, settlePosObj.buttonClicked);
  281. }
  282. postData('load', {filter: 'stageBills;stagePos;settleSelect;tag;settleChange'}, function(result) {
  283. for (const select of result.settleSelect) {
  284. if (select.pid) {
  285. const sp = result.stagePos.find(x => { return x.id === select.pid });
  286. if (sp) sp.selected = true;
  287. } else {
  288. const sb = result.stageBills.find(x => { return x.id === select.lid });
  289. if (sb) sb.selected = true;
  290. }
  291. }
  292. for (const change of result.settleChange) {
  293. const sb = result.stageBills.find(x => { return x.id === change.gcl_id });
  294. if (sb) sb.undoneChange = true;
  295. if (change.mx_id) {
  296. const sp = result.stagePos.find(x => { return x.id === change.mx_id });
  297. if (sp) sp.undoneChange = true;
  298. }
  299. }
  300. settleTree.loadDatas(result.stageBills);
  301. treeCalc.calculateAll(settleTree);
  302. settlePos.loadDatas(result.stagePos);
  303. settlePos.calculateAll();
  304. settleCheck.init();
  305. SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree);
  306. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  307. settlePosObj.loadCurPosData();
  308. });
  309. // 展开收起工具栏
  310. $('a', '.right-nav').bind('click', function () {
  311. const tab = $(this), tabPanel = $(tab.attr('content'));
  312. if (!tab.hasClass('active')) {
  313. $('a', '.side-menu').removeClass('active');
  314. $('.tab-content .tab-select-show').removeClass('active');
  315. tab.addClass('active');
  316. tabPanel.addClass('active');
  317. showSideTools(tab.hasClass('active'));
  318. if (tab.attr('content') === '#search' && !searchLedger) {
  319. searchLedger = $.billsSearch({
  320. selector: '#search',
  321. searchSpread: slSpread,
  322. searchOver: true,
  323. searchEmpty: true,
  324. resultSpreadSetting: {
  325. cols: [
  326. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  327. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  328. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  329. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  330. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  331. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  332. ],
  333. emptyRows: 0,
  334. headRows: 1,
  335. headRowHeight: [32],
  336. headColWidth: [30],
  337. defaultRowHeight: 21,
  338. headerFont: '12px 微软雅黑',
  339. font: '12px 微软雅黑',
  340. selectedBackColor: '#fffacd',
  341. readOnly: true,
  342. },
  343. afterLocated: function () {
  344. settlePosObj.loadCurPosData();
  345. },
  346. });
  347. searchLedger.spread.refresh();
  348. }
  349. } else {
  350. tab.removeClass('active');
  351. tabPanel.removeClass('active');
  352. showSideTools(tab.hasClass('active'));
  353. }
  354. slSpread.refresh();
  355. spSpread.refresh();
  356. });
  357. $.subMenu({
  358. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  359. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  360. key: 'menu.1.0.0',
  361. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  362. callback: function (info) {
  363. if (info.mini) {
  364. $('.panel-title').addClass('fluid');
  365. $('#sub-menu').removeClass('panel-sidebar');
  366. } else {
  367. $('.panel-title').removeClass('fluid');
  368. $('#sub-menu').addClass('panel-sidebar');
  369. }
  370. autoFlashHeight();
  371. }
  372. });
  373. // 加载上下窗口resizer
  374. $.divResizer({
  375. select: '#main-resize',
  376. callback: function () {
  377. slSpread.refresh();
  378. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  379. $(".sp-wrap").height(bcontent-30);
  380. spSpread.refresh();
  381. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  382. }
  383. });
  384. // 工具栏resizer
  385. $.divResizer({
  386. select: '#right-spr',
  387. callback: function () {
  388. slSpread.refresh();
  389. spSpread.refresh();
  390. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  391. }
  392. });
  393. });