
<template>
    <div class="detail-popup">
        <popup ref="popupRef" :async="true" width="80%" @close="handleClose">
            <el-card>
                <el-descriptions :column="3" title="费用报销详情" border>
                    <el-descriptions-item :label="item.lable" label-align="left" align="left" label-class-name="my-label"
                        v-for="(item, index) in descriptionList" :key="index">

                        <span v-if="item.lable != '附件'"> {{ item.value.length > 1 ? formData[item.value[0]][item.value[1]] :
                            formData[item.value[0]]
                        }}</span>
                        <span v-else>
                            <annexLink :annex="formData.annex"></annexLink>
                        </span>
                    </el-descriptions-item>
                </el-descriptions>
            </el-card>
            <flowProcess v-if="!formData?.approve_id || formData.approve_check_status == 4" :flows="flows"
                :submitApi="apiproject_trip_applyApprove" :id="formData?.id" @off="handleClose">
            </flowProcess>
            <flowDetail v-else :approve_id="formData?.approve_id" @off="handleClose" />

        </popup>
    </div>
</template>

<script lang="ts" setup name="customdetail">
import { ref, reactive } from "vue"
import { apiproject_trip_applyApprove, apiproject_trip_applyFlows } from '@/api/flowSet'
const descriptionList = reactive([
    {
        lable: "项目名称",
        value: ['project_name']
    },
    {
        lable: "项目编码",
        value: ['project_code']
    },
    {
        lable: "出差起始地",
        value: ['origin_address']
    },
    {
        lable: "出差目的地",
        value: ['target_address']
    },
    {
        lable: "交通工具",
        value: ['traffic_text']
    },
    {
        lable: "出差时间",
        value: ['start_date']
    },
    {
        lable: "结束时间",
        value: ['end_date']
    },
    {
        lable: "出差事由",
        value: ['reason']
    },
    {
        lable: "历史天数",
        value: ['days']
    },
    {
        lable: "备注",
        value: ['remark']
    },
    {
        lable: "附件",
        value: ['annex']
    },
])

const emit = defineEmits(['success', 'close'])
const popupRef = ref(null)


// 表单数据
const formData: any = reactive({
})
// 获取详情
const setFormData = async (data: Record<any, any>) => {
    Object.assign(formData, data)
    getbidDocumentExaminationFlows()
}

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

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

// 获取审批流程
const flows = ref([])
const getbidDocumentExaminationFlows = async () => {
    if (formData?.approve_id) return
    let res = await apiproject_trip_applyFlows()
    flows.value = res
}

defineExpose({
    open,
    setFormData,
})
</script>
<style lang="scss" scoped>
.tit {
    font-size: 1.2em;
    margin-bottom: 10px;
}

:deep(.my-label) {
    width: 150px;
}
</style>
