ibiz-grid-select.component.ts 2.0 KB
Newer Older
ibiz's avatar
ibiz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
Vue.component('ibiz-grid-select', {
    template: `
    <i-select v-model="value" style="width:100%" transfer label-in-value @on-change="onValueChange">
        <template v-for="(item, index) of items">
            <i-option :value="item.value" :key="index">{{ item.text }}</i-option>
        </template>
    </i-select>
    `,
    data: function() {
        return {
            value: '',
            text: '',
            items: [],
            http: IBizHttp.getInstance(),
            rowData: null,
            column: null,
            grid: null
        }
    },
    created: function() {
        this.grid = this.params.grid;
        this.rowData = this.params.node.data;
        this.column = this.params.column.colDef;
        if(Object.is(this.params.selectType, 'STATIC')) {
            this.value = this.params.value;
            let viewController = this.grid.getViewController();
            this.items = viewController.getCodeList(this.params.codelistId).data;
        } else if(Object.is(this.params.selectType, 'DYNAMIC')) {
            this.value = this.rowData[this.column.name];
            this.text = this.params.value;
            let param: any = {};
            param.srfreferdata = JSON.stringify(this.rowData);
            this.http.post(this.params.url, param).subscribe((success: any) => {
                if (success.ret === 0) {
                    this.items = [...success.items];
                }
            }, (error: any) => {
                console.log(error);
            });
        }
    },
    methods: {
        getValue: function() {
            if(Object.is(this.params.selectType, 'DYNAMIC')) {
                return this.text;
            } else {
                return this.value;
            }
        },
        onValueChange: function(item) {
            if(Object.is(this.params.selectType, 'DYNAMIC')) {
                this.text = item.label;
            }
            this.grid.colValueChange(this.column.name, item.value, this.rowData);
        }
    }
});