
<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> <el-link class="m-2" v-for="item in formData.annex" :href="item.uri"
                                target="_blank">{{ item.name }}</el-link>
                        </span>
                    </el-descriptions-item>
                </el-descriptions>
            </el-card>
            <flowProcess v-if="!formData?.approve_id || formData.approve_check_status == 4" :flows="flows"
                :submitApi="apiproject_travel_reimbursementApprove" :id="formData?.id" @off="handleClose">
            </flowProcess>
            <flowDetail v-else :approve_id="formData?.approve_id" @off="handleClose" />
            <!-- import { apiproject_travel_reimbursementApprove, apiproject_travel_reimbursementFlows } from '@/api/flowSet'
            // 获取审批流程
            const flows = ref([])
            const getbidDocumentExaminationFlows = async () => {
            if (formData?.approve_id) return
            let res = await apiproject_travel_reimbursementFlows()
            flows.value = res
            } -->
        </popup>
    </div>
</template>

<script lang="ts" setup name="customdetail">
import { ref, reactive } from "vue"
import { apiproject_travel_reimbursementApprove, apiproject_travel_reimbursementFlows } from '@/api/flowSet'
const descriptionList = reactive([
    {
        lable: "项目名称",
        value: ['project_name']
    },
    {
        lable: "项目编码",
        value: ['project_code']
    },
    {
        lable: "借款单号",
        value: ['loan_apply_code']
    },
    {
        lable: "冲抵借款金额",
        value: ['offset_loan_amount']
    },
    {
        lable: "报销人",
        value: ['apply_user']
    },
    {
        lable: "报销类型",
        value: ['reimbursement_type_text']
    },
    {
        lable: "报销日期",
        value: ['apply_date']
    },
    {
        lable: "收款人姓名",
        value: ['payee_name']
    },
    {
        lable: "收款银行",
        value: ['payee_bank']
    },
    {
        lable: "收款账号",
        value: ['payee_account']
    },
    {
        lable: "账户编码",
        value: ['bank_account', 'account_sn']
    },
    {
        lable: "开户银行",
        value: ['bank_account', 'deposit_bank']
    },
    {
        lable: "开户名称",
        value: ['bank_account', 'account_name']
    },
    {
        lable: "开户账号",
        value: ['bank_account', 'account']
    },
    {
        lable: "备注",
        value: ['remark']
    },
])

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


// 表单数据
const formData: any = reactive({
    "id": 7,
    "trip_apply_id": 9,
    "project_id": 18,
    "trip_reimbursement_code": "项目差旅报销-20240205-752579",
    "reimbursement_type": "1",
    "loan_apply_id": 8,
    "offset_loan_amount": "12.00",
    "apply_user": "121",
    "apply_date": "2024-02-20",
    "payee_name": "12",
    "payee_bank": "12",
    "payee_account": "121",
    "remark": "212",
    "annex": [
        {
            "uri": "https:\/\/ceshi-engineering.lihaink.cn\/uploads\/files\/20240205\/20240205112036d89cc6685.jpg",
            "name": "20210719150601_4401e.jpg"
        }
    ],
    "bank_account_id": 8,
    "trip_apply_code": "项目出差-20240201-116911",
    "project_name": "第一个项目",
    "project_code": "P-20240126-717033",
    "project_manager": "",
    "loan_apply_code": "项目借款-20240205-930890",
    "loan_amount": "12.00",
    "reimbursement_type_text": "借款冲抵",
    "total_amount": 60,
    "pay_amount": 48,
    "bank_account": {
        "account_sn": "BANK-20240129-566530",
        "deposit_bank": "张伟银行",
        "account_name": "张伟",
        "account": "158845845"
    },
    "approve_id": 5
})
// 获取详情
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_travel_reimbursementFlows()
    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>
