<template>
  <div class="mine-address">
    <div class="mine-address-top">
      <WaybillAddress
        class="address-item"
        v-for="address in addressListFilter"
        :key="address.id"
        :address="address"
        @on-pick="handlePick"
        @on-edit="goEdit"
        :isManager="true"
      ></WaybillAddress>
    </div>
    <div
      class="mine-address-bottom"
      @click="toCreateAddress"
    >
      新建收货地址
    </div>
  </div>
</template>

<script>
import { mapActions, mapGetters, mapMutations } from 'vuex'
// import WaybillAddress from '@/components/addressCmp/waybill-address.vue'
import WaybillAddress from '../addressCmp/waybill-address.vue'
import { errToast,jumpPage } from '@/utils/uniapi.js'
export default {
  // props: {
  //   manager: {
  //     type: Boolean,
  //     default: false
  //   }
  // },
  components: {
    WaybillAddress
  },
  data() {
    return {
      isManager: false,
      addressListFilter: []
    }
  },
  async onShow() {
    try {
      await this.getAddressList()
      let arr = this.addressList || []
      this.addressListFilter = arr.filter(item => item.detailAddress !== '自提订单：详细地址')
    } catch (e) {
      console.error(e)
      errToast(e)
    }
  },
  onLoad(query) {
    let { isManager = false } = query
    this.isManager = isManager
    // console.log('isManager', isManager)
  },
  computed: {
    ...mapGetters({
      addressList: 'addressVue/addressList'
    })
  },
  methods: {
    ...mapActions({
      getAddressList: 'addressVue/getList'
    }),
    ...mapMutations({
      storeWaybillAd: 'addressVue/storeWaybillAd'
    }),
    toCreateAddress() {
      jumpPage('navigateTo','/pagesAddress/create-address/index')
    },
    // 选择地址
    handlePick(address) {
      console.log(address)
      if (this.isManager) {

      } else {
        // 存储地址
        this.storeWaybillAd([address])
        uni.navigateBack({ delta: 1 })
      }
    },
    // 跳转到编辑页面
    goEdit(address) {
      jumpPage('navigateTo',`/pagesAddress/edit-address/index?address=${encodeURIComponent(JSON.stringify(address))}`)
    }
  }
}
</script>

<style lang="scss">
@import "./mine-address.scss";
</style>