<template>
  <div style="width: auto;">
    <partial-view v-ref:pv @condition-changed="selfSearch">
      <criteria-paged :model="model" v-ref:paged :pager="false">
        <criteria partial='criteria' v-ref:criteria>
          <div novalidate class="flex-row auto" partial>
            <div class="form-group" style="flex: 1;">
              <input type="text" class="form-control" v-model="model.f_residential_area"
                     condition="f_residential_area like '%{}%'" placeholder='小区名称'>
            </div>
            <div class="form-group" style="margin-right: 0px;" id='filesArea'>
              <button class="btn btn-success width-100" @click="search()">查询</button>
            </div>
          </div>
        </criteria>
        <data-grid :model="model" partial='list' v-ref:grid >
          <template partial='head'>
            <tr>
              <th>序号</th>
              <th>小区详细地址</th>
              <th>操作</th>
            </tr>
          </template>
          <template partial='body'>
            <td id = "1" style="text-align: center;">{{$index + 1}}</td>
            <td>{{row.f_area_address}}</td>
            <td style="text-align: center;">
              <button type="button" name="button" class="btn btn-link" @click.stop="$parent.$parent.$parent.$parent.foundFile(row)">建档</button>
            </td>
          </template>
        </data-grid>
      </criteria-paged>
    </partial-view>
  </div>
</template>

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

  export default {
    title: '小区列表',
    data () {
      return {
        model: new PagedList('rs/sql/address_getArea', 500, {orderitem: '"a.id desc"'})
      }
    },
    props: ['f_filialeid'],
    ready () {
      this.search({condition: '1=1'})
    },
    methods: {
      foundFile (row) {
        console.log('小区建档', row)
        this.$emit('re-ref', row)
      },
      search (obj) {
        obj.condition += ` and a.f_filialeids  =  '${this.f_filialeid}'`

        this.$refs.pv.load('rs/sql/address_getArea', {data: {orderitem: 'a.id desc', condition: obj.condition}}).then((a) => {
          if (a.data.length === 0) {
          this.model.state = '错误'
          this.model.error = '没有相关的小区信息'
        } else {
          this.model.state = '正确'
          this.model.rows = a.data
        }
        this.$emit("ready")
      })
      },
      selfSearch (datas) {
        datas.condition += ` and a.f_filialeids = '${this.f_filialeid}'`
        this.model.search(datas.condition, this.model)
      },
      // 主要提供外部组件调用，刷新数据
      reflash () {
        this.$refs.paged.$refs.criteria.search()
      }
    }
  }
</script>
