<template>
    <div class="sub_title">
        企业基本信息
    </div>
    <el-divider></el-divider>
    <el-form label-width="136px" inline="true" style="padding: 0 20px 0px 20px;">
        <div>
            <el-form-item label="企业名称">
                {{ detailsInfo.info.companyName }}
            </el-form-item>

            <el-form-item label="统一社会信用代码">
                {{ detailsInfo.info.companyType }}
            </el-form-item>
        </div>
        <el-form-item label="注册地址">
            {{ detailsInfo.info.registerAddress }}
        </el-form-item>
        <el-form-item label="经营地址">
            {{ detailsInfo.info.operateAddress }}
        </el-form-item>
        <div>
            <el-form-item label="法人证件类型">
                {{ detailsInfo.info.certificatetype }}
            </el-form-item>
            <el-form-item label="法人证件号码">
                {{ detailsInfo.info.idNumber }}
            </el-form-item>
            <el-form-item label="营业执照">
                {{ detailsInfo.info.businessLicense }}
            </el-form-item>
            <el-form-item label="身份证国徽面">
                {{ detailsInfo.info.legalFaceUrl }}
            </el-form-item>
            <el-form-item label="身份证肖像面">
                {{ detailsInfo.info.legalNationUrl }}
            </el-form-item>
        </div>
        <div>
            <el-form-item label="法人姓名">
                {{ detailsInfo.info.legalPerson }}
            </el-form-item>
            <el-form-item label="邀请码">
                {{ detailsInfo.info.invitationCode }}
            </el-form-item>
            <el-form-item label="邀请企业名称" style="width:500px">
                <div>
                    {{ detailsInfo.info.invitationCoName }}
                </div>
            </el-form-item>
        </div>
        <el-form-item label="经营范围">
            {{ detailsInfo.info.businessScope }}
        </el-form-item>

    </el-form>
    <div class="sub_title">
        被授权人信息
    </div>
    <el-divider></el-divider>
    <el-form label-width="136px" inline="true" style="padding: 0 80px 0px 0;">
        <div>
            <el-form-item label="被授权人姓名">
                {{ detailsInfo.info.authPerson }}
            </el-form-item>
            <el-form-item label="被授权人身份证">
                {{ detailsInfo.info.authIdNumber }}
            </el-form-item>
            <el-form-item label="被授权人手机号">
                {{ detailsInfo.info.authPhone }}
            </el-form-item>
            <el-form-item label="被授权人邮箱">
                {{ detailsInfo.info.authEmail }}
            </el-form-item>
        </div>
        <div>
            <el-form-item label="法人授权书">
                {{ detailsInfo.info.authDocument }}
            </el-form-item>
            <el-form-item label="被授权人身份证国徽面">
                {{ detailsInfo.info.idNationUrl }}
            </el-form-item>
            <el-form-item label="被授权人身份证肖像面">
                {{ detailsInfo.info.idFaceUrl }}
            </el-form-item>
        </div>
    </el-form>

    <div class="sub_title">
        银行账户信息
    </div>
    <el-divider></el-divider>
    <el-table :data="tableAccountInfo.list" style="width: 100%" border stripe>
        <el-table-column fixed prop="bankName" label="开户行" min-width="120" />
        <el-table-column prop="accountName" label="账户名称" min-width="120" />
        <el-table-column prop="bankAccount" label="银行账号" min-width="120" />
        <el-table-column prop="bankAddress" label="开户行所在地" min-width="120" />
        <el-table-column prop="permitNumber" label="开户许可证核准号（基本存款账号编号）" min-width="120" />
        <el-table-column prop="permitUrl" label="开户行许可证/基本存款账号信息" min-width="120" align="center">
            <template #default="scope">
                <el-button type="text" @click="previewFn(scope.row.permitUrl)">预览</el-button>
            </template>
        </el-table-column>
    </el-table>
    <div class="btn_end" v-if="subType == 'edit'">
        <el-button type="primary" size="small" @click.prevent="auditFn()">
            审批
        </el-button>
        <el-button type="danger" size="small" @click.prevent="rejectFn()">
            驳回
        </el-button>
    </div>
</template>
  
