<template>
  <div class="index">
    <searchContainer
      bannerKey="首页>专利库>专利列表"
      title="专利库"
      @handleQuery="handleQuery"
    >
      <template v-slot>
        <el-row type="flex" style="padding: 20px 0">
          <div style="flex: 1">
            <div style="position: relative">
              <!-- <industrySelect @industryChange="industryChange"></industrySelect> -->
              <div class="total">
                共找到
                <span>{{ total }}</span> 个专利
              </div>
              <div v-loading="loading">
                <section v-for="item in searchResults" :key="item.id">
                  <div style="border: 1px solid #dcdcdc; margin-bottom: 10px">
                    <gainItem :data="item"></gainItem>
                  </div>
                </section>
              </div>

              <pagination
                class="pagination"
                :total="total"
                :pageSizes="[10, 10 << 1, 10 << 2, 10 << 3]"
                v-model:page="queryParams.pageNum"
                v-model:limit="queryParams.pageSize"
                :autoScroll="false"
                @pagination="getDataList"
              />
            </div>
          </div>
          <div class="r">
            <WebContact />
          </div>
        </el-row>
      </template>
    </searchContainer>
  </div>
</template>

<script setup>
// import request from "@/utils/request";
import { onMounted, reactive } from "vue";
import { search } from "@/api/website/home/index";
import WebContact from "@/components/webContact/index.vue";
import searchContainer from "./components/searchContainer.vue";
// import industrySelect from "./components/industrySelect.vue";
import gainItem from "./components/gainItem.vue";
import wordcloud from "./components/wordcloud.vue";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
const queryParams = reactive({
  pageNum: 1,
  pageSize: 5,
  searchType: 4,
  queryType: route.query.queryType,
  query: route.query.keyword,
});
function handleDetail(id) {
  let routeData = router.resolve({
    path: `/searchList/0/detail/${id}`,
    query: { keyword: queryParams.query },
  });
  window.open(routeData.href, "_blank");
}

const loading = ref(false);
// const state = reactive({
//   pageNum: 1,
//   total: 1,
//   pageSize: 10,
//   pageSizes: [10, 10 << 1, 10 << 2, 10 << 3],
//   keyword: "",
//   industryList: [],
//   id1: "",
//   id2: "",
//   id3: "",
//   val: 3,
//   arr: [
//     {
//       name: "Cat",
//       value: 26,
//     },
//     {
//       name: "fish",
//       value: 19,
//     },
//   ],
// });
const searchResults = ref([]);
const total = ref(0);
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 search() {
//   let industry = "";
//   if (state.id1) {
//     industry += state.id1;
//   }
//   if (state.id2) {
//     industry += `-${state.id2}`;
//   }
//   if (state.id3) {
//     industry += `-${state.id3}`;
//   }
//   return request({
//     url: "/v1/search",
//     method: "post",
//     data: {
//       industry,
//       mode: 4,
//       page_num: state.pageNum,
//       page_size: state.pageSize,
//       keyword: state.keyword,
//     },
//   });
// }
const getSearchResult = async () => {
  const resp = await search(queryParams);
  console.log(resp);
};
function handleQuery(keyword) {
  // state.keyword = keyword;
  queryParams.query = keyword;
  getDataList();
}
function industryChange(industry) {
  if (industry.id1) {
    state.id1 = industry.id1;
  }
  if (industry.id2) {
    state.id2 = industry.id2;
  }
  if (industry.id3) {
    state.id3 = industry.id3;
  }
  getDataList();
}

const getDataList = async () => {
  loading.value = true;
  try {
    const resp = await search(queryParams);
    searchResults.value = resp.list;
    total.value = resp.total;
    loading.value = false;
  } catch (error) {
    loading.value = false;
  }
};
</script>

<style lang="scss" scoped>
.total {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 500;
  color: #333333;
  margin-bottom: 20px;
  span {
    font-size: 30px;
    color: #0054ff;
  }
}

.r {
  display: inline-block;
  width: 325px;
  margin-left: 14px;
  min-height: 200px;
  // background-color: #fff;
}

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

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