<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;" @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>
          </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>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'

  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')
      },
      add(){
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.$dispatch('add')
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
      },
      delete(row){
        if(row.id){
          var id = row.id
          this.$resetdelete('rs/entity/t_department', {id: id}, {resolveMsg: '删除成功', rejectMsg: '删除失败'}).then((res) => {
            this.$dispatch('refresh')
          })
        }
      }
    }
  }
</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>
