<template>
	<view class="" >
		
	
	
	<view >
		<image src="../../static/bg.png" mode="" class="bg"></image>
		<view class="top">
			<image src="../../static/auth/5@2x.png" mode=""></image>
		</view>
		<view class="form" v-if="type==1">
			<view class="">
				<view class="item u-flex u-row-between">
					<text style="white-space: nowrap;">姓名</text>
					<input type="text" v-model="name" placeholder="请输入姓名">
				</view>
				<view class="item u-flex u-row-between">
					<text style="white-space: nowrap;">手机号</text>
					<input type="number" v-model="phone" placeholder="请输入手机号">
				</view>
				<view class="item u-flex u-row-between" @click="show=true">
					<text style="white-space: nowrap;">工会</text>
					<view class="u-flex" style="text-align: right;justify-content: flex-end;flex: 1;">
						<text style="color: #FF5B5B;">{{current!=null?current.name:'请选择工会'}}</text>
						<u-icon name="arrow-right" color="#FF5B5B"></u-icon>
					</view>
				</view> 
				<view class="item u-flex u-row-between">
					<text style="white-space: nowrap;">会员号</text>
					<input v-model="uuid" type="text" placeholder="请填写会员号">
				</view>
				<view class="upload">
					<view class="title">
						<text>*</text>上传单位证明
					</view>
					<view class="uploadContent" @click="uploadImg">
						<image :src="workImg" mode="" style="position: absolute;top: 0;right: 0;bottom: 40rpx;left: 0;z-index: 999;width: 100%;height: 400rpx;" v-show="workImg"></image>
						<view class="contentTop">
							<image src="../../static/auth/1@2x.png" mode="" class="bigImg"></image>
							<image src="../../static/auth/2@2x.png" mode="" class="smallImg"></image>
						</view>
						<view class="contentBottom" >
							拍摄单位证明
						</view>
					</view>
					<view class="lookvip" @click="toVip">
						<image src="../../static/auth/3@2x.png" mode=""
							style="width: 28rpx;height: 28rpx;vertical-align: middle;"></image>
						<text>查看会员登记表</text>
						<image src="../../static/auth/4@2x.png" mode=""
							style="width: 12rpx;height: 12rpx;vertical-align: middle;"></image>
					</view>
				</view>
				<view class="upload">
					<view class="title" style="margin-bottom: 18rpx;">
						<text>*</text>上传个人照片<text style="font-size: 20rpx;color: #D2D2D2;">（至少上传一张照片）</text>
					</view>
					<u-upload :fileList="fileList1"  @afterRead="afterRead" @delete="deletePic" name="1" :multiple='false'
						:maxCount="3">
						
						</u-upload>
				</view>
				<u-button text="立即认证" @click="gorenzheng" shape="circle" color="linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%)"
					></u-button>
			</view>
		</view>
		<view class="error u-flex-col u-col-center" v-if="type==3">
			<image src="../../static/auth/error@2x.png" mode=""></image>
			<text style="font-size: 40rpx;font-weight: 600;margin: 48rpx 0 16rpx;">认证失败</text>
			<text>您的实名认证审核没有通过</text>
			<view class="reason">
				{{reason}}
			</view>
			<view class="u-flex u-row-around btnlist">
				<view class="btn1" @click="reset">
					重新认证
				</view>
				<view class="btn" style="color: #fff;"  @click="reset">
					暂不认证
				</view>
			</view>
		</view>
		<view class="error success u-flex-col u-col-center" v-if="type==2">
			<image src="../../static/auth/succes@2x.png" mode=""></image>
			<text style="font-size: 40rpx;font-weight: 600;margin: 48rpx 0 16rpx;">恭喜您认证成功</text>
			<view class="info">
				<view class="infoitem u-flex u-row-between">
					<text>真实姓名</text>
					<input type="text" v-model="name" :disabled="true"  style="text-align: right;flex: 1;">
				</view>
				<view class="infoitem u-flex u-row-between">
					<text>手机号</text>
					<input type="text" v-model="phone" :disabled="true" style="text-align: right;flex: 1;">
				</view>
				<view class="infoitem u-flex u-row-between">
					<text>工会单位</text>
					<input type="text" v-model="unit" :disabled="true"  style="text-align: right;flex: 1;">
				</view>
			</view>
		</view>
		<view class="error u-flex-col u-col-center" v-if="type==4">
			<image src="../../static/auth/shenhe@2x.png" mode=""></image>
			<text style="font-size: 40rpx;font-weight: 600;margin: 48rpx 0 16rpx;">管理员审核中</text>
			<text>请耐心等待审核结果哦～</text>
			
		</view>
		<u-picker :show="show" :columns="columns" keyName="name" @confirm='change' @cancel='cancel' :closeOnClickOverlay='true'>
		</u-picker>
	</view>
	</view>
</template>

