main_tree_col.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 '';
  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. // CSL, 2017-11-28
  24. calcProgramName: function (node) {
  25. let programID = node.data.programID;
  26. if (!programID) return
  27. else return projectObj.project.calcProgram.compiledTemplateMaps[programID];
  28. }
  29. },
  30. readOnly: {
  31. // CSL, 2017-11-28
  32. subType: function (node){
  33. return (node.data.type != 2 && node.data.type != 3&&!MainTreeCol.readOnly.glj(node))||(node.data.type==rationType.gljRation&&MainTreeCol.readOnly.non_editSubType(node));
  34. },
  35. calcProgramName: function (node) {
  36. if (
  37. node.sourceType === projectObj.project.Ration.getSourceType() ||
  38. (projectObj.project.calcProgram.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  39. ) return false
  40. else return true;
  41. },
  42. non_editSubType:function (node) {
  43. return node.data.subType!=201&&node.data.subType!=4&&node.data.subType!=5
  44. },
  45. commonUnitFee: function(node){
  46. return !projectObj.project.calcProgram.isNullBill(node);
  47. },
  48. //根据节点、父节点类型判断是否可用计算基数
  49. calcBaseType: function (node) {
  50. function isDef (v) {
  51. return v !== undefined && v !== null;
  52. }
  53. function isFlag (v) {
  54. return this.isDef(v.flagsIndex) && this.isDef(v.flagsIndex.fixed);
  55. }
  56. let calcBase = projectObj.project.calcBase;
  57. let parent = node.parent;
  58. if(isFlag(node.data) && (node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.SUB_ENGINERRING
  59. || node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.CONSTRUCTION_TECH)){
  60. return true;
  61. }
  62. else if(isFlag(node.data) && node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.CONSTRUCTION_ORGANIZATION){
  63. return false;
  64. }
  65. else {
  66. if(!parent){
  67. return false;
  68. }
  69. else {
  70. return this.calcBaseType(parent);
  71. }
  72. }
  73. },
  74. bills: function (node) {
  75. return node.sourceType === projectObj.project.Bills.getSourceType();
  76. },
  77. ration: function (node) {
  78. return node.sourceType === projectObj.project.Ration.getSourceType();
  79. },
  80. glj: function (node) {
  81. return node.sourceType == projectObj.project.ration_glj.getSourceType();
  82. },
  83. volumePrice: function (node) {
  84. return (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  85. },
  86. non_bills: function (node) {
  87. return node.sourceType !== projectObj.project.Bills.getSourceType();
  88. },
  89. non_ration: function (node) {
  90. return node.sourceType !== projectObj.project.Ration.getSourceType();
  91. },
  92. non_volumePrice: function (node) {
  93. return !(node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  94. },
  95. billsParent: function (node) {
  96. return node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children.length > 0;
  97. },
  98. leafBillsWithDetail: function (node) {
  99. return (!MainTreeCol.readOnly.billsParent(node)) && (node.children.length > 0);
  100. },
  101. forCalcBase: function (node) {
  102. // to do according to billsParentType
  103. return MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.non_bills(node)||MainTreeCol.readOnly.leafBillsWithDetail(node) ||MainTreeCol.readOnly.calcBaseType(node);
  104. },
  105. forUnitFee: function (node) {
  106. return MainTreeCol.readOnly.ration(node) || MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.leafBillsWithDetail(node);
  107. },
  108. forTotalFee: function (node) {
  109. return MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.billsParent(node) || (MainTreeCol.readOnly.leafBillsWithDetail(node));
  110. },
  111. forQuantifyDetail:function (node) {
  112. return !(node.sourceType==ModuleNames.ration||!MainTreeCol.readOnly.billsParent(node));
  113. },
  114. forFeeRate:function (node) {
  115. return MainTreeCol.readOnly.non_bills(node)||MainTreeCol.readOnly.billsParent(node)||MainTreeCol.readOnly.leafBillsWithDetail(node)
  116. },
  117. forQuantity:function (node) {
  118. return MainTreeCol.readOnly.glj(node)||MainTreeCol.readOnly.billsParent(node)
  119. },
  120. forMarketPrice:function (node) {
  121. return MainTreeCol.readOnly.bills(node)||(MainTreeCol.readOnly.ration(node)&&node.data.type == rationType.ration)||gljOprObj.marketPriceReadOnly(node);
  122. }
  123. },
  124. cellType: {
  125. unit: function () {
  126. //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  127. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  128. dynamicCombo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  129. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']);
  130. return dynamicCombo;
  131. },
  132. units: function () {
  133. this.unit;
  134. },
  135. feeRate: function () {
  136. return feeRateObject.getFeeRateEditCellType();
  137. },
  138. calcBase: function () {
  139. return calcBaseView.getCalcBaseCellType();
  140. },
  141. // CSL, 2017-11-28
  142. calcProgramName: function (node) {
  143. if (
  144. node.sourceType === projectObj.project.Ration.getSourceType() ||
  145. (projectObj.project.calcProgram.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  146. ) {
  147. var names = new GC.Spread.Sheets.CellTypes.ComboBox();
  148. names.items(projectObj.project.calcProgram.compiledTemplateNames);
  149. return names;
  150. }
  151. },
  152. // CSL, 2017-11-28
  153. subType: function (node) {
  154. if (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation||node.sourceType === projectObj.project.ration_glj.getSourceType()){
  155. let VPType = sheetCommonObj.getDynamicCombo();;
  156. if (node.data.type == rationType.volumePrice)
  157. VPType.itemHeight(5).items(["人工","材料","机械","主材","设备"])
  158. else if (node.data.type == rationType.gljRation||node.sourceType === projectObj.project.ration_glj.getSourceType())
  159. if(!MainTreeCol.readOnly.non_editSubType(node)){
  160. VPType.itemHeight(3).items(["材料","主材","设备"]);
  161. }else {
  162. return null;
  163. }
  164. return VPType;
  165. };
  166. },
  167. },
  168. getEvent: function (eventName) {
  169. let names = eventName.split('.');
  170. let event = this;
  171. for (let name of names) {
  172. if (event[name]) {
  173. event = event[name];
  174. } else {
  175. return null;
  176. }
  177. }
  178. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  179. return null;
  180. } else {
  181. return event;
  182. }
  183. },
  184. getNumberFormatter: function (digit, align) { // CSL, 2017-11-30 扩展:小数点是否对齐。
  185. if (align) {
  186. switch (digit) {
  187. case 1:
  188. return '0.0';
  189. case 2:
  190. return '0.00';
  191. case 3:
  192. return '0.000';
  193. case 4:
  194. return '0.0000';
  195. case 5:
  196. return '0.00000';
  197. case 6:
  198. return '0.000000';
  199. default:
  200. return '0.00';
  201. };
  202. }
  203. else{
  204. switch (digit) {
  205. case 1:
  206. return '0.#';
  207. case 2:
  208. return '0.##';
  209. case 3:
  210. return '0.###';
  211. case 4:
  212. return '0.####';
  213. case 5:
  214. return '0.#####';
  215. case 6:
  216. return '0.######';
  217. default:
  218. return '0.##';
  219. };
  220. }
  221. }
  222. };
  223. let colSettingObj = {
  224. settingSpread: null,
  225. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  226. loadSetting: function (sheet, setting) {
  227. sheet.setRowCount(setting.cols.length);
  228. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  229. sheet.setColumnCount(1);
  230. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  231. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  232. sheet.setColumnWidth(0, 300);
  233. setting.cols.forEach(function (col, index) {
  234. let i, iCol = 0, cell;
  235. for (i = 0; i < col.head.spanCols.length; i++) {
  236. if (col.head.spanCols[i] !== 0) {
  237. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  238. cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  239. }
  240. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  241. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  242. }
  243. iCol += col.head.spanRows[i];
  244. };
  245. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  246. colWidth = colWidth > col.width ? colWidth : col.width;
  247. sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  248. cell = sheet.getCell(index, 0).value(col.visible);
  249. sheet.autoFitRow(index);
  250. });
  251. },
  252. initSettingSpread: function () {
  253. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  254. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  255. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  256. }
  257. };
  258. $('#column').on('shown.bs.modal', function () {
  259. if (!colSettingObj.settingSpread) {
  260. colSettingObj.initSettingSpread();
  261. }
  262. });
  263. $('#column').on('hide.bs.modal', function () {
  264. let sheet = colSettingObj.settingSpread.getActiveSheet();
  265. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  266. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  267. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  268. }
  269. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
  270. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {projectID: projectObj.project.ID(), main_tree_col: projectObj.project.projSetting.main_tree_col});
  271. });