<template>
    <div class="detail-popup">
        <popup ref="popupRef" title="补充协议名详情" :async="true" width="80%" @confirm="handleSubmit" @close="handleClose">

            <el-card>
                <el-descriptions :column="3" border>
                    <el-descriptions-item label="补充协议名称" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.contract_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="关联主合同" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.supplementary_agreement_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="甲方签约单位" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.part_a_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="联系人" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.part_a_contact }}
                    </el-descriptions-item>
                    <el-descriptions-item label="业主地址" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.part_a_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="联系人" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.part_a_contact }}
                    </el-descriptions-item>
                    <el-descriptions-item label="业主地址" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.part_a_address }}
                    </el-descriptions-item>
                    <el-descriptions-item label="乙方签约单位" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.part_b }}
                    </el-descriptions-item>
                    <el-descriptions-item label="乙方签约人" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.part_b_signatory_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="业务性质" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.business_nature_text }}
                    </el-descriptions-item>
                    <el-descriptions-item label="签订金额" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.signed_amount }}
                    </el-descriptions-item>
                    <el-descriptions-item label="合同付款方式" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.payment_method }}
                    </el-descriptions-item>
                    <el-descriptions-item label="合同主要内容" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.content }}
                    </el-descriptions-item>
                    <el-descriptions-item label="签订部门" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.signed_dept_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="签订负责人" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.signed_head_name }}
                    </el-descriptions-item>

                    <el-descriptions-item label="盖章名称" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.seal_name_text }}
                    </el-descriptions-item>
                    <el-descriptions-item label="是否限制" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.is_limit_text }}
                    </el-descriptions-item>
                    <el-descriptions-item label="限制次数" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.limit_num }}
                    </el-descriptions-item>
                    <el-descriptions-item label="文件类型" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.file_type_text }}
                    </el-descriptions-item>
                    <el-descriptions-item label="盖章份数" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.seal_num }}
                    </el-descriptions-item>
                    <el-descriptions-item label="盖章人" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.seal_user_name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="骑缝盖章" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.plance_seal_text }}
                    </el-descriptions-item>
                    <el-descriptions-item label="发出日期" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.send_date }}
                    </el-descriptions-item>
                    <el-descriptions-item label="邮寄编号" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.mailing_number }}
                    </el-descriptions-item>
                    <el-descriptions-item label="录入人" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.create_user }}
                    </el-descriptions-item>
                    <el-descriptions-item label="录入日期" label-align="left" align="left" label-class-name="my-label"> {{
                        formData.create_time }}
                    </el-descriptions-item>
                    <el-descriptions-item label="附件" label-align="left" align="left" label-class-name="my-label">
                        <annexLink :annex="formData.annex"></annexLink>
                    </el-descriptions-item>
                </el-descriptions>
            </el-card>


            <flowProcess v-if="!formData?.approve_id || formData.approve_check_status == 4" :flows="flows"
                :submitApi="apimarketing_supplementary_agreementApprove" :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 { apimarketing_supplementary_agreementFlows, apimarketing_supplementary_agreementApprove } 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 popupRef = shallowRef<InstanceType<typeof Popup>>()


const tableData = ref([])
// 表单数据
const formData = reactive({
    id: "",
    "contract_name": "",
    "related_contract_id": '',
    "supplementary_agreement_name": '',
    "part_a": '',
    "part_a_name": '',
    "part_a_contact": "",
    "part_a_address": "",
    "part_b": "",
    "part_b_signatory": '',
    "part_b_signatory_name": '',
    "business_nature": '',
    "signed_amount": '',
    "payment_method": "",
    "content": "",
    "annex": [],
    "signed_dept": '',
    "signed_head": '',
    "signed_head_name": '',
    "seal_name": '',
    "is_limit": '',
    "limit_num": '',
    "file_type": '',
    "seal_num": '',
    "seal_user": '',
    "seal_user_name": '',
    "plance_seal": '',
    "send_date": "",
    "mailing_number": "",
    "create_user": "",
    "create_time": ""
})




// 获取详情
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 apimarketing_supplementary_agreementFlows()
    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>
