main_tree_col.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. * Created by Mai on 2017/7/25.
  3. */
  4. let MainTreeCol = {
  5. getText: {
  6. subType: function (node) {
  7. if (node.sourceType === projectObj.project.Bills.getSourceType()) {
  8. return '';
  9. // CSL, 2017-11-29
  10. } else if (node.sourceType === projectObj.project.Ration.getSourceType()) {
  11. if (node.data.type == 1 || node.data.type == undefined) // 兼容旧定额
  12. return '定'
  13. else if (node.data.type == 2){ // 量价
  14. return volumePriceMaps[node.data.subType];
  15. }
  16. else if (node.data.type == 3){ // 工料机定额
  17. return '工料机'; // 这里明细值等张伟城确定
  18. }
  19. } else if (node.sourceType === projectObj.project.ration_glj.getSourceType()) {
  20. return '主';
  21. }
  22. },
  23. // CSL, 2017-11-28
  24. calcProgramName: function (node) {
  25. let programID = node.data.programID;
  26. if (!programID) return
  27. else return projectObj.project.calcProgram.compiledTemplateMaps[programID];
  28. }
  29. },
  30. readOnly: {
  31. subType: function (node){
  32. return (node.data.type != 2 && node.data.type != 3);
  33. },
  34. // CSL, 2017-11-28
  35. calcProgramName: function (node) {
  36. if (
  37. node.sourceType === projectObj.project.Ration.getSourceType() ||
  38. (node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children && node.source.children.length === 0 && projectObj.project.projSetting.billsCalcMode === billsPrice)
  39. ) return false
  40. else return true;
  41. },
  42. bills: function (node) {
  43. return node.sourceType === projectObj.project.Bills.getSourceType();
  44. },
  45. ration: function (node) {
  46. return node.sourceType === projectObj.project.Ration.getSourceType();
  47. },
  48. volumePrice: function (node) {
  49. return (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  50. },
  51. non_bills: function (node) {
  52. return node.sourceType !== projectObj.project.Bills.getSourceType();
  53. },
  54. non_ration: function (node) {
  55. return node.sourceType !== projectObj.project.Ration.getSourceType();
  56. },
  57. non_volumePrice: function (node) {
  58. return !(node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  59. },
  60. billsParent: function (node) {
  61. return node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children.length > 0;
  62. },
  63. leafBillsWithDetail: function (node) {
  64. return (!MainTreeCol.readOnly.billsParent(node)) && (node.children.length > 0);
  65. },
  66. forCalcBase: function (node) {
  67. // to do according to billsParentType
  68. return MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.non_bills(node)||MainTreeCol.readOnly.leafBillsWithDetail(node);
  69. },
  70. forUnitFee: function (node) {
  71. return MainTreeCol.readOnly.ration(node) || MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.leafBillsWithDetail(node);
  72. },
  73. forTotalFee: function (node) {
  74. return MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.billsParent(node) || (MainTreeCol.readOnly.leafBillsWithDetail(node));
  75. },
  76. forQuantifyDetail:function (node) {
  77. return !(node.sourceType==ModuleNames.ration||!MainTreeCol.readOnly.billsParent(node));
  78. }
  79. },
  80. cellType: {
  81. unit: function () {
  82. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  83. combo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  84. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']);
  85. return combo;
  86. },
  87. units: function () {
  88. this.unit;
  89. },
  90. feeRate: function () {
  91. return feeRateObject.getFeeRateEditCellType();
  92. },
  93. // CSL, 2017-11-28
  94. calcProgramName: function (node) {
  95. if (
  96. node.sourceType === projectObj.project.Ration.getSourceType() ||
  97. (node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children && node.source.children.length === 0 && projectObj.project.projSetting.billsCalcMode === billsPrice)
  98. ) {
  99. var names = new GC.Spread.Sheets.CellTypes.ComboBox();
  100. names.items(projectObj.project.calcProgram.compiledTemplateNames);
  101. return names;
  102. }
  103. },
  104. // CSL, 2017-11-28
  105. subType: function (node) {
  106. if (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation){
  107. let VPType = new GC.Spread.Sheets.CellTypes.ComboBox();
  108. if (node.data.type == rationType.volumePrice)
  109. VPType.items(["人工","材料","机械","主材","设备"])
  110. else if (node.data.type == rationType.gljRation)
  111. VPType.items(["材料","主材","设备"]);
  112. return VPType;
  113. };
  114. },
  115. },
  116. getEvent: function (eventName) {
  117. let names = eventName.split('.');
  118. let event = this;
  119. for (let name of names) {
  120. if (event[name]) {
  121. event = event[name];
  122. } else {
  123. return null;
  124. }
  125. }
  126. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  127. return null;
  128. } else {
  129. return event;
  130. }
  131. },
  132. getNumberFormatter: function (digit) {
  133. switch (digit) {
  134. case 1:
  135. return '0.#';
  136. case 2:
  137. return '0.##';
  138. case 3:
  139. return '0.###';
  140. case 4:
  141. return '0.####';
  142. case 5:
  143. return '0.#####';
  144. case 6:
  145. return '0.######';
  146. default:
  147. return '0.##';
  148. }
  149. }
  150. };
  151. let colSettingObj = {
  152. settingSpread: null,
  153. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  154. loadSetting: function (sheet, setting) {
  155. sheet.setRowCount(setting.cols.length);
  156. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  157. sheet.setColumnCount(1);
  158. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  159. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  160. sheet.setColumnWidth(0, 300);
  161. setting.cols.forEach(function (col, index) {
  162. let i, iCol = 0, cell;
  163. for (i = 0; i < col.head.spanCols.length; i++) {
  164. if (col.head.spanCols[i] !== 0) {
  165. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  166. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  167. }
  168. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  169. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  170. }
  171. iCol += col.head.spanRows[i];
  172. };
  173. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  174. colWidth = colWidth > col.width ? colWidth : col.width;
  175. sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  176. cell = sheet.getCell(index, 0).value(col.visible);
  177. sheet.autoFitRow(index);
  178. });
  179. },
  180. initSettingSpread: function () {
  181. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  182. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  183. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  184. }
  185. };
  186. $('#column').on('shown.bs.modal', function () {
  187. if (!colSettingObj.settingSpread) {
  188. colSettingObj.initSettingSpread();
  189. }
  190. });
  191. $('#column').on('hide.bs.modal', function () {
  192. let sheet = colSettingObj.settingSpread.getActiveSheet();
  193. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  194. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  195. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  196. }
  197. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  198. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {projectID: projectObj.project.ID(), main_tree_col: projectObj.project.projSetting.main_tree_col});
  199. });