<template>
	<view class="address-wrap">
		<w-navbar title="收货地址"></w-navbar>
		<view class="body" v-if="hasAdderss">
			<w-address @editSite="toAddSite" :info="info" :is-default="true" />
		</view>
	</view>
</template>

<script>
const app = getApp();
export default {
	data() {
		return {
			background: {
				backgroundColor: 'none'
			},
			info: {
				name: '',
				mobile: '',
				address: '',
				region: [],
			},
		};
	},
	computed: {
		editPen() {
			return process.uniEnv.qn_base_url + 'icon/edit-pen.png'
		},
		hasAdderss() {
			return this.info.address
		},
		addressInfo() {
			return {
				name: this.name,
				mobile: this.mobile,
				address: this.address,
				region: this.region || [],
			}
		}
	},
	onLoad() {
		getApp().trackPage('我的收获地址页')
	},
	onShow() {
		if(this.$u.test.isEmpty(this.vuex_token)) {
			this.$u.route({url: 'pages/login/index'})
		}
		this.getData();
	},
	methods: {
		getData() {
			this.getMineSite()
		},
		getMineSite() {
			this.$u.api.getSiteAddress().then((res) => {
				const data = res.data
				if(res.code == 200 && !this.$u.test.isEmpty(data)) {
					let region = []
					if(data.provinceName && data.cityName && data.districtName) {
						region = [data.provinceName, data.cityName, data.districtName]
					}
					this.info = {
						name: data.name,
						mobile: data.mobile,
						address: data.address,
						region: region,
					}
				}
			})
		},
		toAddSite(title){
			const region = this.info.region.join('-')
			this.$u.route({
				url: 'pages/mine/address/addSite',
				params: {
					type: 'edit',
					region: region,
					name: this.info.name,
					mobile: this.info.mobile,
					address: this.info.address,
				}
			})
		}
	}
};
</script>

<style lang="scss" scoped>
.address-wrap {
	background-color: #F4F5F7;
}
.body {
	padding: 30rpx;
	margin: 30rpx;
	border-radius: 12rpx;
	background-color: #FFFFFF;
}
</style>
