index.vue 4.71 KB
Newer Older
dragondean@qq.com's avatar
dragondean@qq.com committed
1
<template>
2 3 4 5 6 7 8
    <div>
        <el-select
            v-model="index"
            filterable
            clearable
            remote
            reserve-keyword
dragondean@qq.com's avatar
dragondean@qq.com committed
9
            :placeholder="$t('请输入关键词')"
10 11 12
            :remote-method="remoteMethod"
            :loading="loading">
            <el-option
13
            v-for="(item, index) in formattedList"
14
            :key="item.id"
15
            :label="`${item.label}`"
16 17 18
            :value="index">
            </el-option>
        </el-select>
19
        <!-- <el-button v-if="quickable" type="text" @click="showQuickCreate=true" class="ml-10">{{$t('快速新建')}}</el-button> -->
20

21
        <!-- <quick-create v-if="showQuickCreate" @success="onQuickCreateSuccess" @close="showQuickCreate=false" :default="{type}"></quick-create> -->
22
    </div>
dragondean@qq.com's avatar
dragondean@qq.com committed
23 24
</template>
<script>
25
import {getCustomerContactsSelect, getCustomerContactsListByCustomer} from '@/api/ecw/customerContacts'
dragondean@qq.com's avatar
dragondean@qq.com committed
26
import QuickCreateCustomer from '@/components/QuickCreateCustomer'
27
import Vue from 'vue'
dragondean@qq.com's avatar
dragondean@qq.com committed
28
export default {
dragondean@qq.com's avatar
dragondean@qq.com committed
29
    components:{QuickCreateCustomer},
dragondean@qq.com's avatar
dragondean@qq.com committed
30
    props:{
31 32 33 34
        value: [String, Number],
        quickable: {
            type: Boolean,
            default: true
35
        },
36
        type: String, // 客户类别,新建时指定默认类别,也可以根据需要筛选联系人所属的客户类别
dragondean@qq.com's avatar
dragondean@qq.com committed
37 38 39 40 41 42
    },
    data(){
        return {
            index: null,
            list:[],
            loading: false,
43 44
            size: 20,
            showQuickCreate: false
dragondean@qq.com's avatar
dragondean@qq.com committed
45 46
        }
    },
47 48 49 50 51
    computed:{
        formattedList(){
            return this.list.map(item => {
                item.label = item.contactsName
                let more = []
dragondean@qq.com's avatar
dragondean@qq.com committed
52 53 54
                if(item.customerName){
                    more.push(item.customerName)
                }
55 56 57 58 59 60 61 62 63 64 65 66 67
                if(item.phoneNew){
                    more.push(item.phoneNew)
                }
                if(item.email){
                    more.push(item.email)
                }
                if(more.length){
                    item.label += `(${more.join('|')})`
                }
                return item
            })
        }
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
68 69 70 71 72 73 74
    watch:{
        index(val){
            this.$emit('input', val !== null ? this.list[val].customerContactsId: null)
            this.$emit('change', val !== null ? this.list[val]: null)
        },
        value(val){
            this.init()
75 76 77
        },
        showQuickCreate(){
            if(!this.showQuickCreate)return
dragondean@qq.com's avatar
dragondean@qq.com committed
78
            const QuickCreateComp = Vue.extend(QuickCreateCustomer)
79 80
            const dialog = new QuickCreateComp({
                propsData:{
81
                    type: this.type
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
                },
                
            })
            dialog.$on('close', () => {
                console.log('关闭拉')
                this.showQuickCreate = false
                document.body.removeChild(dialog.$el)
                dialog.$destroy()
            })
            dialog.$on('success', (id) => {
                this.onQuickCreateSuccess(id)
                dialog.$emit('close')
            })
            
            dialog.$mount()

            window.dialogComp = dialog
            document.body.append(dialog.$el)
dragondean@qq.com's avatar
dragondean@qq.com committed
100 101 102 103 104 105 106
        }
    },
    created(){
        this.init()
    },
    methods:{
        init(){
107
            console.log('初始化联系人选择', this.value)
dragondean@qq.com's avatar
dragondean@qq.com committed
108 109 110
            if(!this.value) return
            let index = this.list.findIndex(item => item.customerContactsId == this.value)
            if(index < 0){
111 112
                getCustomerContactsSelect({ids: this.value}).then(res => {
                    if(!res.data || !res.data.length){
dragondean@qq.com's avatar
dragondean@qq.com committed
113
                        return this.$message.error(this.$t('联系人信息获取失败'))
114 115
                    }
                    this.list.unshift(res.data[0])
dragondean@qq.com's avatar
dragondean@qq.com committed
116 117 118 119 120 121 122 123 124 125 126 127 128
                    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)
129
        },
130
        onQuickCreateSuccess(data){
131
            this.showQuickCreate = false
132 133 134
            this.list.unshift(data)
            this.index = 0
            /* getCustomerContactsListByCustomer({customerId: id}).then(res => {
135
                if(!res.data || !res.data.length){
dragondean@qq.com's avatar
dragondean@qq.com committed
136
                    return this.$message.error(this.$t('联系人信息获取失败'))
137
                }
138 139 140
                let data = res.data[0]
                data.contactsName = data.name // 字段名跟getCustomerContactsSelect对齐
                this.list.unshift(data)
141
                this.index = 0
142
            }) */
dragondean@qq.com's avatar
dragondean@qq.com committed
143 144 145 146
        }
    }
}
</script>