/** * Created by chen on 2017/8/1. */ var subRateObject={ views:null, datas:null, valueMap:null, canEdit:true, subRateSpread:null, subRateSheet:null, subRateSetting:{ header: [ {headerName: "参数名称", headerWidth: 110, dataCode: "name", dataType: "String"}, {headerName: "参数值", headerWidth: 150, dataCode: "optionValue", dataType: "String",getText:'forOption'} ], view: { lockColumns: [0] }, getText:{ forOption:function (item,val) { let o = _.find(item.optionList,{'selected':true}); return o?o.value:''; } } }, columns: [ { id: 'name', caption: '参数名称', dataField: 'name', width: 250, allowEditing: false }, { id: 'typeName', caption: '参数值', dataField: 'typeName', width: 200, minWidth: 50, allowEditing: true, presenter:'
' }, { id: 'ID', caption: 'ID', dataField: 'ID', width: 80, visible: false, allowEditing: false } ], options :{ allowSorting: false, showRowHeader: true, colMinWidth: 80, rowHeight: 33, allowEditing: this.canEdit, editMode: 'inline', editUnit: 'cell', selectionUnit:(this.canEdit == true) ? "cell" : "row" }, createSpreadView:function () { if (this.views) { this.views.destroy(); this.views = null; } this.views = new GC.Spread.Views.DataView($('#subRate')[0], this.datas, this.columns, new GC.Spread.Views.Plugins.GridLayout(this.options)); this.views["rowDbClick"].addHandler(function () { console.log('hh') }); this.views.invalidate(); document.querySelector('#subRate').focus(); this.addComboboxOption(this.datas); }, reFreshRateViews:function(sender,args) { subRateObject.datas = projectObj.project.FeeRate.getSubViewData(args.item); subRateObject.valueMap=projectObj.project.FeeRate.getValueMap(args.item); subRateObject.createSpreadView(); }, initSubRateSpread:function (item) { if(this.subRateSpread == null){ this.subRateSpread = SheetDataHelper.createNewSpread($("#subRate")[0]); sheetCommonObj.spreadDefaultStyle(this.subRateSpread); this.subRateSheet = this.subRateSpread.getSheet(0); sheetCommonObj.initSheet(this.subRateSheet, this.subRateSetting, 30); this.subRateSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, this.onSubRateSelectChanged); this.subRateSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onSubRateValueChange); //this.subRateSheet.bind(GC.Spread.Sheets.Events.ValueChanged, me.onSheetValueChange); this.subRateSheet.name('subRateSheet'); } /* 20201209 改成和公路一样 subRateObject.datas = projectObj.project.FeeRate.getSubViewData(item); subRateObject.valueMap=projectObj.project.FeeRate.getValueMap(item); */ subRateObject.showSubRateData(); disableRightMenu("subRate",this.subRateSpread); if(projectReadOnly){ if(this.subRateSetting.view.lockColumns){ this.subRateSetting.view.lockColumns = null; } sheetCommonObj.disableSpread(this.subRateSpread); } }, /* 20201209 改成和公路一样 showSubRateData:function () { this.subRateSheet.setRowCount(0); sheetCommonObj.showData(this.subRateSheet, this.subRateSetting, this.datas); this.subRateSheet.setRowCount(this.datas.length); for(let row =0; row < this.datas.length;row++){ this.setComboOptionCell(row,1,this.datas[row],this.subRateSheet); } }, */ showSubRateData:function () { let preSelections = this.subRateSheet.getSelections(); this.datas = projectObj.project.FeeRate.getAllSubRates(); this.subRateSheet.setRowCount(0); sheetCommonObj.showData(this.subRateSheet, this.subRateSetting, this.datas); this.subRateSheet.setRowCount(this.datas.length); let parentMap=_.groupBy(this.datas, 'ParentID'); let visibleMap = {}; this.subRateSheet.suspendPaint(); this.subRateSheet.suspendEvent(); for(let row =0; row < this.datas.length;row++){ this.setComboOptionCell(row,1,this.datas[row],this.subRateSheet); this.setTreeNodeCellType(this.datas,row,parentMap,visibleMap,this.subRateSheet); } this.subRateSheet.resumeEvent(); this.subRateSheet.resumePaint(); if(preSelections){//定位光标到之前的位置 this.subRateSheet.setSelection(preSelections[0].row,preSelections[0].col,preSelections[0].rowCount,preSelections[0].colCount); } }, onSubRateSelectChanged:function (e,info) { info.sheet.repaint(); }, setTreeNodeCellType:function (datas,row,parentMap,visibleMap,sheet) { delete parentMap.undefined;//去掉无用节点 let treeNode = sheetCommonObj.getTreeNodeCellType(datas,row,parentMap); treeNode.treeNodeType = false; if((datas[row].subList && datas[row].subList.length >0)||datas[row].isSub == true ){ treeNode.treeNodeType = true; visibleMap[datas[row].ID] = treeNode.collapsed; } sheet.setCellType(row, 0, treeNode, GC.Spread.Sheets.SheetArea.viewport); if(visibleMap[datas[row].ParentID]) sheet.getRange(row , -1, 1, -1).visible(!visibleMap[datas[row].ParentID]);//显示或隐藏 }, setComboOptionCell:function(row,col,subRate,sheet){ let options=[]; for(let op of subRate.optionList){ options.push({text:op.name,value:op.value}); } let dynamicCombo = sheetCommonObj.getDynamicCombo();//new GC.Spread.Sheets.CellTypes.ComboBox(); dynamicCombo.items(options); dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value); sheet.setCellType(row, col, dynamicCombo, GC.Spread.Sheets.SheetArea.viewport); }, addComboboxOption:function (datas) { _.forEach(datas,function (item) { var selectvalue = 0; _.forEach(item.optionList,function (o) { var option = $("