<template>
	<view class="real-name">
		<view class="item name_item">
			<view class="label">
				班级
			</view>
			<view class="right" @click="goEdit('班级',1,type=0)">
				{{form.truename ? form.truename : '去填写'}}
				<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view>
		<view class="item">
			<view class="label">
				入学时间
			</view>
			<view class="right" @click="goDay">
				<text>
					{{form.class ? form.class : '去填写'}}
				</text>
		
				<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view>
		<view class="item">
			<view class="label">
				专业
			</view>
			<view class="right" @click="goEdit('专业',5,type=0)">
				<text>
					{{form.account ? form.account : '去填写'}}
				</text>
				<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view>
		<!-- <view class="item">
			<view class="label">
				性别
			</view>
			<view class="right">
				<u-radio-group v-model="form.sex" @change="radioGroupChange">
					<u-radio v-for="(item, index) in list_sex" :key="index" :name="item.label">
						{{item.name}}
					</u-radio>
				</u-radio-group>
			</view>
		</view> -->
		
		<!-- <view class="item">
			<view class="label">
				个人照片
			</view>
			<view class="right" @click="goEdit('上传个人照片',2,type=2)">
				{{form.headimg ? '已上传' : '点击上传'}}
				<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view>-->
		<!-- <view class="item"> 
			<view class="label">
				邮箱
			</view>
			<view class="right" @click="goEdit('填写邮箱',4,type=0)">
				{{form.email ? form.email : '去填写'}}
				<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view> -->
		<view class="item">
			<view class="label">
				籍贯
			</view>
			<view class="right" @click="goEdit('籍贯',3,type=0)">
				<text>
					{{form.class ? form.class : '去填写'}}
				</text>

				<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view>


		<view class="item">
			<view class="label">
				政治面貌
			</view>
			<view class="right" @click="goEdit('政治面貌',6,type=0)">
				{{form.mobile ? form.mobile : '去填写'}}
				<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view>
		<!-- <view class="item">
			<view class="label">
				邮箱
			</view>
			<view class="right" @click="goEdit('填写邮箱',4,type=0)">
				{{form.email ? form.email : '去填写'}}
				<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view> -->
		<view class="item" v-if="!form.demand">
			<view class="label">
				学习经历
			</view>
			<view class="right" @click="goEdit('学习经历',9,type=1)">
				去填写<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view>
		<view class="item1" v-if="form.demand">
			<view class="item">
				<view class="label">
					学习经历
				</view>
				<view class="right" @click="goEdit('学习经历',9,type=1)">
					修改<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
				</view>
			</view>
			<view class="dec">
				{{form.demand}}
			</view>
		</view>
		
		<view class="item" v-if="!form.demand">
			<view class="label">
				工作经历
			</view>
			<view class="right" @click="goEdit('工作经历',9,type=1)">
				去填写<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
			</view>
		</view>
		<view class="item1" v-if="form.demand">
			<view class="item">
				<view class="label">
					工作经历
				</view>
				<view class="right" @click="goEdit('工作经历',9,type=1)">
					修改<u-icon name="arrow-right" size="20" margin-left="20"></u-icon>
				</view>
			</view>
			<view class="dec">
				{{form.demand}}
			</view>
		</view>
		
		<u-calendar v-model="calendar_show" :mode="mode"  @change="change_date"></u-calendar>
		
		<u-popup v-model="show" mode="bottom" height="100%">
			<view class="form">
				<view class="back" @click="show=false">
					<u-icon name="arrow-left" size="30"></u-icon>
				</view>
				<u-navbar :is-back="false" title="填写信息"></u-navbar>
				<view class="title">
					{{input_name}}
				</view>
				<view class="input" v-if="type==0">
					<u-input v-model="value" :placeholder=' "请输入" + input_name' />
				</view>
				<!-- 上传图片 -->
				<view class="upload_image" v-if="item==2&&image_edit==0">
					<u-upload ref="uUpload" :action="action" :auto-upload="true" :form-data='imageDate'
						:file-list="fileList" @on-success='uploadSuccess'></u-upload>
				</view>

				<view class="upload_image" v-if="item==2 && image_edit==1">
					<u-image width="100%" height="300rpx" :src="uploadImage"></u-image>
				</view>
				<view class="complate" v-if="item==2 && image_edit==1" @click="reload">
					重新上传
				</view>
				<view class="complate1" v-if="item==2 " @click="complate">
					完成
				</view>
				<!-- textear编辑 -->
				<view class="upload_image" v-if="type==1">
					<u-input v-model="textarea" type="textarea" :border="true"  />
				</view>
				<view class="complate" v-if="item!=2" @click="complate">
					完成
				</view>
				<!-- 性别 -->
				<!-- <view class="upload_image" v-if="type==3">
					<u-radio-group v-model="value_sex" @change="radioGroupChange">
						<u-radio v-for="(item, index) in list_sex" :key="index" :name="item.name"
							:disabled="item.disabled">
							{{item.name}}
						</u-radio>
					</u-radio-group>
				</view> 
 				<view class="complate" v-if="item!=2" @click="complate">
					完成
				</view> -->
			</view>
		</u-popup>
		<!-- <view class="buttom" @click="mentor">
			保存
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				input_name: '',
				item: '',
				image_edit: 0,
				value: '', //输入框的内容
				action: '', //封面图上传地址
				imageDate: {
					file_type: 'img',
					type: 'tearcher_headimg'
				}, //上传图片携带参数
				fileList: [],
				uploadImage: '',
				type: 0, //0input输入框，1textare输入框
				textarea: '',
				form: {
					status: 1,
					sex: 0
				},
				list_sex: [{
						name: '男',
						label: 0
					},
					{
						name: '女',
						label: 1
					},

				],
				rules: {
					name: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式
						trigger: 'blur,change'
					}],
					intro: [{
						min: 5,
						message: '简介不能少于5个字',
						trigger: 'change'
					}]
				},
				calendar_show: false,
				mode: 'date'
			}
		},
		onLoad(options) {
		
			if (options.type == 0) {
				this.getMe()
			}
		},
		onShow() {

			this.action = '/api/base/common/upload'
		},
		methods: {
			
			radioGroupChange(e) {
				console.log(e);
				this.form.sex = e
			},
			getMe() {
				this.$u.get('/base/auth/me').then(res => {
					console.log(res, 'ppp')
					this.form = res.data.type_model
					this.uploadImage = res.data.headimg
					this.image_edit = 1
				})
			},
			//保存修改
			mentor() {

				let id = this.$store.state.vuex_user.type_id
				this.$u.put('/mentor/student/' + id, this.form).then(res => {
					if (res.code == 200) {
						console.log(res, 'pppp')
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						setTimeout(function() {
							uni.switchTab({
								url: './tea_index'
							})
						}, 1500)
					}
				})
			},
			//上传图片成功
			uploadSuccess(data) {
				console.log(data, 'ppp')
				// this.form.headimg = data.data[0].id
				this.form.headimg = data.data[0].url
				this.uploadImage = data.data[0].url
				this.image_edit = 1
			},
			//重新上传
			reload() {
				this.image_edit = 0
				console.log('---------')
				this.fileList = [],
					this.uploadImage = ''
			},
			//修改出生日期
			goDay(){
				this.calendar_show=true
			},
			change_date(e){
				console.log(e,11111)
				this.form.date = e.result
			},
			goEdit(name, item) {
				if (this.uploadImage) {
					this.fileList.push({
						url: this.uploadImage
					})
				}
				this.show = true
				this.item = item
				this.input_name = name
				this.textarea = ''
				this.value = ''
				switch (item) {
					case 1:
						this.value = this.form.truename
						break
					case 2:

						break
					case 3:
						this.value = this.form.class
						break
					case 4:
						this.value = this.form.email
						break
					case 5:
						this.value = this.form.account
						break

					case 6:
						this.value = this.form.mobile
						break
					case 9:
						this.textarea = this.form.demand
						break
					case 10:
						this.sex = this.form.sex
						break

				}

			},
			complate() {
				let item = this.item
				switch (item) {
					case 1:
						this.form.truename = this.value
						break
					case 2:

						break
					case 3:
						this.form.class = this.value
						break
					case 4:
						this.form.email = this.value
						break
					case 5:
						this.form.account = this.value
						break
					case 6:
						this.form.mobile = this.value
						break
					case 9:
						this.form.demand = this.textarea
						break
					case 10:
						this.form.sex = this.value
						break

				}
				this.show = !this.show
			},
			//保存编辑
			save() {
				this.$u.post('/mentor/student', this.form).then(res => {
					console.log(res, 'oopp')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.upload_image {
		width: 90%;
		margin: 0 auto;
	}

	.complate,
	.complate1 {
		width: 50%;
		margin: 0 auto;
		margin-top: 20%;
		line-height: 44px;
		text-align: center;
		height: 44px;
		background: #3B7653;
		opacity: 1;
		border-radius: 24px;
		font-size: 18px;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		opacity: 1;
	}

	.complate1 {
		margin-top: 30px;
	}

	.real-name {
		padding: 0 16px;
		padding-bottom: 40px;
		.name_item{
			margin-top: 20px !important;
		}
		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 46px;
			line-height: 46px;
			// margin-top: 10px;

			.label {
				flex: 0 0 30%;
				font-size: 16px;
				font-family: PingFang SC;
				font-weight: bold;
				line-height: 20px;
				color: #282828;
				opacity: 1;
			}

			.right {
				// flex: 1;
				font-size: 13px;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 20px;
				color: #282828;
				opacity: 0.42;
				text-align: right;
				height: 20px;
				// overflow: hidden;
				display: flex;
				align-items: center;

				text {
					display: inline-block;
					width: 200px;
					height: 20px;
					line-height: 20px;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

			}
		}

		.form {
			position: relative;

			.back {
				position: absolute;
				left: 10px;
				top: 0px;
				width: 30px;
				height: 44px;
				line-height: 44px;
				text-align: center;
				z-index: 9999;
				// background: #18B566;
			}

			.title {
				padding: 0 20px;
				height: 40px;
				line-height: 40px;
			}

			.input {
				margin: 0 20px;
				height: 40px;
				line-height: 40px;
				border-bottom: solid 1px rgba(175, 175, 175, .2);
			}

		}

		.item1 {
			.dec {
				font-size: 13px;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 20px;
				color: #AFAFAF;
				opacity: 1;
				padding-bottom: 10px;
				border-bottom: solid 1px rgba(175, 175, 175, .2);
			}
		}

		.buttom {
			width: 229px;
			height: 56px;
			line-height: 56px;
			background: #3B7653;
			text-align: center;
			border-radius: 28px;
			margin: 0 auto;
			margin-top: 50px;
			font-size: 18px;
			font-family: PingFang SC;
			font-weight: bold;
			color: #fff;
			opacity: 1;
		}

	}
</style>
