<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="state.tabIndex = index"
            >{{ v }}</div>
          </div>
        </el-col>
      </el-row>
      <div style="height: 16px;"></div>
      <el-row>
        <el-col :push="4" :sm="10" :md="12">
          <el-input v-model.trim="state.keyword" placeholder="请输入检索词">
            <template #append>
              <el-button class="x_btns" icon="Search" @click="handleQuery">搜索</el-button>
            </template>
          </el-input>
        </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>
      <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>
  </div>
</template>

<script setup>
import { onMounted, reactive } from "vue";
import { banner } from "@/api/website/home/index";
const router = useRouter();
import request from '@/utils/request'
function indexData () {
  return request({
    url: '/v1/index',
    method: 'get',
  })
}
function handleDetail (mode, keyword) {
  let routeData = router.resolve({ path: `/searchList/${mode}`, query: { keyword } });
  window.open(routeData.href, '_blank');
}

function handleQuery () {
  console.log(state.keyword, state.tabIndex)
  handleDetail(state.tabIndex, state.keyword)
}

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('首页背景').then(res => {
    if (200 == res.code) {
      state.banner = res.data.images
    }
  })
  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;
}
</style>
