main_tree_col.js 15 KB

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