<template>
	<view class="userinfo">
		<view class="user-head u-flex u-row-between">
			<text>头像</text>
			<image :src="userinfo.avatar" mode="aspectFill" @click="uploadimg"></image>
		</view>
		<view class="user-item" @click="tochangename">
			<view class="item-name">
				真实姓名
			</view>
			<view class="item-input u-flex">
				<input type="text" placeholder="请输入真实姓名" :disabled="true" v-model="userinfo.name">
			</view>
		</view>
		<view class="user-item" @click="">
			<view class="item-name">
				学历
			</view>
			<view class="item-input u-flex" @click="show=true">
				<input type="text" placeholder="请选择学历" :disabled="true" v-model="info.education_name">
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="user-item">
			<view class="item-name">
				毕业院校
			</view>
			<view class="item-input u-flex">
				<input type="text" placeholder="请填写毕业院校" v-model="info.name">
				<!-- <u-icon name="arrow-right"></u-icon> -->
			</view>
		</view>
		<view class="user-item" @click="">
			<view class="item-name">
				专业类别
			</view>
			<view class="item-input u-flex">
				<input type="text" placeholder="请填写专业类别" v-model="info.major">
				<!-- <u-icon name="arrow-right"></u-icon> -->
			</view>
		</view>
		<view class="user-item" @click="recruit_show = true">
			<view class="item-name">
				是否统招
			</view>
			<view class="item-input u-flex">
				<input type="text" :disabled="true" placeholder="请选择" v-model="is_recruit">

				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="user-item u-flex-col u-row-center">
			<text class="item-name">时间</text>
			<view class="u-flex u-row-between">
				<view class="item-input" @click="start()">
					<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
						placeholder="上学时间" border placeholderClass='input-style' v-model="info.start_time"></u--input>
				</view>
				<view class="">-</view>
				<view class="" @click="end()">
					<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
						placeholder="毕业时间" inputAlign="center" border placeholderClass='input-style'
						v-model="info.end_time"></u--input>
				</view>
			</view>
		</view>
		<view style="height: 150rpx;"></view>
		<view class="safe-area-inset-bottom"></view>
		<view class="user-down">
			<view class="down-btn u-flex">
				<text @click="save">立即认证</text>
			</view>
			<view class="safe-area-inset-bottom"></view>
		</view>
		<u-picker :show="show" @cancel="show = false" title="学历" keyName="name" :columns="education"
			@confirm="education_confirm"></u-picker>
		<u-picker :show="recruit_show" title="是否统招" @cancel="recruit_show = false" keyName="name"
			:columns="is_recruitlist" @confirm="recruit"></u-picker>
		<u-datetime-picker ref="pickers" title="上学时间" :minDate="minDate1" @confirm="entryConfirm" :show="entryShow"
			mode="year-month" @cancel='entryShow = false'></u-datetime-picker>
		<u-datetime-picker ref="pickers1" title="毕业时间" :minDate="minDate" @confirm="dimissionConfirm"
			:show="dimissionShow" mode="year-month" @cancel='dimissionShow = false'></u-datetime-picker>
	</view>
</template>

