<template>
  <div class="flex" @keyup.enter="search">
    <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="$parent.$parent.style">
                <label class="font_normal_body">组织机构</label>
                  <res-select restype='organization'
                              @res-select="$parent.$parent.getorg"
                              is-mul="false"
                              :initresid='$parent.$parent.curorgid'>
                  </res-select>
            </div>
            <div :class="$parent.$parent.style" >
              <label class="font_normal_body">集中器编码</label>
              <input  type="text" class="input_search" style="width:60%" v-model="model.f_mpc_number"
                      condition="f_mpc_number like '%{}%'" placeholder="集中器编码"/>
            </div>
            <div :class="$parent.$parent.style" v-if="$parent.$parent.areaShow">
              <label class="font_normal_body">集中器</label>
              <input  type="text" class="input_search" style="width:60%" v-model="model.f_mpc_alias"
                      condition="f_mpc_alias like '%{}%'" placeholder="集中器别名"/>
            </div>

            <div class="col-sm-4 form-group button-range">
              <button class="button_search button_spacing" @click="search()" >查询</button>
              <button  class="button_new button_spacing" style="width: max-content;" @click="$parent.$parent.add()">新建</button>
              <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</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-if="$parent.$parent.criteriaShow">
             <div :class="$parent.$parent.style" v-if="!$parent.$parent.areaShow">
               <label class="font_normal_body">安装地址</label>
               <input  type="text" class="input_search" style="width:60%" v-model="model.f_address"
                       condition="f_address 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><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>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>IP地址</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>端口号</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>抄表周期</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>状态</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>组网</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>最后一次通讯时间</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>最新事件</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>最后修改人</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>最后修改时间</nobr></th>
            <th v-show="$parent.$parent.$parent.listshow" ><nobr>表具数量</nobr></th>
            <th><nobr>操作</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center"><nobr>{{$index + 1}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_mpc_number}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_mpc_alias}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_mpc_brand}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_mpc_type}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_mpc_phone}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_mpc_address}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_mpc_ip}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_mpc_port}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_mpc_hand_times}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_mpc_state}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_mpc_network}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_last_message_date}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_new_message}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_modify_user}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow"  style="text-align:center"><nobr>{{row.f_modify_date}}</nobr></td>
            <td v-show="$parent.$parent.$parent.listshow" style="text-align:center"><nobr>{{row.sumuserfiles}}</nobr></td>
            <td><nobr>
<!--              <button type="button" name="button" class="btn btn-link"-->
<!--                      @click.stop="$parent.$parent.$parent.modify(row)">修改</button>-->
              <button type="button" name="button" class="btn btn-link"
                      @click.stop="$parent.$parent.$parent.showlinkmeter(row)">关联表具</button>
              <button type="button" name="button" class="btn btn-link"
                      @click.stop="$parent.$parent.$parent.delete(row)">删除</button>
            </nobr></td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  export default {

    data () {
      return {
        listshow: true,
        criteriaShow: false,
        model: new PagedList('rs/sql/concentratorarchivesQuery', 20),
        addflag: false,
        addtitle: '',

        // 公司下拉
        curorgid: [this.$login.f.orgid],
        f_orgid: '',
        areaShow: true
      }
    },
    title: '集中器管理',
    props: {
      f_filialeids: {
        type: String
      },
      style: {
        type: String,
        default: 'col-sm-2 form-group'
      },
      f_special: {
        type: String
      }
    },
    ready () {
      this.search()
    },
    methods: {
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      search () {
        this.$refs.paged.$refs.cri.search()
        this.listshow = true
      },

      async delete (row) {
        this.$showMessage(`你确定删除${row.f_mpc_alias}集中器？`, ['confirm', 'cancel']).then(async res => {
          if (res === 'confirm') {
            await this.$resetpost('rs/logic/deleteconcentrator', row, {
              resolveMsg: '删除成功!',
              rejectMsg: '删除失败!'
            })
            this.search()
          }
        })
      },
      showlinkmeter (row) {
        // 查看关联表具
        this.$parent.addmeterinfoshow = true
        this.$parent.allarearow = row
      },
      add () {
        if (this.f_filialeids) {
          this.$refs.paged.$refs.grid.selectStore.selected = null
          this.areaShow = false
          this.listshow = false
          this.$dispatch('add')
        } else {
          this.$showAlert('请先选择左上角的所在分公司', 'warning', 2000)
        }
      },
      modify (val) {
        this.areaShow = false
        this.listshow = false
        this.$dispatch('dblclick', val)
      },
      selfSearch (args) {
        this.listshow = true
        this.areaShow = true
        if (!this.f_orgid) {
          this.getorg([this.$login.f.orgid])
        }
        args.condition = `${args.condition} and f_filialeid = ${this.f_orgid}`
        this.model.search(args.condition, args.model)
        this.$dispatch('newsearch')
      },
      // 清空
      clear () {
        this.$refs.paged.$refs.cri.model = {}
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        if (val[0]) this.f_filialeids = val[0]
      }
    }

  }
</script>
