main_tree_col.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. forContain:function (node) {
  131. return MainTreeCol.readOnly.non_ration(node)&&!MainTreeCol.readOnly.glj(node);
  132. }
  133. },
  134. cellType: {
  135. unit: function () {
  136. //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  137. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  138. dynamicCombo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  139. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']);
  140. return dynamicCombo;
  141. },
  142. units: function () {
  143. this.unit;
  144. },
  145. feeRate: function () {
  146. return feeRateObject.getFeeRateEditCellType();
  147. },
  148. calcBase: function () {
  149. return calcBaseView.getCalcBaseCellType();
  150. },
  151. // CSL, 2017-11-28
  152. calcProgramName: function (node) {
  153. if (
  154. node.sourceType === projectObj.project.Ration.getSourceType() ||
  155. (projectObj.project.calcProgram.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  156. ) {
  157. // var names = new GC.Spread.Sheets.CellTypes.ComboBox();
  158. var names = sheetCommonObj.getDynamicCombo();
  159. names.items(projectObj.project.calcProgram.compiledTemplateNames);
  160. return names;
  161. }
  162. },
  163. // CSL, 2017-11-28
  164. subType: function (node) {
  165. if (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation || node.sourceType === projectObj.project.ration_glj.getSourceType()) {
  166. let VPType = sheetCommonObj.getDynamicCombo();
  167. if (node.data.type == rationType.volumePrice)
  168. VPType.itemHeight(5).items(["人工", "材料", "机械", "主材", "设备"])
  169. else if (node.data.type == rationType.gljRation || node.sourceType === projectObj.project.ration_glj.getSourceType())
  170. if (!MainTreeCol.readOnly.non_editSubType(node)) {
  171. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  172. } else {
  173. return null;
  174. }
  175. return VPType;
  176. }
  177. ;
  178. },
  179. },
  180. getEvent: function (eventName) {
  181. let names = eventName.split('.');
  182. let event = this;
  183. for (let name of names) {
  184. if (event[name]) {
  185. event = event[name];
  186. } else {
  187. return null;
  188. }
  189. }
  190. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  191. return null;
  192. } else {
  193. return event;
  194. }
  195. },
  196. getNumberFormatter: function (digit, align) { // CSL, 2017-11-30 扩展:小数点是否对齐。
  197. if (align) {
  198. switch (digit) {
  199. case 1:
  200. return '0.0';
  201. case 2:
  202. return '0.00';
  203. case 3:
  204. return '0.000';
  205. case 4:
  206. return '0.0000';
  207. case 5:
  208. return '0.00000';
  209. case 6:
  210. return '0.000000';
  211. default:
  212. return '0.00';
  213. }
  214. ;
  215. }
  216. else {
  217. switch (digit) {
  218. case 1:
  219. return '0.#';
  220. case 2:
  221. return '0.##';
  222. case 3:
  223. return '0.###';
  224. case 4:
  225. return '0.####';
  226. case 5:
  227. return '0.#####';
  228. case 6:
  229. return '0.######';
  230. default:
  231. return '0.##';
  232. }
  233. ;
  234. }
  235. }
  236. };
  237. let colSettingObj = {
  238. settingSpread: null,
  239. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  240. loadSetting: function (sheet, setting) {
  241. sheet.setRowCount(setting.cols.length);
  242. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  243. sheet.setColumnCount(1);
  244. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  245. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  246. sheet.setColumnWidth(0, 300);
  247. setting.cols.forEach(function (col, index) {
  248. let i, iCol = 0, cell;
  249. for (i = 0; i < col.head.spanCols.length; i++) {
  250. if (col.head.spanCols[i] !== 0) {
  251. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  252. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  253. }
  254. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  255. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  256. }
  257. iCol += col.head.spanRows[i];
  258. }
  259. ;
  260. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  261. colWidth = colWidth > col.width ? colWidth : col.width;
  262. sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  263. cell = sheet.getCell(index, 0).value(col.visible);
  264. sheet.autoFitRow(index);
  265. });
  266. },
  267. initSettingSpread: function () {
  268. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  269. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  270. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  271. }
  272. };
  273. $('#column').on('shown.bs.modal', function () {
  274. if (!colSettingObj.settingSpread) {
  275. colSettingObj.initSettingSpread();
  276. }
  277. });
  278. $('#column').on('hide.bs.modal', function () {
  279. let sheet = colSettingObj.settingSpread.getActiveSheet();
  280. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  281. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  282. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  283. }
  284. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  285. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {
  286. projectID: projectObj.project.ID(),
  287. main_tree_col: projectObj.project.projSetting.main_tree_col
  288. });
  289. });