main_tree_col.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * Created by Mai on 2017/7/25.
  3. */
  4. let MainTreeCol = {
  5. getText: {
  6. type: function (node) {
  7. if (node.sourceType === projectObj.project.Bills.getSourceType()) {
  8. return '';
  9. } else if (node.sourceType === projectObj.project.Ration.getSourceType()) {
  10. return '定';
  11. } else if (node.sourceType === projectObj.project.VolumePrice.getSourceType()) {
  12. return '量';
  13. } else if (node.sourceType === projectObj.project.ration_glj.getSourceType()) {
  14. return '主';
  15. }
  16. }
  17. },
  18. readOnly: {
  19. bills: function (node) {
  20. return node.sourceType === projectObj.project.Bills.getSourceType();
  21. },
  22. ration: function (node) {
  23. return node.sourceType === projectObj.project.Ration.getSourceType();
  24. },
  25. glj: function (node) {
  26. return node.sourceType == projectObj.project.ration_glj.getSourceType();
  27. },
  28. volumePrice: function (node) {
  29. return node.sourceType === projectObj.project.VolumePrice.getSourceType();
  30. },
  31. non_bills: function (node) {
  32. return node.sourceType !== projectObj.project.Bills.getSourceType();
  33. },
  34. non_ration: function (node) {
  35. return node.sourceType !== projectObj.project.Ration.getSourceType();
  36. },
  37. non_volumePrice: function (node) {
  38. return node.sourceType !== projectObj.project.Ration.getSourceType();
  39. },
  40. billsParent: function (node) {
  41. return node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children.length > 0;
  42. },
  43. leafBillsWithDetail: function (node) {
  44. return (!MainTreeCol.readOnly.billsParent(node)) && (node.children.length > 0);
  45. },
  46. forCalcBase: function (node) {
  47. // to do according to billsParentType
  48. return MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.non_bills(node)||MainTreeCol.readOnly.leafBillsWithDetail(node);
  49. },
  50. forUnitFee: function (node) {
  51. return MainTreeCol.readOnly.ration(node) || MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.leafBillsWithDetail(node);
  52. },
  53. forTotalFee: function (node) {
  54. return MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.billsParent(node) || (MainTreeCol.readOnly.leafBillsWithDetail(node));
  55. },
  56. forFeeRate:function (node) {
  57. return MainTreeCol.readOnly.non_bills(node)||MainTreeCol.readOnly.billsParent(node)||MainTreeCol.readOnly.leafBillsWithDetail(node);
  58. },
  59. forQuantity:function (node) {
  60. return MainTreeCol.readOnly.glj(node)||MainTreeCol.readOnly.billsParent(node)
  61. }
  62. },
  63. cellType: {
  64. unit: function () {
  65. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  66. combo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  67. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']);
  68. return combo;
  69. },
  70. feeRate: function () {
  71. return feeRateObject.getFeeRateEditCellType();
  72. },
  73. calcBase: function () {
  74. return calcBaseView.getCalcBaseCellType();
  75. }
  76. },
  77. getEvent: function (eventName) {
  78. let names = eventName.split('.');
  79. let event = this;
  80. for (let name of names) {
  81. if (event[name]) {
  82. event = event[name];
  83. } else {
  84. return null;
  85. }
  86. }
  87. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  88. return null;
  89. } else {
  90. return event;
  91. }
  92. },
  93. getNumberFormatter: function (digit) {
  94. switch (digit) {
  95. case 1:
  96. return '0.#';
  97. case 2:
  98. return '0.##';
  99. case 3:
  100. return '0.###';
  101. case 4:
  102. return '0.####';
  103. case 5:
  104. return '0.#####';
  105. case 6:
  106. return '0.######';
  107. default:
  108. return '0.##';
  109. }
  110. }
  111. };
  112. let colSettingObj = {
  113. settingSpread: null,
  114. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  115. loadSetting: function (sheet, setting) {
  116. sheet.setColumnCount(setting.cols.length);
  117. sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
  118. sheet.setRowCount(1);
  119. sheet.getRange(0, -1, 1, -1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  120. setting.headRowHeight.forEach(function (rowHeight, index) {
  121. sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader);
  122. });
  123. setting.cols.forEach(function (col, index) {
  124. let i, iRow = 0, cell;
  125. for (i = 0; i < col.head.spanCols.length; i++) {
  126. if (col.head.spanCols[i] !== 0) {
  127. cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader);
  128. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]).wordWrap(true);
  129. }
  130. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  131. sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader);
  132. }
  133. iRow += col.head.spanRows[i];
  134. };
  135. sheet.setColumnWidth(index, col.width);
  136. cell = sheet.getCell(0, index).value(col.visible);
  137. });
  138. },
  139. initSettingSpread: function () {
  140. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  141. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.horizontal;
  142. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  143. }
  144. };
  145. $('#column').on('shown.bs.modal', function () {
  146. if (!colSettingObj.settingSpread) {
  147. colSettingObj.initSettingSpread();
  148. }
  149. });
  150. $('#column').on('hide.bs.modal', function () {
  151. let sheet = colSettingObj.settingSpread.getActiveSheet();
  152. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol ++) {
  153. projectObj.project.projSetting.main_tree_col.cols[iCol].visible = sheet.getValue(0, iCol);
  154. projectObj.project.projSetting.mainGridSetting.cols[iCol].visible = sheet.getValue(0, iCol);
  155. }
  156. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  157. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {projectID: projectObj.project.ID(), main_tree_col: projectObj.project.projSetting.main_tree_col});
  158. });