<template>
    <div class="detail-popup">
        <popup ref="popupRef" title="甲方结算详情" :async="true" width="80%" @confirm="handleSubmit" @close="handleClose">
            <el-form ref="formRef" :model="formData" label-width="120px">
                <el-card class="mb-2">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="结算单号">
                                {{ formData.settlement_code }}
                            </el-form-item>
                        </el-col>

                        <el-col :span="12">
                            <el-form-item label="项目名称">
                                {{ formData.project_name }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同编号">
                                {{ formData.contract_name }}
                            </el-form-item>
                        </el-col>

                        <el-col :span="12">
                            <el-form-item label="客户名称">
                                {{ formData.custom_name

                                }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同名称">
                                {{ formData.contract_code
                                }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="结算日期">
                                {{ formData.settlement_date
                                }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="结算金额">
                                {{ formData.settlement_amount }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同金额">
                                {{ formData.contract_amount
                                }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="洽商金额">
                                {{ formData.negotiation_amount
                                }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="结算差异">
                                {{ formData.settlement_difference }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同附件">

                                <annexLink :annex="formData.annex"></annexLink>
                            </el-form-item>
                        </el-col>

                    </el-row>
                </el-card>
                <flowProcess v-if="!formData?.approve_id || formData.approve_check_status == 4" :flows="flows"
                    :submitApi="apiproject_settlementApprove" :id="formData?.id" @off="handleClose">
                </flowProcess>
                <flowDetail v-else :approve_id="formData?.approve_id" @off="handleClose" />
            </el-form>
        </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 { apiproject_settlementApprove, apiproject_settlementFlows } from '@/api/flowSet'
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 formData = reactive({

})



// 获取详情
const setFormData = async (data: Record<any, any>) => {
    Object.assign(formData, data)
    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_settlementFlows()
    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>
