index.vue 1.79 KB
Newer Older
dragondean@qq.com's avatar
dragondean@qq.com committed
1 2 3 4 5 6 7 8 9 10 11 12 13
<template>
    <el-select
        v-model="index"
        filterable
        clearable
        remote
        reserve-keyword
        placeholder="请输入关键词"
        :remote-method="remoteMethod"
        :loading="loading">
        <el-option
        v-for="(item, index) in list"
        :key="item.id"
14
        :label="$l(item, 'company') + '('+item.companyCode+')'"
dragondean@qq.com's avatar
dragondean@qq.com committed
15 16 17 18 19 20
        :value="index">
        </el-option>
    </el-select>
</template>
<script>
import {getSupplier, getSupplierPage} from '@/api/ecw/supplier'
21

dragondean@qq.com's avatar
dragondean@qq.com committed
22 23
export default {
    props:{
24
        companyType: [String, Number],
dragondean@qq.com's avatar
dragondean@qq.com committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
        value: [String, Number]
    },
    data(){
        return {
            index: null,
            list:[],
            loading: false
        }
    },
    watch:{
        index(val){
            this.$emit('input', val !== null ? this.list[val].id: null)
            this.$emit('change', val !== null ? this.list[val]: null)
        },
        value(val){
            this.init()
        }
    },
    created(){
44
        this.remoteMethod('')
dragondean@qq.com's avatar
dragondean@qq.com committed
45 46 47 48 49 50 51 52 53 54 55
        this.init()
    },
    methods:{
        init(){
            if(!this.value) return
            let index = this.list.findIndex(item => item.id == this.value)
            if(index < 0){
                getSupplier(this.value).then(res => {
                    this.list.unshift(res.data)
                    this.index = 0
                })
56
            }else this.index = index
dragondean@qq.com's avatar
dragondean@qq.com committed
57 58
        },
        remoteMethod(keyword){
59
            let params = {
60 61
                pageSize: 500,
                companyType: this.companyType
62 63
            }
            params.keyword = keyword
dragondean@qq.com's avatar
dragondean@qq.com committed
64 65
            this.loading = true
            getSupplierPage(params)
66
                .then(res => this.list = res.data.list)
dragondean@qq.com's avatar
dragondean@qq.com committed
67 68 69 70 71
                .finally(() => this.loading = false)
        }
    }
}
</script>