main_tree_col.js 18 KB

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