<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="content">
				我的地址
			</block>
			<block slot="right">
				<view class="" style="color: #000000; font-size: 26rpx; margin-right: 40rpx;" @tap="jumpAddress()">
					新增地址
				</view>
			</block>
		</cu-custom>
		<view class="" style="margin-top: 15rpx;">
		</view>
		<view class="padding " v-for="(item,index) in myAddresses" :key="index" @click="chooseAddress(item)"
			style="border-bottom: #F3F3F3 1rpx solid; background-color: #FFFFFF;">
			<view class="flex justify-between align-center">
				<view class="flex-direction">
					<view class="" style="font-size: 31rpx;color: #111111;font-weight: bold;">
						{{item.address+item.detailed}}
					</view>
					<view class="flex align-center" style="color: #999999;margin-top: 10rpx;">
						<view class="">
							{{item.name}}
						</view>
						<view class="" style="margin-left: 30rpx;">
							{{item.phone}}
						</view>
					</view>
				</view>
				<view @click.stop="jumpUpdateAddress(item)">
					<image src="../../../static/edit_2x.png" mode="" style="width: 32rpx; height: 32rpx;"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				///1.地址列表
				myAddresses: [],
			}
		},
		onShow() {
			this.getAddressList();
		},
		methods: {
			chooseAddress(item) {
				console.log(item)
				uni.setStorageSync('address', item)
				uni.navigateBack({
					delta: 1
				})
			},
			///1.获取地址列表
			getAddressList() {
				const param = {
					memberId: uni.getStorageSync('userInfo').memberId , //会员id
					merchantId: '1' //商家id
				}
				this.$u.api.addressList(param).then(res => {
					console.log(res, 'resresres')
					if (res.code == 200) {
						this.myAddresses = res.data.addressList
					}
				})

			},
			///2.跳转到地址编辑
			jumpUpdateAddress(obj) {
				uni.navigateTo({
					url: "/pages/mine/minePage/updateAddress?addressInfo=" + JSON.stringify(obj),
				});
			},
			jumpAddress() {
				uni.navigateTo({
					url: "/pages/mine/minePage/updateAddress"
				});
			},

		}
	}
</script>

<style>

</style>
