<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      width="500px"
      height="500px"
      @close="close"
      @keyup.enter.native=""
      :visible.sync="visible">
      <div style="height: calc(100% - 80px);">
        <el-form size="small" :inline="true" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
          <!-- 搜索框-->
          <el-form-item label="" prop="name">
            <el-input size="small" v-model="searchForm.name" placeholder="请输入用户名称" clearable></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="list()" size="small" icon="el-icon-search">查询</el-button>
            <el-button @click="resetSearch()" size="small" icon="el-icon-refresh-right">重置</el-button>
          </el-form-item>
        </el-form>
        <vxe-table
          border="inner"
          auto-resize
          resizable
          height="300px"
          :loading="loading"
          size="small"
          ref="userTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :menu-config="{}"
          :sort-config="{remote:true}"
          :data="dataList"
          :tree-config="{transform: true, rowField: 'id', parentField: 'parentId'}"
          :checkbox-config="{}">
          <vxe-column type="seq" width="60" title="序号"></vxe-column>
          <vxe-column type="checkbox" width="40" ></vxe-column>

          <vxe-column title="姓名" field="name" align="left" tree-node></vxe-column>
        </vxe-table>
      </div>
      <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="close()" icon="el-icon-circle-close">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="getProgramForUser()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>
  import ReimbursementService from '@/api/sys/ReimbursementService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        dataList: [],
        searchForm: {
          name: ''
        }
      }
    },
    reimbursementService: null,
    created () {
      this.reimbursementService = new ReimbursementService()
    },
    components: {
    },
    methods: {
      init () {
        this.title = '人员选择'
        this.visible = true
        this.list()
      },
      // 表单提交
      getProgramForUser () {
        let rows
        if (this.commonJS.isEmpty(this.$refs.userTable.getCheckboxRecords())) {
          this.$message.error('请选择一条数据')
          return
        }
        if (this.$refs.userTable.getCheckboxRecords().length > 1) {
          this.$message.error('最多选择一条数据')
          return
        }
        rows = this.$refs.userTable.getCheckboxRecords()
        if (!rows[0].isUser) {
          this.$message.error('请选择子集数据')
          return
        }
        this.close()
        this.$emit('getProgramForUser', rows)
      },
      list () {
        this.loading = true
        this.reimbursementService.userTree(this.searchForm.name).then(({data}) => {
          this.dataList = data
          this.loading = false
        })
      },
      // 当前页
      currentChangeHandle ({currentPage, pageSize}) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.list()
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.list()
      },
      close () {
        this.detail = ''
        this.visible = false
      }
    }
  }
</script>
<style>
  .messageZindex {
    z-index:9999 !important;
  }
</style>
<style scoped>
  /deep/ .el-dialog__body {
    padding-top: 0px;
  }
</style>
