main_tree_col.js 6.3 KB

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