<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企微主体" prop="corpId">
        <el-select v-model="queryParams.corpId" placeholder="企微主体" size="small" @change="updateCorpId()">
          <el-option
            v-for="dict in myQwCompanyList"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="企微账号" prop="qwUserId">
        <el-input
          v-model="queryParams.qwUserId"
          placeholder="请输入企微账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="企微昵称" prop="qwUserName">
        <el-input
          v-model="queryParams.qwUserName"
          placeholder="请输入企微昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" 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  height="500" border v-loading="loading" :data="customerList" ref="customerList" >
       <el-table-column label="企微昵称" align="center" prop="qwUserName" />
      <el-table-column label="企微账号" align="center" prop="qwUserId" />
      <el-table-column label="企微所属部门" align="center" prop="departmentName" />
	  <el-table-column label="状态" align="center" prop="status" >
	    <template slot-scope="scope">
	      <dict-tag :options="qwStatusOptions" :value="scope.row.status"/>
	    </template>
	   </el-table-column>
      <el-table-column label="企微主体" align="center" prop="corpName" />
      <el-table-column label="操作"   align="center" fixed="right" width="100px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="medium"
            type="primary"
            plain
            @click="handleBind(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="getList"
    />


  </div>
</template>

<script>
import { userList,listUser, getUser, delUser, addUser, updateUser, exportUser, updateUserWeclome,getMyQwCompanyList,getMyQwUserList,relieveFastGptRoleById,staffListUser } from '@/api/qw/user'

export default {
  name: "miniCustomer",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      myQwCompanyList:[],
	  qwStatusOptions:[],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        qwUserId: null,
        corpId: null,
        qwUserName: null,
      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {
      },
    };
  },
  created() {
	  this.getDicts("sys_qw_user_status").then(response => {
	        this.qwStatusOptions = response.data;
	  });
    getMyQwCompanyList().then(response => {
           this.myQwCompanyList = response.data;
           if(this.myQwCompanyList!=null){
             this.queryParams.corpId=this.myQwCompanyList[0].dictValue
             this.getList();
           }
    });
  },
  methods: {
    updateCorpId(){
           this.getList();
     },
    /** 查询客户列表 */
    getList() {
      this.loading = true;

      userList(this.queryParams).then(response => {
        this.customerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    //绑定选择
    handleBind(row){

      this.$emit("bindQwUser",row)
      this.resetQuery();
      this.$refs.customerList.clearSelection();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.corpId= this.myQwCompanyList[0].dictValue;
      this.handleQuery();
    },

  }
};
</script>
<style>
  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
  .el-dialog__wrapper{
    z-index: 100000;
  }
</style>
