main_tree_col.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. //根据节点、父节点类型判断是否可用计算基数
  43. calcBaseType: function (node) {
  44. function isDef (v) {
  45. return v !== undefined && v !== null;
  46. }
  47. function isFlag (v) {
  48. return this.isDef(v.flagsIndex) && this.isDef(v.flagsIndex.fixed);
  49. }
  50. let calcBase = projectObj.project.calcBase;
  51. let parent = node.parent;
  52. if(isFlag(node.data) && (node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.SUB_ENGINERRING
  53. || node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.CONSTRUCTION_TECH)){
  54. return true;
  55. }
  56. else if(isFlag(node.data) && node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.CONSTRUCTION_ORGANIZATION){
  57. return false;
  58. }
  59. else {
  60. if(!parent){
  61. return false;
  62. }
  63. else {
  64. return this.calcBaseType(parent);
  65. }
  66. }
  67. },
  68. bills: function (node) {
  69. return node.sourceType === projectObj.project.Bills.getSourceType();
  70. },
  71. ration: function (node) {
  72. return node.sourceType === projectObj.project.Ration.getSourceType();
  73. },
  74. volumePrice: function (node) {
  75. return (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  76. },
  77. non_bills: function (node) {
  78. return node.sourceType !== projectObj.project.Bills.getSourceType();
  79. },
  80. non_ration: function (node) {
  81. return node.sourceType !== projectObj.project.Ration.getSourceType();
  82. },
  83. non_volumePrice: function (node) {
  84. return !(node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  85. },
  86. billsParent: function (node) {
  87. return node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children.length > 0;
  88. },
  89. leafBillsWithDetail: function (node) {
  90. return (!MainTreeCol.readOnly.billsParent(node)) && (node.children.length > 0);
  91. },
  92. forCalcBase: function (node) {
  93. // to do according to billsParentType
  94. return MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.non_bills(node)||MainTreeCol.readOnly.leafBillsWithDetail(node) ||MainTreeCol.readOnly.calcBaseType(node);
  95. },
  96. forUnitFee: function (node) {
  97. return MainTreeCol.readOnly.ration(node) || MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.leafBillsWithDetail(node);
  98. },
  99. forTotalFee: function (node) {
  100. return MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.billsParent(node) || (MainTreeCol.readOnly.leafBillsWithDetail(node));
  101. },
  102. forQuantifyDetail:function (node) {
  103. return !(node.sourceType==ModuleNames.ration||!MainTreeCol.readOnly.billsParent(node));
  104. }
  105. },
  106. cellType: {
  107. unit: function () {
  108. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  109. combo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  110. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']);
  111. return combo;
  112. },
  113. units: function () {
  114. this.unit;
  115. },
  116. feeRate: function () {
  117. return feeRateObject.getFeeRateEditCellType();
  118. },
  119. calcBase: function () {
  120. return calcBaseView.getCalcBaseCellType();
  121. },
  122. // CSL, 2017-11-28
  123. calcProgramName: function (node) {
  124. if (
  125. node.sourceType === projectObj.project.Ration.getSourceType() ||
  126. (projectObj.project.calcProgram.isLeafBill(node) && projectObj.project.projSetting.billsCalcMode === leafBillGetFeeType.billsPrice)
  127. ) {
  128. var names = new GC.Spread.Sheets.CellTypes.ComboBox();
  129. names.items(projectObj.project.calcProgram.compiledTemplateNames);
  130. return names;
  131. }
  132. },
  133. // CSL, 2017-11-28
  134. subType: function (node) {
  135. if (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation){
  136. let VPType = new GC.Spread.Sheets.CellTypes.ComboBox();
  137. if (node.data.type == rationType.volumePrice)
  138. VPType.items(["人工","材料","机械","主材","设备"])
  139. else if (node.data.type == rationType.gljRation)
  140. VPType.items(["材料","主材","设备"]);
  141. return VPType;
  142. };
  143. },
  144. },
  145. getEvent: function (eventName) {
  146. let names = eventName.split('.');
  147. let event = this;
  148. for (let name of names) {
  149. if (event[name]) {
  150. event = event[name];
  151. } else {
  152. return null;
  153. }
  154. }
  155. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  156. return null;
  157. } else {
  158. return event;
  159. }
  160. },
  161. getNumberFormatter: function (digit, align) { // CSL, 2017-11-30 扩展:小数点是否对齐。
  162. if (align) {
  163. switch (digit) {
  164. case 1:
  165. return '0.0';
  166. case 2:
  167. return '0.00';
  168. case 3:
  169. return '0.000';
  170. case 4:
  171. return '0.0000';
  172. case 5:
  173. return '0.00000';
  174. case 6:
  175. return '0.000000';
  176. default:
  177. return '0.00';
  178. };
  179. }
  180. else{
  181. switch (digit) {
  182. case 1:
  183. return '0.#';
  184. case 2:
  185. return '0.##';
  186. case 3:
  187. return '0.###';
  188. case 4:
  189. return '0.####';
  190. case 5:
  191. return '0.#####';
  192. case 6:
  193. return '0.######';
  194. default:
  195. return '0.##';
  196. };
  197. }
  198. }
  199. };
  200. let colSettingObj = {
  201. settingSpread: null,
  202. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  203. loadSetting: function (sheet, setting) {
  204. sheet.setRowCount(setting.cols.length);
  205. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  206. sheet.setColumnCount(1);
  207. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  208. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  209. sheet.setColumnWidth(0, 300);
  210. setting.cols.forEach(function (col, index) {
  211. let i, iCol = 0, cell;
  212. for (i = 0; i < col.head.spanCols.length; i++) {
  213. if (col.head.spanCols[i] !== 0) {
  214. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  215. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  216. }
  217. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  218. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  219. }
  220. iCol += col.head.spanRows[i];
  221. };
  222. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  223. colWidth = colWidth > col.width ? colWidth : col.width;
  224. sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  225. cell = sheet.getCell(index, 0).value(col.visible);
  226. sheet.autoFitRow(index);
  227. });
  228. },
  229. initSettingSpread: function () {
  230. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  231. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  232. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  233. }
  234. };
  235. $('#column').on('shown.bs.modal', function () {
  236. if (!colSettingObj.settingSpread) {
  237. colSettingObj.initSettingSpread();
  238. }
  239. });
  240. $('#column').on('hide.bs.modal', function () {
  241. let sheet = colSettingObj.settingSpread.getActiveSheet();
  242. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  243. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  244. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  245. }
  246. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  247. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {projectID: projectObj.project.ID(), main_tree_col: projectObj.project.projSetting.main_tree_col});
  248. });