<template>
  <div class="body">
    <div class="head">
      <div class="head-img">
        <img src="../../../public/images/index-1.png" />
      </div>
      <div class="head-info">首页</div>
    </div>

    <div class="user">
      条件：
      <div class="input">
        <el-select
          v-model="listQuery.id"
          filterable
          clearable
          @clear="handleFilter"
          size="mini"
          placeholder="请选择设备"
        >
          <el-option
            v-for="item in list"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </div>

      <div class="input-button">
        <el-row>
          <el-button size="small" type="primary" @click="handleFilter"
            >确定</el-button
          >
        </el-row>
      </div>
    </div>

    <div class="title">今日统计</div>

    <div class="add">
      <div class="add-title">累计通行（次）</div>
      <div class="add-img">
        <img src="../../../public/images/index-2.png" />
      </div>
      <div class="add-num">{{ total }}</div>
    </div>

    <div class="title-1">设备统计</div>

    <div class="title-2">通行人数</div>

    <div class="chart-container">
      <chart height="100%" width="80%" :total="total" />
    </div>
  </div>
</template>

<script>
import Chart from "@/components/Charts/MixChart";
import { fetchList, searchList } from "@/api/index";
export default {
  components: {
    Chart,
    name: "MixChart",
  },
  data() {
    return {
      list: [],
      searchList: [],
      total: 0, //数据的总数//
      listQuery: {
        page: 1,
        limit: 999,
        id: "",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      fetchList(this.listQuery).then((response) => {
        this.list = response.data;
      });
    },
    handleFilter() {
      if (!this.listQuery.id) {
        this.total = 0;
      } else {
        searchList({
          deviceId: this.listQuery.id,
        }).then((response) => {
          this.searchList = response.data;
          this.total = response.total;
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.body {
  width: 1551px;
  margin: 29px 29px 0 31px;

  .head {
    display: flex;
    width: 1380px;
    height: 55px;
    margin-left: 40px;
    border-bottom: 1px solid #cccccc;

    .head-img {
      width: 30px;
      height: 30px;

      img {
        width: 30px;
      }
    }

    .head-info {
      width: 95px;
      height: 22px;
      margin-top: 5px;
      margin-left: 16px;
      font-weight: bold;
    }
  }

  .user {
    display: flex;
    width: 1380px;
    line-height: 112px;
    margin-left: 40px;
    font-size: 9px;

    .input {
      width: 240px;
      margin-left: 11px;
    }

    .input-button {
      margin-left: 39px;
    }
  }

  .title {
    width: 300px;
    height: 40px;
    margin-left: 40px;
    font-weight: bold;
  }

  .add {
    position: relative;
    width: 300px;
    height: 120px;
    margin-left: 40px;
    border-radius: 10px;
    color: #fff;
    background-color: #2b95f8;

    .add-title {
      width: 106px;
      line-height: 49px;
      font-size: 8px;
      font-weight: bold;
      margin-left: 27px;
      border-bottom: 1px solid #fff;
    }

    .add-img {
      position: absolute;
      top: 41px;
      right: 40px;
      width: 46px;
      height: 39px;

      img {
        width: 46px;
      }
    }

    .add-num {
      height: 27px;
      margin-left: 27px;
      margin-top: 22px;
      font-size: 18px;
      font-weight: bold;
    }
  }

  .title-1 {
    width: 300px;
    height: 40px;
    margin-left: 40px;
    margin-top: 37px;
    font-weight: bold;
  }

  .title-2 {
    margin-left: 46px;
    font-size: 15px;
  }

  .chart-container {
    width: 1300px;
    height: calc(100vh - 500px);
    margin-left: 46px;
  }
}
</style>
