index.vue 1.79 KB
Newer Older
lanbaoming's avatar
lanbaoming 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<template>
    <el-select
        v-model="index"
        filterable
        clearable
        remote
        reserve-keyword
        :placeholder="$t('请输入关键词')"
        :remote-method="remoteMethod"
        :loading="loading"
        :size="size">
        <el-option
        v-for="(item, index) in list"
        :key="item.id"
        :label="`${item.nickname}(${item.mobile})`"
        :value="index">
        </el-option>
    </el-select>
</template>
<script>
import {userMemberUserList, getMember} from '@/api/ecw/customer'

export default {
    props:{
        productType: [String, Number],
        value: [String, Number],
        size: String
    },
    data(){
        return {
            index: null,
            list:[],
            loading: false
        }
    },
    watch:{
        index(val){
            this.$emit('input', (val!==''&&val !== null) ? this.list[val].id: null)
            this.$emit('change', (val!==''&&val !== null) ? this.list[val]: null)
        },
        value(val){
            this.init()
        }
    },
    created(){
        this.init()
    },
    methods:{
        init(){
            if(!this.value) return
            let index = this.list.findIndex(item => item.id == this.value)
            if(index < 0){
                getMember(this.value).then(res => {
                    if(!res.data) rurn
                    this.list.unshift(res.data)
                    this.index = 0
                })
            }
        },
        remoteMethod(keyword){
            let params = {
                pageSize: 100
            }
            params.searchKey = keyword
            this.loading = true
            userMemberUserList(params)
                .then(res => this.list = res.data.list)
                .finally(() => this.loading = false)
        }
    }
}
</script>