<template>
	<view class="GuestList">
		<view class="title">
			选择出行人
		</view>
		<view class="guest-box">
			<checkbox-group @change="changeCheck">
				<view v-for="(item,index) in guestList" :key="index" class="guestList-item">

					<view class="guest-info">
						<view class="name">
							{{item.Name}}
						</view>
						<view class="idcard">
							{{item.showIdCard}}
						</view>
					</view>
					<view class="right">
						<image
							src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/CustomizedCar/edit-icon.png"
							mode="aspectFit" class="edit-img" @click="goUrl(item.Id)"></image>
						
							<label class="check-box" @click="changeCheckItem(item,index)">
								<checkbox :checked="item.check" :value="item.Id" style="display: none;" />
								<view class="nocheck" v-if="!item.check" >
								</view>
								<image
									src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/CustomizedCar/checked.png"
									mode="aspectFit" class="check-icon" v-if="item.check" ></image>
							</label>
							
					</view>
				</view>
			</checkbox-group>
		</view>

		<view class="btn-box">
			<view class="add" @click="goUrl">
				新增乘客
			</view>
			<view class="confirm" @click="confirm">
				确认
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		
		data() {
			return {
				guestList:[],
				checkGuestList:[]
			}
		},
		mounted() {
			
			this.getGuestList()
		},
		methods: {
			getGuestList(){
				this.request2({
						url: '/api/AppletDining/GetGuestList',
						data: {}
					},
					res => {
						if (res.resultCode == 1) {
							res.data.forEach(i=>{
							i.check=false
							i.showIdCard=i.IdCard.slice(0,6)+"******"+i.IdCard.slice(-4)	
							})
							this.guestList=res.data
						}
					}
				);
			},
			goUrl(id) {
				if (id) {
					uni.navigateTo({
						url: "/pages/ticketCoupons/addGuest?id=" + id
					})
				} else {
					uni.navigateTo({
						url: "/pages/ticketCoupons/addGuest"
					})
				}

			},
			changeCheck(val){
				this.checkGuestList=[]
				this.guestList.map(i=>{
					val.detail.value.map(x=>{
						if(i.Id==x){
							this.checkGuestList.push(i)
						}
					})
				})
			},
			confirm(){
				this.$emit("confirm",this.checkGuestList)
			},
			changeCheckItem(item,index){
				item.check=!item.check
			}
		}
	}
</script>

<style lang="scss" scoped>
	.GuestList {
		height: 55vh;
		padding: 45rpx;

		.title {
			font-size: 34rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #1B1D1E;
			text-align: center;
		}

		.guest-box {
			height: 35vh;
			margin: 20rpx 0;
			// background-color: #000000;
			overflow-y: scroll;
			overflow-x: hidden;

			.guestList-item {
				height: 145rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.guest-info {
					width: 250rpx;

					.name {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #DFBE6E;
					}

					.idcard {
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #6E6E6E;
					}
				}

				.right {
					width: 270rpx;
					height: 145rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.edit-img {
						width: 32rpx;
						height: 32rpx;
					}
					.check-box{
						display: flex;
					}
					.nocheck{
						width: 40rpx;
						height: 40rpx;
						border: 2rpx solid #D6D6D6;
						border-radius: 50%;
					}
					.check-icon {
						width: 40rpx;
						height: 40rpx;
					}
				}
			}
		}

		.btn-box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 10rpx;

			.add {
				width: 300rpx;
				height: 80rpx;
				background-color: #FFFFFF;
				border: 1rpx solid #111111;
				border-radius: 20rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #111111;
				text-align: center;
				line-height: 78rpx;
			}

			.confirm {
				width: 300rpx;
				height: 80rpx;
				background: #111111;
				border-radius: 20rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				text-align: center;
				line-height: 78rpx;
			}
		}
	}
</style>