<script>
	export default {
		onPullDownRefresh() {
				
				setTimeout(function () {
					uni.stopPullDownRefresh();
				}, 1000);
			},
		onLoad() {
				this.getWorking()
		},
		onShow() {
				this.getType()
				
		},
		data() {
			return {
				
				working:{},
				fileList1: [],
				show: false,
				columns: [
					[]
				],
				current: null,
				name:'',
				phone:'',
				unit:'',
				workImg:'',
				type:'',
				reason:'',
				uuid:''
			}
		},
		methods: {
			toVip(){
					uni.navigateTo({
						url:'./dengjibiao'
					})
			},
			reset(){
				uni.$u.http.post('/api/Authentication/new_authentication').then(res => {
									this.getType()
								})
			},
			getType(){
				uni.$u.http.post('/api/Authentication/show').then(res => {
									this.type=res.data.type
									if(res.data.type==2){
										this.name=res.data.data.username
										this.phone=res.data.data.phone
										this.unit=res.data.data.name
									}
									if(res.data.type==3){
										this.reason=res.data.data.reason
									}
								})
			},
			gorenzheng(){
				if(!this.name){
					this.$u.toast('请输入姓名')
					return
				}
				if(!this.phone){
					this.$u.toast('请输入手机号')
					return
				}
				if(!this.uuid){
					this.$u.toast('请输入会员号')
					return
				}
				if(!this.workImg){
					this.$u.toast('上传单位证明')
					return
				}
				if(this.fileList1.length==0){
					this.$u.toast('上传个人照片')
					return
				}
				var arr=[]
				this.fileList1.forEach(item=>{
					arr.push(item.url)
				})
				let data={
					name:this.name,
					phone:this.phone,
					c_id:this.current.id,
					uuid:this.uuid,
					c_image:this.workImg,
					m_images:arr.toString()
					
					
				}
				uni.$u.http.post('/api/Authentication/authentication',data).then(res => {
					if(res.code==1){
						this.getType()
					}
				})
			},
			uploadImg(){
				var that=this
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: this.$url+'/api/Publics/uploadLocality', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							
							success: (uploadFileRes) => {
								that.workImg=JSON.parse(uploadFileRes.data).data.url
							}
						});
					}
				});
			},
			getWorking(){
				uni.$u.http.post('/api/Publics/working').then(res => {
					this.columns=[res.data]
				})
			},
			change(e) {
				this.current = e.value[0]
				// console.log(this.columns[0][this.current])
				this.show = false
			},
			cancel() {
				this.show = false
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(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++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$url+'/api/Publics/uploadLocality', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(JSON.parse(res.data).data.url)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style lang="scss">
	.success{
		box-sizing: border-box;
		padding: 0 40rpx;
		height: auto;
	}
	.info{
		padding: 40rpx 40rpx 0;
		width: 100%;
		margin-top: 80rpx;
		border-top: 2rpx solid #F3F3F3;
		.infoitem{
			line-height: 100rpx;
			width: 100%;
			font-size: 30rpx;
			color: #222222;
		}
	}
	.btnlist{
		width: 100%;
	}
	.btn1{
		font-weight: 500;
		color: #FFFFFF;
		line-height: 50px;
		background: linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		width: 270rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		font-size: 36rpx;
		border-radius: 48rpx;
		border: 4rpx solid #E6CDE6;
		// border-image: linear-gradient(270deg, rgba(171, 145, 252, 1), rgba(251, 173, 177, 1)) 2 2;
	}
	.btn{
		width: 270rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		background: linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%);
		border-radius: 48rpx;
		font-size: 36rpx;
	}
	.error{
		padding-top: 96rpx;
		padding-bottom: 94rpx;
		margin: 56rpx auto 0;
		width: 690rpx;
		// height: 888rpx;
		background: #FFFFFF;
		border-radius: 40rpx;
		font-size: 24rpx;
		color: #222222;
		image{
			width: 140rpx;
			height: 140rpx;
		}
		.reason{
			padding: 24rpx 20rpx;
			margin: 52rpx auto 64rpx;
			width: 610rpx;
			height: 200rpx;
			background: #F4F4F4;
			border-radius: 20rpx;
		}
	}
	.lookvip {
		font-weight: 500;
		margin-top: 24rpx;
		font-size: 24rpx;
		color: #555555;
		text-align: center;

		text {
			margin: 0 8rpx;
		}
	}

	.uploadContent {
		position: relative;
		margin-top: 32rpx;
		width: 650rpx;
		height: 472rpx;
		font-size: 28rpx;
		color: #fff;
		font-weight: 600;
		background: #F3F4F6;
		border-radius: 20rpx;

		.contentTop {
			height: 400rpx;
			background-color: #F3F4F6;
			position: relative;

			.bigImg {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
				width: 510rpx;
				height: 320rpx;
			}

			.smallImg {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
				width: 116rpx;
				height: 116rpx;
				z-index: 1;
			}
		}

		.contentBottom {
			width: 650rpx;
			height: 72rpx;
			line-height: 72rpx;
			text-align: center;
			background: linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%);
			border-radius: 0px 0px 20rpx 20rpx;
		}
	}

	.upload {
		margin: 20rpx auto;
		width: 690rpx;
		// height: 652rpx;
		padding: 24rpx 20rpx;
		background: #FDFCFE;
		box-shadow: 0px 0px 16rpx 0px rgba(0, 0, 0, 0.0400);
		border-radius: 24rpx;
		box-sizing: border-box;

		.title {
			font-weight: 500;
			font-size: 30rpx;
			color: #222222;

			text {
				color: #FF5B5B;
			}
		}
	}

	.form {
		padding: 0 30rpx;
		margin-top: 36rpx;
		background-color: #fff;
		border-radius: 40rpx 40rpx 0px 0px;
		background: linear-gradient(180deg, #FFFFFF 0%, #F6F2FD 100%);

		.item {
			height: 94rpx;
			line-height: 94rpx;
			border-bottom: 2rpx solid #F5F5F5;

			text {
				font-size: 30rpx;
				color: #222222;
			}

			input {
				text-align: right;
			}
		}
	}

	.top {
		padding-top: 44rpx;
		padding-left: 30rpx;

		image {
			width: 102rpx;
			height: 60rpx;
		}
	}
</style>
