main_tree_col.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. forContentCharacter: function (node) {
  186. return !MainTreeCol.readOnly.bills(node) || (node.data.type !== billType.BILL && node.data.type !== billType.FX);
  187. },
  188. forRuleText: function (node) {
  189. if(MainTreeCol.readOnly.bills(node)){
  190. if(node.data.type === billType.FX || (node.data.type === billType.BILL && node.source.children.length === 0)){
  191. console.log('enter');
  192. return false;
  193. }
  194. }
  195. return true;
  196. }
  197. },
  198. cellType: {
  199. unit: function () {
  200. //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  201. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  202. dynamicCombo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  203. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']).editable(true);
  204. return dynamicCombo;
  205. },
  206. units: function () {
  207. this.unit;
  208. },
  209. feeRate: function () {
  210. return feeRateObject.getFeeRateEditCellType();
  211. },
  212. calcBase: function () {
  213. return calcBaseView.getCalcBaseCellType('bills');
  214. },
  215. // CSL, 2017-11-28
  216. calcProgramName: function (node) {
  217. if (
  218. node.sourceType === projectObj.project.Ration.getSourceType() ||
  219. (calcTools.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  220. ) {
  221. // var names = new GC.Spread.Sheets.CellTypes.ComboBox();
  222. var names = sheetCommonObj.getDynamicCombo();
  223. names.items(projectObj.project.calcProgram.compiledTemplateNames);
  224. return names;
  225. }
  226. },
  227. // Vincent, 2018-01-09
  228. subType: function (node) {
  229. if(node.sourceType!=projectObj.project.Bills.getSourceType()){
  230. let VPType = sheetCommonObj.getDynamicCombo();
  231. if(node.sourceType == projectObj.project.Ration.getSourceType()){//是定额类型
  232. if(node.data.type == rationType.volumePrice){
  233. VPType.itemHeight(5).items(["人工", "材料", "机械", "主材", "设备"])
  234. return VPType;
  235. }else if(node.data.type == rationType.gljRation){
  236. if(!MainTreeCol.readOnly.non_editSubType(node)&&gljOprObj.hasComposition(node.data,true)==false){
  237. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  238. return VPType;
  239. }
  240. }
  241. }else if(node.sourceType === projectObj.project.ration_glj.getSourceType()){//是工料机类型
  242. if(!MainTreeCol.readOnly.non_editSubType(node)&&gljOprObj.hasComposition(node.data)==false){
  243. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  244. return VPType;
  245. }
  246. }
  247. }
  248. },
  249. isSubcontract: function (node){
  250. if (calcTools.isRationCategory(node))
  251. return new GC.Spread.Sheets.CellTypes.CheckBox();
  252. }
  253. },
  254. getEvent: function (eventName) {
  255. let names = eventName.split('.');
  256. let event = this;
  257. for (let name of names) {
  258. if (event[name]) {
  259. event = event[name];
  260. } else {
  261. return null;
  262. }
  263. }
  264. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  265. return null;
  266. } else {
  267. return event;
  268. }
  269. },
  270. getNumberFormatter: function (digit, align) { // CSL, 2017-11-30 扩展:小数点是否对齐。
  271. if (align) {
  272. switch (digit) {
  273. case 1:
  274. return '0.0';
  275. case 2:
  276. return '0.00';
  277. case 3:
  278. return '0.000';
  279. case 4:
  280. return '0.0000';
  281. case 5:
  282. return '0.00000';
  283. case 6:
  284. return '0.000000';
  285. default:
  286. return '0.00';
  287. }
  288. ;
  289. }
  290. else {
  291. switch (digit) {
  292. case 1:
  293. return '0.#';
  294. case 2:
  295. return '0.##';
  296. case 3:
  297. return '0.###';
  298. case 4:
  299. return '0.####';
  300. case 5:
  301. return '0.#####';
  302. case 6:
  303. return '0.######';
  304. default:
  305. return '0.##';
  306. }
  307. ;
  308. }
  309. }
  310. };
  311. let colSettingObj = {
  312. settingSpread: null,
  313. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  314. loadSetting: function (sheet, setting) {
  315. sheet.suspendPaint();
  316. sheet.suspendEvent();
  317. sheet.setRowCount(setting.cols.length);
  318. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  319. sheet.setColumnCount(1);
  320. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  321. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  322. sheet.setColumnWidth(0, 100);
  323. sheet.setColumnWidth(0, 150, GC.Spread.Sheets.SheetArea.rowHeader);
  324. setting.cols.forEach(function (col, index) {
  325. let i, iCol = 0, cell;
  326. for (i = 0; i < col.head.spanCols.length; i++) {
  327. if (col.head.spanCols[i] !== 0) {
  328. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  329. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  330. }
  331. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  332. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  333. }
  334. iCol += col.head.spanRows[i];
  335. };
  336. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  337. colWidth = colWidth > col.width ? colWidth : col.width;
  338. //sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  339. cell = sheet.getCell(index, 0).value(col.visible);
  340. sheet.autoFitRow(index);
  341. });
  342. sheet.resumeEvent();
  343. sheet.resumePaint();
  344. },
  345. initSettingSpread: function () {
  346. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  347. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  348. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  349. }
  350. };
  351. $('#column').on('shown.bs.modal', function () {
  352. if (!colSettingObj.settingSpread) {
  353. colSettingObj.initSettingSpread();
  354. }
  355. });
  356. $('#column').on('hide.bs.modal', function () {
  357. let sheet = colSettingObj.settingSpread.getActiveSheet();
  358. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  359. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  360. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  361. }
  362. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  363. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {
  364. projectID: projectObj.project.ID(),
  365. main_tree_col: projectObj.project.projSetting.main_tree_col
  366. });
  367. });