<template>
  <div class="companyinformation">
    <div class="companyinformation-header">
      <div class="companyinformation-header-main">
        <img src="@/assets/imgs/logo2.png" alt="" @click="$router.push('/home')"/>
        <div class="autocomplete">
          <el-autocomplete
            v-model="state"
            :fetch-suggestions="querySearchAsync"
            placeholder="请输入公司名称"
            @select="handleSelect"
            clearable
            :debounce="500"
            prefix-icon="el-icon-search"
          ></el-autocomplete>
          <el-button @click="search">分析</el-button>
        </div>
      </div>
    </div>
    <div class="companyinformation-container">
      <div class="companyinformation-container-main">
        <div class="companyinformation-container-main-top">
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item to="/home">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ $route.query.name }}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="companyinformation-container-main-info">
          <div class="company-img-po">
            <img src="@/assets/imgs/company/companyinfo.png" alt="" />
          </div>
          <div class="companyinfo-left">
            <div class="companyImg">
              <img src="@/assets/imgs/company/companyicon.png" alt="" />
            </div>
            <div class="zhexian">
              <img src="@/assets/imgs/company/zhexiantu.png" alt="" />
              <span>浏览量：0</span>
            </div>
          </div>
          <!--  -->
          <div class="companyinfo-right">
            <div class="companyinfo-right-top">
              <h1>{{ $route.query.name }}</h1>
              <div class="companyinfo-right-top-type">
                <span>小微企业</span>
                <span>小微企业</span>
                <span>小微企业</span>
              </div>
            </div>
            <div class="companyinfo-right-info">
              <div class="companyinfo-right-info-item">
                法人代表：{{ companyInfo.legalRepresentative }}
              </div>
              <div class="companyinfo-right-info-item">
                注册资本：{{ companyInfo.registeredCapital }}
              </div>
              <div class="companyinfo-right-info-item">
                营业期限：{{ companyInfo.businessTerm }}
              </div>
              <div class="companyinfo-right-info-item">
                统一社会信用代码：{{ companyInfo.creditCode }}
              </div>
              <div class="companyinfo-right-info-item">
                企业地址：{{ companyInfo.businessAddress }}
              </div>
              <div class="companyinfo-right-info-item">
                公司类型：{{companyInfo.companyType}}
              </div>
              <div class="moreinfo">更多信息</div>
            </div>
          </div>
        </div>
        <div class="companyinformation-container-main-certificateinfo">
          <div class="main-certificateinfo-left">
            <div class="companycertificateinfo">
              <h3><i></i> 企业证照信息</h3>
              <table>
                <thead>
                  <tr>
                    <td>工商证照</td>
                    <td>知产证照</td>
                    <td>财税证照</td>
                    <td>资质证照</td>
                    <td>特许资质</td>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>营业执照 1</td>
                    <td>商标注册证 78</td>
                    <td>一般纳税人证 1</td>
                    <td>食品流通许可证 1</td>
                    <td>互联网准入许可证 1</td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="companycertificateinfo">
              <h3><i></i> 竞争企业证照信息</h3>
              <table>
                <thead>
                  <tr>
                    <td colspan="5">工商证照</td>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>营业执照 1</td>
                    <td>商标注册证 78</td>
                    <td>一般纳税人证 1</td>
                    <td>食品流通许可证 1</td>
                    <td>互联网准入许可证 1</td>
                  </tr>
                </tbody>
              </table>
              <table>
                <thead>
                  <tr>
                    <td colspan="5">工商证照</td>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>营业执照 1</td>
                    <td>商标注册证 78</td>
                    <td>一般纳税人证 1</td>
                    <td>食品流通许可证 1</td>
                    <td>互联网准入许可证 1</td>
                  </tr>
                </tbody>
              </table>
              <table>
                <thead>
                  <tr>
                    <td colspan="5">工商证照</td>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>营业执照 1</td>
                    <td>商标注册证 78</td>
                    <td>一般纳税人证 1</td>
                    <td>食品流通许可证 1</td>
                    <td>互联网准入许可证 1</td>
                  </tr>
                </tbody>
              </table>
              <table>
                <thead>
                  <tr>
                    <td colspan="5">工商证照</td>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>营业执照 1</td>
                    <td>商标注册证 78</td>
                    <td>一般纳税人证 1</td>
                    <td>食品流通许可证 1</td>
                    <td>互联网准入许可证 1</td>
                  </tr>
                </tbody>
              </table>
              <table>
                <thead>
                  <tr>
                    <td colspan="5">工商证照</td>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>营业执照 1</td>
                    <td>商标注册证 78</td>
                    <td>一般纳税人证 1</td>
                    <td>食品经营许可证 1</td>
                    <td>互联网准入许可证 1</td>
                  </tr>
                </tbody>
              </table>
              <div class="lookgengduo">
                <span>查看更多</span>
              </div>
            </div>
          </div>
          <div class="main-certificateinfo-right">
            <h1>推荐证照</h1>
            <div class="zhengzhaoimg">
              <img src="@/assets/imgs/company/zhengzhao1.png" alt="" />
              <p>立即办理</p>
            </div>
            <div class="zhengzhaoimg">
              <img src="@/assets/imgs/company/zhengzhao2.png" alt="" />
              <p>立即办理</p>
            </div>
            <div class="zhengzhaoimg">
              <img src="@/assets/imgs/company/zhengzhao3.png" alt="" />
              <p>立即办理</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getCompanyInfoByLikeName,
  getEntregistryByCompanyName
} from "@/api/tmTools.js";
export default {
  data() {
    return {
      state: "",
      companyInfo: {
        name: null,
        legalRepresentative: null,
        managementState: null,
        registeredCapital: null,
        creditCode: null,
        registrID: null,
        organizationCode: null,
        companyType: null,
        registerOffice: null,
        businessAddress: null,
        scope: null,
        dateIssue: null,
        businessTerm: null,
        requestId: null
      }
    };
  },
  mounted() {
    this.state = this.$route.query.name;
    getEntregistryByCompanyName(this.state).then(res => {
      this.companyInfo = res;
    });
  },
  methods: {
    //查询公司详情
    search() {
      if (this.state) {
        this.$router.push({
          path: "/companyinformation",
          query: { name: this.state }
        });
        this.saveLocalStorage();
        getEntregistryByCompanyName(this.state).then(res => {
          this.companyInfo = res;
        });
      }
    },
    //将搜索过的内容存入localStorage
    saveLocalStorage() {
      let companyInfo = JSON.parse(window.localStorage.getItem("companyInfo"));
      if (companyInfo) {
        let index = companyInfo.findIndex(item => {
          return item.value == this.state;
        });
        if (index == -1) {
          companyInfo.unshift({ value: this.state });
          window.localStorage.setItem(
            "companyInfo",
            JSON.stringify(companyInfo)
          );
        }
      } else {
        let companyInfo1 = [];
        companyInfo1.unshift({ value: this.state });
        window.localStorage.setItem(
          "companyInfo",
          JSON.stringify(companyInfo1)
        );
      }
    },
    //模糊查询
    querySearchAsync(queryString, cb) {
      if (this.state == "") {
        //如果没有输入值，则从本地获取数据
        let companyInfo = JSON.parse(
          window.localStorage.getItem("companyInfo")
        );
        if (companyInfo) {
          cb(companyInfo);
        } else {
          cb([]);
        }
      } else {
        //请求企业近似商标数据
        getCompanyInfoByLikeName(this.state).then(res => {
          res.data.map(item => {
            item.value = item.domainEntName;
          });
          console.log(res.data);
          cb(res.data);
        });
      }
    },
    handleSelect(item) {
      console.log(item);
      if (this.state) {
        this.saveLocalStorage();
      }
    }
  }
};
</script>

