<template>
	<view class="add-guest">
		<view class="title">
			乘客姓名
		</view>
		<view class="item">
			<input type="text" placeholder="请输入真实姓名" v-model="msg.Name" />
		</view>
		<view class="title">
			乘客电话
		</view>
		<view class="item">
			<input type="number" placeholder="请输入电话" v-model="msg.Mobile" />
		</view>
		<view class="title">
			乘客身份证号码
		</view>
		<view class="item">
			<input type="number" :maxlength="18" placeholder-class='placeholderStyle' placeholder="请输入18位身份证号码" v-model="msg.IdCard" />
		</view>
		<view class="btn" @click="updateInfo">
			确认
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				msg:{
					ID:0,
					Name:"",
					Mobile:"",
					IdCard:"",
				}
			}
		},
		onLoad(options) {
			let Id=options.id
			if(Id){
				uni.setNavigationBarTitle({
					title: "修改出行人",
				});
				this.msg.ID=Id;
				this.getInfo();
			}else{
				uni.setNavigationBarTitle({
					title: "新增出行人",
				});
			}
			
		},
		methods:{
			getInfo(){
				this.request2({
						url: '/api/AppletDining//GetDMCGuest',
						data: {ID:this.msg.ID}
					},
					res => {
						if (res.resultCode == 1) {
							this.msg.Name=res.data.Name;
							this.msg.Mobile=res.data.Mobile;
							this.msg.IdCard=res.data.IdCard;
						}
					}
				);
			},
			updateInfo(){
				if(!this.msg.Name){
					uni.showToast({
					    title: '请输入真实姓名',
						icon:"none",
					    duration: 2000
					});
					return
				}
				if(!this.msg.Mobile){
					uni.showToast({
					    title: '请输入电话号码',
						icon:"none",
					    duration: 2000
					});
					return
				}
				if(!this.msg.IdCard){
					uni.showToast({
					    title: '请输入18位身份证号码',
						icon:"none",
					    duration: 2000
					});
					return
				}
				this.request2({
						url: '/api/AppletDining//SetDMCGuest',
						data: this.msg
					},
					res => {
						if (res.resultCode == 1) {
							uni.showToast({
							    title: '操作成功',
								icon:"none",
							    duration: 2000
							});
							uni.navigateBack({
								delta:2
							})
							// uni.navigateTo({
							// 	url:"/pages/ticketCoupons/fillOrder"
							// })
						}else{
							uni.showToast({
							    title: '操作失败',
								icon:"none",
							    duration: 2000
							});
						}
					}
				);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.add-guest{
		position: relative;
		height: 100vh;
		padding: 45rpx;
		.title{
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #1F1F1F;
			margin-bottom: 40rpx;
		}
		.item{
			height: 95rpx;
			border-bottom: 1rpx solid #E7E7E7;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #111111;
			line-height: 93rpx;
			margin-bottom: 60rpx;
		}
		.placeholderStyle{
			color: #BABABA;
		}
		.btn{
			width: 650rpx;
			height: 80rpx;
			background-color: #111111;
			border-radius: 20rpx;
			position: absolute;
			left: 50%;
			transform: translateX(-50%);
			bottom: 100rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			text-align: center;
			line-height: 78rpx;
		}
	}
</style>
