<template>
  <div style="flex:1; " class="flex">
    <!--可通过修改此处来达到横屏拖动的目的-->
    <criteria-paged :model="model" v-ref:paged @sort="sort">
      <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 form-group form-input-group" style="width: 20%">
              <label class="control-label">用户编号:</label>
              <input type="text" class="form-control fixed-width" v-model="model.f_userinfo_code" placeholder='用户编号'
                     condition="i.f_userinfo_code like '%{}%'" v-next-el='bbh' v-filter v-focus>
            </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 fixed-width" v-model="model.f_user_name" placeholder='用户姓名'
                     condition="i.f_user_name like '%{}%'" v-next-el='bbh' v-filter v-focus>
            </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 fixed-width" v-model="model.f_merternumber" placeholder='表号'
                     condition="u.f_meternumber like '%{}%'" v-next-el='xq' v-filter v-focus v-el:bbh>
            </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 fixed-width" v-model="model.f_residential_area" placeholder='小区'
                     condition="i.f_residential_area like '%{}%'" v-next-el='bbh' v-filter v-focus>
            </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 fixed-width" v-model="model.f_address" placeholder='地址'
                     condition="i.f_address like '%{}%'" v-next-el='xq' v-filter v-focus v-el:bbh>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label for="startDate" class="control-label">开始日期</label>
              <datepicker id="startDate" placeholder="开始日期" width='100%'
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="true"
                          condition="u.f_input_date >= '{}'">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label for="endDate" class="control-label">结束日期</label>
              <datepicker id="endDate" placeholder="结束日期" width='100%'
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="true"
                          condition="u.f_input_date <= '{}'">
              </datepicker>
            </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 class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">气表分类</label>
              <v-select :value.sync="model.f_meter_classify"
                        v-model="model.f_meter_classify"
                        :options='$parent.$parent.metertypes' placeholder='请选择'
                        condition="b.f_meter_type = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <button class="btn btn-success" style="border-radius: 2px;margin-right: 10px" @click="search()" >查询</button>
            </div>
            <hr>
          </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>信号强度</th>
            <th>电压</th>
            <!--<th>磁干扰</th>-->
            <!--<th>报警关阀</th>-->
            <!--<th>周期关阀</th>-->
            <!--<th>过流保护关阀</th>-->
            <!--<th>关阀走气</th>-->
            <!--<th>拆表报警</th>-->
          </tr>
        </template>
        <template partial='body' partial='list' v-ref:grid>
          <tr>
            <td style="text-align:center">{{row.f_userinfo_code}}</td>
            <td style="text-align:center">{{row.f_user_name}}</td>
            <td style="text-align:center">{{row.f_address}}</td>
            <td style="text-align:center">{{row.f_meternumber}}</td>
            <td style="text-align:center">{{row.f_tablebase}}</td>
            <!--<td style="text-align:center">{{row.f_last_tablebase}}</td>-->
            <!--<td style="text-align:center">{{(row.f_tablebase-row.f_last_tablebase).toFixed(2)}}</td>-->
            <td style="text-align:center;width: 170px;">{{row.f_hand_date}}</td>
            <td style="text-align:center">
              <img :title='row.f_signal' v-if="row.f_signal>-80" src="../../../static/WebMetericon/Signal1.png"
                   height="24" width="50"/>
              <img :title='row.f_signal' v-if="row.f_signal>-100&&row.f_signal<=-80"
                   src="../../../static/WebMetericon/Signal2.png"
                   height="24" width="50"/>
              <img :title='row.f_signal' v-if="row.f_signal>-120&&row.f_signal<=-100"
                   src="../../../static/WebMetericon/Signal3.png"
                   height="24" width="50"/>
              <img :title='row.f_signal' v-if="row.f_signal<=-120" src="../../../static/WebMetericon/Signal4.png"
                   height="24"
                   width="50"/>
            </td>
            <td style="text-align:center">
              <img :title='row.f_batterylevel' v-if="row.f_batterylevel>=6.00"
                   src="../../../static/WebMetericon/Cell1.png" height="24"
                   width="50"/>
              <img :title='row.f_batterylevel' v-if="row.f_batterylevel>=5.65&&row.f_batterylevel<6.00"
                   src="../../../static/WebMetericon/Cell2.png" height="24" width="50"/>
              <img :title='row.f_batterylevel' v-if="row.f_batterylevel>=5.30&&row.f_batterylevel<5.65"
                   src="../../../static/WebMetericon/Cell3.png" height="24" width="50"/>
              <img :title='row.f_batterylevel' v-if="row.f_batterylevel>=4.95&&row.f_batterylevel<5.30"
                   src="../../../static/WebMetericon/Cell4.png" height="24" width="50"/>
              <img :title='row.f_batterylevel' v-if="row.f_batterylevel>=4.60&&row.f_batterylevel<4.95"
                   src="../../../static/WebMetericon/Cell5.png" height="24" width="50"/>
              <img :title='row.f_batterylevel' v-if="row.f_batterylevel<4.6"
                   src="../../../static/WebMetericon/Cell6.png" height="24"
                   width="50"/>
            </td>
            <!--<td style="text-align:center;width: 51px">-->
            <!--<span v-if="row.f_magneticinterference==1" style="color: #ff0005;font-weight:900;">故障</span>-->
            <!--<span v-if="row.f_magneticinterference==0" style="color: #000000;">正常</span>-->
            <!--</td>-->
            <!--<td style="text-align:center;width: 51px">-->
            <!--<span v-if="row.f_alarmshutvalve==1" style="color: #ff0005;font-weight:900;">关阀</span>-->
            <!--<span v-if="row.f_alarmshutvalve==0" style="color: #000000;">正常</span>-->
            <!--</td>-->
            <!--<td style="text-align:center;width: 51px">-->
            <!--<span v-if="row.f_cycleshutvalue==1" style="color: #ff0005;font-weight:900;">关阀</span>-->
            <!--<span v-if="row.f_cycleshutvalue==0" style="color: #000000;">正常</span>-->
            <!--</td>-->
            <!--<td style="text-align:center;width: 51px">-->
            <!--<span v-if="row.f_overcurrentprotection==1" style="color: #ff0005;font-weight:900;">关阀</span>-->
            <!--<span v-if="row.f_overcurrentprotection==0" style="color: #000000;">正常</span>-->
            <!--</td>-->
            <!--<td style="text-align:center;width: 51px">-->
            <!--<span v-if="row.f_leakageflag==1" style="color: #ff0005;font-weight:900;">走气</span>-->
            <!--<span v-if="row.f_leakageflag==0" style="color: #000000;">正常</span>-->
            <!--</td>-->
            <!--<td style="text-align:center;width: 51px">-->
            <!--<span v-if="row.f_splitalarm==1" style="color: #ff0005;font-weight:900;">拆表</span>-->
            <!--<span v-if="row.f_splitalarm==0" style="color: #000000;">正常</span>-->
            <!--</td>-->
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  let readySomething = async function (self) {
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString() + ' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString() + ' 23:59:59'
    await self.$refs.paged.$refs.cri.search()
  }
  export default {
    title: '阀控',
    name: "ValveControl",
    data() {
      return {
        filialeNameStr: null,
        filialeCodeStr: this.$login.f.f_orgids,
        userid: this.$login.f.id,
        source:`tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() != $role$))`,
        model: new PagedList("rs/sql/getValveMeterBrandAndModel", 30)
      }
    },
    ready() {
      readySomething(this).then(() => {
        this.$emit('ready')
    }).catch((error) => {
        this.$emit('error', error)
    })
    },
    methods: {
      search() {
        console.log("this.$parent===", this.$parent)
        this.$parent.showItem = false
        this.$refs.paged.$refs.cri.search()
      },
      getRes(obj) {
        this.filialeNameStr = obj.res
        this.filialeCodeStr = obj.resids
      },
      async selfSearch (args) {
    console.log("this.$parent=2222==", this.$parent)
        this.$parent.showItem = false
        let f_orgstr = this.filialeCodeStr
        console.log('xxxx',f_orgstr)
        args.condition =  `${args.condition} and u.f_orgstr like '${f_orgstr}%'`
        // args.condition =  `${args.condition}`
        console.log('我的阐述',JSON.stringify(args.condition))
        await this.model.search(args.condition, args.model)
        }
    },
  computed: {
      metertypes () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
      }
    }
  }
</script>
