settle_ledger.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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: 'tree_id',
  19. pid: 'tree_pid',
  20. order: 'tree_order',
  21. level: 'tree_level',
  22. fullPath: 'tree_full_path',
  23. isLeaf: 'tree_is_leaf',
  24. rootId: -1,
  25. keys: ['id', 'tid', 'tree_id'],
  26. stageId: 'id',
  27. autoExpand: 3,
  28. markExpandKey: 'settle-select-expand',
  29. markExpandSubKey: window.location.pathname.split('/')[2],
  30. calcFields: ['total_price', 'cur_contract_tp', 'cur_qc_tp', 'cur_gather_tp', 'cur_correct_tp'],
  31. calcFun: function(node) {
  32. if (!node.children || node.children.length === 0) {
  33. node.cur_gather_qty = ZhCalc.add(node.cur_contract_qty, node.cur_qc_qty);
  34. if (node.cur_contract_qty) {
  35. node.cur_correct_tp = ZhCalc.add(node.cur_qc_tp, ZhCalc.mul(node.cur_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  36. } else {
  37. node.cur_correct_tp = node.cur_gather_tp;
  38. }
  39. }
  40. node.cur_gather_tp = ZhCalc.add(node.cur_contract_tp, node.cur_qc_tp);
  41. node.cur_gather_percent = ZhCalc.mul(ZhCalc.div(node.cur_gather_tp, node.cur_final_tp), 100, 2);
  42. node.cur_correct_percent = ZhCalc.mul(ZhCalc.div(node.cur_correct_tp, node.cur_final_tp), 100, 2);
  43. }
  44. };
  45. const settleTree = createNewPathTree('stage', settleTreeSetting);
  46. const settlePosSetting = {
  47. id: 'id', ledgerId: 'lid',
  48. calcFun: function(pos) {
  49. pos.cur_gather_qty = ZhCalc.add(pos.cur_contract_qty, pos.cur_qc_qty);
  50. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  51. pos.cur_gather_percent = ZhCalc.mul(ZhCalc.div(pos.cur_gather_qty, pos.sum), 100, 2);
  52. }
  53. };
  54. const settlePos = new StagePosData(settlePosSetting);
  55. const slSpread = SpreadJsObj.createNewSpread($('#settle-bills')[0]);
  56. const slSheet = slSpread.getActiveSheet();
  57. slSheet.frozenColumnCount(billsSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
  58. slSheet.options.frozenlineColor = '#93b5e4';
  59. const ratioCol = billsSpreadSetting.cols.find(x => {return x.field === 'cur_final_1_percent' || x.field === 'cur_correct_1_percent'});
  60. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'cur_correct_1_percent' : 'cur_final_1_percent';
  61. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  62. if (!data) return defaultColor;
  63. if (data.children && data.children.length > 0) return defaultColor;
  64. if (col.field === 'gxby') {
  65. const def = thirdParty.gxby.find(function (x) {
  66. return x.value === data.gxby_status;
  67. });
  68. if (def && def.color) return def.color;
  69. } else if (col.field === 'dagl') {
  70. const def = thirdParty.dagl.find(function (x) {
  71. return x.value === data.dagl_status;
  72. });
  73. if (def && def.color) return def.color;
  74. }
  75. };
  76. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  77. sjsSettingObj.set3FCols(billsSpreadSetting.cols, [
  78. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  79. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  80. ]);
  81. SpreadJsObj.initSheet(slSheet, billsSpreadSetting);
  82. const spSpread = SpreadJsObj.createNewSpread($('#settle-pos')[0]);
  83. const spSheet = spSpread.getActiveSheet();
  84. spSheet.frozenColumnCount(posSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
  85. spSheet.options.frozenlineColor = '#93b5e4';
  86. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  87. if (!data) return defaultColor;
  88. if (col.field === 'gxby') {
  89. const def = thirdParty.gxby.find(function (x) {
  90. return x.value === data.gxby_status;
  91. });
  92. if (def && def.color) return def.color;
  93. } else if (col.field === 'dagl') {
  94. const def = thirdParty.dagl.find(function (x) {
  95. return x.value === data.dagl_status;
  96. });
  97. if (def && def.color) return def.color;
  98. }
  99. };
  100. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  101. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  102. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  103. ]);
  104. SpreadJsObj.initSheet(spSheet, posSpreadSetting);
  105. const settleBillsObj = {
  106. loadRelaData: function() {
  107. SpreadJsObj.saveTopAndSelect(slSheet, ckBillsSpread);
  108. SpreadJsObj.resetTopAndSelect(spSheet);
  109. settlePosObj.loadCurPosData();
  110. },
  111. selectionChanged: function(e, info) {
  112. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  113. settleBillsObj.loadRelaData();
  114. }
  115. },
  116. topRowChanged(e, info) {
  117. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  118. },
  119. };
  120. slSpread.bind(spreadNS.Events.SelectionChanged, settleBillsObj.selectionChanged);
  121. slSpread.bind(spreadNS.Events.TopRowChanged, settleBillsObj.topRowChanged);
  122. const settlePosObj = {
  123. loadCurPosData: function() {
  124. const billsNode = SpreadJsObj.getSelectObject(slSheet);
  125. if (billsNode) {
  126. spSheet.zh_setting.readOnly = readOnly;
  127. const posRange = settlePos.getLedgerPos(billsNode.lid) || [];
  128. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly);
  129. } else {
  130. spSheet.zh_setting.readOnly = true;
  131. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, [], true);
  132. }
  133. }
  134. };
  135. postData('load', {filter: 'settleBills;settlePos;tag'}, function(result) {
  136. settleTree.loadDatas(result.settleBills);
  137. treeCalc.calculateAll(settleTree);
  138. settlePos.loadDatas(result.settlePos);
  139. settlePos.calculateAll();
  140. SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree);
  141. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  142. settlePosObj.loadCurPosData();
  143. });
  144. // 展开收起工具栏
  145. $('a', '.right-nav').bind('click', function () {
  146. const tab = $(this), tabPanel = $(tab.attr('content'));
  147. if (!tab.hasClass('active')) {
  148. $('a', '.side-menu').removeClass('active');
  149. $('.tab-content .tab-select-show').removeClass('active');
  150. tab.addClass('active');
  151. tabPanel.addClass('active');
  152. showSideTools(tab.hasClass('active'));
  153. if (tab.attr('content') === '#search' && !searchLedger) {
  154. searchLedger = $.billsSearch({
  155. selector: '#search',
  156. searchSpread: slSpread,
  157. searchOver: true,
  158. searchEmpty: true,
  159. resultSpreadSetting: {
  160. cols: [
  161. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  162. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  163. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  164. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  165. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  166. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  167. ],
  168. emptyRows: 0,
  169. headRows: 1,
  170. headRowHeight: [32],
  171. headColWidth: [30],
  172. defaultRowHeight: 21,
  173. headerFont: '12px 微软雅黑',
  174. font: '12px 微软雅黑',
  175. selectedBackColor: '#fffacd',
  176. readOnly: true,
  177. },
  178. afterLocated: function () {
  179. settlePosObj.loadCurPosData();
  180. },
  181. });
  182. searchLedger.spread.refresh();
  183. }
  184. } else {
  185. tab.removeClass('active');
  186. tabPanel.removeClass('active');
  187. showSideTools(tab.hasClass('active'));
  188. }
  189. slSpread.refresh();
  190. spSpread.refresh();
  191. });
  192. $.subMenu({
  193. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  194. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  195. key: 'menu.1.0.0',
  196. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  197. callback: function (info) {
  198. if (info.mini) {
  199. $('.panel-title').addClass('fluid');
  200. $('#sub-menu').removeClass('panel-sidebar');
  201. } else {
  202. $('.panel-title').removeClass('fluid');
  203. $('#sub-menu').addClass('panel-sidebar');
  204. }
  205. autoFlashHeight();
  206. }
  207. });
  208. });