<style lang="scss">
.companyinformation {
  width: 100%;
  .companyinformation-header {
    width: 100%;
    height: 70px;
    background: #000033;
    .companyinformation-header-main {
      width: 1200px;
      height: 100%;
      margin: 0 auto;
      display: flex;
      align-items: center;
      img {
        height: 30px;
        margin-right: 20px;
        cursor: pointer;
      }
      .autocomplete {
        width: 630px;
        height: 40px;
        display: flex;
        border-radius: 2px;
        overflow: hidden;
        .el-autocomplete {
          flex: 1;
          .el-input {
            width: 100%;
            height: 100%;
            .el-input__inner {
              width: 100%;
              height: 100%;
              border-radius: 0;
            }
          }
        }
        .el-button {
          width: 80px;
          height: 40px;
          background: #ffffff;
          border-radius: 1px;
          border: 1px solid #dfe1e5;
          border-left: none;
          font-size: 15px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: rgba(20, 120, 240, 1);
          line-height: 22px;
          padding: 0;
        }
      }
    }
  }
}
.companyinformation-container {
  width: 100%;
  background: #f6f6f6;
  .companyinformation-container-main {
    width: 1200px;
    margin: 0 auto;
    padding: 0 0 30px 0;
  }
}
.companyinformation-container-main-top {
  padding: 15px 0;
}
.companyinformation-container-main-info {
  padding: 25px 20px;
  background: #fff;
  margin-bottom: 14px;
  border: 1px solid #eeeeee;
  display: flex;
  position: relative;
  .company-img-po {
    width: 38px;
    position: absolute;
    top: -2px;
    left: -34px;
    img {
      width: 100%;
    }
  }
  .companyinfo-left {
    width: 102px;
    margin-right: 35px;
    .companyImg {
      width: 102px;
      height: 102px;
      margin-bottom: 15px;
    }
    .zhexian {
      width: 102px;
      background: #f0f7fc;
      padding: 5px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      img {
        width: 100%;
      }
      span {
        font-size: 12px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(108, 109, 109, 1);
        line-height: 17px;
        margin-top: 2px;
      }
    }
  }
  .companyinfo-right {
    flex: 1;
    .companyinfo-right-top {
      width: 100%;
      display: flex;
      margin-bottom: 17px;
      h1 {
        font-size: 22px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(18, 18, 18, 1);
        line-height: 30px;
        margin-right: 20px;
      }
      .companyinfo-right-top-type {
        padding: 5px 0 0;
        span {
          padding: 2px 10px;
          font-size: 12px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(240, 166, 124, 1);
          background: #fdf2ec;
          line-height: 17px;
          margin-right: 10px;
        }
      }
    }
    .companyinfo-right-info {
      padding: 20px 12px;
      background: #f6faff;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      .companyinfo-right-info-item {
        width: 33.33%;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(7, 7, 7, 1);
        line-height: 20px;
        margin-bottom: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .moreinfo {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(20, 120, 240, 1);
        line-height: 20px;
        cursor: pointer;
      }
    }
  }
}
.companyinformation-container-main-certificateinfo {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .main-certificateinfo-left {
    width: 936px;
    .companycertificateinfo {
      width: 100%;
      padding: 16px 16px 1px;
      background: #fff;
      margin-bottom: 15px;
      border: 1px solid rgba(238, 238, 238, 1);
      h3 {
        font-size: 16px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: rgba(51, 51, 51, 1);
        line-height: 22px;
        display: flex;
        align-items: center;
        margin-bottom: 17px;
        i {
          display: inline-block;
          width: 3px;
          height: 14px;
          background: rgba(20, 120, 240, 1);
          margin-right: 5px;
        }
      }
      table {
        width: 100%;
        margin-bottom: 18px;
        thead {
          background: #f0f7fc;
          tr {
            td {
              height: 40px;
              text-align: center;
              font-size: 14px;
              font-family: PingFangSC-Regular, PingFang SC;
              font-weight: 400;
              color: rgba(51, 51, 51, 1);
              line-height: 20px;
              width: 20%;
              border: 1px solid #e4eef6;
            }
          }
        }
        tbody {
          tr {
            td {
              padding: 10px 0;
              height: 40px;
              text-align: center;
              font-size: 14px;
              font-family: PingFangSC-Regular, PingFang SC;
              font-weight: 400;
              color: rgba(51, 51, 51, 1);
              line-height: 20px;
              width: 20%;
              border: 1px solid #e4eef6;
            }
          }
        }
      }
      .lookgengduo {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-bottom: 16px;
        span {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(20, 120, 240, 1);
          line-height: 20px;
          cursor: pointer;
        }
      }
    }
  }
  .main-certificateinfo-right {
    width: 250px;
    h1 {
      width: 100%;
      height: 48px;
      background: rgba(255, 255, 255, 1);
      border: 1px solid rgba(238, 238, 238, 1);
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 18px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: rgba(51, 51, 51, 1);
      line-height: 25px;
      margin-bottom: 14px;
    }
    .zhengzhaoimg {
      width: 100%;
      margin-bottom: 14px;
      position: relative;
      img {
        width: 100%;
      }
      p {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 40px;
        background: rgba(0, 0, 0, 0.64);
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(255, 255, 255, 1);
        line-height: 22px;
      }
    }
  }
}
</style>
