main_tree_col.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. forMarketPrice:function (node) {
  63. return MainTreeCol.readOnly.non_volumePrice(node);
  64. }
  65. },
  66. cellType: {
  67. unit: function () {
  68. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  69. combo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  70. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']);
  71. return combo;
  72. },
  73. feeRate: function () {
  74. return feeRateObject.getFeeRateEditCellType();
  75. },
  76. calcBase: function () {
  77. return calcBaseView.getCalcBaseCellType();
  78. }
  79. },
  80. getEvent: function (eventName) {
  81. let names = eventName.split('.');
  82. let event = this;
  83. for (let name of names) {
  84. if (event[name]) {
  85. event = event[name];
  86. } else {
  87. return null;
  88. }
  89. }
  90. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  91. return null;
  92. } else {
  93. return event;
  94. }
  95. },
  96. getNumberFormatter: function (digit) {
  97. switch (digit) {
  98. case 1:
  99. return '0.#';
  100. case 2:
  101. return '0.##';
  102. case 3:
  103. return '0.###';
  104. case 4:
  105. return '0.####';
  106. case 5:
  107. return '0.#####';
  108. case 6:
  109. return '0.######';
  110. default:
  111. return '0.##';
  112. }
  113. }
  114. };
  115. let colSettingObj = {
  116. settingSpread: null,
  117. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  118. loadSetting: function (sheet, setting) {
  119. sheet.setColumnCount(setting.cols.length);
  120. sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
  121. sheet.setRowCount(1);
  122. sheet.getRange(0, -1, 1, -1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  123. setting.headRowHeight.forEach(function (rowHeight, index) {
  124. sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader);
  125. });
  126. setting.cols.forEach(function (col, index) {
  127. let i, iRow = 0, cell;
  128. for (i = 0; i < col.head.spanCols.length; i++) {
  129. if (col.head.spanCols[i] !== 0) {
  130. cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader);
  131. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]).wordWrap(true);
  132. }
  133. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  134. sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader);
  135. }
  136. iRow += col.head.spanRows[i];
  137. };
  138. sheet.setColumnWidth(index, col.width);
  139. cell = sheet.getCell(0, index).value(col.visible);
  140. });
  141. },
  142. initSettingSpread: function () {
  143. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  144. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.horizontal;
  145. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  146. }
  147. };
  148. $('#column').on('shown.bs.modal', function () {
  149. if (!colSettingObj.settingSpread) {
  150. colSettingObj.initSettingSpread();
  151. }
  152. });
  153. $('#column').on('hide.bs.modal', function () {
  154. let sheet = colSettingObj.settingSpread.getActiveSheet();
  155. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol ++) {
  156. projectObj.project.projSetting.main_tree_col.cols[iCol].visible = sheet.getValue(0, iCol);
  157. projectObj.project.projSetting.mainGridSetting.cols[iCol].visible = sheet.getValue(0, iCol);
  158. }
  159. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  160. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {projectID: projectObj.project.ID(), main_tree_col: projectObj.project.projSetting.main_tree_col});
  161. });