
<template>
    <div class="detail-popup">
        <popup ref="popupRef" title="项目总预算详情" :async="true" width="80%" @confirm="handleSubmit" @close="handleClose">
            <el-descriptions :column="2" title="基本信息" border>

                <el-descriptions-item label="部门名称" label-align="left" align="left" label-class-name="my-label"> {{ formData.dept_name }}</el-descriptions-item>
                <el-descriptions-item label="项目名称" label-align="left" align="left" label-class-name="my-label">{{ formData.project_name }}</el-descriptions-item>
                <el-descriptions-item label="项目编码" label-align="left" align="left" label-class-name="my-label"> {{ formData.project_code }}</el-descriptions-item>
                <el-descriptions-item label="项目利润(元)" label-align="left" align="left" label-class-name="my-label"> {{ formData.profit }}</el-descriptions-item>
                <el-descriptions-item label="项目利润率(%)" label-align="left" align="left" label-class-name="my-label"> {{ formData.profit_rate }}</el-descriptions-item>
                <el-descriptions-item label="合同金额" label-align="left" align="left" label-class-name="my-label"> {{ formData.contract_amount }}</el-descriptions-item>

                <el-descriptions-item label="备注" label-align="left" align="left" label-class-name="my-label"> {{ formData.remark }}</el-descriptions-item>
                <el-descriptions-item label="项目经理" label-align="left" align="left" label-class-name="my-label"> {{ formData.project_manager }}</el-descriptions-item>
                <el-descriptions-item label="预算日期" label-align="left" align="left" label-class-name="my-label"> {{ formData.budget_date }}</el-descriptions-item>
                <el-descriptions-item label="预算清单" label-align="left" align="left" label-class-name="my-label">
                    <div v-if="formData.budget_list && formData.budget_list.length > 0">
                        <div v-for="(item, index) in formData.budget_list" style="margin-left: 5px;display: block;">
                            <a style="margin-left: 10px; color: #4a5dff; align-self: flex-start" :href="item.uri" target="_blank">文件{{ index + 1 }} 查看</a>
                        </div>
                    </div>
                    <div v-else>
                        暂无文件
                    </div>
                </el-descriptions-item>

            </el-descriptions>
            <el-table :data="tableData">
                <el-table-column label="序号" type="index" width="56" show-overflow-tooltip />
                <el-table-column label="分项">
                    <template #default="{ row }">
                        <div>{{ row.name }}</div>
                        <div>{{ row.text }}</div>
                    </template>
                </el-table-column>

                <el-table-column label="预算成本" prop="cost" show-overflow-tooltip />


                <el-table-column label="成本占比" prop="rate" width="156" show-overflow-tooltip />

            </el-table>

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

<script lang="ts" setup name="customdetail">

import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiCustomDetail } from '@/api/custom'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const formDataannex = reactive([])
const datas = reactive({
    provinceOptions: [],
    cityOptions: [],
    areaOptions: [],
});

const tableData = reactive([{
    name: "材料/设备成本(元)",
    text: '用于控制材料成本',
    cost: "", rate: "",
    cl_cost: ''
},
{
    name: "分包成本(元)",
    text: '用于控制分包成本', cost: "", rate: "",
    fb_cost: '',
},
{
    name: "人工成本(元)",
    text: '用于控制工时成本及项目人力成本', cost: "", rate: "",
    rg_cost: ''
},
{
    name: "费用成本(元)",
    text: '用于控制费用报销及差旅报销', cost: "", rate: "",
    fy_cost: ''
},
{
    name: "机械 & 工具成本(元)",
    text: '用于控制机械及设备成本', cost: "", rate: "",
    jj_cost: ''
},

])
// 表单数据
const formData = reactive({

})



// 获取详情
const setFormData = async (data: Record<any, any>) => {
    Object.assign(formData, data)
    tableData[0].cost = data.cl_cost
    tableData[1].cost = data.fb_cost
    tableData[2].cost = data.rg_cost
    tableData[3].cost = data.fy_cost
    tableData[4].cost = data.jj_cost
    tableData[0].rate = (Number(data.cl_cost) / data.total_cost).toFixed(2) + '%'
    tableData[1].rate = (Number(data.fb_cost) / data.total_cost).toFixed(2) + '%'
    tableData[2].rate = (Number(data.rg_cost) / data.total_cost).toFixed(2) + '%'
    tableData[3].rate = (Number(data.fy_cost) / data.total_cost).toFixed(2) + '%'
    tableData[4].rate = (Number(data.jj_cost) / data.total_cost).toFixed(2) + '%'

    // console.log(tableData)

}
const getDetail = async (row: Record<string, any>) => {
    const data = await apiCustomDetail({
        id: row.id
    })
    setFormData(data)
}


// 提交按钮
const handleSubmit = async () => {
    popupRef.value?.close()

}

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

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








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

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