<template>
  <div class="flex" style="flex:1; ">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-inline auto" partial>
          <div class="row">
            <!--<div class="form-group">-->
              <!--<label>使用公司</label>-->
              <!--<res-select restype='organization'-->
                          <!--@res-select="$parent.$parent.getorg"-->
                          <!--:initresid='$parent.$parent.curorgid'>-->
              <!--</res-select>-->
            <!--</div>-->
            <div class="form-group">
              <label>员工姓名</label>
              <input type="text" class="form-control" v-model="model.name"
                     condition="name like '%{}%'" placeholder='员工姓名'>
            </div>
            <div class="form-group">
              <label>登录名</label>
              <input type="text" class="form-control" v-model="model.ename"
                     condition="ename like '%{}%'" placeholder='登录名'>
            </div>
            <div class="form-group">
              <label>部门</label>
              <input type="text" class="form-control" v-model="model.f_department_name"
                     condition="f_department_name like '%{}%'" placeholder='部门'>
            </div>
            <div class="form-group">
              <label>角色</label>
              <input type="text" class="form-control" v-model="model.f_role_name"
                     condition="f_role_name like '%{}%'" placeholder='角色'>
            </div>
          </div>
          <div class="row" style="text-align: right">
            <div class="form-group">
              <button class="btn btn-success width-80" @click="$parent.$parent.search()" v-el:cx>查询</button>
            </div>
            <div class="form-group">
              <button class="btn btn-success width-80" @click="$parent.$parent.createNew()" v-el:cx>新建</button>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th style="text-align: center;">序号</th>
            <th style="text-align: center;">员工编号</th>
            <th style="text-align: center;">员工名称</th>
            <th style="text-align: center;">登录名</th>
            <th style="text-align: center;">电话</th>
            <th style="text-align: center;">所属部门</th>
            <th style="text-align: center;">所属角色</th>
            <th style="text-align: center;">状态</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">{{$index+1}}</td>
          <td style="text-align: center;">{{row.userid}}</td>
          <td style="text-align: center;">{{row.name}}</td>
          <td style="text-align: center;">{{row.ename}}</td>
          <td style="text-align: center;">{{row.f_user_telephone}}</td>
          <td style="text-align: center;">{{row.f_department_name}}</td>
          <td style="text-align: center;">{{row.f_role_name}}</td>
          <td style="text-align: center;">{{row.state}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
  import { PagedList } from 'vue-client'

  export default {
    title: '用户列表',
    data () {
      return {
        model: new PagedList('rs/sql/ldap_getAllUser', 20),
        // 公司下拉
        curorgid: [this.$login.f.id],
        f_orgid: ''
      }
    },
    ready () {
      this.search()
    },
    methods: {
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch (args) {
        let getHasPermissionUsers = await this.$LdapService.getHasNodeByType('user')
        args.condition += `${getHasPermissionUsers}`
        this.model.search(args.condition, args.model)
        this.$dispatch('search')
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
      },
      createNew () {
        this.$dispatch('adduser')
      }
    },
    computed: {
    }
  }
</script>
