<template>
  <div class="flex" >
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.search' v-ref:cri>
        <div novalidate class="form-inline" partial>
          <div >
            <input  type="number" class="form-control" v-model="model.f_userinfo_id" placeholder='客户编号'
                    condition="f_userinfo_id = '{}'" v-next-el='yhxm'
                    :size="model.f_userinfo_id ? model.f_userinfo_id.length  : 4">
          </div>
          <div >
            <input  type="text" class="form-control" v-model="model.f_user_name" placeholder='客户名称'
                    condition="f_user_name like '%{}%'" v-next-el='resentialarea' v-el:yhxm
                    :size="model.f_user_name ? model.f_user_name.length  : 4">
          </div>
          <div >
            <input type="text" class="form-control" v-model="model.f_area" placeholder='区域'
                   condition="f_area like '%{}%'" v-el:xq v-next-el='cx' v-el:resentialarea
                   :size="model.f_area ? model.f_area.length : 2">
          </div>
          <div >
            <input  type="text" class="form-control" v-model="model.f_address" placeholder='客户地址'
                    condition="f_address like '%{}%'" v-next-el='cx' v-el:resentialarea
                    :size="model.f_address ? model.f_address.length * 2 : 4">
          </div>
          <div >
            <input  type="text" class="form-control" v-model="model.f_meterbook_id" placeholder='表册号'
                    condition="f_meterbook_id = '{}'"
                    :size="model.f_meterbook_id ? model.f_meterbook_id.length : 2">
          </div>
          <div >
            <button class="btn btn-success" @click="search()" v-el:cx>查询</button>
          </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>
          </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/singleTableOrderBy_WithView', 50, {orderitem: '"' + this.orderitem + '"',
          items: '"' + this.items + '"',
          tablename: '"' + this.tablename + '"'})
      }
    },
    props: {
      orderitem: {
        type: String,
        default: 'f_userinfo_id'
      },
      tablename: {
        type: String,
        default: 'V_user_table'
      },
      items: {
        type: String,
        default: "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"
      }
    },
    ready () {
      this.search({condition: '1=1', model: this.model})
    },
    methods: {
      // search () {
      //   this.$refs.paged.$refs.criteria.search()
      // },
      search (args) {
        args.condition = `${args.condition} and f_user_state = '正常'`
        if (!this.$login.f.parent.parent.name.includes('统一资源管理')) {
          args.condition = `${args.condition} and f_filialeids = '${this.$login.f.f_orgids}'`
        }
        this.model.search(args.condition, args.model)
      },
      defined () {
        this.definedShow = true
      },
      close () {
        this.definedShow = false
      }
    }
  }
</script>
