<template>
  <div v-loading="loading">
    <searchContainer
      bannerKey="首页>企业库>企业详情"
      :title="t('webSearch.companyLibrary')"
      @handleQuery="handleQuery"
    >
      <template v-slot>
        <div class="head">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item>
              <span class="one">
                <!--                找企业-->
                {{ t("webSearch.findCompany") }}
              </span>
            </el-breadcrumb-item>
            <el-breadcrumb-item>
              <span>
                <!--                企业详情-->
                {{ t("webSearch.companyDetails") }}
              </span>
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <el-row type="flex">
          <div style="flex: 1">
            <div class="item">
              <el-row type="flex" style="padding: 40px 20px">
                <div class="img">
                  <el-image :src="state.companyDetail.image"></el-image>
                  <!-- <img :src="state.companyDetail.image" alt /> -->
                </div>
                <div class="content">
                  <div class="tit">
                    <div style="float: right; visibility: hidden">
                      <span>
                        {{ t("webSearch.matchingDegree") }}
                      </span>
                      <el-rate
                        style="display: inline-block"
                        v-model="state.val"
                        disabled
                      ></el-rate>
                    </div>
                    <div class="text" style="flex: 1">
                      {{ state.companyDetail.name }}
                    </div>
                  </div>
                  <div class="line">
                    <!--                    企业规模-->
                    {{ t("webSearch.companySize") }}
                    ：
                    <span>{{
                      enterpriseOptions.find(
                        (el) => el.key == state.companyDetail.kind
                      )?.[locale] ?? t("webSearch.noData")
                    }}</span>
                  </div>
                  <div class="line">
                    <!--                    核心产品及应用场景-->
                    {{ t("webSearch.coreProducts") }}
                    ：
                    <span>{{ state.companyDetail.product }}</span>
                  </div>
                  <div class="line">
                    <!--                    企业网站-->
                    {{ t("webSearch.companyWebsite") }}
                    ：
                    <a :href="state.companyDetail.url">
                      <span>{{ state.companyDetail.url }}</span>
                    </a>
                  </div>
                </div>
                <div class="keywords" style="flex: 1">
                  <wordcloud
                    v-if="state.companyDetail.keywords"
                    :data="createdData(state.companyDetail.keywords)"
                  ></wordcloud>
                </div>
                <div class="btns">
                  <div class="order" @click="showDocking = true">
                    <!--                    预约对接-->
                    {{ t("webSearch.appointment") }}
                  </div>
                  <div class="share">
                    <!--                    一键分享-->
                    {{ t("webSearch.share") }}
                  </div>
                </div>
              </el-row>
            </div>
            <div class="product">
              <div style="padding: 20px 0">
                <div class="pointTit">
                  {{ t("webSearch.companyIntroduction") }}
                </div>
              </div>
              <div class="html" v-html="state.companyDetail.introduce"></div>
              <!-- <div style="padding: 20px 0">
                <div class="pointTit">生产方向</div>
              </div>
              <section v-if="state.companyDetail.directions">
                <div
                  v-for="(item, index) in state.companyDetail.directions"
                  :key="index"
                  class="describe"
                >
                  {{ item }}
                </div>
              </section> -->
              <div style="padding: 20px 0">
                <div class="pointTit">
                  <!--                  联系人-->
                  {{ t("webSearch.contact") }}
                </div>
              </div>
              <section v-if="state.companyDetail.username">
                {{ state.companyDetail.username }}
              </section>
              <div style="padding: 20px 0">
                <div class="pointTit">
                  <!--                  联系方式-->
                  {{ t("webSearch.contactInformation") }}
                </div>
              </div>
              <section v-if="state.companyDetail.phone">
                {{ state.companyDetail.phone }}
              </section>
              <div style="padding: 20px 0">
                <div class="pointTit">
                  <!--                  邮箱-->
                  {{ t("webSearch.email") }}
                </div>
              </div>
              <section v-if="state.companyDetail.email">
                {{ state.companyDetail.email }}
              </section>

              <div style="padding: 20px 0">
                <div class="pointTit">
                  <!--                  所属领域-->
                  {{ t("webSearch.industry") }}
                </div>
              </div>
              <section v-if="state.companyDetail.industryStr">
                {{ state.companyDetail.industryStr }}
                <!-- <div
                  v-for="(item, index) in state.companyDetail.directions"
                  :key="index"
                  class="describe"
                >
                  {{ item }}
                </div> -->
              </section>
              <div style="padding: 20px 0">
                <div class="pointTit">
                  {{ t("webSearch.location") }}
                </div>
              </div>
              <section>
                {{ state.localtion }}
              </section>
              <div style="padding: 20px 0">
                <div class="pointTit">
                  <!--                  详细地址-->
                  {{ t("webSearch.address") }}
                </div>
              </div>
              <section v-if="state.companyDetail.address">
                {{ state.companyDetail.address }}
              </section>
              <div style="padding: 20px 0">
                <div class="pointTit">
                  <!--                  企业网站-->
                  {{ t("webSearch.companyWebsite") }}
                </div>
              </div>
              <section v-if="state.companyDetail.url">
                {{ state.companyDetail.url }}
              </section>
              <!-- <div style="padding: 20px 0">
                <div class="pointTit">产品列表</div>
              </div>
              <section v-for="item in state.companyProduct" :key="item.id">
                <div style="border: 1px solid #dcdcdc; margin-bottom: 10px">
                  <productItem :data="item"></productItem>
                </div>
              </section> -->
            </div>

            <div style="padding: 20px 0">
              <div class="pointTit">
                {{ t("webSearch.companyRecommend") }}
              </div>
            </div>
            <div>
              <div class="item" v-for="item in state.list" :key="item.id">
                <el-row type="flex" style="padding: 40px 20px">
                  <div class="img">
                    <!-- <img :src="item.image" alt /> -->
                    <el-image :src="item.image" />
                  </div>
                  <div class="content">
                    <div class="tit" @click="handleDetail(item.id)">
                      <!-- <div style="float: right">
                        <span>匹配度</span>
                        <el-rate
                          style="display: inline-block"
                          v-model="state.val"
                          disabled
                        ></el-rate>
                      </div> -->
                      <div class="text" style="flex: 1">
                        {{ item.name }}
                      </div>
                    </div>
                    <div class="line">
                      {{ t("webSearch.companySize") }}
                      ：
                      <span>{{
                        enterpriseOptions.find((el) => el.key == item.kind)?.[
                          locale
                        ] ?? t("webSearch.noData")
                      }}</span>
                    </div>
                    <div class="line">
                      {{ t("webSearch.coreProducts") }}：
                      <span>{{ item.product }}</span>
                    </div>
                    <div class="line">
                      <!--                      企业网站-->
                      {{ t("webSearch.companyWebsite") }}
                      ：
                      <a :href="item.url">
                        <span>{{ item.url || t("webSearch.noData") }}</span>
                      </a>
                    </div>
                  </div>
                  <div class="keywords" style="flex: 1">
                    <wordcloud :data="createdData(item.keywords)"></wordcloud>
                  </div>
                </el-row>
              </div>
            </div>
          </div>
          <div class="r">
            <webContact />
          </div>
        </el-row>
      </template>
    </searchContainer>
    <docking v-model:visible="showDocking"></docking>
  </div>
