index.vue 2.71 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
        remote
        reserve-keyword
8
        :placeholder="placeholder ? placeholder : $t('请选择')"
9 10 11 12 13 14 15 16 17 18 19
        :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
        clearable: Boolean,
25
        placeholder: String,
邓春圆's avatar
邓春圆 committed
26 27 28 29
        manage:{
          type:Boolean,
          default:false
        }
30 31 32 33 34 35 36 37 38 39 40
    },
    data(){
        return {
            index: null,
            list:[],
            loading: false,
            size: 20
        }
    },
    watch:{
        index(val){
41 42
            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)
43 44
        },
        value(val){
dragondean@qq.com's avatar
dragondean@qq.com committed
45 46 47 48
            this.resetIndex()
        },
        list(){
            this.resetIndex()
49 50 51
        }
    },
    created(){
邓春圆's avatar
邓春圆 committed
52 53 54 55 56 57 58
      if(this.manage){
        // 客户经理
        listServiceUser().then(r=>{
          this.list = r.data;
        })
      }else {
        // 全部客户
59
        listSimpleUsers().then(res => {
邓春圆's avatar
邓春圆 committed
60
          this.list = res.data
61
        })
邓春圆's avatar
邓春圆 committed
62 63
      }

64 65 66
        // this.init()
    },
    methods:{
dragondean@qq.com's avatar
dragondean@qq.com committed
67 68 69 70 71
        resetIndex(){
            let index = this.list.findIndex(item => item.id == this.value)
            if(index < 0) this.index = null
            else this.index = index
        }
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 97
        /* 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
98
</script>