main_tree_col.js 17 KB

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