<template>
    <vxe-modal v-model="dialogVisible" :title="title" show-zoom resize show-footer destroy-on-close transfer @hide="close" :width="width" :z-index="1002">
        <template #default>
            <el-form ref="formRef" :model="form" :rules="rules" label-width="auto">
                <div class="mb-10 f-s-14 c-333 f-w-5">
                    修改企业：
                    <span class="c-primary">{{ info?.cpyName }}</span>
                </div>
                <el-form-item label="选择会员级别:" prop="vipLevel">
                    <el-select v-model="form.vipLevel" placeholder="请选择会员级别" clearable style="width: 100%">
                        <el-option v-for="item in dict.vip_level" :key="item.value" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
            </el-form>
        </template>
        <template #footer>
            <el-button @click="close">取消</el-button>
            <el-button type="primary" @click="submitForm">确定</el-button>
        </template>
    </vxe-modal>
</template>

<script setup name="EditVipLevel" lang="ts">
import { editVipLevel } from '@/api/dgtmedicine/member/index';
import { propTypes } from '@/utils/propTypes';
import { FormInstance } from 'element-plus';
const emit = defineEmits(['update:show', 'close', 'success']);
const props = defineProps({
    show: propTypes.bool.def(false),
    title: propTypes.string.def('修改级别'),
    width: propTypes.number.def(560),
    info: propTypes.any.def(null),
    dict: propTypes.object.def({}),
});
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const dialogVisible = ref(false);
const form = ref<any>({
    vipLevel: ''
});
const rules = reactive({
    vipLevel: [{ required: true, message: '请选择会员级别', trigger: 'change' }],
})
const formRef = ref<FormInstance>();
const close = () => {
    formRef.value?.resetFields();
    emit('update:show', false);
    emit('close', false);
};
const submitForm = async () => {
    try {
        await formRef.value?.validate();
        const res = await editVipLevel({ ...form.value, id: props.info?.id });
        if (res) {
            close();
            emit('success', true);
        }
    } catch (error) {
        console.error(error);
    }
};

watch(
    () => props.show,
    (val) => {
        dialogVisible.value = val;
    },
    { immediate: true }
);
</script>
