<template>
	<view class="page">
		<navbar title="在线简历"
		leftClick 
		@leftClick="$utils.navigateBack"/>
		
		
		
		<view class="box">
			<view class="list">
				<view class="item" 
				v-for="(item, index) in list" 
				:key="index">
					<view class="title">
						{{ item.title }}
					</view>
					<view class="tagList">
						<view :class="{act : i == item.index}" 
						@click="clickTag(item, i)" v-for="(t, i) in item.tag"
							:key="t.id">
							{{ t.name || t.adress }}
						</view>
					</view>
				</view>
			</view>
			
			
			<view class="form-sheet-cell">
				<view class="label">
					求职岗位
				</view>
				
				
				<input placeholder="请输入求职岗位"
				v-model="form.title" />
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					您的年龄
				</view>
				<input placeholder="请输入年龄" 
				type="number"
				v-model="form.age" />
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					您的性别
				</view>
				<uv-radio-group v-model="form.sex">
					<view style="display: flex;justify-content: center;">
						<uv-radio
							:customStyle="{margin: '8px'}" 
							v-for="(item, index) in sexList" 
							:key="index" 
							iconSize="30rpx"
							size="40rpx"
							labelSize="26rpx"
							:label="item.name" 
							:name="item.name">
						</uv-radio>
					</view>
				</uv-radio-group>
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					您的民族
				</view>
				<input placeholder="请输入民族" 
				v-model="form.nation" />
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					期望薪资
				</view>
				<view class="price">
					<input placeholder="下限" v-model="form.salaryLow" />
					~
					<input placeholder="上限" v-model="form.salaryUp" />
				</view>
			</view>
			
			<view class="form-sheet-cell"
			@click="openPicker('qualification')">
				<view class="label">
					您的学历
				</view>
				<input placeholder="请选择学历" 
				disabled
				v-model="form.qualification" />
			</view>
			
			<!-- <view class="form-sheet-cell">
							<view class="label">
								您的学历
							</view>
							<input placeholder="请输入您的学历" 
							v-model="form.qualification" />
						</view> -->
			
			<uv-textarea
			v-model="form.brief" 
			count 
			:maxlength="300" 
			autoHeight
			placeholder="请输入个人介绍"></uv-textarea>
			
			
			<view class="uni-color-btn"
			@click="submit">
				发布
			</view>
		</view>
		
		<uv-picker ref="picker"
		:columns="columns" 
		@confirm="pickerConfirm"></uv-picker>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				list: [
					{
						title: '您希望从事的工种',
						tag: [],
						index: 0,
						type : 'typeId',
						
					},
					{
						title: '您希望从事工作的地区',
						tag: [],
						index: 0,
						type : 'areaId',
					},
					{
						title: '您希望从事工作的性质',
						tag: [],
						index: 0,
						type : 'natureId',
					},
				],
				form : {
					sex : '男',
					qulification : '',
					title: '',
					typeId : '',
					areaId : '',
					natureId : '',
					age : '',
					nation : '',
					salaryLow : '',
					salaryUp : '',
					qualification : '',
					brief: '',
				},
				sexList : [
					{
						name : '男',
					},
					{
						name : '女',
					},
				],
				picker : {
					qualification : [
						'初中',
						'高中',
						'专科',
						'本科',
						'研究生',
						'博士',
					],
				},
				pickerKey : 'workAge',
			}
		},
		computed : {
			...mapState(['natureList', 'jobTypeList', 'addressList']),
			columns(){
				return [this.picker[this.pickerKey]]
			},
		},
		onLoad() {
			this.list[0].tag = this.jobTypeList
			this.list[1].tag = this.addressList
			this.list[2].tag = this.natureList
			
			this.queryResumeByUserId()
		},
		methods: {
			clickTag(item, index){
				item.index = index
			},
			openPicker(key, picker){
				this.pickerKey = key
				if(picker){
					picker.open()
				}else{
					this.$refs.picker.open()
				}
			},
			pickerConfirm(e){
				console.log(e);
				let data = e.value[0]
				if(data && data.id){
					this.form[this.pickerKey] = data.id
					this.form[this.pickerKey + '_dictText'] = data.name || data.adress
				}else{
					this.form[this.pickerKey] = data
				}
			},
			// 提交
			submit(){
				
				// if(this.fileList.length == 0){
				// 	return uni.showToast({
				// 		title: '请上传图片',
				// 		icon : 'none'
				// 	})
				// }
				
				this.list.forEach(n => {
					this.form[n.type] = n.tag[n.index].id
				})
				
				if (this.$utils.verificationAll(this.form, {
					    title: '请输入求职岗位',
						typeId : '请选择工种',
						areaId : '请选择工作的地区',
						natureId : '请选择工作的性质',
						age : '请输入您的年龄',
						sex : '请选择性别',
						nation : '请输入您的民族',
						salaryLow : '请输入期望薪资下限',
						salaryUp : '请输入期望薪资上限',
						qualification : '请选择您的学历',
						brief: '请输入个人介绍',
					})) {
					return
				}
				
				let data = {
					title: this.form.title,
					typeId : this.form.typeId,
					areaId : this.form.areaId,
					natureId : this.form.natureId,
					age : this.form.age,
					nation : this.form.nation,
					salaryLow : this.form.salaryLow,
					salaryUp : this.form.salaryUp,
					qualification : this.form.qualification,
					brief: this.form.brief,
					sex: this.form.sex,
				}
				
				if(this.form.id){
					data.id = this.form.id
				}
				
				this.$api('addResume', data, res => {
					if(res.code == 200){
						uni.showToast({
							title: '发布成功!',
							icon: 'none'
						})
						
						setTimeout(uni.navigateBack, 1000, -1)
					}
				})
			},
			queryResumeByUserId(){
				this.$api('queryResumeByUserId', res => {
					if(res.code == 200){
						this.form = res.result.records[0] || {
							sex : '男',
							qulification : '',
						}
						
						if(res.result.records[0]!=null){
							this.form.id=res.result.records[0].id
						}
						
					}
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	.page{
		background-color: #fff;
		min-height: 100vh;
		.box{
			padding: 30rpx;
			.list {
				.item {
					margin-top: 20rpx;
			
					.title {
						font-weight: 900;
						font-size: 30rpx;
					}
			
					.tagList {
						display: flex;
						flex-wrap: wrap;
						padding: 10rpx 0;
			
						view {
							background: rgba($uni-color, 0.1);
							padding: 10rpx 20rpx;
							margin: 10rpx;
							border-radius: 10rpx;
							font-size: 26rpx;
						}
			
						.act {
							color: #fff;
							background: $uni-color;
						}
					}
				}
			}
			
			.form-sheet-cell{
				display: flex;
				background-color: #fff;
				padding: 20rpx;
				align-items: center;
				.label{
					width: 160rpx;
					font-weight: 900;
				}
				.price{
					display: flex;
					text-align: center;
					input{
						width: 150rpx;
						border: 1px solid $uni-color;
						margin: 0 10rpx;
					}
				}
				input{
					flex: 1;
					background-color: rgba($uni-color, 0.1);
					padding: 10rpx 20rpx;
					border-radius: 10rpx;
				}
				.right-icon{
					margin-left: auto;
				}
			}
		
			/deep/ .uv-textarea{
				background-color: rgba($uni-color, 0.1) !important;
				min-height: 400rpx;
			}
		}
	}
</style>