<script setup>
import { ref, computed, onMounted } from "vue";
import { raiInterface } from "@/api/api.js";

const PageSize = ref(12);
const CurrentIndex = ref(1);
const searchList = ref([]);
const total = ref(0);

const exportUser = computed(() => {
  return import.meta.env.VITE_APP_API_ROOT + "/cygx/hostKeyword/download?" + localStorage.getItem("auth") || "";
});

const applyList = () => {
  raiInterface
    .hostKeyword({
      PageSize: PageSize.value,
      CurrentIndex: CurrentIndex.value,
    })
    .then((res) => {
      if (res.Ret === 200) {
        total.value = res.Data.Paging.Totals;
        searchList.value = res.Data.List;
      }
    });
};
const handleCurrentChange = (val) => {
  CurrentIndex.value = val;
  applyList();
};

onMounted(() => {
  applyList();
});
</script>

<template>
  <div class="container-search">
    <el-card>
      <div class="search-top">
        <span>近7天热词</span>
        <div>
          <a :href="exportUser" download>
            <el-button type="primary">下载明细</el-button>
          </a>
        </div>
      </div>
    </el-card>
    <el-card style="margin-top: 20px">
      <el-table style="width: 100%" border :data="searchList">
        <el-table-column label="排序" align="center" width="84" prop="Sort"> </el-table-column>
        <el-table-column align="center" label="关键词" prop="KeyWord"> </el-table-column>
        <el-table-column align="center" label="搜索次数" prop="KeyWordNum"> </el-table-column>
      </el-table>
      <el-pagination @current-change="handleCurrentChange" background layout="pager" :page-size="12" :total="total"> </el-pagination>
    </el-card>
  </div>
</template>

<style scoped lang="scss">
.container-search {
  .search-top {
    display: flex;
    justify-content: space-between;
    span {
      width: 122px;
      height: 40px;
      background: #f0f2f5;
      opacity: 1;
      line-height: 40px;
      text-align: center;
      color: #666666;
    }
  }
  .el-pagination {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
  }
}
</style>
