<template>
    <div class="edit-popup">
        <popup ref="popupRef" :async="true" width="60vw" @close="handleClose" :bottom-btn="false">
            <el-descriptions class="margin-top" :title="popupTitle" :column="3" border>
                <el-descriptions-item label="商品名称">
                    {{ formData.name }}
                </el-descriptions-item>
                <el-descriptions-item label="商品编号">
                    {{ formData.number }}
                </el-descriptions-item>
                <el-descriptions-item label="规格型号">
                    {{ formData.spec }}
                </el-descriptions-item>
                <el-descriptions-item label="商品分类">
                    {{ formData.class }}
                </el-descriptions-item>
                <el-descriptions-item label="商品品牌">
                    {{ formData.brand }}
                </el-descriptions-item>
                <el-descriptions-item label="商品单位">
                    {{ formData.unit }}
                </el-descriptions-item>
                <!-- <el-descriptions-item label="标签">
                    {{ formData.sys_labels_text }}
                </el-descriptions-item> -->
                <el-descriptions-item label="购货价格">
                    {{ formData.buy }}
                </el-descriptions-item>
                <el-descriptions-item label="销货价格">
                    {{ formData.sell }}
                </el-descriptions-item>
                <el-descriptions-item label="零售价格">
                    {{ formData.retail }}
                </el-descriptions-item>
                <el-descriptions-item label="兑换积分">
                    {{ formData.integral }}
                </el-descriptions-item>
                <el-descriptions-item label="税率">
                    {{ formData.tax_rate }}
                </el-descriptions-item>
                <el-descriptions-item label="条形码">
                    {{ formData.code }}
                </el-descriptions-item>
                <!-- <el-descriptions-item label="默认仓库">
                    {{ formData.unit }}
                </el-descriptions-item> -->
                <el-descriptions-item label="商品货位">
                    {{ formData.location }}
                </el-descriptions-item>
                <el-descriptions-item label="库存阈值">
                    {{ formData.stocktip }}
                </el-descriptions-item>
                <el-descriptions-item label="零售名称">
                    {{ formData.retail_name }}
                </el-descriptions-item>
                <el-descriptions-item label="扩展信息">
                    {{ formData.more }}
                </el-descriptions-item>
                <el-descriptions-item label="排序">
                    {{ formData.sort }}
                </el-descriptions-item>
                <el-descriptions-item label="商品图片">
                    <material-picker v-model="formData.imgs" disabled />
                </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: "",
    spec: "",
    class: "",
    brand: "",
    unit: "",
    buy: "",
    sell: "",
    retail: "",
    integral: "",
    code: "",
    tax_rate: "",
    warehouse: "",
    location: "",
    stocktip: "",
    retail_name: "",
    sys_labels_text: "",
    sys_labels: "",
    imgs: "",
    details: "",
    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>
