<template>
  <div class="home-container layout-pd">
    <el-card shadow="hover" class="layout-padding-auto">
      <div class="ors">
        <div class="orstitle">
          <SvgIcon name="ele-InfoFilled" class="font15 color" />
          <p>预警阈值</p>
        </div>
        <div class="orsitem" v-for="item in state.totalnum">
          <b>{{ item.level }}：</b>{{ item.content }}
        </div>
      </div>
      <el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%" border stripe
        :cell-style="{ textAlign: 'center' }" :header-cell-style="{ 'text-align': 'center' }">
        <el-table-column prop="district" label="区县名称" />
        <el-table-column prop="level" label="预警等级">
          <template #default="scope">
            <p v-if="scope.row.level == 1">Ⅰ级预警</p>
            <p v-if="scope.row.level == 2">Ⅱ级预警</p>
            <p v-if="scope.row.level == 3">Ⅲ级预警</p>
            <p v-if="scope.row.level == 4">正常</p>
          </template>
        </el-table-column>
        <el-table-column prop="year" label="日期"></el-table-column>
        <el-table-column prop="ratio" label="近半年同比"></el-table-column>
        <el-table-column prop="content" label="预警内容" show-overflow-tooltip>
          <template #default="scope">
            {{ scope.row.content }}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
        :pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="state.tableData.param.pageNum" background
        v-model:page-size="state.tableData.param.pageSize" layout="total, sizes, prev, pager, next, jumper"
        :total="state.tableData.total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script setup lang="ts" name="priceindex">
import { defineAsyncComponent, reactive, onMounted, ref } from "vue";
import { ElMessageBox, ElMessage, ElNotification } from "element-plus";
import { getApi } from "/@/api/early/data";
import { getAll } from "/@/api/sys/index";

// 引入组件

// 定义变量内容
const state = reactive<any>({
  county: [],
  tableData: {
    data: [],
    total: 0,
    loading: false,
    param: {
      pageNum: 1,
      pageSize: 10,
    },
  },
  totalnum: {}
});

const getCodeApi = async () => {
  let item = await getAll().codeApi();
  state.county = item.data;
  getTableData();
};
// 初始化表格数据
const getTableData = async () => {
  state.tableData.loading = true;
  // 项目
  const data = await getApi().gethalyearList({
    page: state.tableData.param.pageNum,
    limit: state.tableData.param.pageSize,
  });
  state.tableData.data = data.data;
  state.tableData.total = data.count;
  state.tableData.loading = false;
  // 获取总数
  const total = await getApi().gethalyeardata();
  state.totalnum = total.data;
};
// 分页改变
const onHandleSizeChange = (val: number) => {
  state.tableData.param.pageSize = val;
  getTableData();
};
// 分页改变
const onHandleCurrentChange = (val: number) => {
  state.tableData.param.pageNum = val;
  getTableData();
};
// 页面加载时
onMounted(() => {
  getCodeApi();
});
</script>

<style scoped lang="scss">
.ors {
  display: flex;
  flex-direction: column;
  background-color: #ecf2fe;
  padding: 20px;
  margin-bottom: 10px;

  .orsitem {
    display: flex;
    align-items: center;
    padding-left: 20px;
    padding-bottom: 5px;

    b {
      flex: 0 0 5%;
      color: #001330;
    }
  }
}

.orstitle {
  display: flex;
  align-items: center;
  font-weight: bold;
  color: #333;
  font-size: 15px;
  margin-bottom: 10px;

  .color {
    color: #2362e1;
    margin-right: 4px;
  }
}
</style>
