<template>
	<view class="content">
		<navbar title="推荐老板" leftClick @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="switchToDriver">我要推荐司机</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="bossInfo.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="bossInfo.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="onSalaryChange">
							<radio class="re-radio re-width2" value="1" :checked="bossInfo.salary === '1'">是</radio>
							<radio class="re-radio re-width2" value="2" :checked="bossInfo.salary === '2'">否</radio>
						</radio-group>
					</view>
				</view>
				
				<!-- 合作态度评价 -->
				<view class="re-from-line">
					<view class="re-from-label">您推荐的老板合作态度如何？</view>
					<view class="b-relative">
						<radio-group @change="onAttitudeChange">
							<radio class="re-radio re-width3" value="1" :checked="bossInfo.attitude === '1'">很好</radio>
							<radio class="re-radio re-width3" value="2" :checked="bossInfo.attitude === '2'">一般</radio>
							<radio class="re-radio re-width3" value="3" :checked="bossInfo.attitude === '3'">较差</radio>
						</radio-group>
					</view>
				</view>
				
				<!-- 业务规模 -->
				<view class="re-from-line">
					<view class="re-from-label">您推荐的老板业务规模？</view>
					<view class="b-relative">
						<radio-group @change="onScaleChange">
							<radio class="re-radio re-width3" value="1" :checked="bossInfo.scale === '1'">大型</radio>
							<radio class="re-radio re-width3" value="2" :checked="bossInfo.scale === '2'">中型</radio>
							<radio class="re-radio re-width3" value="3" :checked="bossInfo.scale === '3'">小型</radio>
						</radio-group>
					</view>
				</view>
				
				<!-- 公司名称 -->
				<view class="re-from-line">
					<view class="re-from-label">公司名称</view>
					<view class="b-relative">
						<input 
							class="re-from-input" 
							placeholder="请填写公司名称" 
							v-model="bossInfo.companyName" 
						/>
						<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">
						<textarea 
							class="re-from-textarea" 
							placeholder="请简述推荐理由" 
							v-model="bossInfo.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="bossInfo.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 {
		components: {
			navbar
		},
		name: 'UserEnter',
		data() {
			return {
				bossInfo: {
					name: '',
					phone: '',
					salary: '2',
					attitude: '1',
					scale: '2',
					companyName: '',
					reason: '',
					myPhone: ''
				}
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '推荐老板'
			});
		},
		methods: {
			switchToDriver() {
				uni.redirectTo({
					url: '/pages_order/user/driver'
				});
			},
			onNameInput(e) {
				this.bossInfo.name = e.detail.value;
			},
			onPhoneInput(e) {
				this.bossInfo.phone = e.detail.value;
			},
			onSalaryChange(e) {
				this.bossInfo.salary = e.detail.value;
			},
			onAttitudeChange(e) {
				this.bossInfo.attitude = e.detail.value;
			},
			onScaleChange(e) {
				this.bossInfo.scale = e.detail.value;
			},
			submitRecommendation() {
				// 表单验证
				if (!this.bossInfo.name) {
					uni.showToast({ title: '请输入老板姓名', icon: 'none' });
					return;
				}
				if (!this.bossInfo.phone) {
					uni.showToast({ title: '请输入老板手机号', icon: 'none' });
					return;
				}
				if (!/^1[3-9]\d{9}$/.test(this.bossInfo.phone)) {
					uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
					return;
				}
				if (!this.bossInfo.companyName) {
					uni.showToast({ title: '请输入公司名称', icon: 'none' });
					return;
				}
				if (!this.bossInfo.myPhone) {
					uni.showToast({ title: '请输入您的联系方式', icon: 'none' });
					return;
				}
				if (!/^1[3-9]\d{9}$/.test(this.bossInfo.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>