<template>
  <div>
        <el-row :gutter="6">
          <el-col :xs="24" :md="4">
          <treeselect 
          v-model="listQuery.user__dept" 
          :multiple="false" 
          :options="deptOptions" 
          placeholder="所属组织" 
          :disable-branch-nodes="true" 
          @input="handleFilter" 
           clearable/>
          </el-col>
          <el-col :xs="24" :md="2">
          <el-select
            v-model="listQuery.is_fulltime"
            placeholder="是否全职"
            clearable
            class="filter-item"
            
            @change="handleFilter"
          >
            <el-option label="是" value="true"/>
            <el-option label="否" value="false"/>
          </el-select>
          </el-col>
          <el-col :xs="24" :md="6">
          <el-input
            v-model="listQuery.search"
            placeholder="姓名/易记码/编号/注册领域/专业能力"
            class="filter-item"
            @keyup.enter.native="handleFilter"
          />
          </el-col>
          <el-col :xs="24" :md="4">
          <el-button-group>
          <el-button
            class="filter-item"
            type="primary"
            icon="el-icon-search"
            @click="handleFilter"
          >搜索</el-button>
          <el-button
            class="filter-item"
            type="warning"
            icon="el-icon-refresh-left"
            @click="resetFilter"
          >刷新重置</el-button>
          </el-button-group>
          </el-col>
        </el-row>
        <el-table
          v-loading="listLoading"
          :data="tableData.results"
          style="width: 100%;margin-top:10px;"
          border
          fit
          stripe
          highlight-current-row
          max-height="600"
        >
          <el-table-column type="index" width="50" />
          <el-table-column label="编号">
            <template slot-scope="scope" v-if="scope.row.code">{{ scope.row.code }}</template>
          </el-table-column>
          <el-table-column label="账号">
            <template slot-scope="scope">{{ scope.row.user_.username }}</template>
          </el-table-column>
          <el-table-column label="名称">
            <template slot-scope="scope">{{ scope.row.user_.name }}</template>
          </el-table-column>
          <el-table-column label="所属部门">
            <template slot-scope="scope">{{ scope.row.user_.dept_name }}</template>
          </el-table-column>
          <el-table-column label="注册领域">
            <template slot-scope="scope" v-if="scope.row.fields">
              
            <el-tag v-for="(item, index) in scope.row.fields.split(',')" :key="index" style="margin:2px" >{{item}}</el-tag>
              
            </template>
          </el-table-column>
          <el-table-column label="专业能力">
            <template slot-scope="scope" v-if="scope.row.majors">
              <el-tooltip effect="dark" :content="item.abilitys.join('\n')" placement="top-start" v-for="(item, index) in scope.row.majors" :key="index">
            <el-tag  style="margin:2px" type="plain">
              {{item.major}}
            
            </el-tag>
            </el-tooltip>
            </template>
          </el-table-column>
                <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <el-button-group>
          <el-button
            type="primary"
            size="small"
            @click="handleChose(scope)"
          >选中</el-button>
          <el-button
            type="info"
            size="small"
            @click="handleDelete(scope)"
          >详情</el-button>
          </el-button-group>
        </template>
                </el-table-column>
        </el-table>

        <pagination
          v-show="tableData.count>0"
          :total="tableData.count"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.page_size"
          @pagination="getList"
        />
  </div>
</template>
<script>
import { getEmployeeMList, deleteEmployee } from "@/api/employee"
import { getOrgList } from "@/api/org"
import { getDictList } from "@/api/dict"
import Pagination from "@/components/Pagination"
import checkPermission from '@/utils/permission'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { genTree } from '../../utils'
export default {
  name:'Userchose',
  components: { Pagination, Treeselect },
  props:['querydata'],
  data() {
    return {
      tableData: {count:0},
      listLoading: true,
      listQuery: {
        page: 1,
        page_size: 10,
        is_onjob:true
      },
      deptOptions: [],
    };
  },
  created() {
    this.getList();
    this.getdeptOptions()
  },
  methods: {
    checkPermission,
    getList() {
      this.listLoading = true;
      getEmployeeMList(this.listQuery).then(response => {
        if (response.data) {
          this.tableData = response.data
        }
        this.listLoading = false
      });
    },
    getdeptOptions() {
      getOrgList().then(res=>{
        this.deptOptions = genTree(res.data)
      })
    },
    resetFilter() {
      this.listQuery = {
        page: 1,
        page_size: 10,
        is_onjob:true
      }
      this.getList()
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    // handleCreate() {
    //   this.$router.push({path:"/certset/implementrule/create"})
    // },
    handleChose(scope) {
this.$emit('handleChose',scope.row);
    }
  }
};
</script>
