<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="员工昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入员工昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">刷新/重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="userList" ref="userList">
        <el-table-column label="企微员工账号" align="center" prop="qwUserId" />
		    <el-table-column label="员工昵称" align="center" prop="qwUserName" />
        <el-table-column label="员工部门" align="center" prop="departmentName" />
        <el-table-column label="员工昵称" align="center" prop="nickName"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120px" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleSelectionChange(scope.row)"
          >选择此人</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="handlePaginationChange"
    />

  </div>
</template>

<script>
import { listUser } from "@/api/qw/user";


export default {
  name: "qwUserSelectOne",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      selectUsers: null,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企微用户表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        qwUserId: null,
        companyId: null,
        companyUserId: null,
        corpId: null,
        nickName: null
      },
      // 表单参数
      form: {},

      // 表单校验
      rules: {
      }
    };
  },
  created() {



  },
  methods: {
    /** 查询企微用户列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
        // 如果 companyUserId 为 null，移除列
        this.userList = response.rows.filter(column => column.companyUserId !=null);
        this.total = response.total;
        this.loading = false;

      });
    },

    getDetails(corpId){
      this.queryParams.corpId=corpId;
      this.getList()
    },
    handlePaginationChange(row) {
      this.queryParams.pageNum = row.page;
      this.queryParams.pageSize = row.limit;
      this.getList();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        qwUserId: null,
        companyId: null,
        companyUserId: null,
        corpId: null
      };
      this.resetForm("form");
    },
    //确定选择
    confirmSelect(){
      this.$emit("selectUserList",this.selectUsers);
      this.resetSelect();
    },
    //重置选择
    resetSelect(){
      //重置
      this.queryParams={
        pageNum: 1,
        pageSize: 10,
        qwUserId: null,
        companyId: null,
        companyUserId: null,
        corpId: null,
        nickName: null
      },
        this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 选中数据
    handleSelectionChange(selection) {
      this.$emit("selectUser",selection);
    },

  }
};
</script>