<script>
	import {
		profile,
		get_experience,
		getareacity,
		get_sex,
		index,
		activityauth,
		is_auth,
		get_education
	} from "@/units/inquire.js"
	import {
		get
	} from "https"
	import fuxing from "../common/fuxing.js"
	export default {
		data() {
			return {
				dimissionShow: false,
				entryShow: false,
				education: [
					[]
				],
				recruit_show: false,
				show: false,
				workShow: false,
				userinfo: {},
				sexlist: [],
				citylist: [],
				qiye: '',
				jingyanlist: [],
				is_recruit: '',
				is_recruitid: '',
				is_recruitlist: [
					[{
							"name": '统招',
							num: 1
						},
						{
							"name": "非统招",
							num: 0
						}
					]
				],
				// worklist: [{
				// 	label: 'soho猎头',
				// 	value: 'soho'
				// }, {
				// 	label: '就职猎头',
				// 	value: 'job'
				// }],
				info: {
					id: "", //	integer	学校认证ID
					school_id: "", //	integer	学校ID
					name: "", //	string	学校名称
					education_id: "", //	integer	学历ID
					major: "", //	string	专业
					start_time: "", //	string	开始时间
					end_time: "", //	string	毕业时间
					education_name: "", //	string	学历名称
				}
			}
		},
		onLoad() {
			this.getuser()
			this.getconfig()
			this.minDate = Number(new Date('2000-01-01'));
			this.minDate1 = Number(new Date('2000-01-01'));
			this.is_auth()
			this.get_education()
		},
		methods: {
			recruit(e) {
				// console.log(e);
				this.is_recruit = e.value[0].name
				this.is_recruitid = e.value[0].num
				// console.log(this.is_recruit);
				this.recruit_show = false
			},
			async dimissionConfirm(e) {
				const timeFormat = uni.$u.timeFormat;
				let timeValue = await timeFormat(e.value, 'yyyy-mm');
				this.info.end_time = timeValue
				this.dimissionShow = false
			},
			start() {
				this.entryShow = true
				this.$refs.pickers.innerValue = new Date(1577808000000).getTime()
			},
			end() {
				this.dimissionShow = true
				this.$refs.pickers1.innerValue = new Date(1672502400000).getTime()
			},
			async entryConfirm(e) {

				const timeFormat = uni.$u.timeFormat;
				console.log(e.value);
				let timeValue = await timeFormat(e.value, 'yyyy-mm');
				this.info.start_time = timeValue;
				this.entryShow = false
			},
			education_confirm(e) {
				console.log(e);
				console.log(this.info);
				this.info.education_name = e.value[0].name
				this.info.education_id = e.value[0].id
				this.show = false
			},
			get_education() {
				get_education().then(res => {
					this.education[0] = res.data
				})
			},
			is_auth() {
				is_auth().then(res => {
					if (res.data.is_auth == 1) {
						this.info = res.data.info
						this.info.education_id = res.data.info.education.id
						this.info.education_name = res.data.info.education.name
						this.is_recruitid = res.data.info.is_recruit
						if (res.data.info.is_recruit == 1) {
							this.is_recruit = "统招"
						} else {
							this.is_recruit = "非统招"
						}
					}
				})
			},

			//参加工作时间
			async workConfirm(e) {
				const timeFormat = uni.$u.timeFormat;
				let timeValue = await timeFormat(e.value, 'yyyy-mm');
				this.from.job_time = timeValue;
				this.workShow = false
			},
			changework(e) {
				this.userinfo.work_status = e[0].value
			},
			changejingyan(e) {
				this.userinfo.experience_id = e[0].value
				this.userinfo.experience_name = e[0].label
			},
			save() {
				if (!this.userinfo.avatar) {
					this.$u.toast("请上传头像")
					return
				}
				if (!this.userinfo.name) {
					this.$u.toast("请输入真实名字")
					return
				}
				if (!this.info.education_name) {
					this.$u.toast("请选择学历")
					return
				}
				if (!this.info.name) {
					this.$u.toast("请填写毕业院校")
					return
				}
				if (!this.info.major) {
					this.$u.toast("请填写专业类别")
					return
				}
				if (!this.info.start_time) {
					this.$u.toast("请选择上学时间")
					return
				}
				if (!this.info.end_time) {
					this.$u.toast("请选择毕业时间")
					return
				}
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				activityauth({
					name: this.info.name, //学校名称
					is_recruit: this.is_recruitid, //是否统招:0=非统招,1=统招
					education_id: this.info.education_id, //学历ID
					major: this.info.major, //专业
					start_time: this.info.start_time, //	开始时间 例：2023-01
					end_time: this.info.end_time //	毕业时间
				}).then(res => {
					if (res.code == 1) {
						this.$u.toast("修改成功")
						setTimeout(() => {
							const eventChannel = this.getOpenerEventChannel();
							eventChannel.emit('up', this.hangyelist);
							uni.navigateBack()
						}, 800)
					} else {
						this.$u.toast(res.msg)
					}
				})
				// profile({
				// 	avatar: this.userinfo.avatar,
				// 	name: this.userinfo.name,
				// 	industry_first: this.userinfo.industry_first,
				// 	industry_id: this.userinfo.industry_id,
				// 	experience_id: this.userinfo.experience_id,
				// 	work_status: this.userinfo.work_status,
				// 	work_address: this.userinfo.work_address,
				// 	realname: this.userinfo.virtual_name,
				// }).then(res => {
				// 	if (res.code == 1) {
				// 		this.$u.toast("修改成功")
				// 		setTimeout(() => {
				// 			uni.navigateBack()
				// 		}, 800)
				// 	} else {
				// 		this.$u.toast(res.msg)
				// 	}
				// })
			},
			changecity(e) {
				this.userinfo.work_address = `${e[0].label} ${e[1].label}`
			},
			changsex(e) {
				this.userinfo.sex_text = e[0].label
				this.userinfo.sex = e[0].value
				if (this.userinfo.name != this.userinfo.virtual_name && this.userinfo.virtual_name) {
					if (this.userinfo.name.length == 3) {
						this.userinfo.name = this.userinfo.virtual_name[0] + (this.userinfo.sex == 'female' ? '女士' : '先生')
					} else {
						this.userinfo.name = this.userinfo.virtual_name[0] + this.userinfo.virtual_name[1] + (this.userinfo
							.sex == 'female' ? '女士' : '先生')
					}
				}
			},
			getconfig() {
				get_sex().then(res => {
					for (var key in res.data) {
						this.sexlist.push({
							label: res.data[key],
							value: key
						})
					}
				})
				getareacity().then(res => {
					this.citylist = res.data
				})

				get_experience().then(res => {
					this.jingyanlist = res.data
				})
			},
			uploadimg() {
				uni.chooseImage({
					count: 1,
					success: (img) => {
						uni.showLoading({
							mask: true,
							title: "请稍后"
						})
						uni.uploadFile({
							url: this.$url + '/api/common/upload',
							filePath: img.tempFilePaths[0],
							name: 'file',
							success: (res) => {
								uni.hideLoading()
								if (JSON.parse(res.data).code == 1) {
									this.userinfo.avatar = JSON.parse(res.data).data.fullurl
								} else {
									this.$u.toast(JSON.parse(res.data).msg)
								}
							},
							fail: (e) => {
								console.log(e);
							}
						})
					}
				})
			},
			getuser() {
				index().then(res => {
					this.userinfo = res.data.group_info
					this.userinfo.sex_text = {
						'male': '男',
						'female': '女',
						'secret': '保密'
					} [this.userinfo.sex]
					console.log(this.userinfo);
				})
			},
			tochangename() {
				uni.navigateTo({
					url: "/pagesD/change-name?name=" + JSON.stringify({
						name: this.userinfo.name,
						virtual_name: this.userinfo.realname
					}),
					events: {
						getname: (res) => {
							if (res.name) {
								this.userinfo.name = res.name
							} else {
								var name = ''
								fuxing.forEach(val => {
									if (res.virtual_name.indexOf(val) > -1) {
										name = res.virtual_name[0] + res.virtual_name[1] + (this
											.userinfo.sex == 'female' ? '女士' : '先生')
									}
								})
								if (!name) {
									name = res.virtual_name[0] + (this.userinfo.sex == 'female' ? '女士' : '先生')
								}
								this.userinfo.name = name
							}
							this.userinfo.realname = res.virtual_name
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.userinfo {
		padding: 0 32rpx;

		.user-down {
			position: fixed;
			bottom: 0;
			left: 0;
			z-index: 99;
			width: 750rpx;
			background-color: #fff;

			.down-btn {
				padding: 8rpx 32rpx;

				text {
					line-height: 88rpx;
					background: #0C66C2;
					border-radius: 12rpx;
					width: 100%;
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					text-align: center;

				}
			}
		}

		.user-item {
			padding-top: 30rpx;
			border-bottom: 2rpx solid #F0F0F0;

			.item-input {
				height: 100rpx;

				input {
					height: 100rpx;
					flex: 1;
				}
			}

			.item-name {
				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #888888;
			}
		}

		.user-head {
			padding: 32rpx 0;
			border-bottom: 2rpx solid #F0F0F0;

			text {
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #222222;
			}

			image {
				border-radius: 100%;
				width: 120rpx;
				height: 120rpx;
			}
		}
	}
</style>