<template>
	<view class="content">
		<navbar title="推荐司机" :leftClick="true" @leftClick="$utils.navigateBack" />
		<view class="mt20">
			<!-- 页面标题卡片 -->
			<view class="re-card-p32">
				<view class="flex-sb">
					<view class="re-from-label">推荐司机</view>
					<view class="re-card-show" @click="switchToBoss">我要推荐老板</view>
				</view>
				<view class="re-card-context">
					感谢您为我们推荐司机，请您填写下述问题以便我们对您推荐的司机有一个整体的了解。
				</view>
			</view>
			
			<!-- 表单卡片 -->
			<view class="re-card-p32">
				<!-- 司机姓名 -->
				<view class="re-from-line">
					<view class="re-from-label">您推荐的司机姓名</view>
					<view class="b-relative">
						<input 
							maxlength="8" 
							class="re-from-input" 
							placeholder="请填写真实姓名" 
							v-model="driverInfo.name" 
							@input="onNameInput" 
						/>
						<image class="re-from-icon" src="/static/icons/icon01.png"></image>
					</view>
				</view>
				
				<!-- 手机号码 -->
				<view class="re-from-line">
					<view class="re-from-label">司机的手机号码</view>
					<view class="b-relative">
						<input 
							type="number" 
							maxlength="11" 
							class="re-from-input" 
							placeholder="请填写TA的常用联系方式" 
							v-model="driverInfo.phone" 
							@input="onPhoneInput" 
						/>
						<image class="re-from-icon" src="/static/icons/icon02.png"></image>
					</view>
				</view>
				
				<view class="h44"></view>
				
				<!-- 责任心评价 -->
				<view class="re-from-line">
					<view class="re-from-label">您推荐司机责任心强？</view>
					<view class="b-relative">
						<radio-group @change="onResponsibilityChange">
							<radio class="re-radio re-width2" value="1" :checked="driverInfo.responsibility === '1'">是</radio>
							<radio class="re-radio re-width2" value="2" :checked="driverInfo.responsibility === '2'">否</radio>
						</radio-group>
					</view>
				</view>
				
				<!-- 技术水平评价 -->
				<view class="re-from-line">
					<view class="re-from-label">您推荐司机技术水平如何？</view>
					<view class="b-relative">
						<radio-group @change="onSkillChange">
							<radio class="re-radio re-width3" value="1" :checked="driverInfo.skill === '1'">优秀</radio>
							<radio class="re-radio re-width3" value="2" :checked="driverInfo.skill === '2'">良好</radio>
							<radio class="re-radio re-width3" value="3" :checked="driverInfo.skill === '3'">一般</radio>
						</radio-group>
					</view>
				</view>
				
				<!-- 工作经验 -->
				<view class="re-from-line">
					<view class="re-from-label">您推荐司机工作经验？</view>
					<view class="b-relative">
						<radio-group @change="onExperienceChange">
							<radio class="re-radio re-width3" value="1" :checked="driverInfo.experience === '1'">1-3年</radio>
							<radio class="re-radio re-width3" value="2" :checked="driverInfo.experience === '2'">3-5年</radio>
							<radio class="re-radio re-width3" value="3" :checked="driverInfo.experience === '3'">5年以上</radio>
						</radio-group>
					</view>
				</view>
				
				<!-- 推荐理由 -->
				<view class="re-from-line">
					<view class="re-from-label">推荐理由</view>
					<view class="b-relative">
						<textarea 
							class="re-from-textarea" 
							placeholder="请简述推荐理由" 
							v-model="driverInfo.reason" 
							maxlength="200"
						></textarea>
					</view>
				</view>
				
				<!-- 您的联系方式 -->
				<view class="re-from-line">
					<view class="re-from-label">您的联系方式</view>
					<view class="b-relative">
						<input 
							type="number" 
							maxlength="11" 
							class="re-from-input" 
							placeholder="请填写您的联系电话" 
							v-model="driverInfo.myPhone" 
						/>
						<image class="re-from-icon" src="/static/icons/icon02.png"></image>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 底部提交按钮 -->
		<view class="re-end-pand b-fiexd">
			<button @click="submitRecommendation">提交推荐</button>
		</view>
	</view>
</template>

