<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.code }}
                </el-descriptions-item>
                <el-descriptions-item label="条码类型">
                    <dict-value :options="dictData.code_type" :value="formData.type" />
                </el-descriptions-item>
                <el-descriptions-item label="备注信息">
                    {{ formData.data }}
                </el-descriptions-item>
                <el-descriptions-item label="扩展信息">
                    {{ formData.more }}
                </el-descriptions-item>
                <el-descriptions-item label="排序">
                    {{ formData.sort }}
                </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: '',
    code: '',
    type: '',
    data: '',
    more: '',
    sort: '',
})

// 表单验证
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>
