main_tree_col.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. }else if(node.data.type == 4){//安装增加费生成的定额
  19. return '安';
  20. }
  21. } else if (node.sourceType === projectObj.project.ration_glj.getSourceType()) {
  22. return projectObj.project.projectGLJ.getShortNameByID(node.data.subType);//工料机名字缩写
  23. }
  24. },
  25. quantity:function (node) {
  26. if(node.sourceType === projectObj.project.ration_glj.getSourceType()){
  27. return gljOprObj.getTotalQuantity(node.data);
  28. }else {
  29. return calcTools.uiNodeQty(node)?calcTools.uiNodeQty(node):null;
  30. }
  31. },
  32. // CSL, 2017-11-28
  33. calcProgramName: function (node) {
  34. let programID = node.data.programID;
  35. if (!programID) return
  36. else return projectObj.project.calcProgram.compiledTemplateMaps[programID];
  37. },
  38. calcBase: function (node) {
  39. if (node.data.calcBase && node.data.calcBase != ""){
  40. return cbParser.toFExpr(node.data.calcBase);
  41. }
  42. },
  43. code: function (node) {
  44. if(node.sourceType === projectObj.project.Ration.getSourceType() && node.data.type === rationType.ration
  45. && isDef(node.data.code) && isDef(node.data.prefix) && node.data.prefix !== ''){
  46. return node.data.prefix + node.data.code.replace(new RegExp(node.data.prefix, 'g'), '');
  47. }
  48. return isDef(node.data.code) ? node.data.code : '';
  49. },
  50. marketPrice:function (node) {
  51. if((node.sourceType === projectObj.project.Ration.getSourceType()&&node.data.type!=rationType.ration)||node.sourceType==projectObj.project.ration_glj.getSourceType()){
  52. return calcTools.uiGLJPrice(node.data.marketUnitFee);
  53. }
  54. }
  55. },
  56. readOnly: {
  57. // Vincent, 2018-01-09
  58. subType: function (node) {
  59. if (calcTools.isVolumePrice(node)) return false;
  60. if(MainTreeCol.readOnly.bills(node)){
  61. return true;
  62. }
  63. if(MainTreeCol.readOnly.ration(node)){
  64. return true;
  65. }
  66. if(MainTreeCol.readOnly.non_editSubType(node)){
  67. return true;
  68. }else if(gljOprObj.hasComposition(node.data,node.sourceType === ModuleNames.ration)){
  69. return true;
  70. }
  71. return false;
  72. },
  73. calcProgramName: function (node) {
  74. if (
  75. node.sourceType === projectObj.project.Ration.getSourceType() ||
  76. (calcTools.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  77. ) return false
  78. else return true;
  79. },
  80. non_editSubType: function (node) {
  81. return node.data.subType != 201 && node.data.subType != 4 && node.data.subType != 5
  82. },
  83. commonUnitFee: function (node) {
  84. return !(calcTools.isLeafBill(node) && !calcTools.isCalcBaseBill(node) && !calcTools.isInheritFrom(node, [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE]));
  85. },
  86. //根据节点、父节点类型判断是否可用计算基数
  87. calcBaseType: function (node) {
  88. function isDef(v) {
  89. return v !== undefined && v !== null;
  90. }
  91. function isFlag(v) {
  92. return this.isDef(v.flagsIndex) && this.isDef(v.flagsIndex.fixed);
  93. }
  94. let calcBase = projectObj.project.calcBase;
  95. let parent = node.parent;
  96. if (isFlag(node.data) && (node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.SUB_ENGINERRING
  97. || node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.CONSTRUCTION_TECH)) {
  98. return true;
  99. }
  100. else if (isFlag(node.data) && node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.CONSTRUCTION_ORGANIZATION) {
  101. return false;
  102. }
  103. else {
  104. if (!parent) {
  105. return false;
  106. }
  107. else {
  108. return this.calcBaseType(parent);
  109. }
  110. }
  111. },
  112. bills: function (node) {
  113. return node.sourceType === projectObj.project.Bills.getSourceType();
  114. },
  115. ration: function (node) {
  116. return calcTools.isRationItem(node);
  117. },
  118. isSubcontract: function (node) {
  119. return !calcTools.isRationCategory(node);
  120. },
  121. glj: function (node) {
  122. return node.sourceType == projectObj.project.ration_glj.getSourceType();
  123. },
  124. volumePrice: function (node) {
  125. return (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  126. },
  127. non_bills: function (node) {
  128. return node.sourceType !== projectObj.project.Bills.getSourceType();
  129. },
  130. non_ration: function (node) {
  131. return node.sourceType !== projectObj.project.Ration.getSourceType();
  132. },
  133. non_volumePrice: function (node) {
  134. return !(node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  135. },
  136. billsParent: function (node) {
  137. return node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children.length > 0;
  138. },
  139. leafBillsWithDetail: function (node) {
  140. return (!MainTreeCol.readOnly.billsParent(node)) && (node.children.length > 0);
  141. },
  142. forCalcBase: function (node) {
  143. // to do according to billsParentType
  144. return MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.leafBillsWithDetail(node) || MainTreeCol.readOnly.calcBaseType(node);
  145. },
  146. forUnitFee: function (node) {
  147. return MainTreeCol.readOnly.ration(node) || MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.leafBillsWithDetail(node);
  148. },
  149. forTotalFee: function (node) {
  150. return MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.billsParent(node) || (MainTreeCol.readOnly.leafBillsWithDetail(node));
  151. },
  152. forQuantifyDetail: function (node) {
  153. return !(node.sourceType == ModuleNames.ration || !MainTreeCol.readOnly.billsParent(node));
  154. },
  155. forFeeRate: function (node) {
  156. let readOnly = true;
  157. let Bills = projectObj.project.Bills;
  158. //只有当选中节点是清单,并且不属于“分部分项工程”或“技术措施项目”,并且是叶子清单且没有定额/量价/工料机时,费率列才可编辑
  159. if(MainTreeCol.readOnly.bills(node)){
  160. if(!Bills.isFBFX(node)&&!Bills.isTechMeasure(node)&&node.children.length<=0){//不属于“分部分项工程”或“技术措施项目”,并且是叶子清单且没有定额/量价/工料机
  161. readOnly = false;
  162. }
  163. }
  164. return readOnly;
  165. },
  166. forQuantity: function (node) {
  167. if(node.sourceType === projectObj.project.Bills.getSourceType()){
  168. if(node.data.type==billType.DXFY||node.data.type==billType.FB||(node.data.type==billType.BILL&&MainTreeCol.readOnly.billsParent(node))){//大项费用、分部、清单父项行,工程量只读。
  169. return true;
  170. }
  171. }else if(MainTreeCol.readOnly.glj(node)){
  172. return true;
  173. }
  174. return false;
  175. },
  176. forMarketPrice: function (node) {
  177. return MainTreeCol.readOnly.bills(node) ||
  178. (node.sourceType === ModuleNames.ration && node.data.type == rationType.ration) ||
  179. gljOprObj.marketPriceReadOnly(node);
  180. },
  181. forContain:function (node) {
  182. return MainTreeCol.readOnly.non_ration(node)&&!MainTreeCol.readOnly.glj(node);
  183. },
  184. forCode:function (node) {
  185. return MainTreeCol.readOnly.glj(node)|| (node.sourceType === projectObj.project.Ration.getSourceType()&&node.data.type===rationType.gljRation);
  186. },
  187. forUnit:function (node) {
  188. if(MainTreeCol.readOnly.bills(node)&&(node.data.type==billType.DXFY||node.data.type==billType.FB)){//在大项费用、分部行,计量单位只读。
  189. return true;
  190. }else {
  191. return calcTools.isRationItem(node);
  192. }
  193. },
  194. forContentCharacter: function (node) {
  195. return !MainTreeCol.readOnly.bills(node) || (node.data.type !== billType.BILL && node.data.type !== billType.FX);
  196. },
  197. forRuleText: function (node) {
  198. if(MainTreeCol.readOnly.bills(node)){
  199. if(node.data.type === billType.FX || (node.data.type === billType.BILL && node.source.children.length === 0)){
  200. return false;
  201. }
  202. }
  203. return true;
  204. }
  205. },
  206. cellType: {
  207. unit: function () {
  208. //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  209. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  210. dynamicCombo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  211. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']).editable(true);
  212. return dynamicCombo;
  213. },
  214. units: function () {
  215. this.unit;
  216. },
  217. feeRate: function () {
  218. return feeRateObject.getFeeRateEditCellType();
  219. },
  220. calcBase: function () {
  221. return calcBaseView.getCalcBaseCellType('bills');
  222. },
  223. // CSL, 2017-11-28
  224. calcProgramName: function (node) {
  225. if (
  226. node.sourceType === projectObj.project.Ration.getSourceType() ||
  227. (calcTools.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  228. ) {
  229. // var names = new GC.Spread.Sheets.CellTypes.ComboBox();
  230. var names = sheetCommonObj.getDynamicCombo();
  231. names.items(projectObj.project.calcProgram.compiledTemplateNames);
  232. return names;
  233. }
  234. },
  235. // Vincent, 2018-01-09
  236. subType: function (node) {
  237. if(node.sourceType!=projectObj.project.Bills.getSourceType()){
  238. let VPType = sheetCommonObj.getDynamicCombo();
  239. if(node.sourceType == projectObj.project.Ration.getSourceType()){//是定额类型
  240. if(node.data.type == rationType.volumePrice){
  241. VPType.itemHeight(5).items(["人工", "材料", "机械", "主材", "设备"])
  242. return VPType;
  243. }else if(node.data.type == rationType.gljRation){
  244. if(!MainTreeCol.readOnly.non_editSubType(node)&&gljOprObj.hasComposition(node.data,true)==false){
  245. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  246. return VPType;
  247. }
  248. }
  249. }else if(node.sourceType === projectObj.project.ration_glj.getSourceType()){//是工料机类型
  250. if(!MainTreeCol.readOnly.non_editSubType(node)&&gljOprObj.hasComposition(node.data)==false){
  251. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  252. return VPType;
  253. }
  254. }
  255. }
  256. },
  257. isSubcontract: function (node){
  258. if (calcTools.isRationCategory(node))
  259. return new GC.Spread.Sheets.CellTypes.CheckBox();
  260. },
  261. isEstimate:function (node) {
  262. //只对分项、补项、材料(包括混凝土等)、主材、设备有效
  263. if(MainTreeCol.readOnly.glj(node)||(calcTools.isGljRation(node)&&projectObj.project.projectGLJ.isEstimateType(node.data.subType))||(MainTreeCol.readOnly.bills(node)&&(node.data.type == billType.BX||node.data.type == billType.FX))){
  264. return new GC.Spread.Sheets.CellTypes.CheckBox();
  265. }
  266. }
  267. },
  268. editChecking:function(node){
  269. if(node.sourceType==projectObj.project.Bills.getSourceType()&&projectObj.project.isBillsLocked()){
  270. return true;
  271. }
  272. if(gljOprObj.isInstallationNode(node)){//如果是通过安装增加费自动生成的,都是只读类型
  273. return true;
  274. }
  275. return false;
  276. },
  277. setAutoHeight:function (cell,node) {//设置自动行高
  278. cell.wordWrap(MainTreeCol.needAutoFit(node));
  279. },
  280. setAutoFitRow:function (sheet,node) {
  281. if(MainTreeCol.needAutoFit(node)){
  282. sheet.autoFitRow(node.serialNo());
  283. }
  284. },
  285. needAutoFit:function (node) {
  286. let displaySetting = projectObj.project.property.displaySetting;
  287. let billsAutoH = displaySetting && displaySetting.billsAutoHeight?displaySetting.billsAutoHeight:false;
  288. let rationAutoH = displaySetting && displaySetting.rationAutoHeight?displaySetting.rationAutoHeight:false;
  289. if(node.sourceType === projectObj.project.Bills.getSourceType()&&billsAutoH == true){
  290. return true;
  291. }
  292. if(node.sourceType !== projectObj.project.Bills.getSourceType()&& rationAutoH == true){
  293. return true;
  294. }
  295. return false;
  296. },
  297. getEvent: function (eventName) {
  298. let names = eventName.split('.');
  299. let event = this;
  300. for (let name of names) {
  301. if (event[name]) {
  302. event = event[name];
  303. } else {
  304. return null;
  305. }
  306. }
  307. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  308. return null;
  309. } else {
  310. return event;
  311. }
  312. },
  313. getNumberFormatter: function (digit, align) { // CSL, 2017-11-30 扩展:小数点是否对齐。
  314. if (align) {
  315. switch (digit) {
  316. case 1:
  317. return '0.0';
  318. case 2:
  319. return '0.00';
  320. case 3:
  321. return '0.000';
  322. case 4:
  323. return '0.0000';
  324. case 5:
  325. return '0.00000';
  326. case 6:
  327. return '0.000000';
  328. default:
  329. return '0.00';
  330. }
  331. ;
  332. }
  333. else {
  334. switch (digit) {
  335. case 1:
  336. return '0.#';
  337. case 2:
  338. return '0.##';
  339. case 3:
  340. return '0.###';
  341. case 4:
  342. return '0.####';
  343. case 5:
  344. return '0.#####';
  345. case 6:
  346. return '0.######';
  347. default:
  348. return '0.##';
  349. }
  350. ;
  351. }
  352. }
  353. };
  354. let colSettingObj = {
  355. settingSpread: null,
  356. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  357. loadSetting: function (sheet, setting) {
  358. sheet.suspendPaint();
  359. sheet.suspendEvent();
  360. sheet.setRowCount(setting.cols.length);
  361. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  362. sheet.setColumnCount(1);
  363. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  364. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  365. sheet.setColumnWidth(0, 100);
  366. sheet.setColumnWidth(0, 150, GC.Spread.Sheets.SheetArea.rowHeader);
  367. setting.cols.forEach(function (col, index) {
  368. let i, iCol = 0, cell;
  369. for (i = 0; i < col.head.spanCols.length; i++) {
  370. if (col.head.spanCols[i] !== 0) {
  371. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  372. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  373. }
  374. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  375. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  376. }
  377. iCol += col.head.spanRows[i];
  378. };
  379. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  380. colWidth = colWidth > col.width ? colWidth : col.width;
  381. //sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  382. cell = sheet.getCell(index, 0).value(col.visible);
  383. sheet.autoFitRow(index);
  384. });
  385. sheet.resumeEvent();
  386. sheet.resumePaint();
  387. },
  388. initSettingSpread: function () {
  389. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  390. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  391. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  392. }
  393. };
  394. $('#column').on('shown.bs.modal', function () {
  395. if (!colSettingObj.settingSpread) {
  396. colSettingObj.initSettingSpread();
  397. }
  398. });
  399. $('#column').on('hide.bs.modal', function () {
  400. let sheet = colSettingObj.settingSpread.getActiveSheet();
  401. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  402. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  403. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  404. }
  405. SheetDataHelper.massOperationSheet(projectObj.mainSpread.getActiveSheet(), function () {
  406. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  407. });
  408. //refresh nodes to autoFitRow
  409. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots, true);
  410. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {
  411. projectID: projectObj.project.ID(),
  412. main_tree_col: projectObj.project.projSetting.main_tree_col
  413. });
  414. });