<template>
	<view>


		<!-- <image class="img" src="https://xlzx.vvv5g.com/addons/yzd_edu//static/public/img/diy_default/lecture_in_img.png"></image> -->
		<view class="box" v-if="state == 0 || state == 3">
			<view class="item-submit" v-if="state == 3">
				<view>审核未通过, 请重新提交审核</view>
			</view>
<!-- 			<view class="item">
				<view class="item-text">姓名</view>
				<view class="item-input"><input v-model="title" type="text" placeholder="请输入您的姓名"></view>
			</view>
			<view class="item">
				<view class="item-text">手机号</view>
				<view class="item-input"><input v-model="phone" type="text" placeholder="请输入您的手机号"></view>
			</view>
			<view class="item">
				<view class="item-text">账号</view>
				<view class="item-input"><input v-model="username" type="text" placeholder="请输入您的账号">
				</view>
			</view>
			<view class="item">
				<view class="item-text">密码</view>
				<view class="item-input"><input v-model="password" type="password" placeholder="6-20个字母、数字、特殊字符"></view>
			</view>
			<view class="item">
				<view class="item-text">性别</view>
				<view class="item-input">
					<picker style="line-height: 44rpx;" @change="bindPickerChange" :value="index" :range="array" range-key="name">
						<view class="uni-input">{{array[index].name}}</view>
					</picker>
				</view>
			</view> -->
			<view class="item-u">
				<view class="item-text">
					<text>资质</text>
				</view>
				<view v-if="!img" class="choose-outer" @click="choodeImage">
					<text class="up-label">+</text>
					<text class="up-title">证书图片</text>
				</view>
				<image v-if="img" @click="choodeImage" :src="img" mode="aspectFill"
					style="width: 294rpx; height: 198rpx; border-radius: 15rpx;"></image>
			</view>
			<view class="item">
				<view class="item-text">请选择机构</view>
				<view class="item-input">
					<picker style="line-height: 44rpx;" @change="bindPickerChange" :value="index" :range="institutionList" range-key="nickname">
						<view class="uni-input">{{institutionList[index].nickname}}</view>
					</picker>
				</view>
			</view>
			<view class="item-submit">
				<view></view>
			</view>
			<view class="item-submit">
				<view class="item-button" @click="submit">提交审核</view>
			</view>

		</view>
		<view v-if="state == 1">
			<view class="item-submit">
				目前正在审核请耐心等待
			</view>
		</view>
		<view v-if="state == 2">
			<view class="item-submit">
				审核已通过
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '',
				phone: '',
				username: '',
				password: '',
				img: '',
				content: '',
				array: [{
					name: '男'
				}, {
					name: '女'
				}],
				action: '', // 图片上传地址
				index: 0,
				state: 0,
				identity: 0, // 1 咨询师 2机构
				page: 1,
				limit: 999,
				institutionList: [], // 机构列表
			}
		},
		onLoad(option) {
			// this.getInstitutionList();
			this.identity = option.identity;
			this.getInstitutionList();
		},
		methods: {
			//获取机构列表
			getInstitutionList(loading = true) {
				this.$request.getInstitutionList({
					page: this.page,
					limit: this.limit
				}).then( res =>{
					console.log(res)
					this.institutionList = res.data
				}).catch( e=>{
					console.log(e)
				})
			},
			// 选择图片上传
			choodeImage() {
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						// this.img = res.tempFilePaths[0]
						uni.showLoading({
							title: '上传中...'
						})
						uni.uploadFile({
							url: 'https://ocr.lfwhzb.com/api/upload/image', //接口地址
							filePath: res.tempFilePaths[0],
							name: 'upfile',
							success: (uploadFileRes) => {
								uni.hideLoading()
								console.log(uploadFileRes, '111111111111111')
								console.log(uploadFileRes);
								this.img = uploadFileRes.data
							}
						});
					}
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为：' + e.detail.value)
				this.index = e.detail.value
			},
			submit: function(e) {

				if (!this.title) {
					uni.showToast({
						title: '请输入姓名',
						icon: 'none'
					})
					return
				}

				if (!this.phone) {
					uni.showToast({
						title: '请输入手机号码',
						icon: 'none'
					})
					return
				}

				if (!this.username) {
					uni.showToast({
						title: '请输入账号',
						icon: 'none'
					})
					return
				}

				var pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z]).{6,30}');
				if (!pwdRegex.test(this.password)) {
					uni.showToast({
						title: "您的密码复杂度太低（密码中必须包含字母、数字），请及时修改密码！",
						icon: 'none'
					})
					return
				}

				if (!this.img) {
					uni.showToast({
						title: '请上传您的资质',
						icon: 'none'
					})
					return
				}

				this.$post({
					data: {
						do: 'LecturerSettled',
						data: {
							"title": this.title,
							"phone": this.phone,
							"username": this.username,
							"password": this.password,
							"img": this.img,
							"content": '',
							"sex": this.index + 1,
							"user_id": uni.getStorageSync('id'),
						}
					}
				}).then(res => {
					console.log(res, 'ssssssssssssssssssssss')
					uni.showToast({
						title: '添加成功',
						mask: true
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
				})
			}
		}
	}
</script>

<style>
	.item {
		display: flex;
		padding: 27rpx 0;
		border-bottom: 1px solid #f3f3f3;
		align-items: center;
	}

	.box {
		padding: 10rpx 30rpx;
	}

	.item-input {
		padding-left: 10rpx;
		width: 70%;
	}

	.item-text {
		min-width: 115rpx;
	}

	.img {
		width: 100%;
		height: 320rpx;
	}

	.item-button {
		width: 247rpx;
		max-content: 80rpx;
		text-align: center;
		line-height: 80rpx;
		background-color: #04ba8f;
		color: #fff;
		border-radius: 94rpx;
		box-shadow: 0 6rpx 6rpx rgba(0, 0, 0, .05);
		margin: 20rpx 0;
	}

	.item-submit {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.item-u {
		display: flex;
		padding: 10rpx 0;
		align-items: center;
	}

	.choose-outer {
		width: 290rpx;
		height: 198rpx;
		border: 2px dotted #CCCCCC;
		border-radius: 15rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>