<template>
	<view class="main">
		<view class="form_group">
			<view class="lable re">头像</view>
			<view class="bz">
				<text class="icon">&#xe634;</text>
				<text>使用真实头像更容易得到HR的青睐</text>
			</view>
			<avatar v-model="item.avatar" class="avatar"></avatar>
		</view>
		<view class="form_group">
			<view class="lable re">姓名</view>
			<input placeholder="请输入姓名" v-model="item.name" />
		</view>
		<view class="form_group">
			<view class="lable re">性别</view>
			<picker :range="dict.sex" @change="picker($event, 'sex')">
				<input placeholder="请选择性别" v-model="item.sex" :disabled="true" />
				<view class="icon more">&#xe62b;</view>
			</picker>
		</view>
		<view class="form_group">
			<view class="lable re">出生年月</view>
			<multiSelector v-model="item.birthday" :range="dict.birthday" name="出生年月" placeholder="请选择出生年月"></multiSelector>
		</view>
		<view class="form_group">
			<view class="lable re">手机号</view>
			<input type="number" placeholder="请输入手机号" v-model="item.phone" />
		</view>
		<view class="form_group">
			<view class="lable re">邮箱</view>
			<input placeholder="请输入邮箱" v-model="item.email" />
		</view>
		<view class="form_group">
			<view class="lable re">意向职位</view>
			<picker :disabled="true" @click="go('/pages/job/position/classification')">
				<input placeholder="请选择意向职位" v-model="item.positionName" :disabled="true" />
				<view class="icon more">&#xe62b;</view>
			</picker>
		</view>
		<button class="btn" @click="save()">保存</button>
	</view>
</template>
<script>
export default {
	data() {
		return {
			item: {},
			end: this.util.getDate('day'),
			dict: {
				sex: this.util.getData('sex'),
				qualification: this.util.getData('qualification'),
				birthday: [[], []],
				salary: [['面议'], ['']]
			}
		};
	},
	onLoad(e) {
		if (e.item) {
			this.item = JSON.parse(e.item);
		}
		uni.$on('select_city', (res) => {
			this.item.cityName = res.title;
			this.item.cityId = res.id;
			this.$forceUpdate();
		});
		uni.$on('select_position', (res) => {
			this.item.positionName = res.title;
			this.item.positionId = res.id;
			this.$forceUpdate();
		});
	},
	methods: {
		picker(e, tag) {
			if (tag == 'joinDate' || tag == 'birthday') {
				this.item[tag] = e.detail.value;
			} else {
				this.item[tag] = this.dict[tag][e.detail.value];
			}
			this.$forceUpdate();
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		save() {
			let rule = [
				{ name: 'avatar', checkType: 'notnull', errorMsg: '请上传头像' },
				{ name: 'name', checkType: 'notnull', errorMsg: '请输入姓名' },
				{ name: 'sex', checkType: 'notnull', errorMsg: '请上选择性别' },
				{ name: 'birthday', checkType: 'notnull', errorMsg: '请选择出生年月' },
				{ name: 'phone', checkType: 'phone', errorMsg: '请输入正确的手机号' },
				{ name: 'email', checkType: 'email', errorMsg: '请输入正确的邮箱' }
			];
			if (!this.verify.check(this.item, rule)) {
				uni.showModal({ content: this.verify.error, showCancel: false });
				return false;
			}
			this.http.request({
				url: '/app/resume/edit',
				data: this.item,
				method: 'POST',
				success: (res) => {
					uni.showToast({ title: '操作成功' });
					setTimeout(() => {
						uni.$emit('resume');
						uni.navigateBack();
					}, 1500);
				}
			});
		}
	}
};
</script>

<style lang="scss">
textarea {
	padding: 10px;
	height: 150px;
	width: 94%;
	border-radius: 5px;
	background-color: white;
	font-size: 14px;
	line-height: 23px;
}
</style>
