<template>
  <div v-loading="loading">
    <searchContainer
      bannerKey="首页>产品库>产品详情"
      :title="t('webSearch.productLibrary')"
      @handleQuery="handleQuery"
    >
      <template v-slot>
        <div class="head">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item>
              <span class="one">
                {{ t("webSearch.findProduct") }}
              </span>
            </el-breadcrumb-item>
            <el-breadcrumb-item>
              <span>
                <!--                产品详情-->
                {{ t("webSearch.productDetails") }}
              </span>
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <el-row type="flex" style="padding-bottom: 20px">
          <el-col :span="16">
            <div>
              <achievementItem :data="state.expertDetail">
                <template v-slot:des>
                  <div>{{ state.expertDetail.introduce }}</div>
                </template>
              </achievementItem>
              <div class="btns">
                <div class="order" @click="showDocking = true">
                  <!--                预约对接-->
                  {{ t("webSearch.appointment") }}
                </div>
                <div class="share">
                  <!--                一键分享-->
                  {{ t("webSearch.share") }}
                </div>
              </div>

              <div class="detail">
                <div style="padding: 20px 0">
                  <div class="pointTit">
                    <!--                  产品简介-->
                    {{ t("webSearch.productIntroduction") }}
                  </div>
                </div>
                <div class="html" v-html="state.expertDetail.description"></div>
                <div style="padding: 20px 0">
                  <div class="pointTit">
                    <!--                  所属单位-->
                    {{ t("webSearch.unit") }}
                  </div>
                </div>
                <section>
                  {{ state.expertDetail.unit }}
                </section>
                <div style="padding: 20px 0">
                  <div class="pointTit">
                    <!--                  产品领先性-->
                    {{ t("admin.form.productLeadership") }}
                  </div>
                </div>
                <section>
                  <div>
                    {{
                      leadOptions.find(
                        (el) => el.key === state.expertDetail.leadStandard
                      )?.[locale]
                    }}
                  </div>
                </section>
                <div style="padding: 20px 0">
                  <div class="pointTit">
                    <!--                  合作模式-->
                    {{ t("webSearch.cooperationMode") }}
                  </div>
                </div>
                <section>
                  <div>
                    {{
                      cooperationOptions.find(
                        (el) => el.key == state.expertDetail.cooperationMode
                      )?.[locale]
                    }}
                  </div>
                </section>
                <div style="padding: 20px 0">
                  <div class="pointTit">
                    <!--                  应用客户-->
                    {{ t("webSearch.applicationCustomers") }}
                  </div>
                </div>
                <section>
                  <div>
                    {{ state.expertDetail.customer }}
                  </div>
                </section>
              </div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="r">
              <webContact />
            </div>
          </el-col>
        </el-row>
      </template>
    </searchContainer>
    <docking v-model:visible="showDocking"></docking>
  </div>
</template>

<script setup>
import webContact from "@/components/webContact/index.vue";
import achievementItem from "./components/achievementItem.vue";
// import loadMore from "./components/loadMore.vue";
// import request from "@/utils/request";
// import { onMounted } from "vue";
import searchContainer from "./components/searchContainer.vue";

// import wordcloud from "./components/wordcloud.vue";
// import productItem from "./components/productItem.vue";
import { searchProductDetail } from "@/api/website/home";
import { useRoute, useRouter } from "vue-router";
import { computed, reactive, ref } from "vue";
import docking from "./components/docking.vue";
import { cooperationOptions, leadOptions } from "@/utils/parameter";
import { useI18n } from "vue-i18n";

const showDocking = ref(false);
const { t, locale } = useI18n();
const loading = ref(true);

const leadValueField = computed(() =>
  locale.value === "zh" ? "value" : "valueRu"
);
// import {lead}
const state = reactive({
  pageNum: 1,
  pageSize: 4,
  keyword: "",
  val: 3,
  expertDetail: {},
  arr: [
    {
      name: "Cat",
      value: 26,
    },
    {
      name: "fish",
      value: 19,
    },
  ],
  activeName: "first",
});

const router = useRouter();
const route = useRoute();
// const searchResults = ref([]);
// const total = ref(0);
// const queryParams = reactive({
//   pageNum: 1,
//   pageSize: 5,
//   searchType: 5,
//   queryType: route.query.queryType,
//   query: route.query.keyword,
// });
// 建议 列表前4条
// function recommend() {
//   return request({
//     url: "/v1/search",
//     method: "post",
//     data: {
//       mode: 5,
//       page: state.pageNum,
//       page_size: state.pageSize,
//       keyword: state.keyword,
//     },
//   });
// }

// 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) {
  // queryParams.query = state.currentKeyword;
  // queryParams.queryType = state.queryType;
  if (flag) {
    getDataList();
    flag = false;
  } else {
    handleList("achievement", state.currentKeyword);
  }
}

function getDataList() {
  loading.value = true;
  let id = route.params.id;
  if (!id) return;
  searchProductDetail(id)
    //   achievementDetail(id)
    .then(async (resp) => {
      //       if (200 == res.code) {
      console.log(resp.data);
      state.expertDetail = resp.data;
      // state.localtion = await getCity(
      //   resp.data.province,
      //   resp.data.city,
      //   resp.data.district
      // );
      loading.value = false;
    });
}
</script>

<style lang="scss" scoped>
:deep(.el-tabs) {
  .el-tabs__item {
    color: #666666;
    font-size: 14px;
  }

  .el-tabs__item:hover {
    opacity: 0.8;
  }

  .el-tabs__item.is-active {
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #333333;
  }

  .el-tabs__active-bar {
    background-color: #333333;
    height: 4px;
  }

  .el-tabs__nav-wrap::after {
    background-color: transparent;
  }
}

.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;
}

.detail {
  //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;
  }
}

.btns {
  overflow: hidden;
  padding: 0 20px 20px 20px;
  width: 100%;
  background-color: #fff;
  margin-top: -20px;

  div {
    margin-top: 20px;
    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;
  }
}

.achievementItem,
.loadMoreItem {
  padding: 20px;
  background-color: #fff;
  margin-bottom: 10px;

  .tit {
    margin-left: -8px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #333333;
  }

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

.patentItem {
  padding: 20px;
  background-color: #fff;
  margin-bottom: 10px;

  .tit {
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #333333;
  }

  .line {
    padding-left: 8px;
    margin: 10px 0;
    font-size: 14px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
  }
}
</style>
