<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <div class="nowTime">非工作情况统计</div>
    </el-col>

    <!--列表-->
    <el-table
      :data="list"
      highlight-current-row
      v-loading="listLoading"
      :height="tableHeight"
      style="width: 100%;"
    >
      <el-table-column type="index" width="60"></el-table-column>
      <el-table-column prop="name" label="姓名" width="140" sortable></el-table-column>
      <el-table-column label="行为">
        <template slot-scope="scope">{{converType(scope.row.type+1)}}</template>
      </el-table-column>
      <el-table-column prop="time" label="时间" width="180" sortable></el-table-column>
      <el-table-column prop="date" label="日期" width="180" sortable></el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[20 , 50 , 80 , 100]"
        :page-size="20"
        layout="total, sizes, prev, pager, next"
        :total="total"
        style="float:right;"
      ></el-pagination>
    </el-col>
  </section>
</template>

<script>
export default {
  data() {
    return {
      user: JSON.parse(sessionStorage.getItem("user")),

      tableHeight: 0,
      listLoading: false,
      total: 0,
      page: 1,
      size: 20,
      list: []
    };
  },
  methods: {
    //获取异常信息
    getDevianceList() {
      this.listLoading = true;
      this.http.post(
        this.port.time.listDeviance,
        { pageIndex: this.page, pageSize: this.size },
        res => {
          this.listLoading = false;
          if (res.code == "ok") {
            this.list = res.data.records;
            this.total = res.data.total;
          } else {
            this.$message({
              message: res.msg,
              type: "error"
            });
          }
        },
        error => {
          this.listLoading = false;
          this.$message({
            message: error,
            type: "error"
          });
        }
      );
    },

    //分页
    handleCurrentChange(val) {
      this.page = val;
      this.getDevianceList();
    },

    handleSizeChange(val) {
      this.size = val;
      this.getDevianceList();
    },

    //类型枚举转换
    converType(type) {
      switch (type) {
        case 0:
          return "其他";
        case 1:
          return "研发";
        case 2:
          return "上网";
        case 3:
          return "文档";
        case 4:
          return "设计";
        case 5:
          return "美工";
        case 6:
          return "运营";
        case 7:
          return "看小说";
        case 8:
          return "影视娱乐";
        case 9:
          return "听音乐";
        default:
          return "未知";
      }
    }
  },
  created() {
    let height = window.innerHeight;
    this.tableHeight = height - 195;
    const that = this;
    window.onresize = function temp() {
      that.tableHeight = window.innerHeight - 195;
    };
  },
  mounted() {
    this.getDevianceList();
  }
};
</script>

<style lang="scss" scoped>
.nowTime {
  height: 35px;
  line-height: 28px;
  font-size: 18px;
  color: #333;
  margin-left: 10px;
  i {
    margin-right: 10px;
  }
}
</style>
