<template>
	<view>
		<view class="head" v-for="(item,index) in list" :key="index">
			<div class="name">
				{{item.name}}<span>{{item.mobile}}</span>
			</div>
			<div class="address">{{item.address}}{{item.full_address}}</div>
			<div class="xtghs"></div>
			<div class="df aic jcsb">
				<div class="df aic">
					<div class="delete" @click="deleted(item)">删除</div>
					<div class="edit" @click="btn(item)">编辑</div>

				</div>
				<div v-if="box!=1" class="btn-xz" @click="select(item)">选择该地址</div>
			</div>
			<div class="df aic jcsa newly-increased" @click="bnts">新增收货地址</div>
		</view>
		<view class="" v-if="list.length==0">
			<div class="newly df aic jcsa" @click="bnts">添加地址</div>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
					id:'',
					list:[],
					arr:[],
					arr1:[],
					shop:'',
					box:''
			};
		},
		onLoad(id) {
			this.id=id.id
			this.shop=id.shop
			this.box=id.box
			console.log(id);
			let _this=this
			uni.$on('ress', (data) => {
				_this.arr=data
			})



		},
		onUnload() {
			uni.$off('ress')

		},
		onShow() {

			this.$api.sendRequest({
				url: "/api/salesmemberaddress/page",
				data: {
					member_id:this.id,
					store_id:this.shop
				},
				success: res => {
					console.log(res.data.list,'客户地址list');
					this.list=res.data.list
				}
			});
		},
		methods:{
			deleted(item){
				if(this.list.length==1){
					this.$util.showToast({
						title: "至少保留一个地址哦！"
					});
					return
				}
				console.log(item);
				let _this=this
				this.$api.sendRequest({
					url:`/api/salesmemberaddress/delete`,
					data:{
						member_id:item.member_id,//客户id
						id:item.id	//地址id
					},
					success:res=>{
						this.$util.showToast({
							title: '删除成功'
						});
						setTimeout(()=>{
							_this.$api.sendRequest({
								url: "/api/salesmemberaddress/page",
								data: {
									member_id:_this.id
								},
								success: res => {
									console.log(res.data.list,'客户地址list');
									_this.list=res.data.list
								}
							});
						},300)

					}
				})
			},
			select(item){
				console.log(item);
				setTimeout(()=>{
					uni.$emit('inventory',this.arr)
				},600)
				setTimeout(()=>{
					uni.$emit('address',item)
				},500)
				// uni.navigateTo({
				// 	url:`/page_salesman_index/affirm_order/affirm_order?id=${this.id}`
				// })
				setTimeout(()=>{
						uni.navigateBack()
				},500)
			},
			btn(item){

				setTimeout(()=>{
					uni.$emit('item',item)
				},500)
				uni.navigateTo({
					url:`../shipping_ress/shipping_ress?id=${this.id}&&shop=${this.shop}`
				})
			},
			bnts(){

				setTimeout(()=>{
					uni.$emit('newly',this.arr)
				},500)
				uni.navigateTo({
					// url:this.list[this.current.URL]
					url:`../Add_deliveryaddress/Add_deliveryaddress?id=${this.id}&&shop=${this.shop}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.newly{
		width: 690rpx;
		height: 80rpx;
		background: #21BBF3;
		border-radius: 40rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 40rpx;
		position: fixed;
		bottom:82rpx;
		left: 50%;
		transform: translateX(-50%);
	}
.head{
	width: 702rpx;
	// height: 292rpx;
	background: #FFFFFF;
	border-radius: 16rpx;
	margin: 0 auto;
	margin-top: 24rpx;
	padding: 32rpx;
	box-sizing: border-box;
	.name{
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #222222;
		line-height: 40rpx;
		span{
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #999999;
			line-height: 40rpx;
			margin-left: 24rpx;
		}
	}
	.address{
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #222222;
		line-height: 40rpx;
		margin-top: 8rpx;
	}
	.xtghs{
		width: 641rpx;
		height: 1rpx;
		background: #E8E8E8;
		border-radius: 2rpx;
		margin: 32rpx 0;
	}
	.answer{
		width: 28rpx;
		height: 28rpx;
		background: #21BBF3;
		color:#fff ;
		border-radius: 50%;
	}
	.answerrr{
		width: 28rpx;
		height: 28rpx;
		background: #fff;
		border-radius: 50%;
		border: 2rpx solid #ccc;
	}
	.tacit{
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #222222;
		line-height: 34rpx;
		margin-left: 12rpx;
	}
	.delete{
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 34rpx;
		margin-right: 30rpx;
	}
	.edit{
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 34rpx;
	}
	.btn-xz{
		padding: 10rpx 24rpx;
		box-sizing: border-box;
		background-color: rgb(77, 133, 255);
		color: #fff;
		border-radius: 20rpx;
	}
	.newly-increased{
		width: 690rpx;
		height: 80rpx;
		background: #21BBF3;
		border-radius: 40rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 40rpx;
		position: fixed;
		bottom:82rpx;
		left: 50%;
		transform: translateX(-50%);
	}
}
</style>
