<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">
                <div class="item" v-for="item in searchResults" :key="item.id">
                  <el-row type="flex" style="padding: 40px 20px">
                    <div class="img">
                      <!-- <img :src="item.image" alt /> -->
                      <el-image :src="item.image"></el-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">
                        企业规模：
                        <span>{{
                          enterpriseOptions.find((el) => el.key == item.kind)
                            ?.value ?? "后台暂没提供"
                        }}</span>
                      </div>
                      <div class="line">
                        核心产品及应用场景： <span>{{ item.product }}</span>
                      </div>
                      <div class="line">
                        企业网站：
                        <a :href="item.url"
                          ><span>{{ item.url || "后台暂没提供" }}</span></a
                        >
                      </div>
                    </div>
                    <div class="keywords" style="flex: 1">
                      <wordcloud
                        :data="createdData(item.keyword.split(','))"
                      ></wordcloud>
                    </div>
                  </el-row>
                </div>
              </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 WebContact from "@/components/webContact/index.vue";
// import request from "@/utils/request";
import { enterpriseOptions } from "@/utils/parameter";
import { search } from "@/api/website/home/index";
// import { onMounted } from "vue";
import searchContainer from "./components/searchContainer.vue";
// import industrySelect from "./components/industrySelect.vue";
import wordcloud from "./components/wordcloud.vue";
import { useRoute, useRouter } from "vue-router";

const route = useRoute();
const router = useRouter();
const searchResults = ref([]);
const total = ref(0);

const queryParams = reactive({
  pageNum: 1,
  pageSize: 5,
  searchType: 1,
  queryType: route.query.queryType,
  query: route.query.keyword,
});

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

const loading = ref(true);
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,
    },
  ],
});

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: 1,
//       page_num: state.pageNum,
//       page_size: state.pageSize,
//       keyword: state.keyword,
//     },
//   });
// }

function handleQuery(state) {
  // state.keyword = keyword;
  queryParams.query = state.currentKeyword;
  queryParams.queryType = state.queryType;
  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;
    :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>
