<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-3 form-group">
              <label class="font_normal_body">人员编码</label>
              <input  type="text" class="input_search" style="width:60%" v-model="model.f_code"
                      condition="f_code like '%{}%'" placeholder="人员编码"/>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">人员名称</label>
              <input  type="text" class="input_search" style="width:60%" v-model="model.f_name"
                      condition="f_name like '%{}%'" placeholder="人员名称"/>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">人员状态</label>
              <v-select :options='$parent.$parent.personoptions' :value.sync="model.f_state"
                        close-on-select condition="f_state = '{}'"
                        placeholder='人员状态' v-model="model.f_state"></v-select>
            </div>

            <div class="span" style="float:right;">
              <button class="button_search button_spacing" @click="search()">查询</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':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"    @click="$parent.$parent.hidden()"></div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">

            <div class="col-sm-3 form-group">
              <label class="font_normal_body">是否关联</label>
              <v-select :options='$parent.$parent.linkoptions' :value.sync="model.f_islink"
                        close-on-select condition="f_islink = '{}'"
                        placeholder='是否关联' v-model="model.f_islink"></v-select>
            </div>
          </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>
            <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_code}}</td>
            <td style="text-align: center;">{{row.f_name}}</td>
            <td style="text-align: center;">{{row.f_orgname}}</td>
            <td style="text-align: center;">{{row.f_state}}</td>
            <td style="text-align: center;">{{row.f_operate_date}}</td>
            <td style="text-align: center;">{{row.name}}</td>
            <td style="text-align: center;">{{row.ename}}</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>
          </tr>
        </template>
        <template partial='foot'></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">
      <master-compile-list :searchtype="$parent.searchtype"  v-if="editshow" :data="row"></master-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 {
    data () {
      return {
        model: new PagedList('rs/sql/getMasterData',20, {}),
        row: null,
        //控制修改按钮
        editshow:false,
        rowparent: null,
        orgoptions:[],
        depoptiones:[],
        personoptions:[{label:"正式",value:"正式"},{label:"退休",value:"退休"},{label:"试用",value:"试用"}],
        linkoptions:[{label:"是",value:"是"},{label:"否",value:"否"}],

        criteriaShow: false,
      }
    },
    ready(){
      this.search()
    },
    watch:{
      'searchtype'(){
        //if(this.searchtype)
      }
    },
    methods: {
      show() {
        this.criteriaShow = true
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      //修改资源
      modifyRes (obj) {
        delete obj.num
        this.row = obj
        this.row.f_data_type = this.searchtype;
        this.editshow=true
      },
      async deleteDep (val) {
        let res = await this.$showMessage(`确认要删除部门: ${val.name} 吗？`, ['confirm', 'cancel'])
        if (res === 'confirm') {
          let param = []
          param.push(val)
          try {
            await this.$resetpost('rs/data/delete', {data: param}, {resolveMsg: '删除成功！！', rejectMsg: null})
          } catch (error) {
            this.$showAlert(error.data, 'danger', 0)
          }
          this.$dispatch('refresh')
        }
      },
      cancel  () {
        this.row = null
        this.rowparent = null
        this.editshow=false
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch (args) {
      //  let getHasPermissionDepts = await this.$LdapService.getHasNodeByType('department')
       // args.condition += `${getHasPermissionDepts.condition}`
       // this.orgoptions =getHasPermissionDepts.orgoptions
       // this.depoptiones = getHasPermissionDepts.depoptions
        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.editshow=true
        //this.$dispatch('add')
      },
    },
    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>
<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>
