<!-- 行驶证 -->
<template>
	<view class="container">
		<view class="c-top">
			<view class="" @click="getfanhui()">
				<uni-icons type="left" size="18" color="black"></uni-icons>
			</view>
			<view class="c-title"> </view>
			<view class=""></view>
		</view>


		<view class="boxbox">
			<view>
				<view class="top-left">(上传行驶证)</view>
			</view>
			<view class="zhans-img">
				<image src="http://www.nuoyunr.com/lananRsc/detection/xsz.png" mode=""></image>
			</view>
			<u-upload :fileList="fileList2" @afterRead="afterRead1" @delete="deletePic1" name="2" multiple
				:maxCount="1">

			</u-upload>

			<!-- <view class="img-box">

				</view> -->
		</view>

		<view class="anniu" @click="wancheng()">
			<text>完成</text>
		</view>
		<view style="width: 100%; height: 10px;"></view>
	</view>
</template>

<script>
	// import request from '../../utils/request'
	import request from '../../utils/newRequest'
	import config from '@/config'
	import {
		getToken,
		getTenantId
	} from '@/utils/auth'
	export default {
		data() {
			return {
				doing: '',
				imgs: '',
				fileList1: [],
				fileList2: [],
				postData: {
					carPics: '',
					licenseImage: '',
					idCardImage: '',
				},
				baseImageUrl: this.$baseImageUrl
			}
		},
		onLoad() {
			this.imgs = this.$baseUrl
		},
		mounted() {
			// this.getindex()
		},
		methods: {
			async getindex() {
				let res = await request({
					url: '/system/userCar/getInfoCard',
					method: 'get',
				})
				console.log('查看回显', res);

			},
			getfanhui() {
				uni.navigateBack()
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			deletePic1(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			async afterRead1(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,

					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise1(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
					console.log('this[`fileList${event.name}`]: ', this[`fileList${event.name}`]);
				}
			},
			uploadFilePromise1(url) {
				uni.showLoading({
					title: '加载中'
				});
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$newBaseUrl + '/app-api/small-upload/common/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						header: {
							'Authorization': 'Bearer ' + getToken()
						},
						success: (res) => {
							try {
								console.log(res, "1212")
								let img = JSON.parse(res.data);
								this.idCardImage = img.data.url
								console.log('url1', this.idCardImage);
								uni.hideLoading();
								setTimeout(() => {
									resolve(img.data.url)
								}, 1000)
							} catch (e) {
								//TODO handle the exception
								resolve(undefined)
							}

						}
					});
				})
			},
			wancheng() {
				uni.$emit('imgUrl', this.idCardImage)
				uni.navigateBack({
					delta: 1
				})
			},

			async getimg() {
				console.log(this.idCardImage, 111);
				let data = {
					// licenseImage :this.licenseImage,
					imagePath: this.idCardImage,
				}

				const res = await newRequest({
					url: '/system/userCar/appVehicleLicenseOCR',
					method: 'post',
					params: data
				})
				if (res.code == 200) {
					uni.showToast({
						title: '提交成功'
					})
					uni.navigateBack()
				}
				if (res.code != 200) {
					uni.showToast({
						title: '识别失败 请从新上传',
						icon: 'none'
					})
				}




			}


		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: calc(100vh);
		background-color: #F6F6F6;
		// background: url('http://www.nuoyunr.com/lananRsc/jcbjt.png') center no-repeat;
		background-size: 100% 100%;
		box-sizing: border-box;
		padding-bottom: 15px;
	}

	.c-top {
		width: 100%;
		box-sizing: border-box;
		padding: 15px;
		padding-top: 45px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: white;
	}

	.c-title {
		font-size: 18px;
		color: black;
		font-weight: bold;


	}

	.zhans-img {
		width: 95%;
		height: 200px;
		border-radius: 6px;
		// border: 2px solid   #FFE3AD;
		box-sizing: border-box;
		padding: 5px;
		margin: 20px auto;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.boxbox {
		background: white;
		box-sizing: border-box;
		padding: 15px;
		margin-bottom: 20px;
	}

	.cont-top {
		width: 95%;
		margin: 0 auto;
		box-sizing: border-box;
		overflow: hidden;
		padding-bottom: 10px;
		display: flex;
		align-items: center;
		// border-bottom: 1px solid  #FFE3AD;

	}

	.top-right {
		width: 70%;

		input {
			width: 100%;
			color: white;
			font-size: 18px;
			font-weight: 600;
		}
	}

	.top-left {
		color: black;
		font-size: 18px;
		font-weight: 600;
		margin-right: 5px;
	}

	.cont-box {
		margin: 0 auto;
		margin-top: 20px;
		width: 95%;


		display: flex;
		flex-wrap: wrap;
	}

	.box {
		width: 30%;
		height: 40px;
		border-radius: 8px;
		border: 1px solid #FFE3AD;
		margin-top: 10px;
		margin-right: 11px;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 18px;
		color: white;
		font-weight: bold;

	}

	.anniu {
		width: 95%;
		height: 40px;
		border-radius: 6px;
		border: 1px solid #FFE3AD;
		background: #0D2E8D;
		margin: 0 auto;
		margin-bottom: 40px;
		color: white;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 18px;
		font-weight: bold;

	}

	.indexbox {
		background: #FFE3AD;
	}

	.img-box {
		width: 95%;
		margin: 0 auto;
	}

	/deep/.u-upload__wrap__preview__image.data-v-69e2a36e {
		width: 100% !important;
		height: 200px !important;
	}

	/deep/.u-upload__button.data-v-69e2a36e {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 100% !important;
		height: 200PX !important;
		background-color: #f4f5f7;
		border-radius: 2px;

		box-sizing: border-box;
		margin: 0 auto;
	}

	/deep/.u-upload__deletable.data-v-69e2a36e {
		position: absolute;
		top: 0;
		right: 0;
		background-color: #373737;
		height: 26px !important;
		width: 26px !important;
		display: flex;
		flex-direction: row;
		border-bottom-left-radius: 100px;
		align-items: center;
		justify-content: center;
		z-index: 3;
	}

	/deep/.u-icon__icon.data-v-2ee87dc9 {
		font-size: 17px !important;
		line-height: 17px !important;
	}

	/deep/.u-upload__wrap__preview.data-v-69e2a36e {
		border-radius: 2px;
		width: 100% !important;
		margin: 0 8px 8px 0;
		position: relative;
		overflow: hidden;
		display: flex;
		flex-direction: row;
	}
</style>