<template>
  <div class="admin-department">
    <el-form :inline="true">
      <el-form-item label="人员名称">
        <el-input v-model="queryParams.name" size="small" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click="init">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" v-loading="loading" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="name" label="人员名称" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column label="Email" prop="email" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="mobile" label="手机号码" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="remark" label="描述" align="center" show-overflow-tooltip></el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.current" :page-size="queryParams.size" :total="total"
        @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper" background></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "ClientTable",
  props: ["tenantId", "projectId"],
  data() {
    return {
      // 表格的loading
      loading: false,
      // 总条数
      total: 0,
      // 表格数据源
      tableData: [],
      multipleSelection: [],
      id: [],
      users: [],
      // 分页信息以及
      queryParams: {
        tenantId: this.tenantId,
        tenantName: "",
        size: 10,
        current: 1,
      },
    };
  },
  mounted() {
    this.getList();
  },

  computed: {

  },

  methods: {
    init(){
      this.queryParams.current = 1
      this.getList()
    },
    // 获取数据
    getList() {
      this.loading = true;
      let params = {
        projectId: this.projectId,
        ...this.queryParams,
      }
      this.$api
        .getPersonList(params)
        .then((response) => {
          this.tableData = response.data;
          this.total = response.pageColumn.total;
          this.loading = false;
        })
        .catch((error) => {
          this.loading = false;
        });
    },
    // 当选择项发生变化时会触发
    handleSelectionChange(val) {
      this.id = [];
      this.users = []
      this.multipleSelection = val;
      for (let i = 0; i < this.multipleSelection.length; i++) {
        this.id.push(this.multipleSelection[i].id)
        this.users.push({ userId: this.multipleSelection[i].id, tenantId: this.multipleSelection[i].tenantId })
      }
      // console.log(this.users);
      this.$emit('getId', this.id, this.users)
    },
    // 分页信息
    handleCurrentChange(val) {
      this.queryParams.current = val;
      this.getList();
    },

  },
};
</script>

<style lang="scss" scoped>
.admin-department {
  border: 1px solid #eee;
  padding: 20px;
  // border-radius: 8px;
  .pagination{
    margin-top: 10px;
    text-align: right;
  }
}
</style>