<!--特殊考勤日列表-->
<template>
  <div class="app-container">
    <!--筛选条件-->
    <div class="search-div">
      <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">
        <el-row>
          <el-form-item class="selectForm-container-item">
            <el-input v-model.trim="listQuery.keywords" placeholder="真实姓名" clearable/>
          </el-form-item>
          <el-form-item class="selectForm-container-item" />
          <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        </el-row>
      </el-form>
    </div>
    <!--查询结果Table显示-->
    <div>
      <el-row class="table-title">
        <el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>用户列表</div></el-col>
      </el-row>
      <el-table v-loading="listLoading" :data="list" class="table" row-class-name="small-row-class" size="small" border >
        <!--批量选择勾选框列-->
        <!--<el-table-column align="center" type="selection" width="55"/>-->
        <!--序号列-->
        <el-table-column :index="indexMethod" label="#" align="center" type="index"/>
        <!--内容列-->
        <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :align="column.align" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row[column.value] }}</span>
            <!--<span v-if="column.ext">{{ scope.row.ext[column.value] }}</span>-->
          </template>
        </el-table-column>
        <!--操作列-->
        <el-table-column label="24号后是否能备注" align="center" width="180">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.attr1"
              active-text="是"
              inactive-text="否"
              active-value="1"
              inactive-value="0"
              @change="changeSwitch(scope.row)"/>
             </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页-->
    <div class="pagination-container">
      <el-pagination
        v-show="total>listQuery.limit"
        :current-page="listQuery.offset"
        :page-sizes="[20,30,50]"
        :page-size="listQuery.limit"
        :total="total"
        align="center"
        layout="total, sizes, prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>
<script>

import { updateUserAttr1 } from '@/api/attendance'
import { getUserList } from '@/api/user'

export default {
  name: 'RemarksLimit',
  data() {
    return {
      listQuery: {
        keywords: '', // 姓名
        beginTime: '',
        endTime: '',
        deptid: '',
        offset: 1,
        limit: 20,
        page: 1,
        sort: 'id'
      }, // 筛选条件
      columns: [
        {
          text: '真实姓名',
          value: 'name',
          align: 'center'
        },
        {
          text: '所在部门',
          value: 'deptName',
          align: 'center'
        },
        {
          text: '账户',
          value: 'account',
          align: 'center'
        },
        {
          text: '角色',
          value: 'roleName',
          align: 'center'
        }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true // 列表加载动画
    }
  },
  watch: {},
  created() {
    this.fetchData()// 获取数据
  },
  activated() { // 页面激活刷新数据
    this.fetchData()
  },
  methods: {
    // 获取用户数据
    fetchData() {
      this.listLoading = true
      getUserList(this.listQuery).then(response => {
        debugger
        var data= []
        for (var i = 0; i < response.data.rows.length; i++) {
          if(response.data.rows[i].roleName.indexOf('部门领导') > -1){
            data.push(response.data.rows[i])
          }
        }
        this.list = data
        this.total = data.length
        this.listLoading = false
      })
    },
    search() {
      this.fetchData()
    },
    changeSwitch (row) {
      debugger
      const data = {
        id: row.id,
        attr1: row.attr1
      }
      updateUserAttr1(data).then(res => {
        if (res.code === '200' || res.code === 200) {
        } else {
          this.$message.error(res.msg)
        }
        // 调用表格数据
        this.fetchData()
        this.loading = false;
      }).catch({
      })
    },
    // 序号计算
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.fetchData()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:46px;
  .app-container{
    margin-bottom:20px
  }
  .table{
    margin-bottom: 20px;
  }
  .pagination-container{
    margin-bottom: 50px;
  }
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    height: $tableTitleHeight;
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 15px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
</style>
