<template>
    <el-select-v2
        v-model="liaisonId"
        :options="liaisonOption"
        placeholder="请选择客户联系人"
        filterable
    />
</template>

<script setup lang="ts">
    import { listLiaison } from '@/api/customer/liaison';

    const props = defineProps({
        isLiaison: {
            type: Boolean,
            default: true
        }
    })

    const liaisonId = defineModel('liaisonId')
    const liaisonOption = ref([])
    const getLiaison = (customerId: string) => {
        listLiaison({ pageIndex: 1, pageSize: 999999, customerId }).then(res => {
            if(res.success) {
                liaisonOption.value = res.result.records.map((item: { name: string, id: number }) => {
                    let obj = { label: item.name, value: item.id }
                    return obj
                })
            }
        })
    }

    const changeCustomer = (val: string) => {
        if(props.isLiaison) {
            getLiaison(val)
        }
    }

    onMounted(() => {
        getLiaison(null)
    })
</script>
