<template>
	<view class="edit-address">
		<AddressActive :info="address"></AddressActive>
		<u-popup v-model="popupShow" mode="center" border-radius="10">
			<view class="popup-tips">确定要删除该地址吗</view>
			<view class="popup-btn">
				<view class="cancel" @click="popupShow=false">取消</view>
				<view class="determine" @click="delAddress">确定</view>
			</view>
		</u-popup>
		<u-toast ref="uToast" />
	</view>
</template>
<script>
import AddressActive from '@/components/mine/address-active/index'
export default {
	data() {
		return {
			address: {},
			popupShow: false
		}
	},
	components: {
		AddressActive
	},
	onLoad(option) {
		// console.log(JSON.parse(option.item));
		this.address = JSON.parse(option.item);
	},
	onNavigationBarButtonTap() {
		this.popupShow = true
	},
	methods: {
		delAddress() {
			this.deleteAddress().then(() => {
				this.popupShow = false
			})
		},
		async deleteAddress() {
			this.$u.api.deleteAddress({
				address_id: this.address.address_id
			}).then((res)=>{
				if(res.errCode == 0) {
					uni.redirectTo({
						url: '/pageE/more/Address'
					});
					// this.$refs.uToast.show({
					// 	title: res.message,
					// 	type: 'success',
					// 	url: '/pageE/more/Address'
					// })
				} else {
					this.$refs.uToast.show({
						title: res.message,
						type: 'warning'
					})
				}
			})
		},
	},
}
</script>
<style lang="scss" scoped>
.edit-address {
	min-height: calc(100vh - var(--window-top));
	.popup-tips {
		width: 420rpx;
		text-align: center;
		line-height: 104rpx;
		font-size: 28rpx;
		color: rgba(102,102,102,1);
	}
	.popup-btn {
		width: 420rpx;
		display: flex;
		border-top: 2rpx solid #ECECEC;
		> view {
			flex: 1;
			height: 98rpx;
			text-align: center;
			line-height: 98rpx;
			&:first-child {
				border-right: 2rpx solid #ECECEC;
			}
		}
		.determine {
			color: #FF780F;
		}
	}
}
</style>