<template>
  <div>
    <el-row>
      <!--查询条件-->
      <el-col :span="24">
        <Form onsubmit="return false">
          <Form-item>
            <el-input
              v-model="realname"
              placeholder="请输入姓名,回车查询"
              style="width:100%"
              @keyup.enter.native="_formSearch"
            />
          </Form-item>
        </Form>
      </el-col>
      <el-col :span="24">
        <element-table
          ref="pageTable"
          :page-columns="pageColumns"
          :table-height="tableHeight"
          :layout="layout"
          :get-page="getPage"
          show-check-box
          select-data
          @on-result-change="_tableResultChange"
        >
          <el-table-column
            v-for="item in pageColumns"
            :key="item.key"
            show-overflow-tooltip
            sortable
            :prop="item.key"
            :label="item.title"
            :width="item.width"
            :min-width="200"
            :fixed="item.fixed?item.fixed:undefined"
          >
            <template slot-scope="scope">
              <span>{{ scope.row[item.key] }}</span>
            </template>
          </el-table-column>
        </element-table>
      </el-col>
    </el-row>
  </div>
</template>
<script>
/**
 * 待选人员
 */
import { sysUser } from '../../api'
export default {
  props: ['groupId'],
  data() {
    return {
      pageColumns: [
        { title: '用户名', key: 'username' },
        { title: '姓名', key: 'realname' }
      ],
      getPage: {},
      selectData: [],
      type: 0,
      realname: '',
      layout: 'total, prev, pager, next'
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('', 390)
    }
  },
  methods: {
    _open(id) {
      this.realname = ''
      this.orgId = id
      this._formSearch()
    },
    _formSearch() {
      this.$refs.pageTable._pageChange(1)
    },
    _page: async function() {
      const formObj = {
        orgId: this.orgId,
        groupId: this.groupId
      }
      if (this.realname) {
        formObj.realname = this.realname
      }
      Object.assign(formObj, this.$refs.pageTable._searchParams())
      const result = await sysUser.pageFlowExcludeMemberShip(
        this.$serializeForm(formObj)
      )
      if (result) {
        this.getPage = result
        this.$emit('on-result-change', 'search')
        this.$refs.pageTable._initTable()
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'selectData':
          this.$emit('on-result-change', 'click', data)
          break
        case 'dbSelect':
          this.$emit('on-result-change', 'dbClick', data)
          break
      }
    },
    _clearSelection() {
      this.$refs.pageTable._clearSelection()
    },
    // 重置
    _refresh() {
      this.getPage = {}
      this.realname = ''
      this.selectData = []
    }
  }
}
</script>
