main_tree_col.js 14 KB

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