<template>
  <div class="app-container" v-loading="loading">
    <i v-if="info.authState == 1" class="entIcon audit"></i>
    <i v-if="info.authState == 2" class="entIcon pass"></i>
    <i v-if="info.authState == 3" class="entIcon refuse"></i>
    <h3 class="toolbar">
      <span class="title">企业信息</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>企业名称</th>
        <td>{{info.entName}}</td>
        <th>统一社会信用代码</th>
        <td>{{info.license}}</td>
      </tr>
      <tr>
        <th>注册资金（万元）</th>
        <td>{{info.regCapital}}</td>
        <th>工商注册时间</th>
        <td>{{info.regDate}}</td>
      </tr>
      <tr>
        <th>工商注册类型</th>
        <td>{{regTypeFormat}}</td>
        <th>主营产品（服务）所属技术领域</th>
        <td>{{info.mainProducts}}</td>
      </tr>
      <tr>
        <th>通信地址</th>
        <td>{{info.address}}</td>
        <th>邮政编码</th>
        <td>{{info.zipCode}}</td>
      </tr>
      <tr>
        <th>企业所属行政区域</th>
        <td>{{info.provinceName}}{{info.cityName}}{{info.districtName}}</td>
        <th>企业所得税主管税务机关</th>
        <td>{{info.taxOffice}}</td>
      </tr>
    </table>
    <h3 class="toolbar mt20">
      <span class="title">法人信息</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>姓名</th>
        <td>{{info.legalName}}</td>
        <th>身份证号码</th>
        <td>{{info.legalIdCard}}</td>
      </tr>
      <tr>
        <th>手机号码</th>
        <td>{{info.legalMobile}}</td>
        <th>固定电话</th>
        <td>{{info.legalPhone}}</td>
      </tr>
      <tr>
        <th>传真</th>
        <td>{{info.legalFax}}</td>
        <th>E-mail</th>
        <td>{{info.legalEmail}}</td>
      </tr>
    </table>
    <h3 class="toolbar mt20">
      <span class="title">联系人信息</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>姓名</th>
        <td>{{info.linkName}}</td>
        <th>身份证号码</th>
        <td>{{info.linkIdCard}}</td>
      </tr>
      <tr>
        <th>手机号码</th>
        <td>{{info.linkMobile}}</td>
        <th>固定电话</th>
        <td>{{info.linkPhone}}</td>
      </tr>
      <tr>
        <th>传真</th>
        <td>{{info.linkFax}}</td>
        <th>E-mail</th>
        <td>{{info.linkEmail}}</td>
      </tr>
    </table>
    <h3 class="toolbar mt20">
      <span class="title">企业上市信息</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>企业是否上市</th>
        <td>{{listedFlag}}</td>
        <th>企业上市代码</th>
        <td>{{info.listingCode}}</td>
      </tr>
    </table>
    <h3 class="toolbar mt20">
      <span class="title">风险投资信息</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>是否引入风险投资</th>
        <td>{{investFlag}}</td>
        <th>风险投资金额</th>
        <td>{{info.investCapital}}</td>
      </tr>
    </table>
    <h3 class="toolbar mt20">
      <span class="title">高新企业</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>是否为高新企业</th>
        <td>{{techFlag}}</td>
        <th>高新企业编号</th>
        <td>{{info.techCode}}</td>
      </tr>
    </table>
    <h3 class="toolbar mt20">
      <span class="title">上年度是否做加计扣除</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>上年度是否做加计扣除</th>
        <td>{{deductionFlag}}</td>
      </tr>
    </table>
    <h3 class="toolbar mt20">
      <span class="title">附件</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>企业营业执照</th>
        <td>
          <a class="link" :href="info.licensePath" target="_blank" v-if="info.licensePath">企业营业执照</a>
        </td>
        <th>其他附件</th>
        <td>
          <div v-for="(file, index) in list" :key="index">
            <a class="link" :href="file.url" target="_blank">{{file.fileName}}</a>
          </div>
        </td>
      </tr>
    </table>
    <h3 class="toolbar mt20">
      <span class="title">文件水印</span>
    </h3>
    <table class="table_view">
      <tr>
        <th>公司logo</th>
        <td>
          <a class="link" :href="info.logo" target="_blank" v-if="info.logo">公司logo</a>
          <!-- <img :src="info.logo" alt="logo"> -->
        </td>
      </tr>
    </table>
    <div class="oper">
      <el-button @click="cancel" v-if="type == 'view' || type == 'audit'">返回</el-button>
      <template v-if="info.authState == '1' && type == 'audit'">
        <el-button @click="handleAudit">通过审核</el-button>
        <el-button @click="handleRefuse">驳回</el-button>
      </template>
      <template v-if="(type == 'update') && info.authState == '1'">
        <el-button @click="handleUpdate">修改</el-button>
      </template>
    </div>
    <audit-ent v-if="auditEntVisible" ref="auditEnt" @refreshData="getData()"></audit-ent>
  </div>
