main_tree_col.js 15 KB

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