<template>
  <div class="span">
    <criteria-paged :model="model" v-ref:paged :pager="!row && !newArea && !areainfo" @sort="sort">
      <criteria partial='criteria' v-ref:criteria @condition-changed="$parent.selfSearch">
        <div novalidate class="form-inline auto" partial>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_userinfo_id"
                   condition="u.f_userinfo_id='{}'" placeholder='客户编号'
                   :size="model.f_userinfo_id ? model.f_userinfo_id.length : 4">
          </div>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_user_name"
                   condition="u.f_user_name = '{}'" placeholder='用户姓名'
                   :size="model.f_user_name ? model.f_user_name.length * 2 : 4">
          </div>
          <div class="form-group">
            <button class="btn btn-success" @click="$parent.$parent.search()">查询</button>
          </div>
        </div>
      </criteria>
      <div  partial='list'>
        <data-grid :model="model" 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 style="text-align: center;">{{$index + 1}}</td>
            <td style="text-align: center;">{{row.f_userinfo_id}}</td>
            <td style="text-align: center;">{{row.f_user_name}}&nbsp;&nbsp;{{row.f_user_phone ? row.f_user_phone : ''}}</td>
            <td style="text-align: center;">{{row.f_address_detail ? row.f_address + row.f_address_detail : row.f_address}}</td>
            <td style="text-align: center;">{{row.f_user_state}}</td>
            <td style="text-align: center;">
              <button class="btn btn-link" @click="$parent.$parent.$parent.selected(row)">收费</button>
            </td>
          </template>
        </data-grid>
      </div>
    </criteria-paged>
  </div>
</template>

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

  export default {
    data () {
      return {
        model: new PagedList('rs/sql/getInfoForUser', 50)
      }
    },
    ready () {
      this.search()
    },
    methods: {
      search () {
        if (this.$login.f.parent.orgtype !== '总公司') {
          this.$refs.paged.$refs.criteria.model.f_filialeids = [this.$login.f.f_orgids]
        }
        console.log('点击事件，，，，')
        this.$dispatch('research')
        // this.$refs.paged.$refs.criteria.search()
      },
      selfSearch (args) {
        // 如果隶属总公司，不加任何判断
        if (!this.$login.f.parent.parent.name.includes('统一资源管理') && this.$login.f.parent.orgtype !== '总公司') {
          args.condition = `${args.condition} and u.f_filialeids = '${this.$login.f.f_orgids}'`
        }
        this.model.search(args.condition, args.model)
      },
      selected (row) {
        this.$dispatch('selected', {f_userinfo_id: row.f_userinfo_id, f_balance: row.f_balance, f_real_balance: row.f_real_balance, f_curbalance: row.f_curbalance})
      }
    }
  }
</script>
