<template>
  <div style="widows: auto;">
    <criteria-paged :model="model" v-ref:paged :pager="false">
      <criteria partial='criteria' @condition-changed='$parent.selfsearch' v-ref:cri>
        <div novalidate class="select-overspread form-horizontal auto" partial>
          <div class="col-sm-3 form-group" style="padding-right: 5px">
            <input  type="text" class="form-control" v-model="model.f_residential_arearea"
                    condition="f_residential_area like '%{}%'" placeholder="小区"/>
          </div>
          <div class="col-sm-3 form-group" style="padding-right: 5px">
            <input  type="text" class="form-control" v-model="model.f_building"
                    condition="f_building like '%{}%'" placeholder="楼号"/>
          </div>
          <div class="col-sm-3 form-group" style="padding-right: 5px">
            <input  type="text" class="form-control" v-model="model.f_unit"
                    condition="f_unit like '%{}%'" placeholder="单元"/>
          </div>
          <div class="col-sm-3 form-group" style="padding-right: 5px">
            <input  type="text" class="form-control" v-model="model.f_floor"
                    condition="f_floor like '%{}%'" placeholder="楼层"/>
          </div>
          <div class="col-sm-3 form-group" style="padding-right: 5px">
            <input  type="text" class="form-control" v-model="model.f_room"
                    condition="f_room like '%{}%'" placeholder="门牌号"/>
          </div>
          <div class="col-sm-6 form-group" style="padding-right: 5px">
            <input  type="text" class="form-control" v-model="model.f_address"
                    condition="f_address like '%{}%'" placeholder="详细地址"/>
          </div>
          <div class="col-sm-3 form-group">
            <button class="btn btn-success width-80" @click="search()" >查询</button>
            <button class="btn btn-success" @click="$parent.$parent.clear()">清空</button>
          </div>
        </div>
      </criteria>

      <data-grid  :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th><nobr>序号</nobr></th>
            <th><nobr>详细地址</nobr></th>
            <th><nobr>操作</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center"><nobr>{{$index+1}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_address}}</nobr></td>
            <td style="text-align:center">
              <button v-if="row.f_useraddress_id" type="button" name="button" class="btn btn-link" @click.stop="$parent.$parent.$parent.create(row)">修正</button>
              <button v-else type="button" name="button" class="btn btn-link" @click.stop="$parent.$parent.$parent.create(row)">建档</button>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  let readySync = async function (self) {
    return await self.$refs.paged.$refs.cri.search()
  }
  export default {
    data () {
      return {
        model: new PagedList('rs/sql/address_files',30,{orderitem: `'f_create_date desc'`}),
        //分公司id串
        f_filialeids: this.$login.f.f_orgids,
      }
    },
    ready(){
      readySync(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      selfsearch(args){
        //添加分公司查询条件
        args.condition =  `${args.condition} and f_filialeids = '${this.f_filialeids}'`
        console.log(args)
        //执行查询
        this.model.search(args.condition, args.model, args.condValue)
      },
      //清空
      clear(){
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = ''
        })
      },
      create(row){
        //发出事件,用于建档或修正档案
        this.$dispatch('buildfiles',row)
      }
    }
  }
</script>