<script lang="ts" setup>
import { apiGetCompanyInfoById, apiupdateCompanyInfo, apiBusinessUpdateBusiness } from "http/api/enterprise"
import { ElMessage } from "element-plus";
import { ElMessageBoxOpert } from 'utils/elementCom'
const router = useRouter()
const emits = defineEmits(['send'])
const route = useRoute()
const addShow = ref(false)
let title = ref("订单详情")
let detailsInfo: any = reactive({
    info: {}
})
let subType: any = ref("show")

let type: any = "settleIn"
let queryId: any = ""
let coId: any = ""
const show = (val: any) => {
    title.value = val.title
    addShow.value = true
}

const tableAccountInfo = reactive({
    list: []

})

const handleAudit = (auditType: any) => {   // settleIn 企业入驻审核 
    // open 企业业务开通审核 
    // info 企业入驻审核 
    // settleIn 企业入驻审核 

    if (type == 'settleIn') {
        let params = {
            bmCompanyInfo: {
                companyId: queryId,
                status: auditType//1通过，2 驳回

            }
        }
        apiupdateCompanyInfo(params).then((res: any) => {
            console.log("res-apiupdateCompanyInfo", res)
            ElMessage({
                type: 'success',
                message: "审批成功"
            })
            router.go(-1)
        })
    } else if (type == 'open') {

        let params = {

            id: queryId,
            status: auditType//1通过，2 驳回


        }
        apiBusinessUpdateBusiness(params).then((res: any) => {
            console.log("res-apiBusinessUpdateBusiness", res)
            ElMessage({
                type: 'success',
                message: "审批成功"
            })
            router.go(-1)
        })
    } else if (type == 'info') {

    } else if (type == 'settleIn') {

    }



}

const rejectCallBack = async (row: any, value: any) => {
    console.log('editCallBack', row, value)



    if (type == 'settleIn') {
        let params = {
            bmCompanyInfo: {
                companyId: queryId,
                status: "2",//1通过，2 驳回
                auditRemark: value.value
            }
        }
        apiupdateCompanyInfo(params).then((res: any) => {
            console.log("res-apiupdateCompanyInfo", res)
            ElMessage({
                type: 'success',
                message: "驳回成功"
            })
            router.go(-1)

        })
    } else if (type == 'open') {
        let params = {

            id: queryId,
            status: "2",//1通过，2 驳回
            auditRemark: value.value

        }
        apiBusinessUpdateBusiness(params).then((res: any) => {
            console.log("res-apiBusinessUpdateBusiness", res)
            ElMessage({
                type: 'success',
                message: "审批成功"
            })
            router.go(-1)
        })
    }
    // let params = {
    //     rejectReason: value.value,
    //     orderId: detailsInfo.orderId
    // }
    // const res: any = await apiOrderReject(params)
    // if (res.code == 200) {
    //     ElMessage({
    //         type: 'success',
    //         message: '驳回成功'
    //     })
    // }
}

const rejectFn = () => {


    ElMessageBoxOpert(
        '驳回原因',
        '填写驳回原因',
        '确定',
        '取消',
        (val: any) => {
            if (!val) {
                return '请填写类型模板'
            }
        },
        '请填写类型模板',
        rejectCallBack,
        "row",
        'textarea',
        'dangerC'
    )

}

const auditFn = () => {
    handleAudit('1')

}

const initDetails = async () => {
    let id = route.query.id || "1"
    if (type == "open") {
        id = coId
    }
    const res: any = await apiGetCompanyInfoById(id)
    console.log("apiGetCompanyInfoById", res)
    detailsInfo.info = res.data.bmCompanyInfo
    tableAccountInfo.list = res.data.bmCoBank

}

const previewFn = (url: any) => {
    if (!url) {
        ElMessage({
            type: 'warning',
            message: "没有文件"
        })
        return
    }
    window.open(url, "_blank")
}

const initTypeInfo = () => {
    queryId = route.query.id || "1"
    type = route.query.type || 'settleIn'
    subType.value = route.query.subType || "show"//edit
    coId = route.query.coId

    // settleIn 企业入驻审核 
    // open 企业业务开通审核 
    // info 企业入驻审核 
    // settleIn 企业入驻审核 
}

onMounted(() => {
    initTypeInfo()
    initDetails()
})
defineExpose({
    show
})

</script>
  
<style scoped lang="scss">
.sub_title {
    font-size: 16px;
    font-weight: bold;
}

.btn_end {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}
</style>
  