payment_compare.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. $(document).ready(function() {
  2. autoFlashHeight();
  3. class BillsObj {
  4. constructor() {
  5. this.spread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  6. this.sheet = this.spread.getActiveSheet();
  7. this.treeSetting = {
  8. id: 'tree_id',
  9. pid: 'tree_pid',
  10. order: 'tree_order',
  11. level: 'tree_level',
  12. isLeaf: 'tree_is_leaf',
  13. fullPath: 'tree_full_path',
  14. rootId: -1,
  15. };
  16. this.spreadSetting = {
  17. baseCols: [
  18. {title: '编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 230, formatter: '@', cellType: 'tree'},
  19. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  20. {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 150, formatter: '@'},
  21. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},
  22. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  23. ],
  24. extraCols: [
  25. {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qty_{%d}', hAlign: 2, width: 60, type: 'Number', },
  26. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'tp_{%d}', hAlign: 2, width: 60, type: 'Number', },
  27. ],
  28. emptyRows: 3,
  29. headRows: 2,
  30. headRowHeight: [25, 25],
  31. defaultRowHeight: 21,
  32. headerFont: '12px 微软雅黑',
  33. font: '12px 微软雅黑',
  34. readOnly: true,
  35. };
  36. this.spreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  37. function checkDiffer(data) {
  38. const fieldSufs = sheet.zh_setting.fieldSufs;
  39. if (fieldSufs.length <= 1) return false;
  40. const base = data['qty_' + fieldSufs[0]];
  41. for (let i = 1; i< fieldSufs.length; i++) {
  42. const compare = data['qty_' + fieldSufs[i]];
  43. if ((base || compare) && (compare!== base)) return true;
  44. }
  45. }
  46. return checkDiffer(data) ? spreadColor.safe.differ : defaultColor;
  47. };
  48. this.tree = createNewPathTree('ledger', this.treeSetting);
  49. this.ckBillsSpread = window.location.pathname + '-billsSelect';
  50. this.initSpread();
  51. }
  52. refreshSpreadSetting(roles) {
  53. this.spreadSetting.cols = [];
  54. this.spreadSetting.fieldSufs = [];
  55. for (const col of this.spreadSetting.baseCols) {
  56. this.spreadSetting.cols.push(col);
  57. }
  58. for (const role of roles) {
  59. this.spreadSetting.fieldSufs.push(role.order);
  60. for (const ec of this.spreadSetting.extraCols) {
  61. const col = JSON.parse(JSON.stringify(ec));
  62. col.title = _.replace(col.title, '%s', role.name);
  63. col.field = _.replace(col.field, '{%d}', role.order);
  64. this.spreadSetting.cols.push(col);
  65. }
  66. }
  67. }
  68. initSpread(roles = []) {
  69. this.refreshSpreadSetting(roles);
  70. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  71. }
  72. analysisCompareData(datas, roles){
  73. const findHis = function (role, history) {
  74. let his = null;
  75. for (const h of history) {
  76. if (h.times < role.times || (h.times === role.times && h.order <= role.order)) {
  77. his = h;
  78. } else {
  79. break;
  80. }
  81. }
  82. return his;
  83. };
  84. for (const d of datas) {
  85. if (!d.tree_is_leaf) continue;
  86. d.cur_his.sort((x, y) => { return x.times === y.times ? x.order - y.order : x.times - y.times; });
  87. for (const r of roles) {
  88. if (r.latest) {
  89. d[`qty_${r.order}`] = d.cur_qty;
  90. d[`tp_${r.order}`] = d.cur_tp;
  91. } else {
  92. const rHis = findHis(r, d.cur_his);
  93. if (rHis) {
  94. d[`qty_${r.order}`] = rHis.qty;
  95. d[`tp_${r.order}`] = rHis.tp;
  96. }
  97. }
  98. }
  99. }
  100. }
  101. loadData(datas, roles) {
  102. // todo 整理数据
  103. this.initSpread(roles);
  104. this.analysisCompareData(datas, roles);
  105. this.tree.loadDatas(datas);
  106. this.tree.setting.calcFields = roles.map(x => { return `tp_${x.order}`});
  107. treeCalc.calculateAll(this.tree);
  108. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree);
  109. SpreadJsObj.loadTopAndSelect(this.sheet, this.ckBillsSpread);
  110. }
  111. }
  112. const billsObj = new BillsObj();
  113. // 加载安全生产费数据
  114. postData('load', { filter: 'billsCompare;auditFlow' }, function(result) {
  115. billsObj.loadData(result.billsCompare, result.auditFlow);
  116. });
  117. // 导航Menu
  118. $.subMenu({
  119. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  120. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  121. key: 'menu.1.0.0',
  122. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  123. callback: function (info) {
  124. if (info.mini) {
  125. $('.panel-title').addClass('fluid');
  126. $('#sub-menu').removeClass('panel-sidebar');
  127. } else {
  128. $('.panel-title').removeClass('fluid');
  129. $('#sub-menu').addClass('panel-sidebar');
  130. }
  131. autoFlashHeight();
  132. billsObj.spread.refresh();
  133. }
  134. });
  135. // 显示层次
  136. (function (select, sheet) {
  137. $(select).click(function () {
  138. if (!sheet.zh_tree) return;
  139. const tag = $(this).attr('tag');
  140. const tree = sheet.zh_tree;
  141. setTimeout(() => {
  142. showWaitingView();
  143. switch (tag) {
  144. case "1":
  145. case "2":
  146. case "3":
  147. case "4":
  148. tree.expandByLevel(parseInt(tag));
  149. SpreadJsObj.refreshTreeRowVisible(sheet);
  150. break;
  151. case "last":
  152. tree.expandByCustom(() => { return true; });
  153. SpreadJsObj.refreshTreeRowVisible(sheet);
  154. break;
  155. }
  156. closeWaitingView();
  157. }, 100);
  158. });
  159. })('a[name=showLevel]', billsObj.sheet);
  160. });