<template>
	<view>
		<view class="" v-if="auth_status=='0'||zaitijiao">
			<view class="box" >
				<uni-forms ref="form" :modelValue="formData" :rules="rules" label-width="200rpx">
					<uni-forms-item label="姓名" name="name">
						<input class="input" v-model="formData.name" type="text" placeholder="请输入" />
					</uni-forms-item>
					<view class="border"></view>
					<uni-forms-item label="身份证" name="name">
						<input class="input" v-model="formData.card" type="text" placeholder="请输入" />
					</uni-forms-item>
					<view class="border"></view>
					<uni-forms-item label="车型" name="name">
						<picker @change="bindPickerChange" mode='selector' :value="index" :range="carlist" range-key="name">
							<view class="input">{{carlist[carindex].name?carlist[carindex].name:'请选择'}}</view>
						</picker>
						<!-- <input class="input" v-model="formData.card" type="text" placeholder="请输入" /> -->
					</uni-forms-item>
				</uni-forms>
			</view>
			<view class="sfz">
				<view class="sfzwz">身份证照片</view>
				<!--#ifdef MP-WEIXIN -->
				<view class="sfztp">
					<image @click="uploadFile('sfzzm','card_zm_img')" class="sfzimg" :src="formDataxs.sfzzm" mode=""></image>
					<image @click="uploadFile('sfzfm','card_fm_img')"  class="sfzimg" :src="formDataxs.sfzfm" mode=""></image>
				</view>
				<!--#endif-->
				<!--#ifdef APP-PLUS || APP-->
				<view class="sfztp">
					<image @click="uploadFile1('sfzzm','card_zm_img')" class="sfzimg" :src="formDataxs.sfzzm" mode=""></image>
					<image @click="uploadFile1('sfzfm','card_fm_img')"  class="sfzimg" :src="formDataxs.sfzfm" mode=""></image>
				</view>
				<!--#endif-->
			</view>
			<view class="sfz">
				<view class="sfzwz">驾驶证照片</view>
				<!--#ifdef MP-WEIXIN -->
				<view class="sfztp">
					<image class="sfzimg"  @click="uploadFile('jszzm','driving_zm_img')" :src="formDataxs.jszzm" mode=""></image>
					<image class="sfzimg"   @click="uploadFile('jszfm','driving_fm_img')" :src="formDataxs.jszfm" mode=""></image>
				</view>
				<!--#endif-->
				<!--#ifdef APP-PLUS || APP-->
				<view class="sfztp">
					<image class="sfzimg"  @click="uploadFile1('jszzm','driving_zm_img')" :src="formDataxs.jszzm" mode=""></image>
					<image class="sfzimg"   @click="uploadFile1('jszfm','driving_fm_img')" :src="formDataxs.jszfm" mode=""></image>
				</view>
				<!--#endif-->
			</view>
			<view class="sfz">
				<view class="sfzwz">行驶证照片</view>
				<!--#ifdef MP-WEIXIN -->
				<view class="sfztp">
					<image class="sfzimg" @click="uploadFile('xszzm','drive_zm_img')" :src="formDataxs.xszzm" mode=""></image>
					<image class="sfzimg" @click="uploadFile('xszfm','drive_fm_img')" :src="formDataxs.xszfm"  mode=""></image>
				</view>
				<!--#endif-->
				<!--#ifdef APP-PLUS || APP-->
				<view class="sfztp">
					<image class="sfzimg" @click="uploadFile1('xszzm','drive_zm_img')" :src="formDataxs.xszzm" mode=""></image>
					<image class="sfzimg" @click="uploadFile1('xszfm','drive_fm_img')" :src="formDataxs.xszfm"  mode=""></image>
				</view>
				<!--#endif-->
				<button class="subbtn" @click="auth">提交</button>
			</view>
		</view>
		<view class="shzbox" v-if="auth_status=='1'">
			<image src="@/static/shenhe.png" mode="" class="shzimg"></image>
			<view class="shzwz">
				审核中
			</view>
		</view>
		<view class="wtgbox" v-if="auth_status=='3'&&zaitijiao!=true">
			<image src="@/static/weitongguo.png" mode="" class="shzimg"></image>
			<view class="shzwz">
				未通过
			</view>
			<view class="jj">
				拒绝原因
			</view>
			<view class="jjyy">
				{{Info.reason}}
			</view>
			<button class="wtgsubbtn" @click="renzheng">重新认证</button>
		</view>
		<!-- <view class="cgbox" v-if="auth_status=='2'&&zaitijiao!=true"> -->
		<view class="cgbox" v-if="auth_status=='2'">
			<image src="@/static/renzhengchenggong.png" mode="" class="shzimg"></image>
			<view class="shzwz">
				认证成功，快去抢单吧~
			</view>
			<button class="wtgsubbtn" @click="ljqd">立即抢单</button>
			<!-- <button class="wtgsubbtn" @click="renzheng">重新认证</button> -->
		</view>
		<uni-popup ref="permissions_box_popup" background-color="#fff" :mask-click='false'>
			<view class="permissions_box" :style="{'padding-top': (statusBarHeight+64)+'px'}">
				当您使用APP时，为了提供图片上传的功能，我们需要申请相机/存储权限。
			</view>
		</uni-popup>
	</view>
