main_tree_col.js 15 KB

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