<template>
	<view class="content">
		<oct-address
			:lists="addressList"
			:pattern="true"
			:isEdit="edit"
			editColor="#34CE98"
			:btnStyle="{'backgroundColor': '#34CE98'}"
			@onAddress="onInfo"
			@onAdd="$Router.push({name: 'AddressEdit'})"
		/>
		<!--  -->
	</view>
</template>

<script>
	import { list } from '@/apis/interfaces/address'
	export default {
		data() {
			return {
				edit	   : true,
				addressList: []
			};
		},
		onShow(){
			this.edit = this.$Route.query.type === 'edit'
			
			list().then(res => {
				this.addressList = res
			})
		},
		methods: {
			onInfo(val){
				if(this.edit){
					this.$Router.push({
						name	: 'AddressEdit',
						params	: {
							id	: val.address_id
						}
					})
				}else{
					this.$store.commit('setAddress', val)
					this.$Router.back()
				}
			}
		}
	};
</script>

<style lang="scss">
	.content{
		background: #F3F6FB;
		overflow: hidden;
		min-height: 100vh;
	}
</style>
