main_tree_col.js 16 KB

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