<template>
  <div class="flex" >
    <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">
            <label class="font_normal_body">使用公司</label>
            <res-select restype='organization'
                        is-mul="false"
                        @res-select="$parent.$parent.getorg"
                        :initresid="$parent.$parent.curorgid">
            </res-select>
          </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_username"
                    condition="f_username 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_mac_outlets"
                    condition="f_mac_outlets like '%{}%'" placeholder="所属地址">
          </div>
            <div class="span" style="float:right;">
              <button class="button_search" @click="$parent.$parent.search()" v-el:cx>查询</button>
              <button class="button_search" @click="$parent.$parent.add()" v-el:cx>新增</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" >
            <label class="font_normal_body">MAC地址</label>
            <input  type="text" class="input_search" style="width:60%" v-model="model.f_mac_number"
                    condition="f_mac_number like '%{}%'" placeholder="MAC地址">
          </div>


          </div>
        </div>
      </criteria>
      <data-grid  :model="model" partial='list' class="list_area table_sy"  v-ref:grid >
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>使用人员</th>
            <th>所属地址</th>
            <th>MAC地址</th>
            <th>操作</th>
          </tr>
        </template>
        <template partial='body':model="model">
          <tr>
            <td style="text-align:center">{{$index+1}}</td>
            <td style="text-align:center">{{row.f_username}}</td>
            <td style="text-align:center">{{row.f_mac_outlets}}</td>
            <td style="text-align:center">{{row.f_mac_number}}</td>
            <td style="text-align:center">
              <button class="btn btn-link"  @click.stop="$parent.$parent.$parent.del(row)">删除</button>
            </td>
          </tr>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  export default {
    title: 'PC',
    components: {},
    data () {
      return {
        criteriaShow: false,
        model: new PagedList('rs/sql/equipmentQuery', 20),
        curorgid: [this.$login.f.orgid],
        f_orgid: ''
      }
    },
    ready () {
      this.search()
    },
    methods: {
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },

      selfSearch (args) {
        args.condition =  `${args.condition} and f_equipment_type = 'PC' and f_state = '正常' and f_orgid like '${this.f_orgid ? this.f_orgid: this.$login.f.orgid}'`
        this.model.search(args.condition, this.model)
      },
      add () {
        this.$dispatch('add')
      },
      del (row) {
        console.log('要删除了', row)
        row.f_state = '已删除'
        this.$resetpost('rs/entity/t_equipment', row, {warnMsg: '确定要删除这条信息吗？', resolveMsg: '删除成功', rejectMsg: '删除失败'}).then((res) => {
          this.$dispatch('refresh')
        }).catch((error) => {
          this.$dispatch('refresh')
        })
      },
      getorg (val) {
        this.f_orgid = val[0]
      }
    },
    computed: {

    }
  }
</script>
