<template>
  <div class="flex" @keyup.enter="search">
    <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="row">
            <div class="col-sm-2 form-group">
              <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-2 form-group">
              <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="col-sm-2 form-group">
              <label class="font_normal_body">所属公司</label>
              <v-select :options='$parent.$parent.orgoptions' :value.sync="model.orgname"
                        close-on-select condition="orgname like '%{}%'"
                        placeholder='所属公司' v-model="model.orgname"></v-select>
              <!--<input type="text" class="input_search" style="width:60%" v-model="model.orgname"-->
                     <!--condition="orgname like '%{}%'" placeholder='角色名称'>-->
            </div>
            <div class="col-sm-2 form-group button-range" style="float: right">
              <button class="button_search button_spacing" @click="$parent.$parent.search()">查询</button>
              <button class="button_clear button_spacing" @click="clear">清空</button>
              <button class="button_new button_spacing" v-if="$parent.$parent.hasbtn('新建角色')" @click="$parent.$parent.add()">新建角色</button>
              <div style="float: right" class="button_spacing" :class="{'button_shrink_top': criteriaShow,'button_shrink_bottom': !criteriaShow}" @click="$parent.$parent.hidden"></div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">

          </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>
            <th><nobr>创建时间</nobr></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.orgname}}</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>
          <td style="text-align: center;">
<!--
            <button-link type="button" v-if="row.num==0" class="btn btn-link" @click="$parent.$parent.$parent.deleteDep(row)">删除</button-link>
-->
            <button-link type="button"class="btn btn-link" @click="$parent.$parent.$parent.modifyRes(row)">修改</button-link>
          </td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <modal :show.sync="editshow"  v-ref:modal large backdrop="false">
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="cancel"><span>&times;</span></button>
    </header>
    <article slot="modal-body" class="modal-body">
      <role-compile-list  v-if="editshow" :data="row"></role-compile-list>
    </article>
    <footer slot="modal-footer" class="modal-footer">
    </footer>
  </modal>
</template>
<script>
  import { PagedList } from 'vue-client'
  import Util from '../Util'
  export default {
    title: '角色列表',
    data () {
      return {
        model: new PagedList('rs/sql/ldap_getAllRole', 20),
        // 公司下拉
        //控制修改按钮
        editshow:false,
        rowparent: null,
        criteriaShow:false,
        orgoptions:[],
        depoptiones:[]
      }
    },
    ready () {
      this.search()
    },
    methods: {
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      //修改资源
      modifyRes (obj) {
        delete obj.num
        this.row = obj
        this.editshow=true
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch (args) {
        let getHasPermissionRoles = await this.$LdapService.getHasNodeByType('role')
        this.orgoptions =getHasPermissionRoles.orgoptions
        this.depoptiones = getHasPermissionRoles.depoptions
        args.condition += `${getHasPermissionRoles.condition}`
        this.model.search(args.condition, args.model)
        this.$dispatch('search')
      },
      //添加部门
      add(){
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.editshow=true
      },
      cancel  () {
        this.row = null
        this.rowparent = null
        this.editshow=false
      },
      hasbtn (val) {
        if(Util.f.ldapReslist&&Util.f.ldapReslist.includes(val)){
          return true
        }else {
          return false
        }
      },
    },
    computed: {
    },
    events: {
      //提交
      'success' () {
        this.row = null
        this.rowparent = null
        this.editshow=false
        this.$showAlert('操作成功', 'success', 2000)
        this.search()
      },
      //返回
      'cancel' () {
        this.row = null
        this.rowparent = null
        this.editshow=false
        this.$dispatch('cancel')
      },
    },
  }
</script>
