<template>
	<view class="contentV">
		<customNav :shownav="true" :title="$t('index.changydz')" titledetl=""></customNav>
		<view v-if="userAddr!=''" class="contentColumn newaddrcvt">
			<text class="addrV" style="margin: 20rpx;font-size: 30rpx;">{{userAddr.name}}</text>
			<text class="addrV" style="margin: 20rpx;font-size: 28rpx;">{{userAddr.address}}</text>
			<view class="contentInRowS" style="margin: 20rpx;">
				<view class="contentInRowC newaddract" style="background-color: #00A6FF;" @click="addadr">
					<text>{{$t('index.tianjiashdz')}}</text>
				</view>
				<view class="contentColumnC newaddract" style="background-color:black;" @click="addrselect">
					<text>{{$t('index.yihouzais')}}</text>
				</view>
			</view>
		</view>
		<view class="contentColumn" style="margin-bottom: 120rpx;">
			<view v-for="item in addrList">
				<view class="itemView"  @click="selectAddr(item)">
					<view class="textView">
						<text class="addrV textfontB4">{{item.area}}</text>
						<text class="addrV textfontB5">{{item.address}}</text>
						<text class="nameph">{{item.name}}: {{item.phone}}</text>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 10rpx;"></view>
		<view class="addbtV">
			<view class="addbt" @click="newdizhi">{{$t('index.qitadizhi')}}</view>
		</view>
		
	</view>
</template>

<script>
	import api from "@/pages/api/api.js";
		export default {
		data() {
			return {
				addrList:[],
				isNewAddr:false,
				userAddr:''
			}
		},
		onShow() {
			if(this.isNewAddr){
				this.gettempLocate();
				this.isNewAddr=false;
			}
			this.getaddressList();
		},
		methods: {
			newdizhi(){
				this.isNewAddr=true;
				uni.redirectTo({
					url:'/pages/UserCenter/map/map?state=0'
				})
			},
			gettempLocate(){
				uni.setStorageSync('tempLocation','');
				var data = uni.getStorageSync("userAddrLocation");
				if(''==data || undefined==data || null==data){
					return;
				}
				else{
					this.userAddr=data;
					uni.setStorageSync('userAddrLocation',"");
					uni.setStorageSync('tempLocation','');
					return;
				}
			},
			selectAddr(item){
				var addr={
					address:item.address, 
					name:item.area,
					longitude:item.longitude, 
					latitude:item.latitude, 
				}
				uni.setStorageSync('userAddrLocation',addr);
				uni.navigateBack();
			},
			
			getaddressList(){
				api('getaddressList',{
				},res=>{
					this.addrList=res.data.data;
				},failc=>{
					//console.log('getadvertis----',failc)
				})
			},
			addadr(){
				var token = uni.getStorageSync("token");
				if(''==token || undefined==token ||null==token){
					uni.navigateTo({
						url:'/pages/UserCenter/LoginView'
					})
					return;
				}
				uni.setStorageSync('tempLocation',this.userAddr);
				uni.navigateTo({
					url:'/pages/UserCenter/dizhi/newdizhi?id=-2'
				})
			},
			addrselect(){
				uni.setStorageSync('userAddrLocation',this.userAddr);
				uni.navigateBack();
			},
		}
	}
</script>

<style>
.contentV{
	width: 100%;
	position: relative;
	height: 90vh;
}
.newaddrcvt {
	width: 92%;
	margin-left: 4%;
	margin-top: 40rpx;
	margin-bottom: 20rpx;
	box-shadow: 0rpx 0rpx 10rpx 0rpx darkgray;
}

.newaddract{
	font-size: 26rpx;
	width: 43%;
	height: 80rpx;
	color: white;
	text-align: center;
}

.itemView{
	margin: 30rpx;
	padding: 30rpx;
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content:flex-start;
	border-radius: 20rpx;
	box-shadow: 0rpx 0rpx 10rpx 0rpx darkgray;
}

.textView{
	display: flex;
	flex-direction: column;
}

.addrV{
	color: black;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}
.nameph{
	font-size: 28rpx;
	color: darkslategray;
}

.addbtV{
	position: fixed;
	width: 100%;
	height: 120rpx;
	bottom: 0rpx;
	left: 0;
	background-color: whitesmoke;
}

.addbt{
	margin-left: 10%;
	margin-top: 20rpx;
	text-align: center;
	font-size: 36rpx;
	width: 80%;
	height: 80rpx;
	line-height: 80rpx;
	background-color: #00A6FF;
	color: white;
	box-shadow: 0rpx 0rpx 10rpx 0rpx #00A6FF;
	border-radius: 10rpx;
}



</style>