<template>
  <div  class="flex datapanel">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="col-sm-3" >
            <label class="font_normal_body" >所属公司</label>
            <input  type="text" class="input_search" style="width:60%" v-model="model.oname"
                    condition="oname like '%{}%'" placeholder="所属公司"/>
          </div>
          <div class="col-sm-3" >
            <label class="font_normal_body" >部门编号</label>
            <input  type="text" class="input_search" style="width:60%" v-model="model.f_dep_id"
                    condition="f_dep_id like '%{}%'" placeholder="部门名称"/>
          </div>
          <div class="col-sm-3" >
            <label class="font_normal_body" >部门名称</label>
            <input  type="text" class="input_search" style="width:60%" v-model="model.name"
                    condition="name like '%{}%'" placeholder="部门名称"/>
          </div>
          <div class="span" style="float:right;">
            <button class="button_search button_spacing" style="width:80px;margin-left:30px;" @click="search()" v-el:cx>查询</button>
            <button class="button_new button_spacing" style="width:80px;margin-left:20px;" v-if="$parent.$parent.hasbtn('新建部门')" @click="$parent.$parent.add()" v-el:cx>新建部门</button>
          </div>
        </div>
      </criteria>
      <data-grid class="list_area table_sy"  :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>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align: center;">{{$index+1}}</td>
            <td style="text-align: center;">{{row.f_dep_id}}</td>
            <td style="text-align: center;">{{row.name}}</td>
            <td style="text-align: center;">{{row.oname}}</td>
            <td style="text-align: center;">{{row.num}}</td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  import * as Util from '../Util'
  export default {
    data () {
      return {
        model: new PagedList('rs/sql/ldap_getAllDep',20, {}),
        orgCondtionStr:'',
        // 公司下拉
        curorgid: [this.$login.f.id],
        f_orgid: ''
      }
    },
    ready(){
      this.search()
    },
    methods: {
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch (args) {
        let getHasPermissionDepts = await this.$LdapService.getHasNodeByType('department')
        args.condition += `${getHasPermissionDepts}`
        this.model.search(args.condition, args.model)
        this.$dispatch('search')
      },
      hasbtn (val) {
        if(Util.f.ldapReslist&&Util.f.ldapReslist.includes(val)){
          return true
        }else {
          return false
        }
      },
      add(){
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.$dispatch('add')
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
      },
    }
  }
</script>
<style>
  .datapanel {
    color: #333;
    background-color: white;
    box-shadow: darkgrey 0.5px 0.5px 0.5px 0.5px;
    padding: 10px 10px 10px 10px;
    border-radius: 15px;
  }
</style>