</template>

<script>
  import { getEntInfoByIdApi, auditEntApi } from "@/api/admin/ent/ent"
  import AuditEnt from "./components/audit"
  import {getEnclosureApi} from "@/api/enterprise/project/project"
  import {getEntInfoByIdTaxApi} from "@/api/gov/gov"
  import {regTypeOptions, getLabel,yesOrNoOptions} from '@/utils/dataFormat'
  import {downloadEnclosureByIdApi} from "@/api/common/common"
  export default {
    name: 'EntInfo',
    components: {
      AuditEnt
    },
    data () {
      return {
        loading: false,
        id: undefined,
        type: undefined,
        list: [],
        auditEntVisible: false,
        attachType: 'ENT',
        roleType: '',
        info: {
        },
      }
    },
    computed: {
      scopeId() {
        return this.$store.state.user.scopeId
      },
      roles() {
        return this.$store.state.user.roles
      },
      regTypeFormat() {
        return getLabel(regTypeOptions, this.info.regType);
      },
      listedFlag() {
        return getLabel(yesOrNoOptions, this.info.listedFlag);
      },
      investFlag() {
        return getLabel(yesOrNoOptions, this.info.investFlag)
      },
      techFlag() {
        return getLabel(yesOrNoOptions, this.info.techFlag)
      },
      deductionFlag() {
        return getLabel(yesOrNoOptions, this.info.deductionFlag)
      }
    },
    created () {
      this.type = this.$route.query.type || undefined
      this.roleType = this.roles.join(',')
      if(this.roleType == 'entAdmin' || this.roleType == 'entUser') {
        this.id = this.scopeId
        this.dataId = this.scopeId
      }else {
        this.id = this.$route.params.id
        this.dataId = this.$route.params.id
      }
      if(this.id) {
        this.getData()
        this.getEnclosureData()
      }
    },
    methods: {
      getEnclosureData() {
        getEnclosureApi(this.attachType, this.dataId).then(res => {
          this.list = res.data.records
        })
      },
      getData() {
        const id = this.id
        this.loading = true
        if(this.roleType == 'gov') {
          getEntInfoByIdTaxApi(id).then(res => {
            this.loading = false
            this.info = res.data || {}
          })
        }else if(this.roleType == 'manager') {
          getEntInfoByIdApi(id).then(res => {
            this.loading = false
            this.info = res.data || {}
          })
        }

      },
      handleAudit() {
        this.auditEntVisible = true
        this.$nextTick(() => {
          this.$refs.auditEnt.init(this.id)
        })
      },
      handleRefuse() {
        let params = {
          id: this.id,
          authState: '3',
        }
        this.$confirm('是否确认驳回该企业注册?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
            return auditEntApi(params);
          }).then(() => {
            this.$message({
              message: '审核驳回成功',
              type: 'success'
            });
            this.getData()
          })
      },
      handleUpdate() {

      },
      handleView(id) {
        window.open("http://124.232.146.72:7015/api/common/attach/"+id)
      },
      cancel() {
        this.$store.dispatch("tagsView/delView", this.$route); // 关闭当前tab
        this.$router.go(-1);
      }
    }
  }
</script>

<style>
</style>
