<template>
  <div class="app-container">
    <el-card>
      <div>
        <el-input
          v-model="listQuery.name"
          placeholder="姓名"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="handleFilter"
        />
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilter"
          size="small"
        >搜索
        </el-button>
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-refresh-left"
          @click="resetFilter"
          size="small"
        >重置
        </el-button>
      </div>
      <el-table
        v-loading="listLoading"
        :data="userList.results"
        style="width: 100%;margin-top:6px;"
        highlight-current-row
        row-key="id"
        height="100"
        stripe
        border
        v-el-height-adaptive-table="{bottomOffset: 41}"
      >
        <el-table-column type="index" width="50"/>
        <el-table-column align="center" label="工号">
          <template slot-scope="scope">{{ scope.row.number }}</template>
        </el-table-column>
        <el-table-column align="center" label="姓名">
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column align="header-center" label="照片">
          <template slot-scope="scope"><img :src="scope.row.photo" min-width="70" height="70"/></template>
        </el-table-column>
        <el-table-column align="header-center" label="电子签名">
          <template slot-scope="scope"><img :src="scope.row.signature" min-width="70" height="40"/></template>
        </el-table-column>
        <el-table-column align="header-center" label="部门">
          <template
            v-if="scope.row.dept_"
            slot-scope="scope"
          >{{ scope.row.dept_.name }}
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="userList.count>0"
        :total="userList.count"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.page_size"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>
<script>
  import {getEmployeeList,} from "@/api/employee";
  import Pagination from "@/components/Pagination"

  const defaultUser = {
    id: "",
    name: "",
    username: "",
    dept: null,
    avatar: "/media/default/avatar.png"
  };
  export default {
    name: "personStatistics",
    components: {Pagination},
    data() {
      return {
        user: defaultUser,
        userList: {count: 0},
        listLoading: true,
        listQuery: {
          page: 1,
          page_size: 20
        },
      };
    },

    created() {
      this.getList();
    },

    methods: {
      getList() {
        this.listLoading = true;
        getEmployeeList(this.listQuery).then(response => {
          if (response.data) {
            this.userList = response.data
          }
          this.listLoading = false;
        });
      },

      resetFilter() {
        this.listQuery = {
          page: 1,
          page_size: 20
        };
        this.getList();
      },

      handleFilter() {
        this.listQuery.page = 1;
        this.getList();
      }
    }
  };
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
  }

  .avatar {
    width: 100px;
    height: 100px;
    display: block;
  }
</style>
