<template>
  <div v-loading="loading">
    <searchContainer
      bannerKey="首页>实验室库>实验室详情"
      title="实验室库"
      @handleQuery="handleQuery"
    >
      <template v-slot>
        <div class="head">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item>
              <span class="one">找实验室</span>
            </el-breadcrumb-item>
            <el-breadcrumb-item>
              <span>实验室详情</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">
                  <img :src="state.LabDetail.image" alt />
                </div> -->
                <div class="content">
                  <div class="tit">
                    <!-- <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">
                      {{ state.LabDetail.name }}
                    </div>
                  </div>
                  <div class="line">
                    所属领域：
                    <span>{{ state.LabDetail.industryStr }}</span>
                  </div>
                  <div class="line">
                    网址：
                    <a :href="state.LabDetail.url" target="_blank">{{
                      state.LabDetail.url
                    }}</a>
                  </div>
                  <div class="line">
                    所属院所或高校：
                    <!-- <a :href="state.LabDetail.applyName"> -->
                    <span>{{ state.LabDetail.school }}</span>
                    <!-- </a> -->
                  </div>
                </div>
                <div class="keywords" style="flex: 1">
                  <wordcloud
                    v-if="state.LabDetail.keyword"
                    :data="
                      createdData(state.LabDetail.keyword.split(/[,\/]{1}/))
                    "
                  ></wordcloud>
                </div>
                <div class="btns">
                  <div class="order" @click="showDocking = true">预约对接</div>
                  <div class="share">一键分享</div>
                </div>
              </el-row>
            </div>

            <div class="product">
              <div style="padding: 20px 0">
                <div class="pointTit">实验室简介</div>
              </div>
              <div class="html" v-html="state.LabDetail.introduction"></div>
              <div style="padding: 20px 0">
                <div class="pointTit">核心成员及简介</div>
              </div>
              <div class="html" v-html="state.LabDetail.member"></div>
              <div style="padding: 20px 0">
                <div class="pointTit">研究方向</div>
              </div>
              <div
                class="html"
                v-html="state.LabDetail.researchDirection"
              ></div>
              <div style="padding: 20px 0">
                <div class="pointTit">主要技术应用场景</div>
              </div>
              <div
                v-html="
                  state.LabDetail.primaryTechnology?.replaceAll(`/`, `<br />`)
                "
              ></div>
              <div style="padding: 20px 0">
                <div class="pointTit">承担科研项目情况</div>
              </div>
              <div
                v-html="
                  state.LabDetail.researchProject?.replaceAll('/', `</br>`)
                "
              ></div>
              <div style="padding: 20px 0">
                <div class="pointTit">代表性科技成果</div>
              </div>
              <div
                v-html="state.LabDetail.achievement?.replaceAll('/', `</br>`)"
              ></div>
              <div style="padding: 20px 0">
                <div class="pointTit">所属行业领域</div>
              </div>
              <div>{{ state.LabDetail.industryStr }}</div>
            </div>
          </div>
          <div class="r"><webContact /></div>
        </el-row>
      </template>
    </searchContainer>
    <docking v-model:visible="showDocking"></docking>
  </div>
</template>

<script setup>
import webContact from "@/components/webContact/index.vue";
// import request from "@/utils/request";
import { searchLaboratoryDetail } from "@/api/website/home";
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 docking from "./components/docking.vue";
const showDocking = ref(false);
const router = useRouter();
const route = useRoute();
const loading = ref(true);
const state = reactive({
  pageNum: 1,
  pageSize: 4,
  keyword: "",
  val: 3,
  LabDetail: {},
  companyProduct: [],
  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/0/detail/${id}`,
//     query: { keyword: state.keyword },
//   });
//   window.open(routeData.href, "_blank");
// }

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("lab", state.currentKeyword);
  }
}

function getDataList() {
  loading.value = true;

  let id = route.params.id;
  if (!id) return;
  searchLaboratoryDetail(id)
    .then((resp) => {
      const data = resp.data;
      data.introduction = data.introduction
        ?.replaceAll("\n", "</br>")
        ?.replaceAll(" ", "&ensp;");
      data.member = data.member
        ?.replaceAll("\n", "</br>")
        ?.replaceAll(" ", "&ensp;");
      data.researchDirection = data.researchDirection
        ?.replaceAll("/", "</br>")
        ?.replaceAll(" ", "&ensp;");
      state.LabDetail = resp.data;
      loading.value = false;
    })
    .catch((err) => {
      console.log(err);
      loading.value = false;
    });
}
</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;
    img {
      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>
