<!--
  @description: 根据机构查看用户列表-弹框
  @Modifier: haofengxian/hdk
  @date: 2020-11-05 14:52:58
-->
<template>
  <div>
    <div class="clearfix">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item label="用户名" prop="userName">
          <el-input
            v-model.trim="searchForm.userName"
            placeholder="用户名"
          />
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          <el-input
            v-model.trim="searchForm.realName"
            placeholder="用户名"
          />
        </el-form-item>
        <el-form-item class="fr">
          <el-button
            type="primary"
            @click="search('searchForm')"
          >
            搜索
          </el-button>
          <el-button
            plain
            type="info"
            @click="resetForm('searchForm')"
          >
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        ref="singleTable"
        v-loading="loading"
        :data="list"
        size="mini"
      >
        <el-table-column
          type="index"
          label="序号"
          align="center"
        />
        <el-table-column
          align="center"
          header-align="center"
          prop="userName"
          label="用户名"
          min-width="80"
        />
        <el-table-column
          align="center"
          prop="realName"
          header-align="center"
          label="真实姓名"
          min-width="80"
        />
        <el-table-column
          align="center"
          prop="roleName"
          header-align="center"
          label="角色名称"
          min-width="200"
        />
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
  </div>
</template>

<script>
/* 接口*/
import { selectUserListByDepartId } from '@api/rolemanagment/organization'
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  name: 'OrganizationInfoUserListComp',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin],
  props: {
    organizationInformation: {
      type: Object,
      default: function() {
        return {
          id: ''
        }
      }
    }
  },
  data() {
    return {
      loading: true,
      // 搜索信息
      searchForm: {
        realName: '', // 真实姓名
        departId: '', // 机构id
        userName: '' // 用户名
      },
      list: [] // 列表数据
    }
  },
  watch: {
    organizationInformation: {
      handler(newVal, oldVal) { // 请求用户列表
        this.searchForm.departId = newVal.id
        // 加载数据
        this.loadData()
      },
      deep: true
    }
  },
  mounted() {
    this.searchForm.departId = this.organizationInformation.id
    // 加载数据
    this.loadData()
  },
  methods: {
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      selectUserListByDepartId(params).then(response => {
        this.loading = false
        this.list = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)// 过滤空的key
    },
    // 搜索重置
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.search()
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
