<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">
				<input type="text" placeholder="请选择学历" :disabled="true" v-model="userinfo.sex_text">
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="user-item" @click="changehangye">
			<view class="item-name">
				毕业院校
			</view>
			<view class="item-input u-flex">
				<input type="text" placeholder="请选择毕业院校" :disabled="true" v-model="userinfo.industry_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="请选择毕业类型" :disabled="true" v-model="userinfo.experience_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="请选择毕业年份" :disabled="true" :value="userinfo.work_status == 'soho' ? 'soho猎头' : '就职猎头'">
				<u-icon name="arrow-right"></u-icon>
			</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-select v-model="sexshow" :list="sexlist" @confirm="changsex"></u-select>
		<u-select v-model="cityshow" :list="citylist" mode="mutil-column-auto" value-name="id" label-name="name" child-name="childlist" @confirm="changecity"></u-select>
		<u-select v-model="jingyanshow" :list="jingyanlist" value-name="id" label-name="name" @confirm="changejingyan"></u-select>
		<u-select v-model="workshow" :list="worklist" @confirm="changework"></u-select> -->
	</view>
</template>

<script>
	import{profile} from "@/units/inquire.js"
	import fuxing from "../common/fuxing.js"
	export default {
		data() {
			return {
				userinfo: {},
				sexlist: [],
				citylist: [],
				qiye: '',
				jingyanlist: [],
				worklist: [{
					label: 'soho猎头',
					value: 'soho'
				}, {
					label: '就职猎头',
					value: 'job'
				}]
			}
		},
		onLoad() {
			this.getuser()
			this.getconfig()
		},
		methods: {
			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.userinfo.sex) {
					this.$u.toast("请选择性别")
					return
				}
				if (!this.userinfo.industry_name) {
					this.$u.toast("请选择猎头行业")
					return
				}
				if (!this.userinfo.experience_name) {
					this.$u.toast("请选择经验")
					return
				}
				if (!this.userinfo.work_status) {
					this.$u.toast("请选择就职状态")
					return
				}
				if (!this.userinfo.work_address) {
					this.$u.toast("请选择工作地址")
					return
				}
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				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() {
				this.$u.post('/api/commons/get_sex').then(res => {
					for (var key in res.data) {
						this.sexlist.push({
							label: res.data[key],
							value: key
						})
					}
				})
				this.$u.post('/api/commons/get_area_city').then(res => {
					this.citylist = res.data
				})
				this.$u.post('/api/commons/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() {
				this.$u.post('/api/headhunter.user/index').then(res => {
					this.userinfo = res.data.group_info
					this.userinfo.sex_text = {
						'male': '男',
						'female': '女',
						'secret': '保密'
					} [this.userinfo.sex]
				})
			},
			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>