<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'
                          class="select select_list"
                          style="width: 60%"
                          @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_brand_spec"
                     placeholder='设备名称' condition="f_brand_spec like '%{}%'">
            </div>
            <div class="span" style="float:right;">
              <button class="button_search" @click="$parent.$parent.search()" v-el:cx>查询</button>
              <button class="button_new" @click="$parent.$parent.add()">新增</button>
              <div style="float: right" class="button_spacing"
                   :class="{'button_shrink_top': criteriaShow,'button_shrink_bottom': !criteriaShow}"
                   @click="criteriaShow = !criteriaShow">
              </div>
            </div>
          </div>
          <div class="row" v-show="criteriaShow">
            <div class="col-sm-3">
              <label class="font_normal_body">设备型号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_typenumber"
                     placeholder='设备型号' condition="f_typenumber like '%{}%'">
            </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_typename"
                     placeholder='设备品牌' condition="f_typename like '%{}%'">
            </div>
          </div>
        </div>
      </criteria>

      <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
        <template partial='head'>
          <tr>
            <th>
              <nobr>序号</nobr>
            </th>
            <th>
              <nobr>设备名称</nobr>
            </th>
            <th>
              <nobr>设备品牌</nobr>
            </th>
            <th>
              <nobr>设备型号</nobr>
            </th>
            <th>
              <nobr>设备价格</nobr>
            </th>
            <th>
              <nobr>使用分公司</nobr>
            </th>
            <th>
              <nobr>操作</nobr>
            </th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center">{{ $index + 1 }}</td>
            <td style="text-align:center">{{ row.f_brand_spec }}</td>
            <td style="text-align:center">{{ row.f_typename }}</td>
            <td style="text-align:center">{{ row.f_typenumber }}</td>
            <td style="text-align:center">{{ row.f_unitprice }}</td>
            <td style="text-align:center">{{ row.f_filialename }}</td>
            <td style="text-align:center">
              <button class="button_new" @click.stop="$parent.$parent.$parent.deldevice(row)">删除</button>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
/**
 *设备查询列表
 */
import {PagedList} from 'vue-client'

export default {
  data () {
    return {
      model: new PagedList('rs/sql/getdevice', 20),
      show: false,
      // 公司下拉
      curorgid: [this.$login.f.orgid],
      // 分公司查询条件
      f_filialeids: ''
    }
  },
  props: {},
  ready () {
    this.search()
  },
  methods: {
    search () {
      this.$refs.paged.$refs.cri.search()
      this.$dispatch('search')
    },
    getorg (val) {
      this.f_filialeids = this.$login.convertToIn(val)
    },
    selfSearch (args) {
      if (!this.f_filialeids) {
        this.getorg(this.curorgid)
      }
      console.log('查询。。。', this.f_filialeids)
      if (this.f_filialeids) {
        args.condition = `f_filialeid  in ${this.f_filialeids} and ${args.condition}`
      }
      this.$refs.paged.$refs.grid.$el.scrollTop = 0
      this.model.search(args.condition, args.model)
    },
    deldevice (row) {
      this.$showMessage('删除后不可恢复，确认删除吗？', ['confirm', 'cancel']).then((res) => {
        if (res == 'confirm') {
          this.$resetpost('rs/logic/deletedevice', {id: row.id}, {resolveMsg: '删除成功', rejectMsg: '删除失败'})
          this.search()
        }
      })
    },
    add () {
      // 新增时取消选中状态
      this.$refs.paged.$refs.grid.selectStore.selected = null
      this.$dispatch('select-changed')
    }
  },
  watch: {}
}
</script>
