<template>
  <div>
    <el-table :data="tableData" style="width: 100%" height="600">
      <el-table-column prop="userName" label="user Name"></el-table-column>
      <el-table-column prop="fullName" label="full Name"></el-table-column>
      <el-table-column prop="eamil" label="Eamil">
        <!-- <template slot-scope="scope">
          <span v-if="scope.row.autoUpdate == '0'">true</span>
          <span v-else>false</span>
        </template> -->
      </el-table-column>
      <el-table-column
        prop="lastloginTime"
        label="Last Login Time"
      ></el-table-column>
      <el-table-column prop="role" label="role">
        <template slot-scope="scope">
          <span class="role-text" @click="editRole(scope.row)">
            {{ scope.row.role }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="action" label="Action" width="250px">
        <template slot-scope="scope">
          <el-checkbox v-model="scope.row.isCheck" />
        </template>
      </el-table-column>
      <template slot="empty" v-if="tableData.length == 0">
        <span>No data available</span>
      </template>
    </el-table>
    <el-pagination
      v-if="total > 0"
      :page-size="limit"
      :current-page.sync="page"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      background
      :page-sizes="[10, 20, 50, 100]"
      layout="prev, sizes, pager, next"
    ></el-pagination>
    <edit-role ref="editRole" />
  </div>
</template>
<script>
import editRole from "./components/editRole.vue";
export default {
  components: { editRole },
  data() {
    return {
      tableData: [
        {
          eamil: "Jinkang.Yang@t-systems.com",
          userName: "Yangjinkang",
          fullName: "Yangjinkang",
          role: "Admin",
          isCheck: true,
          lastloginTime: "2022-2-22",
        },
      ],
      maxHeight: 0,
      page: 1,
      limit: 10,
      total: 0,
    };
  },
  created() {
    // this.getTableData();
  },
  methods: {
    getTableData() {
      const { page, limit } = this;
      GetGroups({ currentPage: page, pageSize: limit }).then((res) => {
        const { data } = res;
        this.tableData = data.records;
        this.total = data.total;
        if (page > 0 && data.records.length == 0) {
          this.handleCurrentChange(page - 1);
        }
      });
    },
    toDelete(id) {
      DeleteGroup({ groupId: id }).then((res) => {
        if (res.httpCode == 200) {
          this.$message.success("delete success");
          this.handleCurrentChange(this.page);
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    editRole(item) {
      this.$refs.editRole.show(item);
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getTableData();
    },
    handleSizeChange(val) {
      this.limit = val;
      this.handleCurrentChange(1);
    },
  },
};
</script>
<style scoped>
.role-text {
  cursor: pointer;
  color: rgb(11, 44, 85);
  border-bottom: solid 1px rgb(11, 44, 85);
}
</style>
