<template>
	<view>
		<view class="w100 rows rowsc rowsl rowsm" v-if="addList.length>0">
			<view class="w-710 h-256 bgff br-20 rowsl rows rowsm mb-20" v-for="(item,index) in addList" :key="index" @click="AddDetail(item)">
				<view class="w-652 h-182 pt-24" style="border-bottom: 1rpx solid #f5f5f5;">
					<view class="rows rowsm">
						<image class="w-52 h-52" src="/static/images/01_13wz.png" mode=""></image>
						<text class="fw-b fs-30 col333 mr-20 ml-20">{{item.name}}</text>
						<text class="fs-24 col333">{{item.mobile}}</text>
						<view class="w-52 h-32 bg br-5 ml-14 fs-20 rows rowsm rowsc colfff" v-if="item.is_switch==1">默认</view>
					</view>
					<view class="fs-28 col666 two_overflow mt-20">
						{{item.region}} {{item.address}}
					</view>
				</view>
				<view class="w100 rows h-70 rows rowsm pr-30 pl-30 rowse">
					<view class="rows rowsm">
						<image class="w-40 h-40 mr-40" src="/static/images/04_12bianji.png" mode="" @click.stop="$tools.goNext(`/pageOne/mes/addEdit?id=${item.id}`)"></image>
						<image class="w-40 h-40" src="/static/images/04_12sahnchu.png" mode="" @click.stop="deleteAddressByAddId(item.id)"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="w100 rows rowsc h-600 rowsm" v-else>
			<image class="w-436 h-366" src="/static/other/5.png" mode=""></image>
		</view>
		<view class="w100 rows rowsc fixed h-150 rowsm" style="bottom: 0rpx;">
			<view class="w-690 h-88 lh-88 bg fw-b fs-30 tct br-100 colfff" @click="$tools.goNext('/pageOne/mes/addNew')">
				新增收货地址
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				addList:[],
				isBack:false
			}
		},
		onShow() {
			this.addreslist()
		},
		onLoad(options) {
			if(options.type) {
				this.isBack = true
			}
		},
		methods:{
			// 地址列表
			addreslist(){
				this.$tools.axiosFromToken("POST","address/addreslist").then(res => {
					this.addList = res.data
				})
			},
			// 删除地址
			deleteAddressByAddId(id){
				let _this = this
				uni.showModal({
					title: '提示',
					content: '确定要删除地址吗？',
					success: function (res) {
						if (res.confirm) {
							_this.$tools.axiosFromToken("POST","address/deleteAddress",{id}).then(res => {
								_this.$tools.showtt(res.msg)
								if(res.code != 1) return
								_this.addreslist()
							})
						} 
					}
				});
			},
			AddDetail(item){
				getApp().globalData.addressDetail = item
				if(this.isBack){
					this.$tools.goBack()
				}
			}
		}
	}
</script>

<style>
	page{
		background-color: #F7F6FA;
		padding-top: 20rpx;
	}
</style>