<template>
	<view class="bg">
		<view >
			<view class="item" v-for="(item,index) in travelList" :key="index">
				<view class="name">
					<view class="">
						{{item.name}}
					</view>
					<view class="">
						{{item.tel}}
						<span v-if="item.is_default==1">默认</span>
					</view>
				</view>
				<view class="idcard">
					<view class="">
						{{item.document_type_text}}:
					</view>
					<view class="">
						{{item.id_number}}
					</view>
				</view>
				<view class="item-btn">
					<view class="choice">
						<!-- <image src="https://static.ticket.sz-trip.com/yandu/images/user/dui.png" mode="aspectFill"
							v-if="item.is_default==1">
						</image>
						<view class="yuan" v-else @click.stop="defaultC(item)">
			
						</view>
						<view class="">
							默认出行人
						</view> -->
					</view>
					<view class="btn-list">
						<view class="btn-item" @click.stop="edit(item.id)">
							修改
						</view>
						<view class="btn-item" @click.stop="delet(item)">
							删除
						</view>
					</view>
				</view>
			</view>
		
			<view class="no-data" v-if="travelList.length<=0">
				<image :src="showImg('/uploads/20241203/6398b49184a0b2be61b92ad65e0f86cd.png')"></image>
				<view>暂无常用出行人赶快去添加吧~</view>
			</view>
			
		</view>
		
		<view class="btn-box">
			<navigator url="/subPackages/user/myContactsAdd" class="btn">添加出行人</navigator>
		</view>
	</view>
</template>

<script>
	export default {
		name: "travelerList",
		data() {
			return {
				travelList: [],
			};
		},
		onShow() {
			this.init()
		},
		methods: {
			init () {
				// 出行人信息
				this.Post({}, "/api/user/contactList").then(res => {
					if (res) this.travelList = res.data
				})
				
				
			},
			delet(item) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要删除该出行人吗?',
					cancelText: "再想想",
					confirmColor: "#000",
					success: function(res) {
						if (res.confirm) {
							that.Post({
								id: item.id
							}, "/api/user/delDetail").then(res => {
								if (res) {
									uni.showToast({
										icon: "none",
										title: res.msg
									})
								}
								that.init()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			defaultC(item) {
				this.Post({
					id: item.id,
					is_default: 1
				}, "/api/user/editContact").then(res => {
					if (res.code == 1) {
						this.travelList.forEach(i => i.is_default = 0)
						item.is_default = !item.is_default
					}
				})
			},
			// 修改出行人信息
			edit(id){
				let url = ''
				if(this.showType) {
					url = '/subPackages/user/myAddressAdd?id='+id
				}else {
					url = "/subPackages/user/myContactsAdd?type=edit&id="+id
				}
				uni.navigateTo({
					url: url
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	*{
		box-sizing: border-box;
	}
	.bg {
		position: relative;
		background: #F5F5F5;
		min-height: calc(100vh - 44px);
		overflow-x: hidden;
		padding-bottom: 200rpx;
	}
	
	.item {
		width: 697rpx;
		background: #FFFFFF;
		border-radius: 13rpx;
		margin: 28rpx auto 0;
		padding: 26rpx;
		
		.name,
		.idcard {
			display: flex;
			font-size: 31rpx;
			font-weight: bold;
			color: #000000;
		}
		
		.name {
			view:last-child{
				margin-left: 40rpx;
			}
			
			span {
				padding: 3rpx 9rpx;
				background: #96684F;
				border-radius: 7rpx;
				font-weight: bold;
				font-size: 24rpx;
				color: #FFFFFF;
				margin-left: 15rpx;
			}
		}
		
		.idcard {
			margin-top: 26rpx;
		
			view:last-child {
				margin-left: 14rpx;
				max-width: 492rpx;
		
			}
		}
		
		.item-btn {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 40rpx;
		
			.choice {
				display: flex;
				align-items: center;
		
				view:last-child {
					margin-left: 20rpx;
		
					font-size: 27rpx;
		
					font-weight: 500;
					color: #333333;
				}
		
				image {
					width: 40rpx;
					height: 40rpx;
				}
				
				.yuan {
					width: 40rpx;
					height: 40rpx;
					background: rgba(255, 200, 37, 0);
					border: 1rpx solid #999999;
					border-radius: 20rpx;
				}
			}
		
			.btn-list {
				display: flex;
				align-items: center;
		
				view {
					width: 134rpx;
					height: 54rpx;
					background: #FFFFFF;
					border: 1px solid #999999;
					border-radius: 7rpx;
		
		
					font-size: 27rpx;
					font-weight: 500;
					color: #333333;
					line-height: 52rpx;
					text-align: center;
				}
		
				view:last-child {
					margin-left: 14rpx;
				}
			}
		}
	}
	
	.btn-box {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 160rpx;
		padding: 26rpx;
		background-color: #F5F5F5;
		
		.btn {
			width: 100%;
			line-height: 80rpx;
			height: 80rpx;
			background: #96684F;
			border-radius: 7rpx;
			font-weight: 500;
			font-size: 36rpx;
			color: #fff;
			text-align: center;
		}
	}

	.no-data{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 400rpx;
		image{
			width: 372rpx;
			height: 200.67rpx;
		}
		view{
			width: 185rpx;
			height: 72rpx;
			font-weight: 500;
			font-size: 27rpx;
			color: #666666;
			margin-top: 78rpx;
		}
	}
	
</style>
