<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.side_station_code }}
                    </el-descriptions-item>
                    <el-descriptions-item label="旁站类型" label-align="left" align="left">
                        {{ formData.side_station_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.position }}
                    </el-descriptions-item>
                    <el-descriptions-item label="施工人数" label-align="left" align="left">
                        {{ formData.workers }}
                    </el-descriptions-item>
                    <el-descriptions-item label="管理人数" label-align="left" align="left">
                        {{ formData.managers }}
                    </el-descriptions-item>
                    <el-descriptions-item label="旁站开始时间" label-align="left" align="left">
                        {{ formData.start_time }}
                    </el-descriptions-item>
                    <el-descriptions-item label="旁站结束时间" label-align="left" align="left">
                        {{ formData.end_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.situation }}
                    </el-descriptions-item>
                    <el-descriptions-item label="旁站" label-align="left" align="left">
                        {{ formData.side_station_result_text }}
                    </el-descriptions-item>
                    <el-descriptions-item label="旁站人员" label-align="left" align="left">
                        {{ formData.side_station_user }}
                    </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">
                        <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.side_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.side_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_side_station_result } from '@/api/supervision_side_station'
import { timeFormat } from '@/utils/util'
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({
    id: '',
    project_id: '',
    side_station_code: '',
    side_station_type: '',
    check_item_id: '',
    position: '',
    company_id: '',
    start_time: '',
    end_time: '',
    workers: '',
    managers: '',
    side_station_type_text: "",
    situation: '',
    side_station_result: '',
    side_station_user: '',
    check_item_detail_ids: [],
    side_station_result_text: "",
    annex: [],
    create_user: "",
    create_time: "",
    project_name: '',
    inspection_code: '',
    is_important: "",
    inspection_type: '',
    check_item_name: "",
    inspection_user: '',
    company_name: '',
    inspection_content: '',
    is_importent: '',
    follow_user: '',
    check_item_detail_name: '',
    side_result: [],
    side_problem: []
})


// 获取详情
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_inspection_result({ inspection_id: formData.id }).then(res => {
    //     formData.inspection_result = res.lists
    // })
    // apisupervision_problem({ data_id: formData.id, data_type: 1 }).then(res => {
    //     formData.inspection_problem = res.lists
    // })
    apisupervision_side_station_result({ side_station_id: formData.id }).then(res => {
        formData.side_result = res.lists
    })
    apisupervision_problem({ data_id: formData.id, data_type: 2 }).then(res => {
        formData.side_problem = res.lists
    })
}


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

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



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