<template>
	<view class="wrapper">
		<view class="oneText">

			<span class="nameSpan">姓名：</span><input type="text" class="nameInp" placeholder="请输入姓名" v-model="name">
		</view>
		<view class="twoText">

			<span class="cardSpan">身份证号：</span><input type="text" class="cardInp" placeholder="请输入身份证号" v-model="card">
		</view>
		<view class="cccc">
			<button class="cccBut"  @click="chooseVideo">实名验证</button>
		</view>
		<view class="postFrom">
			<button class="fromBut"  @click="getAuthen">确认提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: "",
				card: '',
				videoUrl: {},
				videoYes: false,
				Jbool: false
			};
		},
		methods: {
			chooseVideo() {
				// console.log(this.name,this.card);
				if (this.name == '') {
					return uni.$u.toast('请输入姓名');
				} else if (this.card == '') {
					return uni.$u.toast('请输入身份证号');
				}
				uni.chooseVideo({
					sourceType: ['camera'],
					compressed: true,
					maxDuration: 10,
					camera: 'front',
					success: res => {

						// console.log(res.tempFile);
						this.videoYes = true
						this.videoUrl = res.tempFile

					},
					fail: e => {
						console.log(e);
					}
				})
			},
			getAuthen() {
				if (this.Jbool) {
					return uni.showToast({
						title: "正在上传"
					})
				}
				this.Jbool=true
				// console.log(123);
				// uni.$u.route({ url: 'pages/mine/index'});
				if (this.name == '') {
					return uni.$u.toast('请输入姓名');
				} else if (this.card == '') {
					return uni.$u.toast('请输入身份证号');
				} else if (!this.videoYes) {
					return uni.$u.toast('请完成实名验证');
				}
				uni.uploadFile({
					url: "/api/user/real_person_auth",
					file: this.videoUrl,
					name: "video",
					formData: {
						"name": this.name,
						"id_card": this.card //其他表单字段，可根据需求添加
					},
					success: function(res) {
						this.Jbool = false
						uni.hideLoading()
						uni.showToast({
							title: "上传成功"
						})
						// console.log(res);
						setTimeout(function() {
							uni.navigateBack()
						}, 2000)
					},
					fail: function(err) {
						this.Jbool = false
						uni.hideLoading()
						uni.showToast({
							title: "上传失败"
						})
					}
				})

			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'Authentication.scss';
	// @import 'index.scss';
</style>