main_tree_col.js 14 KB

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