<template>
    <div class="edit-popup">
        <popup ref="popupRef" :async="true" width="550px" @close="handleClose" :bottom-btn="false">
            <el-descriptions class="margin-top" :title="popupTitle" :column="1" border>
                <el-descriptions-item label="单位名称">
                    {{ formData.name }}
                </el-descriptions-item>
                <el-descriptions-item label="单位编号">
                    {{ formData.number }}
                </el-descriptions-item>
                <el-descriptions-item label="是否散装">
                    {{ formData.is_bulk ? '是' : '否' }}
                </el-descriptions-item>
                <el-descriptions-item label="备注信息">
                    {{ formData.data }}
                </el-descriptions-item>
            </el-descriptions>
        </popup>
    </div>
</template>

<script lang="ts" setup name="brandEdit">
import Popup from '@/components/popup/index.vue'
import type { PropType } from 'vue'
defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
const emit = defineEmits(['success', 'close'])
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')


// 弹窗标题
const popupTitle = computed(() => {
    return '单位详情'
})

// 表单数据
const formData = reactive({
    id: '',
    name: '',
    py: '',
    number: '',
    data: '',
    is_bulk: '',
})

// 表单验证
const formRules = reactive<any>({
    name: [{
        required: true,
        message: '请输入品牌名称',
        trigger: ['blur']
    }]
})


// 获取详情
const setFormData = async (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }


}



// 提交按钮
// const handleSubmit = async () => {
//     await formRef.value?.validate()
//     const data = { ...formData, }
//     mode.value == 'edit'
//         ? await apiBrandEdit(data)
//         : await apiBrandAdd(data)
//     popupRef.value?.close()
//     emit('success')
// }

//打开弹窗
const open = (type = 'add') => {
    mode.value = type
    popupRef.value?.open()
}

// 关闭回调
const handleClose = () => {
    emit('close')
}



defineExpose({
    open,
    setFormData,
})
</script>