</template>

<script setup>
import docking from "./components/docking.vue";
import webContact from "@/components/webContact/index.vue";
// import request from "@/utils/request";
import { searchEnterpriseDetail } from "@/api/website/home";
import { enterpriseOptions } from "@/utils/parameter";
// import { onMounted, reactive, ref } from "vue";
import searchContainer from "./components/searchContainer.vue";
import wordcloud from "./components/wordcloud.vue";
// import productItem from "./components/productItem.vue";
import { useRoute, useRouter } from "vue-router";
import { search } from "@/api/website/home";
import { getCity } from "@/utils/city";
import { useI18n } from "vue-i18n";

const { t, locale } = useI18n();
const router = useRouter();
const route = useRoute();
const loading = ref(true);
const showDocking = ref(false);
const state = reactive({
  pageNum: 1,
  pageSize: 4,
  keyword: "",
  val: 3,
  companyDetail: {},
  companyProduct: [],
  // 获取所在地
  localtion: "",
  // const location = ref("");
  arr: [
    {
      name: "Cat",
      value: 26,
    },
    {
      name: "fish",
      value: 19,
    },
  ],
});

function createdData(arr) {
  let l = [];
  let snap = JSON.parse(JSON.stringify(arr));
  snap.map((e) => {
    l.push({ name: e, value: 30 });
    return { name: e, value: 30 };
  });
  return l;
}

