<template>
  <div style="flex:1;" class="flex auto">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' v-ref:criteria  @condition-changed='$parent.selfSearch'>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
          <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">表号:</label>
            <input type="text" class="form-control" v-model="model.f_meternumber"
                   condition="f_meternumber='{}'" placeholder='表号' v-next-el="aa" style="width:100px;">
          </div>
          <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">表计电话:</label>
            <input type="text" class="form-control" v-model="model.f_meter_phone"
                   condition="f_meter_phone='{}'" style="width:100px;" placeholder='表计电话'>
          </div>
          <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">终端名称:</label>
            <input type="text" class="form-control" v-model="model.f_terminal_id"
                   condition="f_terminal_id like'%{}%'" style="width:100px;" placeholder='终端名称'>
          </div>
          <!--<div class="form-group">-->
            <!--<input type="text" class="form-control" v-model="model.f_isuse"-->
                   <!--condition="f_isuse='{}'" style="width:100px;" placeholder='使用状态' >-->
          <!--</div>-->
          <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">厂商代码:</label>
            <input type="text" class="form-control" v-model="model.f_vender"
                   condition="f_vender like'%{}%'" style="width:100px;" placeholder='厂商代码'>
          </div>
          <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">imei码:</label>
            <input type="text" class="form-control" v-model="model.f_imei"
                   condition="f_imei='{}'" style="width:100px;" placeholder='imei码'>
          </div>
          <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">imsi码:</label>
            <input type="text" class="form-control" v-model="model.f_imsi"
                   condition="f_imsi='{}'" style="width:100px;" placeholder='imsi码'>
          </div>
          <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">组织机构</label>
            <right-tree :userid.sync='$parent.$parent.userid' :source.sync='$parent.$parent.source'  @re-res="$parent.$parent.getRes"></right-tree>
          </div>


          </div>
          <div class="row">
            <div class="span" style = "float:right;margin-top:10px">

                <!-- <file-upload class="my-file-uploader" name="myFile"
                action="rs/file/upload" tagname="上传多个文件" :headers="$parent.$parent.headers"></file-upload> -->
                <file-upload class="my-file-uploader" name="meterinfoUploadFile" class="btn btn-success" style="border-radius: 2px;margin-right: 10px"
                             action="rs/file/upload" tagname="文件上传" :headers="$parent.$parent.headers" multiple v-ref:file></file-upload>

            </div>
            <div class="span" style = "float:right;margin-top:10px">
            <button class="btn btn-success" style="border-radius: 2px;margin-right: 10px" @click="search()" >查询</button>
              </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>表号</th>
            <th>终端名称</th>
            <th>表计电话</th>
            <th>表流量</th>
            <th>表通道类型</th>
            <th>阀控标识</th>
            <th>表通讯序号</th>
            <th>imei码</th>
            <th>imsi码</th>
            <th>厂商代码</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">{{$index+1}}</td>
          <td>{{row.f_meternumber}}</td>
          <td>{{row.f_terminal_id}}</td>
          <td>{{row.f_meter_phone}}</td>
          <td>{{row.f_diameter}}</td>
          <td>{{row.f_iot_type}}</td>
          <td>{{row.f_valvemark}}</td>
          <td>{{row.f_telecomm_no}}</td>
          <td>{{row.f_imei}}</td>
          <td>{{row.f_imsi}}</td>
          <td>{{row.f_vender}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
  import { PagedList } from 'vue-client'
  import  *  as  WebmeterUtil from  '../WebmeterUtil'
  import vue from 'vue'

  export default {
    title: '物联网表信息',
    data () {
      return {
        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() == $organization$))`,
        model: new PagedList('rs/sql/singleTable_OrderBy', 20, {items: '"*"', tablename: '"t_meterinfo"', orderitem: '"id"'}),
        headers: {'username': vue.$login.f.name, 'blodid': WebmeterUtil.guid()}
      }
    },
    ready () {
      this.search()
    },
    methods: {
      getRes(obj) {
        this.filialeNameStr = obj.res
        this.filialeCodeStr = obj.resids
      },
      search () {
        this.$refs.paged.$refs.criteria.search()
      },
      async selfSearch (args) {
        let f_orgstr = this.filialeCodeStr
          console.log('xxxx',f_orgstr)
          args.condition =  `${args.condition} and f_filialeids like '${f_orgstr}%'`
          // args.condition =  `${args.condition}`
          console.log('我的阐述',JSON.stringify(args.condition))
           await this.model.search(args.condition, args.model)
      },
      fileparse (name, val) {
      }
    },
    events: {
      onFileUpload: function (file, res) {
        let data = {
          tablename: 't_meterinfo',
          filepath: res.path,
          f_filialeids: this.$login.f.f_orgids
        }
        this.$resetpost('rs/logic/meterinfo_import', {data: data}, {resolveMsg: '上传成功', rejectMsg: '上传失败'}).then((res) => {
          this.search()
        })
      }
    }
  }

</script>
