<template>
	<view class="content">
		<view class="container">
			<view class="my-header">
				<view class="my-icons" @click="goback"> <uni-icons type="left" size="16"></uni-icons> </view>
				<view class="my-text">收货地址</view>
				<view class="my-icons"></view>
			</view>
			<!-- 顶部区域 -->
			<view class="box-xianze" v-for="(item,index) in dataList" :key="index">
				<view class="" @click="choose(item)">
					<view style="display: flex;align-items: center;margin-bottom: 5px;">
						<view class="">{{item.name || '--'}}</view>
						<view style="margin: 0 10px;" v-if="item.sex==0"> 先生</view>
						<view style="margin: 0 10px;" v-if="item.sex==1"> 女士</view>
						<view class=""> {{item.mobile || '--'}}</view>
					</view>
				</view>
				<view class="box-xia">

					<view class="box-left" @click="chooseDefault(item)">

						<view class="acvf" v-if="item.checked == false"></view>
						<view class="acv" v-else><u-icon name="checkbox-mark" color="#fff" size="14"></u-icon></view>
						<view style="font-size: 14px; color: #999; ">默认信息</view>
					</view>
					<view class="box-right">
						<view style="display: flex;" @click="goedit(item)">
							<u-icon name="edit-pen-fill" size="12"></u-icon>
							<view style="margin-left: 5px;">编辑</view>
						</view>

						<view style="display: flex;" @click="delInfo(item)">
							<u-icon name="trash" size="12"></u-icon>
							<view style="margin-left: 5px;">删除</view>
						</view>

					</view>
				</view>
			</view>

			<view class="bottom-anniu" @click="goedit()">
				<view class="">新增预留信息</view>
			</view>

		</view>
	</view>
</template>

<script>
	import config from '@/config'
	import request from '../../utils/request'

	export default {
		data() {
			return {
				title: '',
				dataList: '',
				checkboxValue1: [],
				checked: true,
			}
		},
		onShow() {
			this.getList();
		},
		components: {

		},
		methods: {
			chooseDefault(data) {
				console.log(data);
				if (data.checked == false) {
					data.ifDefault = 1
				} else {
					data.ifDefault = 2
				}
				request({
					url: '/business/userManager/mtUserExpressAddress',
					method: 'put',
					data: data
				}).then((res) => {
					if (res.code == 200) {
						this.getList()
						console.log(res, 81);
					}
				})
			},
			getList() {
				request({
					url: '/business/userManager/mtUserExpressAddress/getList',
					method: 'get',
				}).then((res) => {
					if (res.code == 200) {
						this.dataList = res.data
						this.dataList.forEach(item => {
							item.checked = false
							if (item.ifDefault == 1) {
								item.checked = true
							}
						})
						console.log(res, this.dataList, 98);
						this.$forceUpdate()
					}
				})
			},
			goedit(data) {

				if (data != null) {
					console.log(data)
					//传值
					uni.$on('unAddressInfo', function() {
						uni.$emit('addressInfo', data)
					})
				}
				uni.navigateTo({
					url: '/pagesHome/editress/editress'
				})
			},
			// 删除
			delInfo(data) {
				request({
					url: '/business/userManager/mtUserExpressAddress',
					method: 'delete',
					params: {
						id: data.id
					}
				}).then((res) => {
					if (res.code == 200) {
						this.getList()
					}
				})
			},
			choose(data) {
				//传值
				uni.$on('unChooseAddr', function() {
					uni.$emit('chooseAddr', data)
				})
				uni.navigateBack()
			},
			goback() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #f4f5f6;
	}

	.container {
		width: 100%;
		height: 100vh;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.my-header {
		width: 100%;
		height: 88px;
		background: #ffffff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #000;
		box-sizing: border-box;
		padding: 0px 15px;
		padding-top: 40px;

		.my-icons {
			width: 20px;

		}

		position: fixed;
		top: 0px;
	}

	.bottom-anniu {
		width: 90%;
		height: 40px;
		display: flex;
		align-items: center;
		background: #FF9655;
		color: white;
		justify-content: center;
		position: fixed;
		bottom: 40px;
		left: 50%;

		transform: translateX(-50%);
		border-radius: 50px;

	}

	.box-xianze {
		width: 95%;
		background-color: #ffffff;
		margin: 10px auto;
		padding: 10px;
		box-sizing: border-box;
	}

	.box-left {
		display: flex;
		align-items: center;
	}

	.box-right {
		width: 30%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 14px;
		color: #333333;
	}

	.tapl {
		width: 40px;
		height: 20px;
		border-radius: 6px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #1678ff;
		border: 1px solid #1678ff;
		font-size: 14px;
	}

	.box-xia {
		display: flex;
		justify-content: space-between;
		margin-top: 20px;
	}

	.acvf {
		border-radius: 50%;
		border: 1px solid #eee;
		height: 16px;
		width: 16px;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 10px;
	}

	.acv {
		border-radius: 50%;
		border: 1px solid #1678ff;
		height: 16px;
		width: 16px;
		background: #1678ff;
		color: #fff;
		margin-right: 10px;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>