<template>
	<view class="center">
		<view>
			<view style="margin: 0 auto;height: 240px;" @click="idUp">
				<image v-bind:src = "id1" class="picture"></image>
				<view class="floats" v-if="certificates == true">
					<image src="../../static/img/authentication/xiangji@3x.png" style="width: 60px;height: 50px;">
					</image>
					<view class="words">
						上传身份证头像页
					</view>
				</view>
			</view>
			<view style="margin: 0 auto;height: 240px;" @click="idLow">
				<image v-bind:src = "id2" class="picture"></image>
				<view class="floats" v-if="certificatesTwo == true">
					<image src="../../static/img/authentication/xiangji@3x.png" style="width: 60px;height: 50px;">
					</image>
					<view class="words">
						上传身份证国徽页
					</view>
				</view>
			</view>
		</view>
		<view class="c-row b-b">
			<text class="tit">姓名</text>
			<view class="con-list">
				<input placeholder="请填写姓名" name="input" v-model="identityAuthenticationInfo.customerName"></input>
			</view>
		</view>
		<view class="c-row b-b">
			<text class="tit">身份证号</text>
			<view class="con-list">
				<input placeholder="请填写身份证号" name="input"
					v-model="identityAuthenticationInfo.customerNumberCard"></input>
			</view>
		</view>
		 <button class="btns btn"  @click="jumpUrl">下一步</button>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		name: "buy",
		data() {
			return {
				
				id:[],
				id1:"../../static/img/authentication/identityup(3).png",
				id2:"../../static/img/authentication/identitylow(3).png",
				identityImgs1:{},
				identityAuthenticationInfo:{},
				certificates:true,
				certificatesTwo:true,
			}
		},
		onLoad(options){
			this.identityAuthenticationInfo = JSON.parse(options.identityAuthenticationInfo)
			console.log(this.identityAuthenticationInfo)
		},
		methods:{
			jumpUrl(){
				this.identityAuthenticationInfo.cardAddressUrl = this.id.toString()
				if(this.id[0] == '' || this.id[0] == null){
					this.$api.msg('请上传身份证正面')
					return
				}
				if(this.id[1] == '' || this.id[1] == null){
					this.$api.msg('请上传身份证反面')
					return
				}
				if (!this.identityAuthenticationInfo.customerName) {
					this.$api.msg('姓名不能为空')
					return
				}
				if (this.identityAuthenticationInfo.customerName.length < 2 || this.identityAuthenticationInfo.customerName.length > 10) {
					this.$api.msg('姓名输入错误')
					return
				}
				if (!this.identityAuthenticationInfo.customerNumberCard) {
					this.$api.msg('身份证号不能为空')
					return
				}	
				if (this.identityAuthenticationInfo.customerNumberCard.length != 18) {
					this.$api.msg('身份证号输入错误')
					return
				}
				var model = JSON.stringify(this.identityAuthenticationInfo);
				uni.navigateTo({
					url: `/pageD/identity/companyIdentityThree?identityAuthenticationInfo=` + model,
				})
			},
			idUp(){
				var that = this
				uni.chooseImage({
					success: function(res) {
						uni.uploadFile({
							url: 'https://www.zthymaoyi.com/upload/admin',
							filePath: res.tempFilePaths[0],
							name: 'file',
							success(res) {
								var data = res.data
								var strToObj = JSON.parse(data)			
								that.id[0] = strToObj.url
								that.id1 = strToObj.url
								that.certificates = false
								that.identityImgs1.personImg = strToObj.url
								that.$api.doRequest('get', '/driverViewInfo/personShibie', that.identityImgs1).then(res => {
									if(res.data.data.recPerson != null){
										if(res.data.data.recPerson != ""){
										that.$set(that.identityAuthenticationInfo,'customerName',res.data.data.recPerson)
										}
									}
									if(res.data.data.recPersonNo != null){
										if(res.data.data.recPersonNo != ""){
										that.$set(that.identityAuthenticationInfo,'customerNumberCard',res.data.data.recPersonNo)
										}
									}
								}).catch(res => {
									uni.showToast({
										title: res.data.message,
										icon: 'none',
										duration: 2000
									})
								})
							}
						})
					}
				})
			},
			idLow(){
				var that = this
				uni.chooseImage({
					success: function(res) {
						uni.uploadFile({
							url: 'https://www.zthymaoyi.com/upload/admin',
							filePath: res.tempFilePaths[0],
							name: 'file',
							success(res) {
								var data = res.data
								var strToObj = JSON.parse(data)			
								that.id[1] = strToObj.url
								that.id2 = strToObj.url
								that.certificatesTwo = false
								that.identityImgs1.personImg = strToObj.url
								that.$api.doRequest('get', '/driverViewInfo/personShibie', that.identityImgs1).then(res => {
									if(res.data.data.recPerson != null){
										if(res.data.data.recPerson != ""){
											that.$set(that.identityAuthenticationInfo,'customerName',res.data.data.recPerson)
										}
										
									}
									if(res.data.data.recPersonNo != null){
										if(res.data.data.recPersonNo != ""){
											that.$set(that.identityAuthenticationInfo,'customerNumberCard',res.data.data.recPersonNo)
										}
										
									}
								}).catch(res => {
									uni.showToast({
										title: res.data.message,
										icon: 'none',
										duration: 2000
									})
								})
							}
						})
					}
				})
			},
		}
	}
</script>

<style>
	.center {
		padding: 10px 20px;
		background-color: #F5F6FA;
	}
	.c-row {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding: 20rpx 30rpx;
		position: relative;
	}
	.con-list {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		-webkit-flex-direction: column;
		flex-direction: column;
		color: #303133;
		line-height: 40rpx;
		text-align: right;
		padding-right: 20rpx;
		font-size: 14px;
	}

	.btn {
		margin-top: 10px;
		background-color: #FFFFFF;
		border-radius: 25px;
		border: none;
	}

	.btns {
		background-color: #22C572;
		color: white;
	}
	.picture{
		width: 100%;
		 height: 220px;
		 text-align: center;
		 margin-top: 10px;
	}
	.words{
		font-size: 18px;
		font-weight: 600;
		color: #617E8B;
		}
		.floats{
			position: relative;
			top: -150px;
			text-align: center;
		}
</style>
