
<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"
                                type='primary'>{{ item.name }}</el-link>
                        </span>
                    </el-descriptions-item>

                </el-descriptions>
            </el-card>

            <el-card>
                <template #header>
                    报销明细
                </template>
                <div class="mt-4">
                    <el-table :data="formData.reimbursement_detail">
                        <el-table-column label="一级科目" prop="first_level_subject" show-overflow-tooltip />
                        <el-table-column label="金额" prop="amount" show-overflow-tooltip />
                        <el-table-column label="备注" prop="remark" show-overflow-tooltip width="120" />
                    </el-table>
                </div>
            </el-card>
            <el-card>
                <template #header>
                    发票明细
                </template>
                <div class="mt-4">
                    <el-table :data="formData.invoice_detail">
                        <el-table-column label="发票类型" prop="invoice_type_text" show-overflow-tooltip />
                        <el-table-column label="发票编号" prop="invoice_sn" show-overflow-tooltip />
                        <el-table-column label="发票税率" prop="tax_rate_text" show-overflow-tooltip />
                        <el-table-column label="发票形式" prop="invoice_form_text" show-overflow-tooltip width="100" />
                        <el-table-column label="发票金额" prop="invoice_amount" show-overflow-tooltip />
                        <el-table-column label="备注" prop="remark" show-overflow-tooltip />
                        <el-table-column label="附件" prop="annex" show-overflow-tooltip>
                            <template #default="{ row }">
                                <div v-for="item, index in  row.annex" :key="index">
                                    <el-link :href="item.uri" type="primary" target="_blank"> {{ item.name }}</el-link>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </el-card>

            <flowProcess v-if="!formData?.approve_id || formData.approve_check_status == 4" :flows="flows"
                :submitApi="apiproject_expense_reimbursementApprove" :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_expense_reimbursementApprove, apiproject_expense_reimbursementFlows } from '@/api/flowSet'
import { apiProjectExpenseReimbursementDetailLists } from "@/api/project_expense_reimbursement_detail.ts"
import { apiProjectExpenseReimbursementInvoiceDetailLists } from "@/api/project_expense_reimbursement_invoice_detail.ts"


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']
    },
    {
        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()
    let res = await apiProjectExpenseReimbursementDetailLists({ expense_reimbursement_id: data.id })
    formData.reimbursement_detail = res.lists
    let res2 = await apiProjectExpenseReimbursementInvoiceDetailLists({ expense_reimbursement_id: data.id })
    formData.invoice_detail = res2.lists
}

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

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

// 获取审批流程
const flows = ref([])
const getbidDocumentExaminationFlows = async () => {
    if (formData?.approve_id) return
    let res = await apiproject_expense_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>
