<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" partial>
            <div class="form-group" style="flex: 1;">
              <input type="text" class="input_search" style="width:60%" v-model="model.f_area_address"
              condition="f_area_address 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>
              <button type="button" name="button" class="btn btn-link" @click.stop="$parent.$parent.$parent.$parent.foundAddress(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/getArea', 500, {orderitem: '"a.id desc"'})
    }
  },
  ready () {
    this.search({condition: '1=1'})
  },
  methods: {
    foundFile (row) {
      this.$GetSaleParam.GetInstallman()
      this.$GetSaleParam.getGasman()
      this.$dispatch('bulid-files', '小区批量建档', row)
    },
    foundAddress (row) {
      this.$dispatch('bulid-address', '地址管理', row)
    },
    search (obj) {
      obj.condition += ` and a.f_filialeids  =  '${this.$login.f.f_orgids}'`

      this.$refs.pv.load('rs/sql/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.$login.f.f_orgids}'`
      this.model.search(datas.condition, this.model)
    },
    // 主要提供外部组件调用，刷新数据
    reflash () {
      this.$refs.paged.$refs.criteria.search()
    }
  }
}
</script>
