main_tree_col.js 11 KB

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