<template>
  <div class="auto select-overspread">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-3" >
              <label class="font_normal_body">客户编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code" placeholder='客户编号'
                     condition="f_userinfo_code = '{}'" @keyup.enter="search()">
            </div>
            <div class="form-group col-sm-2 button-range" >
              <button class="button_search" style="margin-right: 10px"  @click="search()" v-el:cba>查询</button>

            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" class="table_sy"  partial='list' 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>

          </tr>
        </template>
        <template partial='body' >
          <tr >
            <td style="text-align:center;">{{$index+1}}</td>
             <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_user_phone}}</td>
            <td style="text-align:center">{{row.f_address}}</td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

export default {
  title: '安检记录列表',
  props: ['row'],
  data () {
    return {
      rowdata: this.row,
      model: new PagedList('rs/sql/getUserByCheckBook', 50)
    }
  },
  ready(){
    if(this.row){
      let condition=''
      if(this.row.f_check_book_type1=='小区'){
        this.model.url = 'rs/sql/getUserByCheckBook'
        condition  = `ta.f_check_book_id =${this.row.f_check_book_id} and ta.id=${this.row.id}`
      }else{
        this.model.url = 'rs/sql/getUserByCheckBookCompany'
        condition  = `tc.f_check_book_id =${this.row.f_check_book_id} and tc.id=${this.row.id}`
      }
      this.model.search(condition)
      //只显示用户页面
      this.row.f_check_book_type='用户'
    }
  },
  watch: {
    'row' (val) {
      if (val) {
        this.rowdata = val
        let condition=''
        if(this.row.f_check_book_type1=='小区'){
          condition  = `ta.f_check_book_id =${val.f_check_book_id} and ta.id=${val.id}`
        }else{
          condition  = `tc.f_check_book_id =${val.f_check_book_id} and tc.id=${val.id}`
        }
        this.model.search(condition)
      }
    }
  },
  methods: {
    selfSearch (args) {
      if (this.rowdata.id) {
        if(this.rowdata.f_check_book_type1=='小区'){
          args.condition += `and ta.f_check_book_id =${this.rowdata.f_check_book_id} and ta.id=${this.rowdata.id}`
        }else{
          args.condition += `and tc.f_check_book_id =${this.rowdata.f_check_book_id} and tc.id=${this.rowdata.id}`
        }
        this.model.search(args.condition)
      } else {
        this.$showMessage('请选择片区')
      }
    }
  }
}
</script>
