<template>
  <div id="unit" class="flex-row">
    <div :class="{'basic-main':!useraddressShow,'binary-left':useraddressShow}">
      <file-address-list @select-changed="selected" v-ref:addresslist :style="style" :select=select :company=company :f_filialeids.sync="f_filialeids"></file-address-list>
    </div>
    <div v-show="useraddressShow"  class="binary-right">
      <div class="flex">
        <file-user-address v-ref:useraddressmsg
                      :f_filialeids.sync="f_filialeids" :row="row"></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: [],
        row: {},
        useraddressShow: false,
        addressId: null,
        style:'col-sm-2 '
      }
    },
    props:{
      select: {
        type: Boolean,
        default: false
      }
      ,
      // company: {
      //   default: this.$login.f.orgid
      // }
      company:{
        type: String,
        default: ''
      }
    },
    methods:{
      selected(obj){
        this.style='col-sm-3 '
        if(obj.val&&obj.val.id){
          if (obj.val.f_filialeid != this.f_filialeids) {
            this.refresh()
            return
          }
          // 呼叫中心需要
          this.$dispatch('re-ref', obj.val)
          this.addressId=obj.val.id
          this.useraddressShow=true
          this.$refs.useraddressmsg.cleardara()
          this.$refs.useraddressmsg.initdata()
          this.$refs.useraddressmsg.usertype=obj.val.f_user_type
          this.$refs.useraddressmsg.operation='modify'
          this.$refs.useraddressmsg.onedata='one'
          this.$refs.useraddressmsg.model=Object.assign({},obj.val)
          if(obj.val.f_special=='1'){
            this.$refs.useraddressmsg.usertype = true
          }else{
            this.$refs.useraddressmsg.usertype = false
          }
          if (obj.val.f_slice_area) {
            this.$refs.useraddressmsg.model.slice_area = [{
              name: this.$refs.useraddressmsg.model.f_slice_area,
              code: this.$refs.useraddressmsg.model.f_area_code
            }]
          }
        }
      },
      refresh () {
        this.addressId=null
        this.useraddressShow = false
        this.$refs.addresslist.$refs.paged.$refs.cri.search()
      }
    },
    events:{
      'add'(val){
        this.style='col-sm-3 '
        this.useraddressShow = true
        this.$refs.useraddressmsg.cleardara()
        this.addressId=null
        //true为新增特殊地址
        if (val!='民用') {
          //非民用
          this.$refs.useraddressmsg.usertype = true
          this.$refs.useraddressmsg.onedata = 'one'
        }else{
          this.$refs.useraddressmsg.usertype = false
        }
        this.$refs.useraddressmsg.operation='add'
        this.$refs.useraddressmsg.pcdslist=[]
        this.$refs.useraddressmsg.streetslist=[]
        this.$refs.useraddressmsg.areaslist=[]
        this.$refs.useraddressmsg.initdata()
      },
      'confirm' () {
        this.style='col-sm-2 '
        this.addressId=null
        this.$refs.addresslist.$refs.paged.$refs.cri.search()
        this.useraddressShow = false
      },
      'modify'(area){
        this.style='col-sm-2 '
      },
      'cancel' () {
        this.style='col-sm-2 '
        this.addressId=null
        this.$refs.addresslist.$refs.paged.$refs.cri.search()
        this.useraddressShow = false
      },
    }
  }
</script>
<style>
</style>
