main_tree_col.js 14 KB

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