settle_ledger.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. };
  118. slSpread.bind(spreadNS.Events.SelectionChanged, settleBillsObj.selectionChanged);
  119. slSpread.bind(spreadNS.Events.TopRowChanged, settleBillsObj.topRowChanged);
  120. const settlePosObj = {
  121. loadCurPosData: function() {
  122. const billsNode = SpreadJsObj.getSelectObject(slSheet);
  123. if (billsNode) {
  124. spSheet.zh_setting.readOnly = readOnly;
  125. const posRange = settlePos.getLedgerPos(billsNode.id) || [];
  126. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly);
  127. } else {
  128. spSheet.zh_setting.readOnly = true;
  129. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, [], true);
  130. }
  131. }
  132. };
  133. postData('load', {filter: 'settleBills;settlePos;tag'}, function(result) {
  134. settleTree.loadDatas(result.settleBills);
  135. treeCalc.calculateAll(settleTree);
  136. settlePos.loadDatas(result.settlePos);
  137. settlePos.calculateAll();
  138. SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree);
  139. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  140. settlePosObj.loadCurPosData();
  141. });
  142. // 展开收起工具栏
  143. $('a', '.right-nav').bind('click', function () {
  144. const tab = $(this), tabPanel = $(tab.attr('content'));
  145. if (!tab.hasClass('active')) {
  146. $('a', '.side-menu').removeClass('active');
  147. $('.tab-content .tab-select-show').removeClass('active');
  148. tab.addClass('active');
  149. tabPanel.addClass('active');
  150. showSideTools(tab.hasClass('active'));
  151. if (tab.attr('content') === '#search' && !searchLedger) {
  152. searchLedger = $.billsSearch({
  153. selector: '#search',
  154. searchSpread: slSpread,
  155. searchOver: true,
  156. searchEmpty: true,
  157. resultSpreadSetting: {
  158. cols: [
  159. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  160. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  161. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  162. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  163. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  164. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  165. ],
  166. emptyRows: 0,
  167. headRows: 1,
  168. headRowHeight: [32],
  169. headColWidth: [30],
  170. defaultRowHeight: 21,
  171. headerFont: '12px 微软雅黑',
  172. font: '12px 微软雅黑',
  173. selectedBackColor: '#fffacd',
  174. readOnly: true,
  175. },
  176. afterLocated: function () {
  177. settlePosObj.loadCurPosData();
  178. },
  179. });
  180. searchLedger.spread.refresh();
  181. }
  182. } else {
  183. tab.removeClass('active');
  184. tabPanel.removeClass('active');
  185. showSideTools(tab.hasClass('active'));
  186. }
  187. slSpread.refresh();
  188. spSpread.refresh();
  189. });
  190. $.subMenu({
  191. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  192. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  193. key: 'menu.1.0.0',
  194. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  195. callback: function (info) {
  196. if (info.mini) {
  197. $('.panel-title').addClass('fluid');
  198. $('#sub-menu').removeClass('panel-sidebar');
  199. } else {
  200. $('.panel-title').removeClass('fluid');
  201. $('#sub-menu').addClass('panel-sidebar');
  202. }
  203. autoFlashHeight();
  204. }
  205. });
  206. });