<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="row">
          <div class="col-sm-3">
            <label class="font_normal_body">使用公司</label>
            <right-tree :userid.sync='$parent.$parent.userid' :source.sync='$parent.$parent.source'  @re-res="$parent.$parent.getRes" > </right-tree>
          </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_terminal_number"
                    condition="f_terminal_number 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>
        </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>操作</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_terminal_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 {
        model: new PagedList('rs/sql/equipmentQuery', 20),
        filialeNameStr: this.$login.f.f_fengongsi,
        filialeCodeStr: this.$login.f.f_orgids,
        userid:this.$login.f.id,
        source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() != $role$))`
      }
    },
    ready () {
      console.log('看看终端类型',  this.equipmentType)
      this.search()
    },
    methods: {
      search () {
        this.$refs.paged.$refs.cri.search()
      },

      selfSearch (args) {
        args.condition =  `${args.condition} and f_equipment_type = 'PHONE' and f_state = '正常' and f_orgid like '${this.filialeCodeStr}%'`
        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')
        })
      },
      getRes (obj) {
        this.filialeNameStr = obj.res
        this.filialeCodeStr = obj.resids
      },
    },
    computed: {

    }
  }
</script>
