<template>
	<view class="" >
		
	
	
	<view  v-if="status!=3&&status!=1">
		<image src="../../static/bg.png" mode="" class="bg"></image>
		<view class="top">
			注册会员
			<image src="../../static/index/goback.png" mode="" @click="goback"></image>
		</view>
		<view class="form" >
			<view class="">
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">昵称</text>
					<input type="text" v-model="nickname" placeholder="请输入您的昵称">
				</view>
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">单位名称</text>
					<input type="text" v-model="unit" placeholder="请输入您的单位名称">
				</view>
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">姓名</text>
					<input type="text" v-model="name" placeholder="请输入姓名">
				</view>
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">性别</text>
					<u-radio-group 
					    v-model="radiovalue1"
					    placement="row"
					  >
					    <u-radio
					      :customStyle="{marginBottom: '8px'}"
					      v-for="(item, index) in radiolist1"
					      :key="item.id"
					      :label="item.name"
					      :name="item.id"
					    >
					    </u-radio>
					  </u-radio-group>
				</view>
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">身份证号</text>
					<input type="text" v-model="idcard" placeholder="请输入您的身份证号">
				</view>
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">年龄</text>
					<input type="number" v-model="age" placeholder="请输入您的年龄">
				</view> 
				<view class="item u-flex u-row-between" @click="show=true">
					<text class="itemText" style="white-space: nowrap;">学历</text>
					<view class="u-flex" style="text-align: right;justify-content: flex-end;flex: 1;">
						<text >{{current!=null?current:'请选择您的学历'}}</text>
						<u-icon name="arrow-right" ></u-icon>
					</view>
				</view> 
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">身高</text>
					<input type="number" v-model="height" placeholder="请输入您的身高(cm)">
				</view>
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">体重</text>
					<input type="number" v-model="weight" placeholder="请输入您的体重(kg)">
				</view>
				<view class="item u-flex  u-row-between">
					<text class="itemText" style="white-space: nowrap;">现居地</text>
					<view class=" u-flex">
						<input type="text" @click="showaddress=true" :disabled="true" placeholder="请选择现居地" style="flex: 1;"
							v-model="address.length==0?'':address[0].name+'-'+address[1].name">
						<u-icon name="arrow-down"></u-icon>
						
					</view>
				</view>
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">手机号</text>
					<input type="number" v-model="phone" placeholder="请输入手机号">
				</view>
				
				<view class="item u-flex u-row-between">
					<text class="itemText" style="white-space: nowrap;">验证码</text>
					<view class="u-flex" >
						<input v-model="code" type="text" placeholder=" ">
						<text style="color: #2A63F3;background: linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%);-webkit-background-clip: text;-webkit-text-fill-color: transparent;white-space: nowrap;" @click="getCode">{{count}}</text>
					</view>
				</view>
				<view class="item1  u-col-center">
					<text class="itemText" style="white-space: nowrap;margin-bottom: 28rpx;">个人生活照</text>
					<u-upload
						:fileList="fileList"
						@afterRead="afterRead"
						@delete="deletePic"
						name="3"
						:multiple='false'
						:maxCount=1
						:previewFullImage="true"
						width="110"
							height="110"
							
					></u-upload>
				</view>
				
				
			</view>
		</view>
		<view class="" style="margin: 60rpx 30rpx 0;padding-bottom: 50rpx;">
			<u-button text="确定" @click="gorenzheng" shape="circle" color="linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%)"
				></u-button>
		</view>
		
		<u-picker :show="showaddress" @cancel='showaddress=false' keyName="name" title="居住地" ref="uPicker"
			:columns="addresscolumns" @confirm="addressconfirm"></u-picker>
		<u-picker :show="show" :columns="columns" keyName="name" @confirm='change' @cancel='cancel' :closeOnClickOverlay='true'>
		</u-picker>
	</view>
	<view class="error u-flex-col u-col-center" v-if="status==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 u-flex-col u-col-center" v-if="status==1">
		<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>
	</view>
</template>

