settle_select.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 settleBillsObj = {
  104. loadRelaData: function() {
  105. SpreadJsObj.saveTopAndSelect(slSheet, ckBillsSpread);
  106. SpreadJsObj.resetTopAndSelect(spSheet);
  107. settlePosObj.loadCurPosData();
  108. },
  109. selectionChanged: function(e, info) {
  110. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  111. settleBillsObj.loadRelaData();
  112. }
  113. },
  114. topRowChanged(e, info) {
  115. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  116. },
  117. buttonClicked: function(e, info) {
  118. if (!info.sheet.zh_setting) return;
  119. const col = info.sheet.zh_setting.cols[info.col];
  120. if (col.field !== 'selected') return;
  121. const node = SpreadJsObj.getSelectObject(info.sheet);
  122. node.selected = !node.selected;
  123. if (node.children && node.children.length > 0) {
  124. const posterity = tsObj.tenderSourceTree.getPosterity(node);
  125. for (const p of posterity) {
  126. p.selected = node.selected;
  127. if (!p.children || p.children.length === 0){
  128. if (p.selected) {
  129. tsObj._addTender(p);
  130. } else {
  131. tsObj._removeTender(p);
  132. }
  133. }
  134. }
  135. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  136. } else {
  137. if (node.selected) {
  138. tsObj._addTender(node);
  139. } else {
  140. tsObj._removeTender(node);
  141. }
  142. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  143. }
  144. tsObj.reloadResultData();
  145. },
  146. };
  147. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  148. slSpread.bind(spreadNS.Events.SelectionChanged, settleBillsObj.selectionChanged);
  149. slSpread.bind(spreadNS.Events.TopRowChanged, settleBillsObj.topRowChanged);
  150. const settlePosObj = {
  151. loadCurPosData: function() {
  152. const billsNode = SpreadJsObj.getSelectObject(slSheet);
  153. if (billsNode) {
  154. spSheet.zh_setting.readOnly = readOnly;
  155. const posRange = settlePos.getLedgerPos(billsNode.id) || [];
  156. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly);
  157. } else {
  158. spSheet.zh_setting.readOnly = true;
  159. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, [], true);
  160. }
  161. }
  162. };
  163. postData('load', {filter: 'stageBills;stagePos;settleSelect;tag'}, function(result) {
  164. for (const select of result.settleSelect) {
  165. if (select.pid) {
  166. const sp = result.stagePos.find(x => { return x.id === select.pid });
  167. if (sp) sp.selected = true;
  168. } else {
  169. const sb = result.stageBills.find(x => { return x.id === select.lid });
  170. if (sb) sb.selected = true;
  171. }
  172. }
  173. settleTree.loadDatas(result.stageBills);
  174. treeCalc.calculateAll(settleTree);
  175. settlePos.loadDatas(result.stagePos);
  176. settlePos.calculateAll();
  177. SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree);
  178. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  179. settlePosObj.loadCurPosData();
  180. });
  181. // 展开收起工具栏
  182. $('a', '.right-nav').bind('click', function () {
  183. const tab = $(this), tabPanel = $(tab.attr('content'));
  184. if (!tab.hasClass('active')) {
  185. $('a', '.side-menu').removeClass('active');
  186. $('.tab-content .tab-select-show').removeClass('active');
  187. tab.addClass('active');
  188. tabPanel.addClass('active');
  189. showSideTools(tab.hasClass('active'));
  190. if (tab.attr('content') === '#search' && !searchLedger) {
  191. searchLedger = $.billsSearch({
  192. selector: '#search',
  193. searchSpread: slSpread,
  194. searchOver: true,
  195. searchEmpty: true,
  196. resultSpreadSetting: {
  197. cols: [
  198. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  199. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  200. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  201. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  202. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  203. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  204. ],
  205. emptyRows: 0,
  206. headRows: 1,
  207. headRowHeight: [32],
  208. headColWidth: [30],
  209. defaultRowHeight: 21,
  210. headerFont: '12px 微软雅黑',
  211. font: '12px 微软雅黑',
  212. selectedBackColor: '#fffacd',
  213. readOnly: true,
  214. },
  215. afterLocated: function () {
  216. settlePosObj.loadCurPosData();
  217. },
  218. });
  219. searchLedger.spread.refresh();
  220. }
  221. } else {
  222. tab.removeClass('active');
  223. tabPanel.removeClass('active');
  224. showSideTools(tab.hasClass('active'));
  225. }
  226. slSpread.refresh();
  227. spSpread.refresh();
  228. });
  229. $.subMenu({
  230. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  231. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  232. key: 'menu.1.0.0',
  233. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  234. callback: function (info) {
  235. if (info.mini) {
  236. $('.panel-title').addClass('fluid');
  237. $('#sub-menu').removeClass('panel-sidebar');
  238. } else {
  239. $('.panel-title').removeClass('fluid');
  240. $('#sub-menu').addClass('panel-sidebar');
  241. }
  242. autoFlashHeight();
  243. }
  244. });
  245. // 加载上下窗口resizer
  246. $.divResizer({
  247. select: '#main-resize',
  248. callback: function () {
  249. slSpread.refresh();
  250. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  251. $(".sp-wrap").height(bcontent-30);
  252. spSpread.refresh();
  253. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  254. }
  255. });
  256. // 工具栏resizer
  257. $.divResizer({
  258. select: '#right-spr',
  259. callback: function () {
  260. slSpread.refresh();
  261. spSpread.refresh();
  262. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  263. }
  264. });
  265. });