<script setup>
	// 
	import util from '@/common/js/util.js'
	// 
	import {
		ref,
		reactive,
		computed,
		watch,
		onMounted,
		onUnmounted,
		defineEmits,
	} from 'vue'

	const props = defineProps({
		shopEdit: {
			type: Boolean,
			default: true
		},
		address: {
			type: Object,
			default: () => ({})
		}
	})
	// 
	const emit = defineEmits(['update:address'])

	onMounted(() => {
		// 开启监听
		addListener()
	})

	onUnmounted(() => {
		console.log('onUnmounted')
		// 移除监听
		removeListener()
	})

	// 开启监听
	function addListener() {
		// 选择收货地址
		uni.$on('selectAddress', (event) => {
			console.log('selectAddress', event)
			emit('update:address', event);
		})
	}

	// 移除监听
	function removeListener() {
		console.log('off selectAddress')
		// 移除收货地址
		uni.$off('selectAddress')
	}

	// 跳转
	function link(url) {
		uni.navigateTo({
			url
		})
	}
</script>

<template>
	<view class="address df fdr aic jcc" v-if="address.id">
		<!-- 图标 -->
		<view class="icon mr20">
			<image class="wh45" src="/static/address.png" mode="aspectFill" />
		</view>

		<!-- 收获地址 姓名电话 -->
		<view class="info f1">
			<!-- 收获地址 -->
			<view class="location">
				<text class="c333 f30">{{address.province}}{{address.city}}{{address.country}}{{address.detail}}</text>
			</view>
			<!-- 姓名电话 -->
			<view class="name">
				<text class="c999 f26">{{address.name}} {{address.mobile}}</text>
			</view>
		</view>

		<!-- 选择地址 -->
		<view v-if="shopEdit" class="button btn ti plr20 ml20"
			@click="link('/pages/mine/address/index?select=1&addressId='+address.id)">
			<text class="text">选择地址</text>
		</view>
	</view>

	<view class="fmid" @click="link('/pages/mine/address/index?select=1')" v-else>
		<text class="c999 f28">暂无默认地址</text>
		<uni-icons type="right" color="#999" size="30rpx" />
	</view>
</template>

<style lang="scss" scoped>
	// 
	.button {
		border: 2rpx solid #FF9B27;

		.text {
			font-size: 24rpx;
			color: #FF9B27;
		}
	}
</style>