settle_gather.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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, settleAtt;
  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. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  40. node.end_gather_qty = ZhCalc.add(node.end_contract_qty, node.end_qc_qty);
  41. if (node.end_contract_qty) {
  42. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  43. } else {
  44. node.end_correct_tp = node.end_gather_tp;
  45. }
  46. }
  47. node.cur_gather_tp = ZhCalc.add(node.cur_contract_tp, node.cur_qc_tp);
  48. node.cur_gather_percent = ZhCalc.mul(ZhCalc.div(node.cur_gather_tp, node.cur_final_tp), 100, 2);
  49. node.cur_correct_percent = ZhCalc.mul(ZhCalc.div(node.cur_correct_tp, node.cur_final_tp), 100, 2);
  50. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  51. node.pre_gather_percent = ZhCalc.mul(ZhCalc.div(node.pre_gather_tp, node.pre_final_tp), 100, 2);
  52. node.pre_correct_percent = ZhCalc.mul(ZhCalc.div(node.pre_correct_tp, node.pre_final_tp), 100, 2);
  53. node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
  54. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  55. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  56. }
  57. };
  58. const settleTree = createNewPathTree('stage', settleTreeSetting);
  59. const settlePosSetting = {
  60. id: 'id', ledgerId: 'lid',
  61. calcFun: function(pos) {
  62. pos.cur_gather_qty = ZhCalc.add(pos.cur_contract_qty, pos.cur_qc_qty);
  63. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  64. pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty);
  65. }
  66. };
  67. const settlePos = new StagePosData(settlePosSetting);
  68. const slSpread = SpreadJsObj.createNewSpread($('#settle-bills')[0]);
  69. const slSheet = slSpread.getActiveSheet();
  70. slSheet.frozenColumnCount(billsSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
  71. slSheet.options.frozenlineColor = '#93b5e4';
  72. const ratioCol = billsSpreadSetting.cols.find(x => {return x.field === 'cur_final_1_percent' || x.field === 'cur_correct_1_percent'});
  73. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'cur_correct_1_percent' : 'cur_final_1_percent';
  74. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  75. if (!data) return defaultColor;
  76. if (data.children && data.children.length > 0) return defaultColor;
  77. if (col.field === 'gxby') {
  78. const def = thirdParty.gxby.find(function (x) {
  79. return x.value === data.gxby_status;
  80. });
  81. if (def && def.color) return def.color;
  82. } else if (col.field === 'dagl') {
  83. const def = thirdParty.dagl.find(function (x) {
  84. return x.value === data.dagl_status;
  85. });
  86. if (def && def.color) return def.color;
  87. }
  88. };
  89. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  90. sjsSettingObj.set3FCols(billsSpreadSetting.cols, [
  91. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  92. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  93. ]);
  94. billsSpreadSetting.afterLocate = function (node) {
  95. settleAtt.getCurAttHtml(node);
  96. };
  97. SpreadJsObj.initSheet(slSheet, billsSpreadSetting);
  98. const spSpread = SpreadJsObj.createNewSpread($('#settle-pos')[0]);
  99. const spSheet = spSpread.getActiveSheet();
  100. spSheet.frozenColumnCount(posSpreadSetting.cols.findIndex(x => { return x.field === 'total_price'; }) + 1);
  101. spSheet.options.frozenlineColor = '#93b5e4';
  102. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  103. if (!data) return defaultColor;
  104. if (col.field === 'gxby') {
  105. const def = thirdParty.gxby.find(function (x) {
  106. return x.value === data.gxby_status;
  107. });
  108. if (def && def.color) return def.color;
  109. } else if (col.field === 'dagl') {
  110. const def = thirdParty.dagl.find(function (x) {
  111. return x.value === data.dagl_status;
  112. });
  113. if (def && def.color) return def.color;
  114. }
  115. };
  116. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  117. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  118. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  119. ]);
  120. SpreadJsObj.initSheet(spSheet, posSpreadSetting);
  121. const settleBillsObj = {
  122. loadRelaData: function() {
  123. SpreadJsObj.saveTopAndSelect(slSheet, ckBillsSpread);
  124. SpreadJsObj.resetTopAndSelect(spSheet);
  125. settlePosObj.loadCurPosData();
  126. },
  127. selectionChanged: function(e, info) {
  128. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  129. settleBillsObj.loadRelaData();
  130. }
  131. },
  132. topRowChanged(e, info) {
  133. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  134. }
  135. };
  136. slSpread.bind(spreadNS.Events.SelectionChanged, settleBillsObj.selectionChanged);
  137. slSpread.bind(spreadNS.Events.TopRowChanged, settleBillsObj.topRowChanged);
  138. const settlePosObj = {
  139. loadCurPosData: function() {
  140. const billsNode = SpreadJsObj.getSelectObject(slSheet);
  141. if (billsNode) {
  142. const posRange = settlePos.getLedgerPos(billsNode.lid) || [];
  143. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, posRange, readOnly);
  144. } else {
  145. SpreadJsObj.loadSheetData(spSheet, SpreadJsObj.DataType.Data, [], true);
  146. }
  147. }
  148. };
  149. postData('gather/load', null, function(result) {
  150. settleTree.loadDatas(result.bills);
  151. treeCalc.calculateAll(settleTree);
  152. settlePos.loadDatas(result.pos);
  153. settlePos.calculateAll();
  154. SpreadJsObj.loadSheetData(slSheet, SpreadJsObj.DataType.Tree, settleTree);
  155. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  156. settlePosObj.loadCurPosData();
  157. });
  158. // 展开收起工具栏
  159. $('a', '.right-nav').bind('click', function () {
  160. const tab = $(this), tabPanel = $(tab.attr('content'));
  161. if (!tab.hasClass('active')) {
  162. $('a', '.side-menu').removeClass('active');
  163. $('.tab-content .tab-select-show').removeClass('active');
  164. tab.addClass('active');
  165. tabPanel.addClass('active');
  166. showSideTools(tab.hasClass('active'));
  167. if (tab.attr('content') === '#search' && !searchLedger) {
  168. searchLedger = $.billsSearch({
  169. selector: '#search',
  170. searchSpread: slSpread,
  171. searchOver: true,
  172. searchEmpty: true,
  173. keyId: 'tree_id',
  174. resultSpreadSetting: {
  175. cols: [
  176. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  177. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  178. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  179. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  180. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  181. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  182. ],
  183. emptyRows: 0,
  184. headRows: 1,
  185. headRowHeight: [32],
  186. headColWidth: [30],
  187. defaultRowHeight: 21,
  188. headerFont: '12px 微软雅黑',
  189. font: '12px 微软雅黑',
  190. selectedBackColor: '#fffacd',
  191. readOnly: true,
  192. },
  193. afterLocated: function () {
  194. settlePosObj.loadCurPosData();
  195. },
  196. });
  197. searchLedger.spread.refresh();
  198. }
  199. } else {
  200. tab.removeClass('active');
  201. tabPanel.removeClass('active');
  202. showSideTools(tab.hasClass('active'));
  203. }
  204. slSpread.refresh();
  205. spSpread.refresh();
  206. });
  207. $.subMenu({
  208. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  209. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  210. key: 'menu.1.0.0',
  211. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  212. callback: function (info) {
  213. if (info.mini) {
  214. $('.panel-title').addClass('fluid');
  215. $('#sub-menu').removeClass('panel-sidebar');
  216. } else {
  217. $('.panel-title').removeClass('fluid');
  218. $('#sub-menu').addClass('panel-sidebar');
  219. }
  220. autoFlashHeight();
  221. }
  222. });
  223. // 加载上下窗口resizer
  224. $.divResizer({
  225. select: '#main-resize',
  226. callback: function () {
  227. slSpread.refresh();
  228. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  229. $(".sp-wrap").height(bcontent-30);
  230. spSpread.refresh();
  231. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  232. }
  233. });
  234. // 工具栏resizer
  235. $.divResizer({
  236. select: '#right-spr',
  237. callback: function () {
  238. slSpread.refresh();
  239. spSpread.refresh();
  240. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  241. if (searchLedger) searchLedger.spread.refresh();
  242. }
  243. });
  244. // 显示层次
  245. (function (select, sheet) {
  246. $(select).click(function () {
  247. const tag = $(this).attr('tag');
  248. const tree = sheet.zh_tree;
  249. if (!tree) return;
  250. setTimeout(() => {
  251. showWaitingView();
  252. switch (tag) {
  253. case "1":
  254. case "2":
  255. case "3":
  256. case "4":
  257. case "5":
  258. tree.expandByLevel(parseInt(tag));
  259. SpreadJsObj.refreshTreeRowVisible(sheet);
  260. break;
  261. case "last":
  262. tree.expandByCustom(() => { return true; });
  263. SpreadJsObj.refreshTreeRowVisible(sheet);
  264. break;
  265. }
  266. closeWaitingView();
  267. }, 100);
  268. });
  269. })('a[name=showLevel]', slSheet);
  270. });