main_tree_col.js 13 KB

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