<template>
  <section class="loanDetail">
    <ai-detail>
      <ai-title slot="title" title="经营主体详情" isShowBottomBorder isShowBack @onBackClick="$router.push({query:{}})">
        <template #rightBtn>
          <el-button v-if="isAuthing" type="primary" @click="dialog=true">审核</el-button>
        </template>
      </ai-title>
      <template #content>
        <el-form size="small" label-width="160px">
          <ai-card title="贷款申请">
            <template #content>
              <el-row type="flex" class="flexWrap">
                <el-form-item label="产品名称">{{ detail.enterpriseName }}</el-form-item>
                <el-form-item label="贷款银行">{{ detail.enterpriseName }}</el-form-item>
                <el-form-item label="贷款金额">{{ detail.enterpriseName }}</el-form-item>
                <el-form-item label="期望使用期限">{{ detail.enterpriseName }}</el-form-item>
                <el-form-item label="企业名称">{{ detail.enterpriseName }}</el-form-item>
                <el-form-item label="资金用途">{{ detail.unifiedCode }}</el-form-item>
                <el-form-item label="联系人">{{ dict.getLabel('enterpriseType', detail.enterpriseType) }}</el-form-item>
                <el-form-item label="身份证号">{{ detail.areaName }}</el-form-item>
                <el-form-item label="联系方式">{{ detail.address }}</el-form-item>
                <el-form-item label="申请时间">{{ detail.address }}</el-form-item>
              </el-row>
              <el-form-item label="备注">{{ detail.operationPeriod }}</el-form-item>
            </template>
          </ai-card>
          <ai-card title="办理结果" v-if="!isAuthing">
            <template #content>
              <el-row type="flex" class="flexWrap">
                <el-form-item label="贷款进度">{{ detail.auditUserName }}</el-form-item>
                <el-form-item label="贷款银行">{{ detail.auditPhone }}</el-form-item>
                <el-form-item label="贷款经理">{{ detail.auditDescription }}</el-form-item>
                <el-form-item label="联系方式 ">{{ detail.auditUserName }}</el-form-item>
                <el-form-item label="放款金额">{{ detail.auditPhone }}</el-form-item>
                <el-form-item label="放款日期">{{ detail.auditDescription }}</el-form-item>
                <el-form-item label="实际使用期限">{{ detail.auditDescription }}</el-form-item>
                <el-form-item label="操作时间">{{ detail.auditDescription }}</el-form-item>
              </el-row>
            </template>
          </ai-card>
        </el-form>
      </template>
    </ai-detail>
    <ai-dialog :visible.sync="dialog" title="审批" @closed="form={}" @onConfirm="submitAudit" width="560px">
      <el-form :model="form" :rules="rules" ref="AuditForm" size="small" label-width="120px">
        <el-form-item label="审批结果" prop="auditStatus">
          <ai-select v-model="form.auditStatus" :selectList="dict.getDict('auditStatus')"/>
        </el-form-item>
        <el-form-item label="审批意见" prop="auditDescription">
          <el-input type="textarea" v-model="form.auditDescription" placeholder="请输入"/>
        </el-form-item>
      </el-form>
    </ai-dialog>
  </section>
</template>

<script>
export default {
  name: "loanDetail",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  computed: {
    isAuthing() {
      return this.detail.status == "0"
    }
  },
  data() {
    return {
      dialog: false,
      detail: {},
      form: {},
      rules: {
        auditStatus: [{required: true, message: "请选择审批结果"}]
      }
    }
  },
  methods: {
    getDetail() {
      let {id} = this.$route.query
      this.instance.post("/appportaluserenterprise/queryDetailById", null, {
        params: {id}
      }).then(res => {
        if (res?.data) {
          this.detail = res.data
        }
      })
    },
    submitAudit() {
      this.$refs.AuditForm.validate(v => {
        if (v) {
          let {id} = this.detail
          this.instance.post("/appportaluserenterprise/auditEnterprise", null, {
            params: {id, ...this.form}
          }).then(res => {
            if (res?.code == 0) {
              this.dialog = false
              this.$message.success("提交成功!")
              this.getDetail()
            }
          })
        }
      })
    }
  },
  created() {
    this.dict.load("auditStatus")
    this.getDetail()
  }
}
</script>

<style lang="scss" scoped>
.loanDetail {
  height: 100%;

  .flexWrap {
    flex-wrap: wrap;

    .el-form-item {
      width: 50%;
    }
  }
}
</style>
