main_tree_col.js 12 KB

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