<template>
    <div class="detail-popup">
        <popup ref="popupRef" title="人工预算详情" :async="true" width="80%" @confirm="handleSubmit" @close="handleClose">
            <el-descriptions :column="2" border>

                <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.labor_budget_code }}</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">
                    <div v-if="formData.annex && formData.annex.length > 0">
                        <div v-for="(item, index) in formData.annex" style="margin-left: 5px;display: block;">
                            <el-link style="margin-left: 10px; color: #4a5dff; align-self: flex-start" :href="item.uri"
                                target="_blank">文件{{ index + 1 }}查看</el-link>
                        </div>
                    </div>
                    <div v-else>
                        暂无附件
                    </div>
                </el-descriptions-item>
            </el-descriptions>

            <div>
                <el-table :data="tableData" stripe style="width: 100%">
                    <el-table-column label="工种名称" prop="job_type_name" show-overflow-tooltip />
                    <el-table-column label="人工说明" prop="desc" show-overflow-tooltip />
                    <el-table-column label="单位" prop="unit" show-overflow-tooltip />
                    <el-table-column label="数量" prop="num" show-overflow-tooltip />
                    <el-table-column label="单价" prop="price" show-overflow-tooltip />
                    <el-table-column label="金额" prop="amount" show-overflow-tooltip />
                    <el-table-column label="备注" prop="remark" show-overflow-tooltip />
                </el-table>
            </div>
            <div style="margin: 10px 0;">
                <el-pagination v-model:current-page="pager1.page_no" v-model:page-size="pager1.page_size"
                    :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="total"
                    @size-change="handleSizeChange1" @current-change="handleCurrentChange1" />
            </div>

            <flowProcess v-if="!formData?.approve_id || formData.approve_check_status == 4" :flows="flows"
                :submitApi="apiproject_labor_budgetApprove" :id="formData?.id" @off="handleClose">
            </flowProcess>
            <flowDetail v-else :approve_id="formData?.approve_id" @off="handleClose" />
            <!-- import { apiproject_labor_budgetApprove, apiproject_labor_budgetFlows } from '@/api/flowSet'
            // 获取审批流程
            const flows = ref([])
            const getbidDocumentExaminationFlows = async () => {
            if (formData?.approve_id) return
            let res = await apiproject_labor_budgetFlows()
            flows.value = res
            } -->
        </popup>
    </div>
</template>

<script lang="ts" setup name="customdetail">
import { apiProjectLaborBudgetDetailLists } from '@/api/project_labor_budget_detail'
import { apiproject_labor_budgetApprove, apiproject_labor_budgetFlows } from '@/api/flowSet'
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiCustomDetail } from '@/api/custom'
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 pager1 = reactive({
    page_size: 10,
    page_no: 1,
    customer_demand_id: ""
})
const total = ref(0)
const datas = reactive({
    provinceOptions: [],
    cityOptions: [],
    areaOptions: [],
});

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

})

//条数
const handleSizeChange1 = (val: number) => {

    pager1.page_size = val
    budgetDetailLists(formData.id)
}

//分页
const handleCurrentChange1 = (val: number) => {
    pager1.page_no = val
    budgetDetailLists(formData.id)
}

//获取预算明细列表
const budgetDetailLists = (id) => {
    apiProjectLaborBudgetDetailLists({ 'page_no': pager1.page_no, 'page_size': pager1.page_size, labor_budget_id: id }).then((res) => {
        tableData.value = res.lists
        total.value = res.count
    })

}

// 获取详情
const setFormData = async (data: Record<any, any>) => {
    Object.assign(formData, data)
    budgetDetailLists(data.id)
    if (data.annex && data.annex.length > 0) {

        const arry1 = data.annex.map((item: any, index: any) => {
            return {
                name: `文件${index + 1}`,
                uri: item
            };
        });
        Object.assign(formDataannex, arry1)
    }
    getbidDocumentExaminationFlows()
}

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


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

}

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

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

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






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

<style lang="scss" scoped>
.tit {
    font-size: 1.2em;
    margin-bottom: 10px;
}

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