main_tree_col.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. }else if(node.data.type == 4){//安装增加费生成的定额
  19. return '安';
  20. }
  21. } else if (node.sourceType === projectObj.project.ration_glj.getSourceType()) {
  22. return projectObj.project.projectGLJ.getShortNameByID(node.data.subType);//工料机名字缩写
  23. }
  24. },
  25. quantity:function (node) {
  26. if(node.sourceType === projectObj.project.ration_glj.getSourceType()){
  27. return gljOprObj.getTotalQuantity(node.data);
  28. }else {
  29. return calcTools.uiNodeQty(node)?calcTools.uiNodeQty(node):null;
  30. }
  31. },
  32. // CSL, 2017-11-28
  33. calcProgramName: function (node) {
  34. let programID = node.data.programID;
  35. if (!programID) return
  36. else return projectObj.project.calcProgram.compiledTemplateMaps[programID];
  37. },
  38. calcBase: function (node) {
  39. if (node.data.calcBase && node.data.calcBase != ""){
  40. return cbParser.toFExpr(node.data.calcBase);
  41. }
  42. },
  43. code: function (node) {
  44. if(!isDef(node)){
  45. return '';
  46. }
  47. let rst = '';
  48. if(node.sourceType === projectObj.project.Ration.getSourceType() && node.data.type === rationType.ration
  49. && isDef(node.data.code) && isDef(node.data.prefix) && node.data.prefix !== ''){
  50. rst = node.data.prefix + node.data.code.replace(new RegExp(node.data.prefix, 'g'), '');
  51. }
  52. else
  53. rst = isDef(node.data.code) ? node.data.code : '';
  54. if (node.data.adjustState && rst != '')
  55. rst = rst + rationPrefix.replace;
  56. return rst;
  57. },
  58. marketPrice:function (node) {
  59. if((node.sourceType === projectObj.project.Ration.getSourceType()&&node.data.type!=rationType.ration)||node.sourceType==projectObj.project.ration_glj.getSourceType()){
  60. if(node.data.marketUnitFee) return calcTools.uiGLJPrice(node.data.marketUnitFee);
  61. }
  62. },
  63. feeRate:function (node) {
  64. if(node.data.feeRateID){
  65. let rate = projectObj.project.FeeRate.getFeeRateByID(node.data.feeRateID);
  66. if (rate) return rate.rate;
  67. }
  68. return node.data.feeRate;
  69. }
  70. },
  71. readOnly: {
  72. // Vincent, 2018-01-09
  73. subType: function (node) {
  74. if (calcTools.isVolumePrice(node)) return false;
  75. if(MainTreeCol.readOnly.bills(node)){
  76. return true;
  77. }
  78. if(MainTreeCol.readOnly.ration(node)){
  79. return true;
  80. }
  81. if(MainTreeCol.readOnly.non_editSubType(node)){
  82. return true;
  83. }else if(gljOprObj.hasComposition(node.data,node.sourceType === ModuleNames.ration)){
  84. return true;
  85. }
  86. return false;
  87. },
  88. calcProgramName: function (node) {
  89. if (node.sourceType === projectObj.project.Ration.getSourceType() ||
  90. (calcTools.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  91. ) {
  92. //当打勾估价项目选项后,该定额取费专业只读
  93. if(node.data.evaluationProject == 1){
  94. return true;
  95. }
  96. return false;
  97. }
  98. return true;
  99. },
  100. non_editSubType: function (node) {
  101. return node.data.subType != 201 && node.data.subType != 4 && node.data.subType != 5
  102. },
  103. commonUnitFee: function (node) {
  104. // 2018-11-15 zhang
  105. let Bills =projectObj.project.Bills;
  106. if(node.sourceType == ModuleNames.bills){//针对清单、分项部分
  107. // 当前属于分部分项、施工技术措施项目,综合单价只读。
  108. if(Bills.isFBFX(node)||Bills.isTechMeasure(node)) return true;
  109. // 不属于分部分项、施工技术措施项目的部分,如果不是叶子清单,或有基数计算/定额/量价/人材机 只读
  110. if(!calcTools.isLeafBill(node)||calcTools.isCalcBaseBill(node)||node.children.length > 0)return true;
  111. }
  112. //当前是定额,综合单价只读。 2018-11-15
  113. if(MainTreeCol.readOnly.ration(node)) return true;
  114. return false;
  115. },
  116. commonTotalFee: function (node) {
  117. // 09-29 zhang
  118. // 当前属于分部分项、施工技术措施项目,综合单价只读。
  119. /*if(Bills.isFBFX(node)||Bills.isTechMeasure(node)){
  120. return true;
  121. }*/
  122. //如果不是叶子清单,或有基数计算/定额/量价/人材机 只读
  123. if(!calcTools.isLeafBill(node)||calcTools.isCalcBaseBill(node)||node.children.length > 0){
  124. return true;
  125. }
  126. return false;
  127. },
  128. //根据节点、父节点类型判断是否可用计算基数
  129. calcBaseType: function (node) {
  130. function isDef(v) {
  131. return v !== undefined && v !== null;
  132. }
  133. function isFlag(v) {
  134. return this.isDef(v.flagsIndex) && this.isDef(v.flagsIndex.fixed);
  135. }
  136. let calcBase = projectObj.project.calcBase;
  137. let parent = node.parent;
  138. if (isFlag(node.data) && (node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.SUB_ENGINERRING
  139. || node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.CONSTRUCTION_TECH)) {
  140. return true;
  141. }
  142. else if (isFlag(node.data) && node.data.flagsIndex.fixed.flag === calcBase.fixedFlag.CONSTRUCTION_ORGANIZATION) {
  143. return false;
  144. }
  145. else {
  146. if (!parent) {
  147. return false;
  148. }
  149. else {
  150. return this.calcBaseType(parent);
  151. }
  152. }
  153. },
  154. bills: function (node) {
  155. return node.sourceType === projectObj.project.Bills.getSourceType();
  156. },
  157. ration: function (node) {
  158. return calcTools.isRationItem(node);
  159. },
  160. isSubcontract: function (node) {
  161. return !calcTools.isRationCategory(node);
  162. },
  163. glj: function (node) {
  164. return node.sourceType == projectObj.project.ration_glj.getSourceType();
  165. },
  166. specialProvisional:function (node) {
  167. //是否使用了专项暂定合计基数,使用了的节点不可设置专项暂定(会造成循环计算)
  168. //只允许“第100章至700章清单”下的叶子清单可选
  169. let belongFlagList = cbTools.getBelongFlagList(node);
  170. return !(node.sourceType == ModuleNames.bills && node.source.children.length == 0 && belongFlagList.includes(fixedFlag.ONE_SEVEN_BILLS));
  171. },
  172. volumePrice: function (node) {
  173. return (node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  174. },
  175. non_bills: function (node) {
  176. return node.sourceType !== projectObj.project.Bills.getSourceType();
  177. },
  178. non_ration: function (node) {
  179. return node.sourceType !== projectObj.project.Ration.getSourceType();
  180. },
  181. non_volumePrice: function (node) {
  182. return !(node.data.type == rationType.volumePrice || node.data.type == rationType.gljRation);
  183. },
  184. billsParent: function (node) {
  185. return node.sourceType === projectObj.project.Bills.getSourceType() && node.source.children.length > 0;
  186. },
  187. leafBillsWithDetail: function (node) {
  188. return (!MainTreeCol.readOnly.billsParent(node)) && (node.children.length > 0);
  189. },
  190. forCalcBase: function (node) {
  191. // to do according to billsParentType
  192. return MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.leafBillsWithDetail(node) || MainTreeCol.readOnly.calcBaseType(node);
  193. },
  194. forUnitFee: function (node) {
  195. return MainTreeCol.readOnly.ration(node) || MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.leafBillsWithDetail(node);
  196. },
  197. forTotalFee: function (node) {
  198. return MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.billsParent(node) || (MainTreeCol.readOnly.leafBillsWithDetail(node));
  199. },
  200. forQuantifyDetail: function (node) {
  201. return !(node.sourceType == ModuleNames.ration || !MainTreeCol.readOnly.billsParent(node));
  202. },
  203. forFeeRate: function (node) {
  204. let readOnly = true;
  205. let Bills = projectObj.project.Bills;
  206. //只有当选中节点是清单,并且不属于“分部分项工程”或“技术措施项目”,并且是叶子清单且没有定额/量价/工料机时,费率列才可编辑
  207. if(MainTreeCol.readOnly.bills(node)){
  208. if(!Bills.isFBFX(node)&&!Bills.isTechMeasure(node)&&node.children.length<=0){//不属于“分部分项工程”或“技术措施项目”,并且是叶子清单且没有定额/量价/工料机
  209. readOnly = false;
  210. }
  211. }
  212. return readOnly;
  213. },
  214. forQuantity: function (node) {
  215. if(node.sourceType === projectObj.project.Bills.getSourceType()){
  216. if(node.data.type==billType.DXFY||node.data.type==billType.FB||(node.data.type==billType.BILL&&MainTreeCol.readOnly.billsParent(node))){//大项费用、分部、清单父项行,工程量只读。
  217. return true;
  218. }
  219. }else if(MainTreeCol.readOnly.glj(node)){
  220. return true;
  221. }
  222. return false;
  223. },
  224. forQuantity2:function (node) {
  225. if(node.sourceType !== ModuleNames.bills) return true;//不是清单,只读
  226. if(node.data.type==billType.DXFY||(node.data.type==billType.BILL&&MainTreeCol.readOnly.billsParent(node))) return true;//大项费用、清单父项行,工程量只读。
  227. return false
  228. },
  229. forMarketPrice: function (node) {
  230. return MainTreeCol.readOnly.bills(node) ||
  231. (node.sourceType === ModuleNames.ration && node.data.type == rationType.ration) ||
  232. gljOprObj.marketPriceReadOnly(node);
  233. },
  234. forContain:function (node) {
  235. return MainTreeCol.readOnly.non_ration(node)&&!MainTreeCol.readOnly.glj(node);
  236. },
  237. forCode:function (node) {
  238. let Bills = projectObj.project.Bills;
  239. if(MainTreeCol.readOnly.glj(node)|| (node.sourceType === projectObj.project.Ration.getSourceType()&&node.data.type===rationType.gljRation)){//是主材或者设备、或者是工料机类型的定额
  240. return true;
  241. }
  242. if(Bills.isTopThreeNode(node)){//是大项1、2、3项的编号设置为只读
  243. return true;
  244. }
  245. return false;
  246. },
  247. forName:function (node) {
  248. if(projectObj.project.Bills.isTopThreeNode(node)){//是大项1、2、3项的编号设置为只读
  249. return true;
  250. }
  251. return false;
  252. },
  253. forUnit:function (node) {
  254. if(MainTreeCol.readOnly.bills(node)&&(node.data.type==billType.DXFY||node.data.type==billType.FB)){//在大项费用、分部行,计量单位只读。
  255. return true;
  256. }else {
  257. return calcTools.isRationItem(node);
  258. }
  259. },
  260. forContentCharacter: function (node) {
  261. return !MainTreeCol.readOnly.bills(node) || (node.data.type !== billType.BILL && node.data.type !== billType.FX);
  262. },
  263. forRuleText: function (node) {
  264. if(MainTreeCol.readOnly.bills(node)){
  265. if(node.data.type === billType.FX || (node.data.type === billType.BILL && node.source.children.length === 0)){
  266. return false;
  267. }
  268. }
  269. return true;
  270. }
  271. },
  272. cellType: {
  273. unit: function (node,setting) {
  274. let tips = "";
  275. //在这里做要不要显示的判断
  276. if(node.sourceType == ModuleNames.bills &&projectObj.ifItemCharHiden(setting)){//清单、并且项目特征列隐藏的时候悬浮提示
  277. tips = node.data.itemCharacterText?node.data.itemCharacterText:'';
  278. }
  279. if(node.sourceType == ModuleNames.ration && node.data.type == rationType.ration){//定额类型时,显示人材机,工作内容等
  280. //这里的人材机需要进行过滤,在初始化时组装会影响性能,应实时显示
  281. tips = MainTreeCol.getRationUnitTips
  282. }
  283. let dynamicCombo = sheetCommonObj.getTipsCombo(true,tips,setting,node);//sheetCommonObj.getDynamicCombo(true);
  284. dynamicCombo.itemHeight(10).items(['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  285. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']).editable(true);
  286. return dynamicCombo;
  287. },
  288. units: function () {
  289. this.unit;
  290. },
  291. feeRate: function () {
  292. return feeRateObject.getFeeRateEditCellType();
  293. },
  294. quantity:function (node) {
  295. if(!MainTreeCol.readOnly.forQuantity(node)){
  296. return quantityEditObj.getQuantityEditCellType();
  297. }
  298. },
  299. calcBase: function () {
  300. return calcBaseView.getCalcBaseCellType('bills');
  301. },
  302. // CSL, 2017-11-28
  303. calcProgramName: function (node) {
  304. if (
  305. node.sourceType === projectObj.project.Ration.getSourceType() ||
  306. (calcTools.isLeafBill(node) && projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  307. ) {
  308. // var names = new GC.Spread.Sheets.CellTypes.ComboBox();
  309. var names = sheetCommonObj.getDynamicCombo();
  310. names._maxDropDownItems = 10;
  311. names.items(projectObj.project.calcProgram.compiledTemplateNames);
  312. return names;
  313. }
  314. },
  315. // Vincent, 2018-01-09
  316. subType: function (node) {
  317. if(node.sourceType!=projectObj.project.Bills.getSourceType()){
  318. let VPType = sheetCommonObj.getDynamicCombo();
  319. if(node.sourceType == projectObj.project.Ration.getSourceType()){//是定额类型
  320. if(node.data.type == rationType.volumePrice){
  321. VPType.itemHeight(5).items(["人工", "材料", "机械", "主材", "设备"])
  322. return VPType;
  323. }else if(node.data.type == rationType.gljRation){
  324. if(!MainTreeCol.readOnly.non_editSubType(node)&&gljOprObj.hasComposition(node.data,true)==false){
  325. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  326. return VPType;
  327. }
  328. }
  329. }else if(node.sourceType === projectObj.project.ration_glj.getSourceType()){//是工料机类型
  330. if(!MainTreeCol.readOnly.non_editSubType(node)&&gljOprObj.hasComposition(node.data)==false){
  331. VPType.itemHeight(3).items(["材料", "主材", "设备"]);
  332. return VPType;
  333. }
  334. }
  335. }
  336. },
  337. isSubcontract: function (node){
  338. if (calcTools.isRationCategory(node))
  339. return new GC.Spread.Sheets.CellTypes.CheckBox();
  340. },
  341. isEstimate:function (node) {
  342. //只对分项、补项、材料(包括混凝土等)、主材、设备有效
  343. if(MainTreeCol.readOnly.glj(node)||(calcTools.isGljRation(node)&&projectObj.project.projectGLJ.isEstimateType(node.data.subType))||(MainTreeCol.readOnly.bills(node)&&(node.data.type == billType.BX||node.data.type == billType.FX))){
  344. return new GC.Spread.Sheets.CellTypes.CheckBox();
  345. }
  346. },
  347. unitPriceAnalysis:function (node) {
  348. if(node.sourceType == ModuleNames.bills) return new GC.Spread.Sheets.CellTypes.CheckBox();
  349. },
  350. evaluationProject:function (node) {
  351. if(node.sourceType == ModuleNames.ration) return new GC.Spread.Sheets.CellTypes.CheckBox();
  352. },
  353. commonTotalFee: function (node) {
  354. let readOnly = projectReadOnly || !calcBaseView.ifEdit('bills', projectObj.project.mainTree.items.indexOf(node));
  355. return sheetCommonObj.getCusButtonCellType(projectObj.onCommonTotalFeeButtonClick,readOnly) //projectObj.getCommonTotalFeeCellType();
  356. },
  357. specialProvisional: function (node) {
  358. if(!MainTreeCol.readOnly.specialProvisional(node)){
  359. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  360. dynamicCombo.items(["材料","工程设备","专业工程",""]);
  361. return dynamicCombo;
  362. }
  363. }
  364. },
  365. editChecking:function(node){
  366. if(node.sourceType==projectObj.project.Bills.getSourceType()&&projectObj.project.isBillsLocked()&&projectObj.project.withinBillsLocked(node)){
  367. return true;
  368. }
  369. if(gljOprObj.isInstallationNode(node)){//如果是通过安装增加费自动生成的,都是只读类型
  370. return true;
  371. }
  372. return false;
  373. },
  374. setAutoHeight:function (cell,node) {//设置自动行高
  375. cell.wordWrap(MainTreeCol.needAutoFit(node));
  376. },
  377. setAutoFitRow:function (sheet,node) {
  378. if(MainTreeCol.needAutoFit(node)){
  379. sheet.autoFitRow(node.serialNo());
  380. }
  381. },
  382. needAutoFit:function (node) {
  383. let displaySetting = projectObj.project.property.displaySetting;
  384. let billsAutoH = displaySetting && displaySetting.billsAutoHeight?displaySetting.billsAutoHeight:false;
  385. let rationAutoH = displaySetting && displaySetting.rationAutoHeight?displaySetting.rationAutoHeight:false;
  386. if(node.sourceType === projectObj.project.Bills.getSourceType()&&billsAutoH == true){
  387. return true;
  388. }
  389. if(node.sourceType !== projectObj.project.Bills.getSourceType()&& rationAutoH == true){
  390. return true;
  391. }
  392. return false;
  393. },
  394. getEvent: function (eventName) {
  395. let names = eventName.split('.');
  396. let event = this;
  397. for (let name of names) {
  398. if (event[name]) {
  399. event = event[name];
  400. } else {
  401. return null;
  402. }
  403. }
  404. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  405. return null;
  406. } else {
  407. return event;
  408. }
  409. },
  410. getNumberFormatter: function (digit, align) { // CSL, 2017-11-30 扩展:小数点是否对齐。
  411. if (align) {
  412. switch (digit) {
  413. case 1:
  414. return '0.0';
  415. case 2:
  416. return '0.00';
  417. case 3:
  418. return '0.000';
  419. case 4:
  420. return '0.0000';
  421. case 5:
  422. return '0.00000';
  423. case 6:
  424. return '0.000000';
  425. default:
  426. return '0';
  427. }
  428. ;
  429. }
  430. else {
  431. switch (digit) {
  432. case 1:
  433. return '0.#';
  434. case 2:
  435. return '0.##';
  436. case 3:
  437. return '0.###';
  438. case 4:
  439. return '0.####';
  440. case 5:
  441. return '0.#####';
  442. case 6:
  443. return '0.######';
  444. default:
  445. return '0';
  446. };
  447. }
  448. },
  449. getRationUnitTips:function (node) {
  450. let tips="";
  451. let ration_glj = projectObj.project.ration_glj;
  452. let gljList = gljOprObj.filterGljByRation(node.data, ration_glj.datas);
  453. gljList = gljUtil.sortRationGLJ(gljList);
  454. for(let glj of gljList){
  455. tips += `${glj.code} ${glj.name}${glj.specs ? '&nbsp;&nbsp;&nbsp;' + glj.specs : ''}&nbsp;&nbsp&nbsp;${glj.unit}&nbsp;&nbsp;&nbsp;${glj.quantity}<br>`;
  456. }
  457. if(node.data.content && node.data.content.toString().trim() !== ''){
  458. tips += `工作内容:<br>`;
  459. tips += `${node.data.content.replace(/\n/g,"<br>")}<br>`;
  460. }
  461. if(node.data.annotation && node.data.annotation.toString().trim() !== ''){
  462. tips += `附注:<br>`;
  463. tips += `${node.data.annotation.replace(/\n/g,"<br>")}<br>`;
  464. }
  465. return tips
  466. }
  467. };
  468. let colSettingObj = {
  469. settingSpread: null,
  470. checkBox: new GC.Spread.Sheets.CellTypes.CheckBox(),
  471. loadSetting: function (sheet, setting) {
  472. sheet.suspendPaint();
  473. sheet.suspendEvent();
  474. sheet.setRowCount(setting.cols.length);
  475. sheet.setColumnCount(setting.headRows, GC.Spread.Sheets.SheetArea.rowHeader);
  476. sheet.setColumnCount(1);
  477. sheet.getRange(-1, 0, -1, 1).cellType(this.checkBox).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  478. sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.colHeader).value('显示');
  479. sheet.setColumnWidth(0, 100);
  480. sheet.setColumnWidth(0, 240, GC.Spread.Sheets.SheetArea.rowHeader);
  481. setting.cols.forEach(function (col, index) {
  482. let i, iCol = 0, cell;
  483. for (i = 0; i < col.head.spanCols.length; i++) {
  484. if (col.head.spanCols[i] !== 0) {
  485. cell = sheet.getCell(index, iCol, GC.Spread.Sheets.SheetArea.rowHeader);
  486. cell.value(col.head.titleNames[i]).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  487. //cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]);
  488. }
  489. if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
  490. sheet.addSpan(index, iCol, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.rowHeader);
  491. }
  492. iCol += col.head.spanRows[i];
  493. };
  494. let colWidth = sheet.getColumnWidth(index, GC.Spread.Sheets.SheetArea.rowHeader);
  495. colWidth = colWidth > col.width ? colWidth : col.width;
  496. //sheet.setColumnWidth(index, colWidth, GC.Spread.Sheets.SheetArea.rowHeader);
  497. cell = sheet.getCell(index, 0).value(col.visible);
  498. sheet.autoFitRow(index);
  499. });
  500. sheet.resumeEvent();
  501. sheet.resumePaint();
  502. },
  503. initSettingSpread: function () {
  504. this.settingSpread = SheetDataHelper.createNewSpread($('#col_setting_spread')[0], {sheetCount: 1});
  505. sheetCommonObj.spreadDefaultStyle(this.settingSpread);
  506. this.settingSpread.options.showScrollTip = GC.Spread.Sheets.ShowScrollTip.vertical;
  507. this.settingSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, function (sender, args) {
  508. if(args.sheet.isEditing()){
  509. args.sheet.endEdit(true);
  510. }
  511. });
  512. this.loadSetting(this.settingSpread.getActiveSheet(), projectObj.project.projSetting.main_tree_col);
  513. },
  514. dataChanged: function () {
  515. let sheet = this.settingSpread.getActiveSheet();
  516. for(let row = 0; row < sheet.getRowCount(); row++){
  517. let orgData = projectObj.project.projSetting.main_tree_col.cols[row].visible;
  518. let newData = sheet.getValue(row, 0);
  519. if(orgData != newData){
  520. return true;
  521. }
  522. }
  523. return false;
  524. },
  525. updateColSetting: function (skipSetValue = false) {
  526. let mainSheet = projectObj.mainSpread.getActiveSheet();
  527. if(!skipSetValue){
  528. let sheet = this.settingSpread.getActiveSheet();
  529. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  530. projectObj.project.projSetting.main_tree_col.cols[iRow].visible = sheet.getValue(iRow, 0);
  531. projectObj.project.projSetting.mainGridSetting.cols[iRow].visible = sheet.getValue(iRow, 0);
  532. }
  533. }
  534. SheetDataHelper.massOperationSheet(mainSheet, function () {
  535. SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, mainSheet);
  536. //左右滚动条到最左边
  537. mainSheet.showColumn(projectObj.project.projSetting.mainGridSetting.frozenCols, GC.Spread.Sheets.HorizontalPosition.left);
  538. });
  539. //refresh nodes to autoFitRow
  540. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots, true);
  541. if(!skipSetValue){
  542. //列设置将项目特征和工作内容都取消打钩后,更新快速列设置
  543. if(!this.getVisible('itemCharacterText')){
  544. switchTznrHtml(true);
  545. }
  546. if(this.getVisible('itemCharacterText')){
  547. switchTznrHtml(false);
  548. }
  549. }
  550. //别人分享过来的项目,打开时,“显示特征”按钮应有效,不影响数据的修改
  551. if(!projectReadOnly){
  552. projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {
  553. projectID: projectObj.project.ID(),
  554. main_tree_col: projectObj.project.projSetting.main_tree_col
  555. });
  556. }
  557. },
  558. setVisible: function (field, visible) {
  559. let mainTreeCols = projectObj.project.projSetting.main_tree_col.cols;
  560. for(let colSetting of mainTreeCols){
  561. if(colSetting.data.field === field){
  562. colSetting.visible = visible;
  563. break;
  564. }
  565. }
  566. let mainGridCols = projectObj.project.projSetting.mainGridSetting.cols;
  567. for(let colSetting of mainGridCols){
  568. if(colSetting.data.field === field){
  569. colSetting.visible = visible;
  570. break;
  571. }
  572. }
  573. },
  574. getVisible: function(field){
  575. let cols = projectObj.project.projSetting.main_tree_col.cols;
  576. for(let colSetting of cols){
  577. if(colSetting.data.field === field){
  578. return colSetting.visible;
  579. }
  580. }
  581. return false;
  582. },
  583. getColByField: function (field) {
  584. let cols = projectObj.project.projSetting.main_tree_col.cols;
  585. for(let i = 0; i < cols.length; i++){
  586. let colSetting = cols[i];
  587. if(colSetting.data.field === field){
  588. return i;
  589. }
  590. }
  591. return null;
  592. },
  593. getFieldByCol: function (col) {
  594. let cols = projectObj.project.projSetting.main_tree_col.cols;
  595. let colSetting = cols[col];
  596. return colSetting ? colSetting.data.field : null;
  597. }
  598. };
  599. function switchTznrHtml(show) {
  600. if(show){
  601. $('#switchTznr').html('<i class="fa fa-eye" aria-hidden="true"></i> 显示特征');
  602. }
  603. else {
  604. $('#switchTznr').html('<i class="fa fa-eye-slash" aria-hidden="true"></i> 隐藏特征');
  605. }
  606. }
  607. $('#switchTznr').click(function () {
  608. let me = colSettingObj;
  609. let cur = $(this).text();
  610. if(cur.includes('显示特征')){
  611. switchTznrHtml(false);
  612. me.setVisible('itemCharacterText', true);
  613. me.updateColSetting(true);
  614. }
  615. else {
  616. switchTznrHtml(true);
  617. me.setVisible('itemCharacterText', false);
  618. me.updateColSetting(true);
  619. }
  620. let mainSheet = projectObj.mainSpread.getActiveSheet();
  621. mainSheet.showRow(mainSheet.getActiveRowIndex(), GC.Spread.Sheets.VerticalPosition.center);
  622. });
  623. $('#poj-set').on('shown.bs.modal', function (e) {
  624. if (!colSettingObj.settingSpread) {
  625. colSettingObj.initSettingSpread();
  626. if(projectReadOnly){
  627. disableSpread(colSettingObj.settingSpread);
  628. }
  629. }
  630. if($('#tab_display_setting').hasClass('active')){
  631. let sheet = colSettingObj.settingSpread.getActiveSheet();
  632. SheetDataHelper.massOperationSheet(sheet, function () {
  633. for(let row = 0; row < sheet.getRowCount(); row++){
  634. let orgData = projectObj.project.projSetting.main_tree_col.cols[row].visible;
  635. sheet.setValue(row, 0, orgData);
  636. }
  637. });
  638. }
  639. });
  640. $('#poj-set').on('hidden.bs.modal', function (e) {
  641. if (colSettingObj.settingSpread) {
  642. //恢复
  643. let sheet = colSettingObj.settingSpread.getActiveSheet();
  644. SheetDataHelper.massOperationSheet(sheet, function () {
  645. for(let row = 0; row < sheet.getRowCount(); row++){
  646. let orgData = projectObj.project.projSetting.main_tree_col.cols[row].visible;
  647. sheet.setValue(row, 0, orgData);
  648. }
  649. });
  650. }
  651. });
  652. $('#tab_display_setting').on('shown.bs.tab', function () {
  653. if(colSettingObj.settingSpread){
  654. colSettingObj.settingSpread.refresh();
  655. }
  656. });