<template>
    <div class="el-form-item--col">
        <el-select v-model="selectedValue" :placeholder="placeholder" @change="onChange">
            <el-option v-for="item in dataList" :key="item.cusbankid" :label="item.cusbankname"
                :value="item.cusbankid" />
        </el-select>
    </div>
</template>

<script lang="ts" setup>
import { computed, toRaw } from 'vue'
import { useRequest } from '@/hooks/request'
import { getAllBankCus } from '@/services/api/bank'
import { i18n } from '@/stores'

const props = defineProps({
    modelValue: String,
    placeholder: {
        type: String,
        default: i18n.global.t('common.pleasechoice')
    }
})

const emit = defineEmits(['update:modelValue', 'change'])

const selectedValue = computed({
    get: () => props.modelValue,
    set: (val) => emit('update:modelValue', val)
})

const { dataList } = useRequest(getAllBankCus)

const onChange = (value: string) => {
    const item = dataList.value.find((item) => item.cusbankid === value)
    emit('change', item && toRaw(item))
}
</script>

<style lang="less">
@import './index.less';
</style>