<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-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.f_role_id"
                     condition="f_role_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="$parent.$parent.search()" v-el:cx>查询</button>
              <button class="button_new button_spacing" style="width:80px;margin-left:30px;" v-if="$parent.$parent.hasbtn('新建角色')" @click="$parent.$parent.createNew()" 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><nobr>序号</nobr></th>
            <th><nobr>角色编号</nobr></th>
            <th><nobr>角色名称</nobr></th>
            <th><nobr>创建时间</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">{{$index+1}}</td>
          <td style="text-align: center;">{{row.f_role_id}}</td>
          <td style="text-align: center;">{{row.name}}</td>
          <td style="text-align: center;">{{row.f_create_date}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
  import { PagedList } from 'vue-client'
  import * as Util from '../Util'
  export default {
    title: '角色列表',
    data () {
      return {
        model: new PagedList('rs/sql/ldap_getAllRole', 20),
        // 公司下拉
        curorgid: [this.$login.f.id],
        f_orgid: ''
      }
    },
    ready () {
      this.search()
    },
    methods: {
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch (args) {
        let getHasPermissionRoles = await this.$LdapService.getHasNodeByType('role')
        args.condition += `${getHasPermissionRoles}`
        this.model.search(args.condition, args.model)
        this.$dispatch('search')
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
      },

      createNew () {
        this.$dispatch('addrole')
      },
      hasbtn (val) {
        if(Util.f.ldapReslist&&Util.f.ldapReslist.includes(val)){
          return true
        }else {
          return false
        }
      },
    },
    computed: {
    }
  }
</script>