<script>
	import AddressPicker from "@/components/lingdang-AddressPicker/AddressPicker.vue"
	export default {
		components:{
			AddressPicker
		},
		onPullDownRefresh() {
				
				setTimeout(function () {
					uni.stopPullDownRefresh();
				}, 1000);
			},
		onLoad() {
			this.getAddress()
				this.getInfo()
		},
		onShow() {
				
				
		},
		data() {
			return {
				fileList:[],
				address:[],
				showaddress:false,
				nickname:'',
				radiolist1: [{
				            name: '男',
				            id: 1
				          },
				            {
				              name: '女',
				              id: 2
				            }
				          ],
				radiovalue1:'',
				status:0,
				s:60,
				count:'获取验证码',
				code:'',
				age:'',
				height:'',
				weight:'',
				unit:'',
				idcard:'',
				working:{},
				fileList1: [],
				show: false,
				columns: [
					['高中','大专','本科','硕士','博士']
				],
				current: null,
				name:'',
				phone:'',
				workImg:'',
				type:'',
				reason:'',
				uuid:'',
				addresscolumns: [
					[{"id": 1,
						"name": "临沂市"}
					],
					[{"id":1480,"name":"兰山区"},{"id":1481,"name":"罗庄区"},{"id":1482,"name":"河东区"},{"id":1483,"name":"沂南县"},{"id":1484,"name":"郯城县"},{"id":1485,"name":"沂水县"},{"id":1486,"name":"兰陵县"},{"id":1487,"name":"费县"},{"id":1488,"name":"平邑县"},{"id":1489,"name":"莒南县"},{"id":1490,"name":"蒙阴县"},{"id":1491,"name":"临沭县"}]
				],
			}
		},
		methods: {
			getAddress() {
				uni.$u.http.post('/api/index/linyi').then(res => {
					this.addresscolumns[1] = res.data
				})
			},
			// 删除图片
						deletePic(event) {
							console.log(event)
							var that=this
							this.fileList=[]
			
						},
						// 新增图片
						async afterRead(event) {
							console.log('event',event)
							// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
							let lists = [].concat(event.file)
							// let fileListLen = this.fileList.length
							lists.map((item) => {
								this.fileList.push({
									...item,
									status: 'uploading',
									message: '上传中'
								})
							})
							for (let i = 0; i < lists.length; i++) {
								const result = await this.uploadFilePromise(lists[i].url)
								console.log('result',result)
								uni.$u.http.post('/api/user/upload_album',{image:result,type:1}).then(res => {
									if(res.code==1){
										this.getpersonPhoto()
									}
								})
								// let item = this.fileList[fileListLen]
								// this.fileList.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)
									}
								});
							})
						},
			addressconfirm(e){
				console.log(e)
				this.address = e.value
				this.showaddress = false
			},
			goback(){
					uni.switchTab({
						url:'./index'
					})
			},
			reset(){
					this.status=0
			},
			getInfo() {
				uni.$u.http.post('/api/user/userinfo').then(res => {
					if (res.code == 1) {
						this.status=res.data.is_info
						if(res.data.is_info==3){
							this.reason=res.data.reason
						}
					}
				})
			},
			getCode(){
			if (this.s == 60) {
				if (!this.phone) {
					uni.showToast({
						title: "请输入手机号",
						duration: 2000,
						icon: "none",
					});
					return false;
				}
				      
				uni.$u.http.post('/api/Sms/alsend',{phone:this.phone}).then((res) => {
					uni.hideLoading()
					uni.showToast({
						title: res.msg,
						duration: 2000,
						icon: "none",
					});
					if (res.code == 1) {
						this.time = setInterval(() => {
							this.s--
							this.count = `${this.s}s`
							if (this.s <= 0) {
								this.s = 60
								this.count = '重新发送'
								clearInterval(this.time)
							}
						}, 1000)
					}
				});
				}
			},
			changeAddress(result) {
					// this.info.province_id=result.data[0].id
					// this.info.city_id=result.data[1].id
					this.area_id=result.data[2].id
				this.address = '';
				result.data.forEach((item, index) => {
					if (index === 0) {
						this.address += item.name
					} else {
						this.address += '-' + item.name
					}
				});
				let arr = this.info.address.split('-');
			},
			gorenzheng(){
				if(!this.nickname){
					this.$u.toast('请输入昵称')
					return
				}
				if(!this.name){
					this.$u.toast('请输入姓名')
					return
				}
				if(!this.radiovalue1){
					this.$u.toast('请选择性别')
					return
				}
				if(!this.idcard){
					this.$u.toast('请输入身份证号')
					return
				}
				if(!this.age){
					this.$u.toast('请输入年龄')
					return
				}
				if(!this.height){
					this.$u.toast('请输入身高')
					return
				}
				if(!this.weight){
					this.$u.toast('请输入体重')
					return
				}
				if(this.address.length==0){
					this.$u.toast('请选择现居地')
					return
				}
				if(this.current==null){
					this.$u.toast('请选择学历')
					return
				}
				if(this.fileList.length==0){
					this.$u.toast('请上传个人生活照')
					return
				}
				if(!this.phone){
					this.$u.toast('请输入手机号')
					return
				}
				if(!this.code){
					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
				// }
				
				let data={
					type:1,
					nickname:this.nickname,
					workshow:this.unit,
					username:this.name,
					sex:this.radiovalue1,
					ID_car:this.idcard,
					age:this.age,
					education:this.current,
					height:this.height,
					weight:this.weight,
					area_id:this.address[1].id,
					headimg:this.fileList[0].url,
					phone:this.phone,
					code:this.code,
					
				}
				uni.$u.http.post('/api/index/member_basic',data).then(res => {
									if(res.code==1){
										this.$u.toast(res.msg)
										this.getInfo() 
									}
								})
			},
			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
							}
						});
					}
				});
			},

			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.splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this.fileList.length
				lists.map((item) => {
					this.fileList.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[fileListLen]
					this.fileList.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">
	.u-radio-group{
		justify-content: flex-end;
	}
	// #ifdef H5
	page{
		background: url(/static/bg.png) no-repeat;
	}
	//#endif
	.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;
		}
	}
	.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{
		margin-top: 30rpx;
		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: 36rpx 30rpx 0;
		background-color: #fff;
		border-radius: 40rpx ;
		background: #fff;

		.item {
			height: 94rpx;
			line-height: 94rpx;
			border-bottom: 2rpx solid #F5F5F5;
			
			text {
				font-size: 30rpx;
				color: #222222;
				position: relative;
			}
			.itemText::after{
				content: "*";
				position: absolute;
				color: #E02020;
			}

			input {
				text-align: right;
			}
		}
		.item1{
			text {
				font-size: 30rpx;
				color: #222222;
				position: relative;
			}
			.itemText::after{
				content: "*";
				position: absolute;
				color: #E02020;
			}
			
			input {
				text-align: right;
			}
		}
	}

	.top {
		position: relative;
		padding-top: 44rpx;
		text-align: center;
		font-size: 36rpx;
		font-weight: 600;

		image {
			width: 64rpx;
			height: 64rpx;
			position: absolute;
			left: 30rpx;
			
		}
	}
</style>
