main_tree_col.js 19 KB

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