<template>
  <div>
    <Row>
      <!--查询条件-->
      <Col span="24">
      <Form onsubmit="return false">
        <Form-item>
          <Input
            v-model="realname"
            placeholder="请输入姓名,回车查询"
            style="width:100%"
            icon="ios-search-strong"
            @on-enter="_formSearch"
          />
        </Form-item>
      </Form>
      </Col>
      <Col span="24">
        <element-table
        ref="pageTable"
        :page-columns="pageColumns"
        :table-height="305"
        :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 v-if="item.sex">{{ scope.row.sex === 1 ? '女' : '男' }}</span>
            <span v-else>{{ scope.row[item.key] }}</span>
          </template>
        </el-table-column>
      </element-table>
      </Col>
    </Row>
  </div>
</template>
<script>
/**
 * 待选人员
 */
import { sysUser } from '../../api'
export default {
  props: ['groupId'],
  data() {
    return {
      pageColumns: [
        { title: '用户名', key: 'username', width: 150 },
        { title: '姓名', key: 'realname', width: 100 },
        { title: '性别', key: 'sex', sex: true }
      ],
      getPage: {},
      selectData: [],
      type: 0,
      realname: ''
    }
  },
  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 = ''
    }
  }
}
</script>
