<template>
  <div>
    <div class="flex-row-center top-box">
      <div class="flex-row-center" style="flex: 1; align-items: flex-end">
        <span class="title">{{ name }}</span>
        <i class="el-icon-edit" style="cursor: pointer" @click="editRole()"></i>
      </div>
      <span style="font-wight: bold; margin-right: 5px">Search User</span>
      <el-input v-model="userName" style="width: 300px" />
      <el-button
        style="margin-left: 10px"
        icon="el-icon-search"
        type="primary"
        @click="getTableData()"
      ></el-button>
    </div>
    <el-table
      :data="tableData"
      style="width: 100%; margin-top: 10px"
      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"> </el-table-column>
      <el-table-column prop="action" label="Operate" width="250px">
        <template slot-scope="scope">
          <span class="role-text" @click="toDelete(scope.row)">delete</span>
        </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-item ref="editItem" />
  </div>
</template>
<script>
import EditItem from "../roleList/components/editItem.vue";
export default {
  components: { EditItem },
  data() {
    return {
      userName: "",
      name: "asdf",
      tableData: [
        {
          userName: "Yangjinkang",
          fullName: "Yangjinkang",
          eamil: "Jinkang.Yang@t-systems.com",
        },
      ],
      maxHeight: 0,
      page: 1,
      limit: 10,
      total: 0,
    };
  },
  created() {
    const { id, name } = this.$route.query;
    // 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);
          this.$message.error(res.msg);
        }
      });
    },
    editRole() {
      this.$refs.editItem.show({ id: 123, roleName: this.name });
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getTableData();
    },
    handleSizeChange(val) {
      this.limit = val;
      this.handleCurrentChange(1);
    },
  },
};
</script>
<style scoped>
.title {
  font-size: 30px;
  font-weight: bold;
  margin-right: 20px;
  line-height: 30px;
}
.acition-btn {
  cursor: pointer;
  border-bottom: solid 1px rgb(91, 91, 212);
  color: rgb(91, 91, 212);
}
.top-box {
  border-bottom: dashed 1px #f3f3f3;
  padding-bottom: 8px;
}
.role-text {
  cursor: pointer;
  color: rgb(11, 44, 85);
  border-bottom: solid 1px rgb(11, 44, 85);
}
</style>
