main_tree_col.js 30 KB

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