| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 | /** * 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: 250, dataCode: "name", dataType: "String"},            {headerName: "参数值", headerWidth: 200, 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:'<div><select class="form-control form-control-sm" id="{{=it.ID}}" onchange="subRateObject.subRateChange(this)" style="width: 100%">  </select></div>'        },        {            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]);            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');        }        subRateObject.datas = projectObj.project.FeeRate.getSubViewData(item);        subRateObject.valueMap=projectObj.project.FeeRate.getValueMap(item);        console.log(subRateObject.datas);        console.log(subRateObject.valueMap);        subRateObject.showSubRateData();    },    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);        }    },    onSubRateSelectChanged:function (e,info) {        info.sheet.repaint();    },    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) {        //<option value ="volvo">Volvo</option> <option value ="saab">Saab</option> <option value="opel">Opel</option> <option value="audi">Audi</option>        _.forEach(datas,function (item) {            var selectvalue = 0;            _.forEach(item.optionList,function (o) {                var option =  $("<option>").val(o.value).text(o.name);                $('#'+item.ID).append(option);                if(o.selected){                    selectvalue = o.value;                }            })            $('#'+item.ID).val(selectvalue);        })    },    subRateChange:function(select){        var me = subRateObject;        var selectValueList=[];        var selectMap={};        if(me.datas&&me.datas.length>0){            $.bootstrapLoading.start();            _.forEach(me.datas,function (d,key) {                var selectValue = $('#'+d.ID).val();                selectValueList.push(selectValue);                selectMap[key]=selectValue;            })            var mapID =selectValueList.join('-');           var  rate = me.valueMap[mapID];            feeRateObject.updateBySelect(rate,selectMap,mapID);        }    },    onSubRateValueChange:function (e,info) {        console.info(info);        let me = subRateObject, selectValueList=[],selectMap={};        if(me.datas&&me.datas.length>0){            _.forEach(me.datas,function (d,key) {                if(info.row == key){                    selectMap[key]=info.newValue;                }else {                    let o = _.find(d.optionList,{'selected':true});                    selectMap[key]=o.value;                }                selectValueList.push(selectMap[key]);            })            var mapID =selectValueList.join('-');            var rate = me.valueMap[mapID];            feeRateObject.updateBySelect(rate,selectMap,mapID);        }    },    destorySpreadView:function () {        if(this.views){            this.views.destroy();            this.views = null;        }        subRateObject.datas=null;        subRateObject.valueMap=null;    }}
 |