<template>
  <avue-input-table :disabled="disabled" :props="props" :column="column" :formatter="formatter" :on-load="loadResidential" v-model="value" placeholder="请选择"></avue-input-table>
</template>

<script>

  import {getList} from "@/api/community/agency";

  export default {
    name: "select-dialog-agency",
    data(){
      return {
        column:{
          children:{
            border: true,
            column: [{
              label: '社区名称',
              search:true,
              prop: 'name'
            },
            {
              label: "所属省",
              prop: "regionProvince",
            },
            {
              label: "所属市",
              prop: "regionCity",
            },
            {
              label: "所属区",
              prop: "regionArea",
            },
            {
              label: "所属街道",
              prop: "regionStreet",
            },
            {
              label: "详细地址",
              search: true,
              prop: "address",
              },
            ],
          },
        },
        props: {
          label: 'name',
          value: 'id'
        },
        value: '0'
      }
    },
    props: {
      callback: {
        type: Function
      },
      id: {
        type: String
      },
      name: {
        type: String
      },
      disabled: {
        type: Boolean,
        default: false
      },
    },
    methods: {
      formatter(row){
        if(!row.name) return '';
        if (row.name && this.callback){
          this.callback(row)
        }
        return row.name
      },
      loadResidential({ page, value, data }, callback){
        if (value) {
          callback({
            id: this.id,
            name: this.name,
          })
          return
        }
        //分页查询信息
        getList(page.currentPage, page.pageSize, data).then(res => {
          var data = res.data.data;
          callback({total: data.total, data: data.records});
        })
      },
    }
  }
</script>

<style scoped>

</style>
