main_tree_col.js 13 KB

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