<template>
	<view class="pages flex flex_column">
		<u-read-more toggle close-text="展开全部">
			<view class="uuid-list">
				<view class="flex align_center" v-for="item in uuid" :key="item.code">
					<view class="uuid-info">
						<view>轮胎名称：{{item.name}}</view>
						<view class="uuid">轮胎唯一码：{{item.code}}</view>
					</view>
					<view class="uuid-img">
						<image style="width: 100%;height: 80px;background: #eaeaea;" :src="item.img"></image>
					</view>
				</view>
			</view>
		</u-read-more>
		
		<view class="forms">
			<view class="forms-tits">车辆信息</view>
			<view class="flex align_center">
				<view class="labes"><text>*</text>扫描VIN码:</view>
				<view class="inputs"><image style="width: 100%;height: 35px;background: #eaeaea;" :src="tempImg"></image></view>
				<view class="btns" @click="openCamera"><image src="../../static/tab/tab_scan_normal.png"></image></view>
			</view>
			<view class="flex align_center">
				<view class="labes"><text>*</text>识别VIN码:</view>
				<view class="inputs"><u-input :focus="focusInput" v-model="form.vinCode" maxlength="17" border clearable type="text" placeholder="请输入VIN码"></u-input></view>
			</view>
			<view class="flex align_center">
				<view class="labes"><text>*</text>里程数:</view>
				<view class="inputs"><u-input v-model="form.mileage" disabled border clearable @click="openKey('number')" placeholder="请输入里程数"></u-input></view>
				<view class="btns">KM</view>
			</view>
			<view class="flex align_center">
				<view class="labes">车牌号:</view>
				<view class="inputs"><u-input v-model="form.carNo" disabled @click="openKey('car')" maxlength="12" border clearable type="text" placeholder="请输入车牌号"></u-input></view>
			</view>
		</view>
		 
		<view class="buttons flex align_center">
			<u-button type="default" @click="toBack">上一步</u-button>
			<u-button type="primary" @click="saveForm">确定</u-button>
		</view>
		<u-keyboard :mode="keyMode" cancel-text="清空" @cancel="clearVal" @change="valChange" @backspace="backspace" v-model="showkeyboard"></u-keyboard>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyMode: 'number',
				showkeyboard: false,
				tempImg: '',
				form:{
					vinCode: '',
					mileage: '',
					carNo: ''
				},
				uuid: [],
				focusInput: false
			}
		},
		onLoad() {
			const tempData = this.$store.state.vuex_uuidTempData
			this.uuid = tempData&&tempData.uuid ? tempData.uuid : []
		},
		onShow() {
			const ret = this.$store.state.vuex_tempData
			if(ret&&ret.retCode){
				this.tempImg = ret.filePath
				this.form.vinCode = ret.retCode
			}
			this.focusInput = ret&&ret=="inputCode"
		},
		onHide() {
			this.$store.state.vuex_tempData = null
		},
		methods: {
			toBack(){
				uni.redirectTo({
					url: "/pagesA/qualityPolicy/creatOrder"
				})
			},
			// 按键被点击(点击退格键不会触发此事件)
			valChange(val) {
				if(this.keyMode == 'number'){
					this.form.mileage += val;
				}
				if(this.keyMode == 'car'){
					this.form.carNo += val;
				}
			},
			// 退格键被点击
			backspace() {
				if(this.keyMode == 'number' && this.form.mileage.length){
					console.log(this.form.mileage)
					this.form.mileage = this.form.mileage.substr(0, this.form.mileage.length - 1)
				}
				if(this.keyMode == 'car' && this.form.carNo.length){
					console.log(this.form.carNo)
					this.form.carNo = this.form.carNo.substr(0, this.form.carNo.length - 1)
				}
			},
			// 清空键盘输入框
			clearVal(){
				if(this.keyMode == 'number'){
					this.form.mileage = '';
				}
				if(this.keyMode == 'car'){
					this.form.carNo = '';
				}
			},
			openKey(mode){
				this.keyMode = mode
				this.showkeyboard = true
			},
			openCamera(){
				uni.navigateTo({
					url: "/pages/scan-frame/scan-frame?pageType=UUID"
				})
			},
			saveForm(){
				if(this.form.vinCode == ''){
					uni.showToast({
						icon: 'none',
						title: '请扫描或手动输入VIN码'
					})
					return
				}
				if(this.form.mileage == ''){
					uni.showToast({
						icon: 'none',
						title: '请输入里程数'
					})
					return
				}
				
				this.$store.state.vuex_uuidTempData.carInfo = this.form
				uni.redirectTo({
					url: "/pagesA/qualityPolicy/creatCustomInfo"
				})
			}
		}
	}
</script>

<style lang="less">
.pages{
	height: 100vh;
	background: #f8f8f8;
	padding-bottom: 6rem;
	overflow: auto;
	.uuid-list{
		background: #fff;
		text-indent: 0;
		line-height: normal;
		font-size: 28rpx;
		> view{
			justify-content: space-between;
			border-bottom: 1px solid #eee;
			padding: 0.6rem 1rem;
		}
		color: #666;
		.uuid-info{
			flex-grow: 1;
			padding-right: 1rem;
			.uuid{
				color: #333;
			}
			> view{
				padding: 0.3rem 0;
			}
		}
		.uuid-img{
			width: 7rem;
		}
		margin-bottom: 0.5rem;
	}
	.buttons{
		padding: 1rem 2rem 2rem;
		position: fixed;
		width: 100%;
		bottom: 0;
		left: 0;
		background: #fff;
		z-index: 10000;
		border-top: 1px solid #eee;
		justify-content: space-around;
		/deep/ .u-btn{
			width: 7rem;
		}
	}
}
.forms{
	background: #fff;
	.forms-tits{
		font-weight: bold;
		color: #333;
	}
	> view{
		border-bottom: 1px solid #eee;
		padding: 0.6rem 1rem;
	}
	.labes{
		width: 6rem;
		text-align: right;
		padding-right: 0.6rem;
		text{
			color: red;
			margin-right: 5px;
		}
	}
	.inputs{
		flex-grow: 1;
	}
	.btns{
		width: 3rem;
		text-align: center;
		image{
			width: 1.6rem;
			height: 1.6rem;
		}
	}
}
</style>
