index.vue 2.64 KB
Newer Older
1 2 3 4
<template>
    <el-select
        v-model="index"
        filterable
dragondean@qq.com's avatar
dragondean@qq.com committed
5
        :clearable="clearable"
6 7 8 9 10 11 12 13 14 15 16 17 18 19
        remote
        reserve-keyword
        placeholder="请选择"
        :loading="loading">
        <el-option
        v-for="(item, index) in list"
        :key="item.id"
        :label="`${item.nickname}`"
        :value="index">
        </el-option>
    </el-select>
</template>
<script>
import {getCustomerContactsSelect, getCustomerContacts} from '@/api/ecw/customerContacts'
邓春圆's avatar
邓春圆 committed
20
import {listServiceUser, listSimpleUsers} from '@/api/system/user'
21 22
export default {
    props:{
dragondean@qq.com's avatar
dragondean@qq.com committed
23
        value: [String, Number],
邓春圆's avatar
邓春圆 committed
24 25 26 27 28
        clearable: Boolean,
        manage:{
          type:Boolean,
          default:false
        }
29 30 31 32 33 34 35 36 37 38 39
    },
    data(){
        return {
            index: null,
            list:[],
            loading: false,
            size: 20
        }
    },
    watch:{
        index(val){
40 41
            this.$emit('input', val !== null && val !== undefined && val != '' ? this.list[val].id : null)
            this.$emit('change', val !== null && val !== undefined && val != '' ? this.list[val]: null)
42 43
        },
        value(val){
dragondean@qq.com's avatar
dragondean@qq.com committed
44 45 46 47
            this.resetIndex()
        },
        list(){
            this.resetIndex()
48 49 50
        }
    },
    created(){
邓春圆's avatar
邓春圆 committed
51 52 53 54 55 56 57
      if(this.manage){
        // 客户经理
        listServiceUser().then(r=>{
          this.list = r.data;
        })
      }else {
        // 全部客户
58
        listSimpleUsers().then(res => {
邓春圆's avatar
邓春圆 committed
59
          this.list = res.data
60
        })
邓春圆's avatar
邓春圆 committed
61 62
      }

63 64 65
        // this.init()
    },
    methods:{
dragondean@qq.com's avatar
dragondean@qq.com committed
66 67 68 69 70
        resetIndex(){
            let index = this.list.findIndex(item => item.id == this.value)
            if(index < 0) this.index = null
            else this.index = index
        }
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
        /* init(){
            console.log('初始化联系人选择', this.value)
            if(!this.value) return
            let index = this.list.findIndex(item => item.customerContactsId == this.value)
            if(index < 0){
                getCustomerContactsSelect({ids: this.value}).then(res => {
                    if(!res.data || !res.data.length){
                        return this.$message.error('联系人信息获取失败')
                    }
                    this.list.unshift(res.data[0])
                    this.index = 0
                })
            }
        }, */
        /* remoteMethod(keyword){
            let params = {
                size: this.size
            }
            params.searchKey = keyword
            this.loading = true
            getCustomerContactsSelect(params)
                .then(res => this.list = res.data)
                .finally(() => this.loading = false)
        } */
    }
}
邓春圆's avatar
邓春圆 committed
97
</script>