<template>
  <div
    class="box"
    style="background-size: cover; background-color: #fff"
    :style="{ backgroundImage: state.banner ? `url(${state.banner})` : '' }"
  >
    <div>
      <el-row>
        <el-col :push="4" :sm="10" :md="12">
          <div class="tab">
            <div
              v-for="(v, index) in state.tabList"
              :class="{ active: state.tabIndex == index }"
              @click="switchTab(index)"
            >
              {{ v }}
            </div>
          </div>
        </el-col>
      </el-row>
      <div style="height: 16px"></div>
      <el-form :model="queryParams" :rules="queryRules" ref="queryRef">
        <el-row>
          <el-col :push="4" :sm="10" :md="12">
            <el-form-item prop="keyword">
              <el-input
                v-model.trim="queryParams.keyword"
                placeholder="请输入检索词"
              >
                <template #suffix>
                  <el-form-item prop="queryType">
                    <el-select
                      v-model="queryParams.queryType"
                      placeholder="请选择搜索类型"
                      class="search-type-select"
                    >
                      <el-option
                        v-for="item in queryTypeList[state.tabIndex]"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      />
                    </el-select>
                  </el-form-item>
                </template>
                <template #append>
                  <el-button
                    class="x_btns"
                    type="primary"
                    icon="Search"
                    @click="handleQuery"
                    >搜索</el-button
                  >
                </template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :push="4" :sm="10" :md="8">
            <div class="btnsWrap">
              <el-button class="x_btns" @click="handleQuery"
                >发布需求</el-button
              >
              <el-button class="x_btns" @click="handleQuery"
                >专家机构录入</el-button
              >
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div style="height: 15vh"></div>
      <el-row>
        <el-col :push="3" :pull="3" :span="18">
          <div class="numBox">
            <div>
              <div class="val">{{ state.data.expert_count }}</div>
              <div class="des">专家数量</div>
            </div>
            <div>
              <div class="val">
                {{ state.data.patent_count + state.data.achievement_count }}
              </div>
              <div class="des">专利成果数量</div>
            </div>
            <div>
              <div class="val">{{ state.data.demand_count }}</div>
              <div class="des">需求数量</div>
            </div>
            <div>
              <div class="val">{{ state.data.docking_count }}</div>
              <div class="des">对接数量</div>
            </div>
            <div>
              <div class="val">{{ state.data.company_count }}</div>
              <div class="des">实验室数量</div>
            </div>
          </div>
        </el-col>
      </el-row>
      <!-- <div class="icp-beian">
        <el-link type="primary" href="https://beian.miit.gov.cn/"
          >皖ICP备18001784号</el-link
        >
      </div> -->
    </div>
    <!-- <webFooter></webFooter> -->
  </div>
</template>

<script setup>
import { onMounted, reactive } from "vue";
import { banner } from "@/api/website/home/index";
import { useRouter } from "vue-router";
// import request from "@/utils/request";

const router = useRouter();
// function indexData() {
//   return request({
//     url: "/v1/index",
//     method: "get",
//   });
// }
const queryParams = reactive({
  queryType: undefined,
  keyword: "",
});
const queryRules = reactive({
  queryType: [{ required: true, trigger: "change", message: "请选择搜索类型" }],
  keyword: [{ required: true, trigger: "blur", message: "请选择搜索关键词" }],
});
const queryRef = ref();
const searchTypeList = ref([
  "enterprise",
  "achivement",
  "lab",
  "patent",
  "expert",
  "demand",
]);
// const patentQueryTypeList = ;
const queryTypeList = [
  [
    { value: "1", label: "通过企业名称搜索" },
    { value: "2", label: "通过企业简介搜索" },
    { value: "3", label: "通过关键词搜索" },
    { value: "4", label: "通过生产方向搜索" },
    { value: "5", label: "通过产品搜索" },
  ],
  [],
  [],
  [
    { value: "1", label: "通过标题搜索" },
    { value: "2", label: "通过摘要搜索" },
    { value: "3", label: "通过主权项搜索" },
  ],
  [
    { value: "1", label: "通过专家名称搜索" },
    { value: "2", label: "通过个人简介搜索" },
    { value: "3", label: "通过关键词搜索" },
  ],
  [],
];
const switchTab = (index) => {
  state.tabIndex = index;
  // queryParams.queryType = undefined
  queryRef.value.resetFields("queryType");
};
const handleDetail = async (mode, keyword, queryType) => {
  await queryRef.value.validate();
  const routeData = router.resolve({
    path: `/searchList/${mode}`,
    query: { keyword, queryType },
  });
  window.open(routeData.href, "_blank");
};

function handleQuery() {
  console.log(queryParams.keyword, state.tabIndex);
  handleDetail(
    searchTypeList.value[state.tabIndex],
    queryParams.keyword,
    queryParams.queryType
  );
}

const state = reactive({
  keyword: "",
  tabList: ["找企业", "找成果", "找实验室", "找专利", "找专家", "接需求"],
  tabIndex: 0,
  banner: "",
  data: {
    expert_count: 0,
    company_count: 0,
    patent_count: 0,
    achievement_count: 0,
    demand_count: 0,
    docking_count: 0,
  },
});

onMounted(() => {
  banner({ locals: "首页背景" }).then((resp) => {
    console.log(resp);
    state.banner = resp.data[0].images;
  });
  state.data = {
    expert_count: 15,
    company_count: 9,
    patent_count: 181233,
    achievement_count: 12,
    demand_count: 0,
    docking_count: 0,
    distribution: {
      expert: null,
      laboratory: null,
      demand: null,
      patent: null,
      achievement: null,
      company: null,
    },
  };
  // indexData().then((res) => {
  //   if (200 == res.code) {
  //     state.data = res.data;
  //   }
  // });
  // console.log("onmunted");
});
</script>

<style lang="scss" scoped>
.x_btns {
  font-size: 14px !important;
  font-weight: 400;
}
.box {
  height: 100%;
  width: 100%;
  display: flex;
  display: -webkit-flex;
  align-items: center;
  justify-content: center;
  & > div {
    width: 100%;
  }
}
.btnsWrap {
  margin: 0 0 0 40px;
  .el-button {
    height: 36px;
    padding: 10px 25px;
  }
}

.numBox {
  display: flex;
  display: -webkit-flex;
  & > div {
    flex: 1;
    height: 200px;
    display: -webkit-flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
  }
  .val {
    font-size: 36px;
    font-family: DIN;
    font-weight: 400;
    color: #333333;
    margin-bottom: 10px;
  }
  .des {
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #333333;
  }
}

.tab {
  width: 480px;
  height: 42px;
  overflow: hidden;
  & > div {
    width: 80px;
    height: 42px;
    line-height: 42px;
    text-align: center;
    font-size: 14px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #333333;
    float: left;
    cursor: pointer;
    user-select: none;
  }
  & > div.active {
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    line-height: 38px;
    background-image: url(./img/index1-bg1.png);
    background-size: cover;
  }
}
.wrap {
  padding-left: 460px;
}
.search {
  width: 720px;
}
.icp-beian {
  width: 100vw;
  text-align: center;
  position: absolute;
  bottom: 10px;
}
// :deep(.el-input__inner) {
//   border: 0px solid blueviolet !important;
// }
.search-type-select {
  margin: 1px 0;
  :deep(.el-input__inner) {
    // border: 0px solid blueviolet !important;
    height: 30px;
    box-shadow: none;
  }
  :deep(.el-input.is-focus .el-input__inner) {
    box-shadow: none;
  }
}
</style>
