<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_terminal_number"
                      condition="f_terminal_number 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_phone"
                      condition="f_phone like '%{}%'" placeholder="联系电话">
            </div>

            <div class="span" style="float:right;">
              <button type="button" class="button_search" @click="search()" v-el:cx>查询</button>
              <button type="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">&nbsp;&nbsp;&nbsp;所在地</label>
              <input  type="text" class="input_search" style="width:60%" v-model="model.f_address"
                      condition="f_address 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_name"
                      condition="f_terminal_name 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_machine_number"
                      condition="f_machine_number 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_bank_name"
                      condition="f_bank_name like '%{}%'" placeholder="所属银行">
            </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>
            <th>联系电话</th>
            <th>所在地</th>
            <th>所属银行</th>
            <th>电池电量</th>
            <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_terminal_number}}</td>
            <td style="text-align:center">{{row.f_terminal_name}}</td>
            <td style="text-align:center">{{row.f_machine_number}}</td>
            <td style="text-align:center">{{row.f_phone}}</td>
            <td style="text-align:center">{{row.f_address}}</td>
            <td style="text-align:center">{{row.f_bank_name}}</td>
            <td style="text-align:center">{{row.f_battery_level}}</td>
            <td style="text-align:center">{{row.f_is_login}}</td>
            <td style="text-align:center">{{row.f_hybrid_version}}</td>
            <td style="text-align:center">{{row.f_appVer}}</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: '终端控制',
    components: {},
    data () {
      return {
        model: new PagedList('rs/sql/equipmentQuery', 20),
        curorgid: [this.f_filialeid],
        f_orgid: '',
        f_filialeids:'',
        criteriaShow: false
      }
    },
    props: ['f_filialeid'],
    ready () {
      this.search()
    },
    methods: {

      search () {
        console.log("111111111111111111111111111111111111")
        this.$refs.paged.$refs.cri.search()
      },

      selfSearch (args) {
        args.condition =  `${args.condition} and f_equipment_type = 'POS' and f_state = '正常' and f_orgid = '${this.f_filialeid ? this.f_orgid: this.$login.f.orgid}'`
        this.model.search(args.condition, this.model)
        this.$dispatch('research')
      },

      add () {
        if (this.f_filialeid) {
          this.$parent.f_filialeid=this.f_filialeid
          this.$dispatch('add')
        } else {
          this.$showAlert('请先选择左上角的所在分公司', 'warning', 2000)
        }

      },

      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]
        this.f_filialeid = val[0]
        this.search()
      },
      hidden(){
        this.criteriaShow = !this.criteriaShow
      }
    },
    computed: {

    }
  }
</script>
