main_tree_col.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. (projectObj.project.calcProgram.isLeafBill(node) && projectObj.project.projSetting.billsCalcMode === leafBillGetFeeType.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. (projectObj.project.calcProgram.isLeafBill(node) && projectObj.project.projSetting.billsCalcMode === leafBillGetFeeType.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, align) { // CSL, 2017-11-30 扩展:小数点是否对齐。
  133. if (align) {
  134. switch (digit) {
  135. case 1:
  136. return '0.0';
  137. case 2:
  138. return '0.00';
  139. case 3:
  140. return '0.000';
  141. case 4:
  142. return '0.0000';
  143. case 5:
  144. return '0.00000';
  145. case 6:
  146. return '0.000000';
  147. default:
  148. return '0.00';
  149. };
  150. }
  151. else{
  152. switch (digit) {
  153. case 1:
  154. return '0.#';
  155. case 2:
  156. return '0.##';
  157. case 3:
  158. return '0.###';
  159. case 4:
  160. return '0.####';
  161. case 5:
  162. return '0.#####';
  163. case 6:
  164. return '0.######';
  165. default:
  166. return '0.##';
  167. };
  168. }
  169. }
  170. };
  171. let colSettingObj = {
  172. settingSpread: null,
  173. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  174. loadSetting: function (sheet, setting) {
  175. sheet.setRowCount(setting.cols.length);
  176. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  177. sheet.setColumnCount(1);
  178. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  179. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  180. sheet.setColumnWidth(0, 300);
  181. setting.cols.forEach(function (col, index) {
  182. let i, iCol = 0, cell;
  183. for (i = 0; i < col.head.spanCols.length; i++) {
  184. if (col.head.spanCols[i] !== 0) {
  185. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  186. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  187. }
  188. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  189. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  190. }
  191. iCol += col.head.spanRows[i];
  192. };
  193. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  194. colWidth = colWidth > col.width ? colWidth : col.width;
  195. sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  196. cell = sheet.getCell(index, 0).value(col.visible);
  197. sheet.autoFitRow(index);
  198. });
  199. },
  200. initSettingSpread: function () {
  201. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  202. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  203. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  204. }
  205. };
  206. $('#column').on('shown.bs.modal', function () {
  207. if (!colSettingObj.settingSpread) {
  208. colSettingObj.initSettingSpread();
  209. }
  210. });
  211. $('#column').on('hide.bs.modal', function () {
  212. let sheet = colSettingObj.settingSpread.getActiveSheet();
  213. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  214. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  215. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  216. }
  217. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  218. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {projectID: projectObj.project.ID(), main_tree_col: projectObj.project.projSetting.main_tree_col});
  219. });