<template>
  <div class="flex" style="flex: 1;">
    <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="form-group col-sm-4">
              <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="form-group col-sm-4">
              <label class="font_normal_body">客户编号</label>
              <input  type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_code" placeholder='客户编号'
                      condition="f_userinfo_code = '{}'">
            </div>
            <div class="span" style="float:right;">
              <button class="button_search button_spacing" @click="search()">查询</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-show="$parent.$parent.criteriaShow">
            <div class="form-group col-sm-4">
              <label class="font_normal_body">客户名称</label>
              <input  type="text" style="width:60%" class="input_search" v-model="model.f_user_name" placeholder='客户名称'
                      condition="f_user_name like '%{}%'">
            </div>
            <div class="form-group col-sm-4">
              <label class="font_normal_body">客户地址</label>
              <input  type="text" style="width:60%" class="input_search" v-model="model.f_address" placeholder='客户地址'
                      condition="f_address 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>
          </tr>
        </template>
        <template partial='body'>
          <td>{{$index+1}}</td>
          <td style="text-align:center">{{row.f_user_name}}</td>
          <td style="text-align:center">{{row.f_user_id}}</td>
          <td style="text-align:center">{{row.f_meter_brand}}</td>
          <td style="text-align:center">{{row.f_meter_style}}</td>
          <td style="text-align:center">{{row.f_totalsplit_type}}</td>
        </template>
      </data-grid>
    </criteria-paged>
    <user-defined-message :show="definedShow" v-ref:printbill v-on:toggle="close"></user-defined-message>
  </div>
</template>

<script>
  /**
   *阶梯水价查询列表
   */
  import { PagedList } from 'vue-client'

  export default {
    data () {
      return {
        model: new PagedList('rs/sql/getUserAndMeter', 30, {items: '"f_user_name, f_user_id, f_meter_brand, f_meter_style, case when f_totalsplit_type is null then \'分表\' else f_totalsplit_type end f_totalsplit_type"'}),
        criteriaShow: false,
        curorgid: [this.$login.f.orgid],
        f_filialeid: this.$login.convertToIn(this.$login.f.orgid)
      }
    },
    ready () {
      this.search()
    },
    methods: {
      getorg (val) {
        this.f_filialeid = this.$login.convertToIn(val)
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      clear () {
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch (args) {
        if (this.f_filialeid) {
          args.condition = `f_filialeid in ${this.f_filialeid} and ${args.condition}`
        }
        console.log('----------2222222---------------')
        console.log(args)
        console.log('------------22222222-------------')
        this.model.search(args.condition, args.model)
      },
      defined () {
        this.definedShow = true
      },
      close () {
        this.definedShow = false
      }
    }
  }
</script>
