<template>
  <div id="unit" class="flex-row">
    <div :class="{'basic-main':!useraddressShow,'binary-left':useraddressShow}" v-show="isSelect">
      <file-address-list @select-changed="selected" v-ref:addresslist :style="style" :select=select :company=company :f_filialeids.sync="f_filialeids" :isedites="isedites"></file-address-list>
    </div>
    <div v-show="useraddressShow"  :class="{'basic-main':!isSelect, 'binary-right': isSelect}">
      <div class="flex">
        <file-user-address :f_filialeids.sync="f_filialeids" :is_pecial="isSpecial" :isedit="isSelect" :row="row" v-ref:fileuseraddress></file-user-address>

        <file-user-address-change v-if="addressId" :address_id="addressId"></file-user-address-change>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    title: '地址管理',
    components: {
    },
    data () {
      return {
        // 分公司id串
        f_filialeids: this.$login.f.orgid,
        area: [],
        street: [],
        residential: [],
        useraddressShow: false,
        addressId: null,
        row: {},
        isSpecial: false
      }
    },
    props: {
      isSelect: {
        type: Boolean,
        default: false
      },
      fileinfo: {
        type: Object,
        default: {}
      },
      company: {
        type: String,
        default: ''
      },
      showselectaddress: {
        type: Boolean,
        default: false
      },
      isedites: {
        type: Boolean,
        default: false
      }
    },
    watch: {
      'showselectaddress' (val) {
        this.refresh()
        if (val && !this.isSelect) {
          this.initData(this.fileinfo)
        }
      }
    },
    methods: {
      selected () {
      },
      refresh () {
        this.addressId = null
        this.useraddressShow = false
        this.$refs.addresslist.$refs.paged.$refs.cri.search()
      },
      initData (val) {
        if (val.f_address) {
          this.useraddressShow = true
          this.addressId = val.id
          this.row = Object.assign({}, this.row, val)
        } else {
          this.useraddressShow = false
        }
      }
    },
    events: {
      'add' (val) {
        this.useraddressShow = true
        // true为新增特殊地址
        this.$refs.fileuseraddress.cleardara()
        this.addressId = null
        // true为新增特殊地址
        if (val != '民用') {
          // 非民用
          this.$refs.fileuseraddress.usertype = true
          this.$refs.fileuseraddress.onedata = 'one'
        } else {
          this.$refs.fileuseraddress.usertype = false
        }
        this.$refs.fileuseraddress.operation = 'add'
        this.$refs.fileuseraddress.pcdslist = []
        this.$refs.fileuseraddress.streetslist = []
        this.$refs.fileuseraddress.areaslist = []
        this.$refs.fileuseraddress.initdata()
      },
      'confirm' () {
        this.addressId = null
        this.$refs.addresslist.$refs.paged.$refs.cri.search()
        this.useraddressShow = false
      },
      'cancel' () {
        this.addressId = null
        this.$refs.addresslist.$refs.paged.$refs.cri.search()
        this.useraddressShow = false
      }
    }
  }
</script>
<style>
</style>
