main_tree_col.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. let readOnly = true;
  156. let Bills = projectObj.project.Bills;
  157. //只有当选中节点是清单,并且不属于“分部分项工程”或“技术措施项目”,并且是叶子清单且没有定额/量价/工料机时,费率列才可编辑
  158. if(MainTreeCol.readOnly.bills(node)){
  159. if(!Bills.isFBFX(node)&&!Bills.isTechMeasure(node)&&node.children.length<=0){//不属于“分部分项工程”或“技术措施项目”,并且是叶子清单且没有定额/量价/工料机
  160. readOnly = false;
  161. }
  162. }
  163. return readOnly;
  164. },
  165. forQuantity: function (node) {
  166. if(node.sourceType === projectObj.project.Bills.getSourceType()){
  167. if(node.data.type==billType.DXFY||node.data.type==billType.FB||(node.data.type==billType.BILL&&MainTreeCol.readOnly.billsParent(node))){//大项费用、分部、清单父项行,工程量只读。
  168. return true;
  169. }
  170. }else if(MainTreeCol.readOnly.glj(node)){
  171. return true;
  172. }
  173. return false;
  174. },
  175. forMarketPrice: function (node) {
  176. return MainTreeCol.readOnly.bills(node) ||
  177. (node.sourceType === ModuleNames.ration && node.data.type == rationType.ration) ||
  178. gljOprObj.marketPriceReadOnly(node);
  179. },
  180. forContain:function (node) {
  181. return MainTreeCol.readOnly.non_ration(node)&&!MainTreeCol.readOnly.glj(node);
  182. },
  183. forCode:function (node) {
  184. return MainTreeCol.readOnly.glj(node)|| (node.sourceType === projectObj.project.Ration.getSourceType()&&node.data.type===rationType.gljRation);
  185. },
  186. forUnit:function (node) {
  187. if(MainTreeCol.readOnly.bills(node)&&(node.data.type==billType.DXFY||node.data.type==billType.FB)){//在大项费用、分部行,计量单位只读。
  188. return true;
  189. }else {
  190. return calcTools.isRationItem(node);
  191. }
  192. },
  193. forContentCharacter: function (node) {
  194. return !MainTreeCol.readOnly.bills(node) || (node.data.type !== billType.BILL && node.data.type !== billType.FX);
  195. },
  196. forRuleText: function (node) {
  197. if(MainTreeCol.readOnly.bills(node)){
  198. if(node.data.type === billType.FX || (node.data.type === billType.BILL && node.source.children.length === 0)){
  199. return false;
  200. }
  201. }
  202. return true;
  203. }
  204. },
  205. cellType: {
  206. unit: function () {
  207. //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  208. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  209. dynamicCombo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  210. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']).editable(true);
  211. return dynamicCombo;
  212. },
  213. units: function () {
  214. this.unit;
  215. },
  216. feeRate: function () {
  217. return feeRateObject.getFeeRateEditCellType();
  218. },
  219. calcBase: function () {
  220. return calcBaseView.getCalcBaseCellType('bills');
  221. },
  222. // CSL, 2017-11-28
  223. calcProgramName: function (node) {
  224. if (
  225. node.sourceType === projectObj.project.Ration.getSourceType() ||
  226. (calcTools.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  227. ) {
  228. // var names = new GC.Spread.Sheets.CellTypes.ComboBox();
  229. var names = sheetCommonObj.getDynamicCombo();
  230. names.items(projectObj.project.calcProgram.compiledTemplateNames);
  231. return names;
  232. }
  233. },
  234. // Vincent, 2018-01-09
  235. subType: function (node) {
  236. if(node.sourceType!=projectObj.project.Bills.getSourceType()){
  237. let VPType = sheetCommonObj.getDynamicCombo();
  238. if(node.sourceType == projectObj.project.Ration.getSourceType()){//是定额类型
  239. if(node.data.type == rationType.volumePrice){
  240. VPType.itemHeight(5).items(["人工", "材料", "机械", "主材", "设备"])
  241. return VPType;
  242. }else if(node.data.type == rationType.gljRation){
  243. if(!MainTreeCol.readOnly.non_editSubType(node)&&gljOprObj.hasComposition(node.data,true)==false){
  244. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  245. return VPType;
  246. }
  247. }
  248. }else if(node.sourceType === projectObj.project.ration_glj.getSourceType()){//是工料机类型
  249. if(!MainTreeCol.readOnly.non_editSubType(node)&&gljOprObj.hasComposition(node.data)==false){
  250. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  251. return VPType;
  252. }
  253. }
  254. }
  255. },
  256. isSubcontract: function (node){
  257. if (calcTools.isRationCategory(node))
  258. return new GC.Spread.Sheets.CellTypes.CheckBox();
  259. }
  260. },
  261. getEvent: function (eventName) {
  262. let names = eventName.split('.');
  263. let event = this;
  264. for (let name of names) {
  265. if (event[name]) {
  266. event = event[name];
  267. } else {
  268. return null;
  269. }
  270. }
  271. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  272. return null;
  273. } else {
  274. return event;
  275. }
  276. },
  277. getNumberFormatter: function (digit, align) { // CSL, 2017-11-30 扩展:小数点是否对齐。
  278. if (align) {
  279. switch (digit) {
  280. case 1:
  281. return '0.0';
  282. case 2:
  283. return '0.00';
  284. case 3:
  285. return '0.000';
  286. case 4:
  287. return '0.0000';
  288. case 5:
  289. return '0.00000';
  290. case 6:
  291. return '0.000000';
  292. default:
  293. return '0.00';
  294. }
  295. ;
  296. }
  297. else {
  298. switch (digit) {
  299. case 1:
  300. return '0.#';
  301. case 2:
  302. return '0.##';
  303. case 3:
  304. return '0.###';
  305. case 4:
  306. return '0.####';
  307. case 5:
  308. return '0.#####';
  309. case 6:
  310. return '0.######';
  311. default:
  312. return '0.##';
  313. }
  314. ;
  315. }
  316. }
  317. };
  318. let colSettingObj = {
  319. settingSpread: null,
  320. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  321. loadSetting: function (sheet, setting) {
  322. sheet.suspendPaint();
  323. sheet.suspendEvent();
  324. sheet.setRowCount(setting.cols.length);
  325. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  326. sheet.setColumnCount(1);
  327. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  328. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  329. sheet.setColumnWidth(0, 100);
  330. sheet.setColumnWidth(0, 150, GC.Spread.Sheets.SheetArea.rowHeader);
  331. setting.cols.forEach(function (col, index) {
  332. let i, iCol = 0, cell;
  333. for (i = 0; i < col.head.spanCols.length; i++) {
  334. if (col.head.spanCols[i] !== 0) {
  335. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  336. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  337. }
  338. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  339. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  340. }
  341. iCol += col.head.spanRows[i];
  342. };
  343. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  344. colWidth = colWidth > col.width ? colWidth : col.width;
  345. //sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  346. cell = sheet.getCell(index, 0).value(col.visible);
  347. sheet.autoFitRow(index);
  348. });
  349. sheet.resumeEvent();
  350. sheet.resumePaint();
  351. },
  352. initSettingSpread: function () {
  353. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  354. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  355. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  356. }
  357. };
  358. $('#column').on('shown.bs.modal', function () {
  359. if (!colSettingObj.settingSpread) {
  360. colSettingObj.initSettingSpread();
  361. }
  362. });
  363. $('#column').on('hide.bs.modal', function () {
  364. let sheet = colSettingObj.settingSpread.getActiveSheet();
  365. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  366. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  367. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  368. }
  369. SheetDataHelper.massOperationSheet(projectObj.mainSpread.getActiveSheet(), function () {
  370. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  371. });
  372. //refresh nodes to autoFitRow
  373. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots, true);
  374. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {
  375. projectID: projectObj.project.ID(),
  376. main_tree_col: projectObj.project.projSetting.main_tree_col
  377. });
  378. });