<script>
	import navbar from '@/components/base/navbar.vue'
	
	export default {
		name: 'UserDriver',
		components: {
			navbar
		},
		data() {
			return {
				driverInfo: {
					name: '',
					phone: '',
					responsibility: '1',
					skill: '1',
					experience: '1',
					reason: '',
					myPhone: ''
				}
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '推荐司机'
			});
		},
		methods: {
			switchToBoss() {
				uni.redirectTo({
					url: '/pages_order/user/enter'
				});
			},
			onNameInput(e) {
				this.driverInfo.name = e.detail.value;
			},
			onPhoneInput(e) {
				this.driverInfo.phone = e.detail.value;
			},
			onResponsibilityChange(e) {
				this.driverInfo.responsibility = e.detail.value;
			},
			onSkillChange(e) {
				this.driverInfo.skill = e.detail.value;
			},
			onExperienceChange(e) {
				this.driverInfo.experience = e.detail.value;
			},
			submitRecommendation() {
				// 表单验证
				if (!this.driverInfo.name) {
					uni.showToast({ title: '请输入司机姓名', icon: 'none' });
					return;
				}
				if (!this.driverInfo.phone) {
					uni.showToast({ title: '请输入司机手机号', icon: 'none' });
					return;
				}
				if (!/^1[3-9]\d{9}$/.test(this.driverInfo.phone)) {
					uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
					return;
				}
				if (!this.driverInfo.myPhone) {
					uni.showToast({ title: '请输入您的联系方式', icon: 'none' });
					return;
				}
				if (!/^1[3-9]\d{9}$/.test(this.driverInfo.myPhone)) {
					uni.showToast({ title: '请输入正确的联系方式', icon: 'none' });
					return;
				}
				
				uni.showToast({
					title: '推荐提交成功',
					icon: 'success'
				});
				
				setTimeout(() => {
					uni.navigateBack();
				}, 1500);
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 20rpx;
		min-height: 100vh;
		background-color: #f5f5f5;
		padding-bottom: 120rpx;
	}
	
	.mt20 {
		margin-top: 20rpx;
	}
	
	.re-card-p32 {
		background-color: #fff;
		border-radius: 10rpx;
		padding: 32rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}
	
	.flex-sb {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.re-from-label {
		font-size: 30rpx;
		font-weight: 500;
		color: #333;
	}
	
	.re-card-show {
		padding: 10rpx 20rpx;
		background-color: #007AFF;
		color: #fff;
		border-radius: 20rpx;
		font-size: 24rpx;
	}
	
	.re-card-context {
		margin-top: 20rpx;
		font-size: 26rpx;
		color: #666;
		line-height: 1.5;
	}
	
	.re-from-line {
		margin-bottom: 40rpx;
		
		&:last-child {
			margin-bottom: 0;
		}
		
		.re-from-label {
			font-size: 28rpx;
			margin-bottom: 20rpx;
		}
	}
	
	.b-relative {
		position: relative;
	}
	
	.re-from-input {
		width: 100%;
		height: 80rpx;
		padding: 0 60rpx 0 20rpx;
		border: 1rpx solid #e0e0e0;
		border-radius: 8rpx;
		font-size: 28rpx;
		box-sizing: border-box;
	}
	
	.re-from-textarea {
		width: 100%;
		height: 120rpx;
		padding: 20rpx;
		border: 1rpx solid #e0e0e0;
		border-radius: 8rpx;
		font-size: 28rpx;
		box-sizing: border-box;
		resize: none;
	}
	
	.re-from-icon {
		position: absolute;
		right: 20rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 32rpx;
		height: 32rpx;
	}
	
	.h44 {
		height: 44rpx;
	}
	
	.re-radio {
		margin-right: 40rpx;
		font-size: 28rpx;
	}
	
	.re-width2 {
		width: calc(50% - 20rpx);
	}
	
	.re-width3 {
		width: calc(33.33% - 27rpx);
	}
	
	.re-end-pand {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 20rpx;
		background-color: #fff;
		border-top: 1rpx solid #f0f0f0;
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
		
		button {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			background-color: #007AFF;
			color: #fff;
			border-radius: 40rpx;
			font-size: 32rpx;
			border: none;
		}
	}
	
	.b-fiexd {
		position: fixed;
	}
</style>