<template>
    <div class="edit-popup">
        <popup ref="popupRef" :async="true" width="80vw" @close="handleClose">
            <el-form ref="formRef" :model="formData" label-width="100px">
                <el-descriptions column="3" title="工程监理--验收登记详情" border>
                    <el-descriptions-item label="项目名称" label-align="left" align="left">
                        {{ formData.project_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="编号" label-align="left" align="left">
                        {{ formData.accept_code }}
                    </el-descriptions-item>
                    <el-descriptions-item label="验收类型" label-align="left" align="left">
                        {{ formData.accept_type_text }}
                    </el-descriptions-item>
                    <el-descriptions-item label="单位工程" label-align="left" align="left">
                        {{ formData.check_item_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="验收内容" label-align="left" align="left">
                        {{ formData.accept_content }}
                    </el-descriptions-item>
                    <el-descriptions-item label="验收位置" label-align="left" align="left">
                        {{ formData.accept_position }}
                    </el-descriptions-item>
                    <el-descriptions-item label="验收时间" label-align="left" align="left">
                        {{ formData.accept_time }}
                    </el-descriptions-item>
                    <el-descriptions-item label="施工单位" label-align="left" align="left">
                        {{ formData.company_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="检查表单选择" label-align="left" align="left">
                        {{ formData.check_item_detail_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="备注" label-align="left" align="left">
                        {{ formData.remark }}
                    </el-descriptions-item>
                    <el-descriptions-item label="创建人" label-align="left" align="left">
                        {{ formData.create_user }}
                    </el-descriptions-item>
                    <el-descriptions-item label="创建时间" label-align="left" align="left">
                        {{ formData.create_time }}
                    </el-descriptions-item>
                    <el-descriptions-item label="附件" label-align="left" align="left">
                        <el-link class="mr-5" type="primary" v-for="item in formData.annex" :href="item.uri">
                            {{ item.name }}
                        </el-link>
                    </el-descriptions-item>
                </el-descriptions>
            </el-form>
            <el-card class="mt-5">
                <template #header>
                    巡视结果列表
                </template>
                <el-table :data="formData.accept_check_result">
                    <el-table-column label="检查类别" prop="check_type" show-overflow-tooltip />
                    <el-table-column label="检查内容" prop="check_content" show-overflow-tooltip />
                    <el-table-column label="是否必检" prop="must_check_text" show-overflow-tooltip />
                    <el-table-column label="是否检查结果必检" prop="check_result_text" show-overflow-tooltip />
                </el-table>
            </el-card>
            <el-card>
                <template #header>
                    巡视问题列表
                </template>
                <el-table :data="formData.accept_check_problem">
                    <el-table-column label="问题分类" prop="problem_cate_text" show-overflow-tooltip />
                    <el-table-column label="问题说明" prop="problem_description" show-overflow-tooltip />
                    <el-table-column label="问题名称" prop="problem_name" show-overflow-tooltip />
                </el-table>
            </el-card>
        </popup>
    </div>
</template>

<script lang="ts" setup name="supervisionInspectionEdit">
import Popup from '@/components/popup/index.vue'
import { apisupervision_accept_result } from '@/api/supervision_accept'
import { apisupervision_problem } from '@/api/supervision_inspection'




const emit = defineEmits(['success', 'close'])
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')

// 表单数据
const formData = reactive({
    project_id: '',
    accept_code: '',
    accept_type: '',
    check_item_id: '',
    accept_content: '',
    accept_position: '',
    accept_time: '',
    company_id: '',
    accept_result: '',
    check_item_detail_ids: [],
    remark: '',
    create_user: "",
    create_time: "",
    check_item_name: "",
    company_name: '',
    check_item_detail_name: '',
    id: '',
    project_name: '',
    annex: [],
    accept_check_result: [],
    accept_check_problem: [],
    accept_type_text: ""
})


// 获取详情
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]
        }
    }
    apisupervision_accept_result({ accept_id: formData.id }).then(res => {
        formData.accept_check_result = res.lists
    })
    apisupervision_problem({ data_id: formData.id, data_type: 3 }).then(res => {
        formData.accept_check_problem = res.lists
    })
}


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

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



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