<template>
  <div  class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' class="search_area" v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
<!--          <div class="col-sm-3 form-group form-input-group" >-->
<!--            <label class="font_normal_body">使用公司</label>-->
<!--            <res-select restype='organization'-->
<!--                        @res-select="$parent.$parent.getorg"-->
<!--                        :initresid='$parent.$parent.curorgid'>-->
<!--            </res-select>-->
<!--          </div>-->
          <div class="row">
            <div class="col-sm-3 form-group form-input-group" >
              <label class="font_normal_body">登&nbsp;&nbsp;录&nbsp;&nbsp;名</label>
              <input  type="text" class="input_search" v-model="model.ename" style="width: 90px"
                      condition="ename like '%{}%'" placeholder="登录名"
                      />
            </div>
            <div class="col-sm-3 form-group form-input-group" >
              <label class="font_normal_body">员工姓名</label>
              <input  type="text" class="input_search" v-model="model.name" style="width: 90px"
                      condition="name like '%{}%'" placeholder="员工姓名"
                      />
            </div>
            <div class="col-sm-3 form-group form-input-group">
              <label class="font_normal_body">员工电话</label>
              <input type="text" class="input_search" v-model="model.f_user_phone" style="width: 90px"
                     condition="f_user_telephone like '%{}%'" placeholder='员工电话'
                     />
            </div>

            <div class="col-sm-3 form-group form-input-group">
              <label class="font_normal_body">部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门</label>
              <input type="text" class="input_search" v-model="model.f_department_name" style="width: 90px"
                     condition="f_department_name like '%{}%'" placeholder='部门'>
            </div>
            <div class="col-sm-3 form-group form-input-group">
              <label class="font_normal_body">角&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色</label>
              <input type="text" class="input_search" v-model="model.f_role_name" style="width: 90px"
                     condition="f_role_name like '%{}%'" placeholder='角色'>
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <button class="button_search" style="width:80px;margin-left:30px;" @click="search()" v-el:cx>查询</button>
              <button class="button_export" style="width:80px;margin-left:20px;" @click="$parent.$parent.add()" v-el:cx>新增员工</button>
            </div>
          </div>

          <!--<div class="form-group">-->
            <!--<v-select id="f_bill_style"-->
                      <!--v-model="model.f_staff_state"-->
                      <!--placeholder='在职状态'-->
                      <!--:value.sync="model.f_staff_state"-->
                      <!--:options='$parent.$parent.getstaffstate'-->
                      <!--condition= "f_staff_state = '{}'"-->
                      <!--close-on-select>-->
            <!--</v-select>-->
          <!--</div>-->

          <div class="col-sm-3 form-group form-input-group">
            <!--<export-excel :data="$parent.$parent.getCondition"-->
                          <!--:field="$parent.$parent.getfield"-->
                          <!--sqlurl="rs/logic/saleExport" sql-name="staffQuery" template-name='员工信息查询导出'  :choose-col="true"></export-excel>-->
            <!--<export-excel :data="{items: 'f_parentid,f_user_name,f_sex,f_age,f_parentname,f_job,f_user_phone,f_staff_state,f_operator_date,f_address,f_operate,f_filiale,f_remark',-->
            <!--orderitem: 'f_operator_date',tablename: 't_staff',-->
            <!--condition: condition}" bean='员工信息列表导出' sqlurl="rs/logic/exportfile"></export-excel>-->
          </div>
        </div>
      </criteria>
      <data-grid  :model="model" partial='list' class="list_area table_sy" v-ref:grid>
        <template partial='head'>
          <tr>
            <th style="text-align: center;">序&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</th>
            <th style="text-align: center;">登&nbsp;&nbsp;录&nbsp;&nbsp;名</th>
            <th style="text-align: center;">员工名称</th>
            <th style="text-align: center;">电&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话</th>
            <th style="text-align: center;">所属部门</th>
            <th style="text-align: center;">所属角色</th>
            <th>操&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作</th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align: center;">{{$index+1}}</td>
            <td style="text-align: center;">{{row.f_parentid}}</td>
            <td style="text-align: center;">{{row.f_parentname}}</td>
            <td style="text-align: center;">{{row.f_address}}</td>
            <td style="text-align: center;">{{row.f_department_name}}</td>
            <td style="text-align: center;">{{row.rolenames}}</td>
            <td style="text-align:center">
            <button type="button" name="button" class="btn btn-link"
                    @click.stop="$parent.$parent.$parent.delete(row)"
                    v-if="row.f_staff_state=='作废'">删除</button>
               <button type="button" name="button" class="btn btn-link"
                      v-if="row.f_staff_state!='作废'">修正</button>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  // import exportConfig from '../../service/exportConfig'
  let readySync = async function (self) {
    await self.$refs.paged.$refs.cri.search()
  }

  export default {
    data () {
      return {
        model: new PagedList('rs/sql/staffQuery',20, {}),
        orgCondtionStr:'',
        // 公司下拉
        curorgid: [this.$login.f.id],
        f_orgid: ''
      }
    },
    ready(){
      readySync(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      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_user', {id: id}, {resolveMsg: '删除成功', rejectMsg: '删除失败'}).then((res) => {
            this.$dispatch('refresh')
          })
        }
      }
    },
    computed: {
      getCondition(){
        return {condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr}
      },
      getfield(){
        return exportConfig.staffConfig
      },
      getstaffstate () {
        return this.$appdata.getParam('在职状态')
      }
    }
  }
</script>
<style>

</style>
