<template>
	<view class="container">
		
		<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" labelWidth="120">
			<u-form-item label="有无挂车" prop="form.has_mount" borderBottom ref="item1">
				<u-radio-group v-model="form.has_mount" placement="row" @change="groupChange">
					<u-radio shape="square" name="1" label="有"></u-radio>
					<span style="width: 40px;"></span>
					<u-radio shape="square" name="0" label="无"></u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="挂车车牌" prop="form.mount_license" borderBottom ref="item1">
				<!-- <view class="input_sbtn" style="display: flex;" @click="show_cate = true">
					<u--input v-model="form.mount_license" border="none" placeholder="请选择挂车车牌"></u--input>
					<u-icon name="arrow-right"></u-icon>
				</view> -->
				<car-number-input class="car-number-input" @numberInputResult="numberInputResult2"
					:defaultStr="form.mount_license"></car-number-input>
			</u-form-item>
			<u-form-item label="牵引车" prop="form.tractor_license" borderBottom ref="item1">
				<car-number-input class="car-number-input" @numberInputResult="numberInputResult"
					:defaultStr="form.tractor_license"></car-number-input>
			</u-form-item>
			<u-form-item label="手机号" prop="form.phone_num" borderBottom ref="item1">
				<u--input v-model="form.phone_num" border="none" placeholder="请输入手机号"></u--input>
			</u-form-item>
			<u-form-item label="入园目的" prop="form.mission_name" borderBottom ref="item1">
				<view class="input_sbtn" style="display: flex;" @click="show_mudi = true">
					<u--input v-model="form.mission_name" border="none" placeholder="请选择入园目的"></u--input>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</u-form-item>


		</u--form>

		<u-button type="primary" class="btn" text="提交信息" shape="circle" @click="add"></u-button>

		<u-picker :show="show_mudi" :columns="columns_mudi" @confirm="confirmMudi"></u-picker>

	</view>

</template>

<script>
import config from '../../common/config'
	import {
		get,
		post
	} from '@/common/request.js'
	export default {
		data() {
			return {
				show_mudi: false,
				columns_mudi: [
					['装货/卸货', '维修/洗车/停车', '常驻', '维修', '洗车', '停车', '检测', '洗罐']
				],

				form: {
					has_mount: "0",//有无挂车
					mission: "",//入园目的
					mission_name: "",//入园目的--显示名称
					tractor_license: "", //牵引车牌号
					mount_license:"",//挂车车牌
					phone_num:config.driverInfo.phone,//手机号
					reporter_name:config.driverInfo.account
				},
				rules: {}
			}
		},
		onLoad(option) {
			if(option.vehicleNo){
				this.form.tractor_license = option.vehicleNo
			}
		},
		methods: {
			async add() {
				
				if(this.form.has_mount == 1 && this.form.mount_license.trim().length != 7 && this.form.mount_license.trim().length != 8){
					uni.showToast({
						title:'请输入挂车车牌',
						icon:'none'
					})
					return false
				}
				await post('/myapi/api/yq_driver/enParkReport', {
					...this.form
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '上报成功',
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/order/park'
							})
						}, 500)
					}
				})
				
			},
			groupChange(e) {
				this.has_mount = e
			},
			confirmMudi(e) {
				this.form.mission_name = e.value[0]
				this.form.mission = e.indexs[0] + 1
				this.show_mudi = false
			},
			numberInputResult(e) {
				this.form.tractor_license = e
			},numberInputResult2(e) {
				this.form.mount_license = e
			},

		}
	}
</script>

<style scoped lang="less">
	.car-number-input {
		width: 100%;
	}

	.container {
		padding: 20px;

		.tag_title {
			width: 80px;
			height: 30px;
			display: flex;
			align-items: center;
		}

		.btn {
			margin-top: 20px;
		}
	}
</style>