function handleDetail(id) {
  let routeData = router.resolve({
    path: `/searchList/enterprise/detail/${id}`,
    query: { keyword: route.query.keyword, queryType: route.query.queryType },
  });
  router.push(routeData);
}

function handleList(mode, keyword) {
  router.push({
    path: `/searchList/${mode}`,
    query: { keyword, queryType: route.query.queryType },
  });
}

// 首次加载数据，其后跳转页面
let flag = true;

function handleQuery(state) {
  state.keyword = state.currentKeyword;
  if (flag) {
    getDataList();
    flag = false;
  } else {
    handleList("enterprise", state.currentKeyword);
  }
}

function getDataList() {
  loading.value = true;
  // recommend().then((res) => {
  //   if (200 == res.code) {
  //     // 总条数
  //     state.total = res.data.count;
  //     state.list = res.data.data;
  //     console.log(res.data.data);
  //   }
  // });
  let id = route.params.id;
  if (!id) return;
  searchEnterpriseDetail(id)
    .then(async (resp) => {
      state.companyDetail = resp.data;
      state.localtion = await getCity(
        resp.data.province,
        resp.data.city,
        resp.data.district
      );
      loading.value = false;
    })
    .catch((err) => {
      console.log(err);
      loading.value = false;
    });
  search({
    query: route.query.keyword,
    searchType: 1,
    queryType: route.query.queryType,
  }).then((resp) => {
    const recommendList = resp.list.filter(
      // (el) => el.id != state.companyDetail.id
      (el) => el.id != id
    );
    state.list = recommendList;
    state.total = resp.total;
  });
  // companyProduct(id).then((res) => {
  //   if (200 == res.code) {
  //     state.companyProduct = res.data.data;
  //   }
  // });
}
</script>

<style lang="scss" scoped>
.head {
  padding: 15px 0px;

  span {
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
  }

  .one {
    color: #333333;
  }
}

.r {
  display: inline-block;
  width: 325px;
  margin-left: 14px;
  min-height: 200px;
}

.product {
  width: 661px;
  box-sizing: border-box;
  padding: 20px;
  background: #fff;

  .describe {
    font-size: 14px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    margin-bottom: 5px;
  }
}

.pointTit {
  position: relative;
  padding-left: 10px;
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 500;
  color: #333333;

  &:before {
    content: "";
    top: 8px;
    left: 0px;
    position: absolute;
    display: block;
    width: 5px;
    height: 5px;
    background: #0054ff;
  }
}

.item {
  overflow: hidden;
  background-color: #fff;
  margin-bottom: 16px;

  .btns {
    overflow: hidden;
    padding-top: 20px;
    width: 100%;

    div {
      text-align: center;
      float: right;
      cursor: pointer;
      user-select: none;
      width: 101px;
      height: 36px;
      font-size: 14px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      line-height: 36px;
      box-sizing: border-box;

      &:hover {
        opacity: 0.7;
      }
    }

    .share {
      color: #333333;
      background: #f2f6ff;
      border: 1px solid #dcdcdc;
      margin-right: 10px;
    }

    .order {
      background: #0054ff;
      color: #ffffff;
      border: none;
    }
  }

  .img {
    width: 90px;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;

    :deep(.el-image) {
      width: 90px;
      height: 90px;
      border-radius: 50%;
    }
  }

  .content {
    display: inline-block;
    width: 390px;

    .line {
      font-size: 16px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #666666;
      margin: 10px 0;

      span {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        color: #333;
      }
    }
  }

  .keywords {
    flex: 1;
    width: 129px;
    height: 129px;
  }

  .tit {
    width: 100%;
    overflow: hidden;
    cursor: pointer;

    .text {
      margin-right: 200px;
      overflow: hidden;

      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 20px;
      font-family: Source Han Sans CN;
      font-weight: bold;
      color: #333333;
    }
  }
}
</style>