</template>

<script>
	const systemInfoSync = uni.getSystemInfoSync()
	import permision from "@/js_sdk/wa-permission/permission.js"
	export default {
		data() {
			return {
				formDataxs:{
					sfzzm: require('@/static/card-01.png'),
					sfzfm:require('@/static/card-02.png'),
					jszzm:require('@/static/card-03.png'),
					jszfm:require('@/static/card-04.png'),
					xszzm:require('@/static/card-05.png'),
					xszfm:require('@/static/card-06.png')
				},
				formData: {
					car_type:''
				},
				carindex:'',
				auth_status:'',
				Info:{},
				zaitijiao:false,
				carlist:[],
				statusBarHeight: 0
			}
		},
		onLoad(e) {
			console.log('this.auth_status',e);
			this.auth_status=e.auth_status
		},
		onReady() {
			this.statusBarHeight = systemInfoSync.statusBarHeight;
		},
		onShow() {
			this.authInfo()
			this.carTypeList()
		},
		methods: {
			recorderAuthModal: function () {
				const that = this;
				uni.showModal({
					title: '温馨提示',
					content: '为了提供图片上传的功能，我们需要申请相机/存储权限，请您确认授权，否则无法使用该功能~',
					cancelText: '关闭',
					confirmText: '去授权',
					success(res) {
						that.$refs.permissions_box_popup.close('top')
						if (res.confirm) {
							permision.gotoAppPermissionSetting()
						}
					}
				})
			},
			uploadFile1(a,b) {
				const that = this;
				// APP检查权限
				if(uni.getSystemInfoSync().platform == 'android') {
					plus.android.checkPermission(
						'android.permission.WRITE_EXTERNAL_STORAGE',
						granted => {
						  if (granted.checkResult==-1){
							that.$refs.permissions_box_popup.open('top')
						  }else{
							tthat.$refs.permissions_box_popup.close('top')
							that.uploadFile(a,b);
						  }
						},
						error => {
						  console.error('Error checking permission:', error.message);
						}
					  );
					 that.requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE')
					return ;
				}
				that.uploadFile(a,b);
				
			},
			recorderAuthModal: function () {
				const that = this;
				uni.showModal({
					title: '温馨提示',
					content: '为了提供图片上传的功能，我们需要申请相机/存储权限，请您确认授权，否则无法使用该功能~',
					cancelText: '关闭',
					confirmText: '去授权',
					success(res) {
						that.$refs.permissions_box_popup.close('top')
						if (res.confirm) {
							permision.gotoAppPermissionSetting()
						}
					}
				})
			},
			async requestAndroidPermission(permisionID) {
				const that = this;
				var result = await permision.requestAndroidPermission(permisionID);
				if(result != 1){
					that.recorderAuthModal();
				}else{
					that.$refs.permissions_box_popup.close('top')
				}
			},
			bindPickerChange(e){
				this.carindex=e.detail.value
				console.log(e.detail.value);
				this.formData.car_type=this.carlist[e.detail.value].value
			},
			carTypeList(){
				this.$api.carTypeList().then(res=>{
					console.log(1245,res.data);
					this.carlist=res.data
					
				})
			},
			renzheng(){
				console.log('this.Info.car_type',this.Info.car_type);
				this.zaitijiao=true
				this.formDataxs.sfzzm=this.Info.card_zm_img_url
				this.formDataxs.sfzfm=this.Info.card_fm_img_url
				this.formDataxs.jszzm=this.Info.driving_zm_img_url
				this.formDataxs.jszfm=this.Info.driving_fm_url
				this.formDataxs.xszzm=this.Info.drive_zm_url
				this.formDataxs.xszfm=this.Info.drive_fm_img_url
				this.carlist.forEach((el,i)=>{
					if(el.value==this.Info.car_type){
						this.carindex=i
					}
				})
				
				// id
				this.formData.card_zm_img=this.Info.card_zm_img
				this.formData.card_fm_img=this.Info.card_fm_img
				this.formData.driving_zm_img=this.Info.driving_zm_img
				this.formData.driving_fm_img=this.Info.driving_fm_img
				this.formData.drive_zm_img=this.Info.drive_zm_img
				this.formData.drive_fm_img=this.Info.drive_fm_img
				this.formData.name=this.Info.name
				this.formData.card=this.Info.card
				this.formData.car_type=this.Info.car_type
			},
			authInfo(){
				this.$api.authInfo().then(res=>{
					this.Info=res.data
				})
			},
			auth(){
				this.$api.auth(this.formData).then(res=>{
					uni.showToast({
						icon: "none",
						title: res.data.msg,
						duration: 3000
					});
					if(res.code==200){
						uni.switchTab({
							url: "/pages/user/index"
						})
					}
				})
			},
			uploadFile(i,e){
				uni.chooseImage({
					count:1,
					success: (chooseImageRes) => {
						console.log('tempFilePaths',chooseImageRes);
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: 'https://logistics.njrenzhou.cn/api/uploadFile', //的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'user': 'test'
							},
							success: (uploadFileRes) => {
								console.log(123);
								this.formDataxs[i]=JSON.parse(uploadFileRes.data).data.url
								this.formData[e]=JSON.parse(uploadFileRes.data).data.id
							}
						});
					}
				});
			},
			ljqd(){
				uni.switchTab({
					url:'/pages/index/index'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.wtgsubbtn{
		margin-top: 80rpx;
		width: 702rpx;
		height: 98rpx;
		background: #0D5DC9;
		box-shadow: 0rpx 4rpx 13rpx 0rpx rgba(14,94,157,0.4);
		border-radius: 49rpx;
		border: 1px solid #0D5DC9;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 98rpx;
	}
	.wtgbox{
		background: #fff;
		height: 1624rpx;
	}
	.jjyy{
		width: 592rpx;
		height: 80rpx;
		background: #F9F9F9;
		border-radius: 10rpx;
		margin-left: 54rpx;
		margin-top: 21rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 30rpx;
		color: #E45050;
		line-height: 40rpx;
		padding: 25rpx;
	}
	.jj{
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 30rpx;
		color: #333333;
		line-height: 40rpx;
		margin-left: 54rpx; 
		margin-top: 21rpx;
	}
	.shzwz{
		text-align: center;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 36rpx;
		color: #333333;
		line-height: 80rpx;
	}
	.shzimg {
		width: 160rpx;
		height: 160rpx;
		margin-top: 119rpx;
		margin-left: 295rpx;
	}

	.shzbox {
		height: 1624rpx;
		background: #fff;
	}

	.subbtn {
		margin-top: 50rpx;
		width: 630rpx;
		height: 98rpx;
		background: #0D5DC9;
		box-shadow: 0rpx 4rpx 13rpx 0rpx rgba(14, 94, 157, 0.4);
		border-radius: 49rpx;
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 98rpx;
	}

	.sfztp {
		margin-top: 49rpx;
		display: flex;
		justify-content: space-between;
	}

	.sfzimg {
		width: 332rpx;
		height: 216rpx;
	}

	.sfz {
		background: #fff;
		margin-top: 20rpx;
		padding: 24rpx;
	}

	.sfzwz {
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 36rpx;
		color: #333333;
		line-height: 40rpx;
	}

	/deep/ .uni-forms-item {
		margin-bottom: 24rpx;
	}
	/deep/ .uni-forms-item__label {
		font-family: Alibaba PuHuiTi;
		font-weight: 400;
		font-size: 30rpx;
		color: #333333;
	}
	.border {
		border: 1px solid #EAEAEA;
		margin-bottom: 10rpx;
	}

	.input {
		margin-top: 15rpx;
		text-align: right;
	}

	.box {
		padding: 24rpx;
		background: #fff;
	}
</style>