<template>
	<view class="index-page">
		<!-- 顶部 -->
		<view class="index-navbar">
			<view style="position: relative;height: 392rpx;">
				<image class="index-bg" src="@/static/images/bg.png" mode=""></image>
				<u-navbar bgColor='rgba(0,0,0,0)' placeholder @leftClick="return1">

				</u-navbar>
				<view class="header-down " :style="{marginTop:height+'rpx'}"
					style="padding: 28rpx 0 0 32rpx;box-sizing: border-box;">
					<view class="mingpianfont">
						你的求职期望
					</view>
					<view class="explain">
						<text>我们会根据你的求职意向，为你推荐精准的职</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 个人信息 -->
		<view class="personal">
			<view class="body-input u-flex-col u-row-center ">
				<text class="input-title">期望职位</text>
				<view class="" @click="changefenlei">
					<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
						placeholder="请选择期望职位" border placeholderClass='input-style' suffixIcon="arrow-right"
						suffixIconStyle="font-size: 32rpx;font-weight: 400;color: #CACACA;"
						v-model="category_job_name"></u--input>
				</view>
			</view>
			<view class="body-input u-flex-col u-row-center">
				<text class="input-title">期望城市</text>
				<view class="" @click="cityShow = true">
					<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
						placeholder="请选择您的期望城市" border placeholderClass='input-style' suffixIcon="arrow-right"
						suffixIconStyle="font-size: 32rpx;font-weight: 400;color: #CACACA;"
						v-model="job_intention.city"></u--input>
				</view>
			</view>
			<view class="body-input u-flex-col u-row-center">
				<text class="input-title">期望行业</text>
				<view class="" @click="changehangye">
					<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
						placeholder="请选择您的期望行业" border placeholderClass='input-style' suffixIcon="arrow-right"
						suffixIconStyle="font-size: 32rpx;font-weight: 400;color: #CACACA;"
						v-model="category_industry_name"></u--input>
				</view>
			</view>
			<!-- 			<view class="body-input u-flex-col u-row-center">
				<text class="input-title">期望薪资</text>
				<view class="" @click="show = true">
					<u--input :value="label" :disabled="true" disabledColor="#fff" customStyle="padding:0 !important"
						type="text" placeholder="请选择您的期望薪资" border placeholderClass='input-style'
						suffixIcon="arrow-right"
						suffixIconStyle="font-size: 32rpx;font-weight: 400;color: #CACACA;"></u--input>
				</view>
			</view> -->
			<view class="body-input u-flex-col u-row-center">
				<text class="input-title">期望薪资</text>
				<view class="u-flex u-row-between">
					<view style="width: 80rpx;color: rgba(26, 28, 36, 0.8);font-size: 30rpx;" class=""
						@click="salarytype = true">
						{{salary_type}}
					</view>
					<u-icon name="arrow-down-fill" color="rgba(26, 28, 36, 0.8)" size="8"></u-icon>
					<u--input inputAlign='center' border style='width:50rpx' class=""
						v-model="job_intention.salary">{{job_intention.salary||''}}</u--input>K
					<text style="margin-left: 100rpx;">*</text>
					<u--input inputAlign='center' border style='width:50rpx' class=""
						v-model="job_intention.salary_month">{{job_intention.salary_month||''}}</u--input>
					<text style="color: rgba(26, 28, 36, 0.8);font-size: 30rpx;">薪资</text>
				</view>
			</view>
			<view class="body-input u-flex-col u-row-center" @click="show1 = true">
				<text class="input-title">所属领域</text>
				<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
					placeholder="请选择您要选择的领域" border placeholderClass='input-style' suffixIcon="arrow-right"
					suffixIconStyle="font-size: 32rpx;font-weight: 400;color: #CACACA;"
					v-model="category_name"></u--input>
			</view>
			<view class="body-input u-flex-col u-row-center">
				<text class="input-title">优势亮点(选填)</text>
				<u--input disabledColor="#fff" customStyle="padding:0 !important" type="text" placeholder="请填写" border
					placeholderClass='input-style' suffixIcon="arrow-right"
					suffixIconStyle="font-size: 32rpx;font-weight: 400;color: #CACACA;"
					v-model="job_intention.advantage"></u--input>
			</view>
			<view class="" style="height: 250rpx;"></view>
			<view class="button" @click="next">
				开启求职之旅
			</view>
		</view>
		<!-- 选择器 -->
		<u-picker ref="uPicker" keyName="name" title="期待城市" :defaultIndex="indexs" :show="cityShow" :columns="cityList"
			@confirm="cityconfirm" @cancel="cityShow = false" @change="changeHandler"></u-picker>
		<!-- 		<u-picker keyName="label" title="期待薪资" :show="show" :columns="xinzilist" @confirm="confirm"
			@cancel="show = false"></u-picker> -->
		<u-picker title="薪资类型" keyName="name" :show="salarytype" @confirm="salarytypefunction" :columns="salarytypelist"
			@cancel='salarytype = false'></u-picker>
		<u-picker ref="uPicker1" keyName="name" title="所属领域" :defaultIndex="indexs" :show="show1"
			:columns="category_list" @confirm="category1" @cancel="show1 = false" @change="changecategory"></u-picker>
	</view>
</template>

<script>
	import {
		getAllArea,
		create,
		profile,
		get_category_field
	} from "@/units/inquire.js"
	export default {
		data() {
			return {
				salarytypelist: [
					[{
						name: '月薪',
						type: 'month'
					}, {
						name: '年薪',
						tupe: 'year'
					}]
				],
				salarytype: false,
				category_list: [],
				category_industry_name: "", //行业
				category_job_name: "", //职位
				cityShow: false,
				province: [], //省数据
				city: [], //市数据
				area: [], //区数据
				cityList: [], //城市列表
				show: false,
				from: {},
				label: "",
				addressData: {},
				job_experience: {},
				project_experience: {},
				education_experience: {},
				salary_type: '月薪',
				category_name: '',
				show1: '',
				addressData: {
					id: "",
					province: "",
					city: "",
					area: "",
					detail: "",
					userName: "",
					phone: "",
					isDefault: false
				}, //地址数据
				job_intention: {
					city: "", //城市地点
					advantage: '', //优势亮点
					salary: '',
					province_id: "", //期望省份ID
					city_id: "", //期望城市ID
					salary_type: "month", //薪资类型: year = 年薪;month = 月薪
					salary_month: "", //一年多少薪
					category_job_first: "", //职位分类一级ID
					category_job_second: "", //职位分类二级ID
					category_job_id: "", //职位分类三级ID
					category_industry_first: "", //行业一级ID
					category_industry_id: "", //行业二级ID
					category_field_id: '',
					category_field_first: ''
				},
				xinzilist: [

				],
			}
		},
		onLoad() {
			this.AllArea()
			this.xinzi()
			this.get_category_field()
			if (uni.getStorageSync("from")) {
				console.log(uni.getStorageSync("from"));
				this.from = uni.getStorageSync("from")
			}
			if (uni.getStorageSync('radiovalue1') == 2) {

				if (uni.getStorageSync("job_experience3")) {
					this.job_experience = uni.getStorageSync("job_experience3")
				}
				if (uni.getStorageSync("project_experience3")) {
					this.project_experience = uni.getStorageSync("project_experience3")
				}
				if (uni.getStorageSync("education_experience3")) {
					this.education_experience = uni.getStorageSync("education_experience3")
				}
			} else {
				if (uni.getStorageSync("job_experience1")) {
					this.job_experience = uni.getStorageSync("job_experience1")
				}
				if (uni.getStorageSync("project_experience1")) {
					this.project_experience = uni.getStorageSync("project_experience1")
				}
				if (uni.getStorageSync("education_experience1")) {
					this.education_experience = uni.getStorageSync("education_experience1")
				}
			}
			if (uni.getStorageSync("addressData1")) {
				this.addressData = uni.getStorageSync("addressData1")
			}
			// if (uni.getStorageSync("job_experience1")) {
			// 	this.job_experience = uni.getStorageSync("job_experience1")
			// }
			// if (uni.getStorageSync("project_experience1")) {
			// 	this.project_experience = uni.getStorageSync("project_experience1")
			// }
			// if (uni.getStorageSync("education_experience1")) {
			// 	this.education_experience = uni.getStorageSync("education_experience1")
			// }
			// if (uni.getStorageSync("job_intention1")) {
			// 	this.job_intention = uni.getStorageSync("job_intention1")
			if (uni.getStorageSync("category_industry_name")) {
				this.category_industry_name = uni.getStorageSync("job_intention1")
			}
			if (uni.getStorageSync("category_job_name")) {
				this.category_job_name = uni.getStorageSync("category_job_name")
			}
		},
		methods: {
			category1(e) {
				let a = ''
				if (e.value[1]) {
					a = e.value[0].name + e.value[1].name
				} else {
					a = e.value[0].name
				}
				if (e.value[1]) {
					this.job_intention.category_field_id = e.value[1].id
					this.job_intention.category_field_first = e.value[0].id
				} else {
					this.job_intention.category_field_first = e.value[0].id
				}
				// let ids = String(e.value[0].id) + String(e.value[1].id)


				this.category_name = a
				this.show1 = false
				// this.city1 = e.value.join("")
			},
			changecategory(e) {
				const {
					columnIndex, //当前改变值的列下标
					value,
					values, // values为当前变化列的数组内容
					indexs, //当前地区值下标
					picker = this.$refs.uPicker1
				} = e
				//columnIndex代表第几列，意思是下标为0的列发生变化

				if (columnIndex === 0) {
					if (this.category_two[indexs[0]]) {
						picker.setColumnValues(1, this.category_two[indexs[0]].map(v => {
							return {
								name: v.name,
								id: v.id
							}
						}))
					} else {
						value = ""
					}
					// picker.setColumnValues(2, this.area[indexs[0]][0].map(v => {
					// 	return {
					// 		name: v.name,
					// 		id: v.id
					// 	}
					// }))
				}
			},
			get_category_field() {
				get_category_field().then(res => {
					res.data.forEach(item => {
						if (item.childlist) {

						} else {
							item.childlist = []
							res.data.push(item)
						}
					})

					this.category_field_first = res.data.map(t => {
						return {
							name: t.name,
							id: t.id
						}
					})
					console.log("aaa", this.category_field_first);
					this.category_two = res.data.map(t => {
						if (t.childlist) {
							var c = []
							c = t.childlist.map(v => {
								console.log(v);
								return {
									name: v.name,
									id: v.id
								}
							})
						}
						return c
					})
					console.log('category_two', this.category_two);
					let a = []
					let b = []
					this.category_field_first.map(res => {
						a.push({
							name: res.name,
							id: res.id,
						})
					})
					this.category_two[0].map(res => {
						b.push({
							name: res.name,
							id: res.id,
						})
					})
					this.category_list = [a, b]
				})
			},
			salarytypefunction(e) {
				this.job_intention.salary_type = e.value[0].salary_type
				this.salary_type = e.value[0].name
				this.salarytype = false
			},
			xinzi() {
				var xinzilist = []
				for (var i = 1; i <= 100; i++) {
					xinzilist.push({
						label: `${i}K`,
						value: i
					})
				}
				this.xinzilist.push(xinzilist)
			},
			confirm(e) {
				this.job_intention.salary = e.value[0].value
				this.label = e.value[0].label
				this.show = false
			},
			cityconfirm(e) {
				let a = e.value[0].name + e.value[1].name + e.value[2].name
				// let ids = String(e.value[0].id) + String(e.value[1].id) + String(e.value[2].id)
				this.job_intention.city_id = e.value[1].id
				this.job_intention.province_id = e.value[0].id
				// this.city1 = e.value.join("")
				this.job_intention.city = a
				this.cityShow = false
			},
			// jobConfirm(e) {
			// 	// this.job = e.value[0].name
			// 	// this.from.job_status_id = e.value[0].id
			// 	// this.jobShow = false
			// }, //所有地区
			AllArea() {
				getAllArea().then((res) => {
					this.province = res.data.map(t => {
						return {
							name: t.name,
							id: t.id
						}
					})
					console.log("aaa", this.province);
					this.city = res.data.map(t => t.children.map(v => {
						return {
							name: v.name,
							id: v.id
						}
					}))
					this.area = res.data.map(t => t.children.map(v => v.children.map(i => {
						return {
							name: i.name,
							id: i.id
						}
					})))
					//默认显示数据
					// this.cityList = [
					// 	this.province.map(res => res.name),
					// 	this.city[0].map(res => res.name),
					// 	this.area[0][0].map(res => res.name)
					// ]
					let a = []
					let b = []
					let c = []
					this.province.map(res => {
						a.push({
							name: res.name,
							id: res.id,
						})
					})
					this.city[0].map(res => {
						b.push({
							name: res.name,
							id: res.id,
						})
					})
					this.area[0][0].map(res => {
						c.push({
							name: res.name,
							id: res.id,
						})
					})

					this.cityList = [a, b, c]
					console.log(33, this.cityList);
					if (this.addressData.province && this.addressData.city && this.addressData.area) {
						//省索引
						let pIdx = this.province.findIndex(v => v.name == this.addressData.province);
						//根据省索引设置默认市数据
						this.columns[1] = this.city[pIdx].map(res => res.name)
						//市索引
						let cIdx = this.city[pIdx].findIndex(v => v.name == this.addressData.city);
						//根据市索引设置默认区数据
						this.columns[2] = this.area[pIdx][cIdx].map(res => res.name)
						//区索引
						let aIdx = this.area[pIdx][cIdx].findIndex(v => v.name == this.addressData.area);
						this.indexs = [pIdx, cIdx, aIdx];
						// console.log(pIdx, cIdx, aIdx);
						console.log(this.indexs);
					}
				})
			},
			changeHandler(e) {
				const {
					columnIndex, //当前改变值的列下标
					value,
					values, // values为当前变化列的数组内容
					indexs, //当前地区值下标
					picker = this.$refs.uPicker
				} = e
				//columnIndex代表第几列，意思是下标为0的列发生变化

				if (columnIndex === 0) {
					picker.setColumnValues(1, this.city[indexs[0]].map(v => {
						return {
							name: v.name,
							id: v.id
						}
					}))
					picker.setColumnValues(2, this.area[indexs[0]][0].map(v => {
						return {
							name: v.name,
							id: v.id
						}
					}))
				}
				if (columnIndex === 1) {
					picker.setColumnValues(2, this.area[indexs[0]][indexs[1]].map(v => {
						return {
							name: v.name,
							id: v.id
						}
					}))
				}
			},
			changefenlei() {
				uni.navigateTo({
					url: "/pagesA/change-zhiwei",
					events: {
						changefenlei: (res) => {
							this.job_intention.category_job_first = res[0].id //职位分类一级ID
							this.job_intention.category_job_second = res[1].id //职位分类二级ID
							this.job_intention.category_job_id = res[2].id //职位分类三级ID
							this.category_job_name = res[2].name //职位名称
						}
					}
				})
			},
			changehangye() {
				uni.navigateTo({
					url: "/pagesA/change-hangye1",
					events: {
						changehangye: (res) => {
							console.log(res);
							console.log(res[1].name);
							this.job_intention.category_industry_first = res[0].id //行业一级ID
							this.job_intention.category_industry_id = res[1].id //行业二级ID
							this.category_industry_name = res[1].name //行业名称
						}
					}
				})
			},
			return1() {
				uni.navigateBack()
			},
			next() {
				let pre = "job_intention"
				let nObj = Object.keys(this.job_intention).reduce((a, c) => (a[`${pre}.${c}`] = this.job_intention[c],
					a), {});
				uni.setStorageSync("job_intention", nObj)
				uni.setStorageSync("job_intention1", this.job_intention)
				profile({
					...this.user,
					invitation_code: uni.getStorageSync('invitation_code')
				}).then(res => {

				})
				if (uni.getStorageSync('radiovalue1') == 1) {
					create({
						...this.from,
						job_experience: [this.job_experience],
						project_experience: [this.project_experience],
						education_experience: [this.education_experience],
						job_intention: [this.job_intention]
					}).then(res => {
						if (res.code == 1) {
							uni.switchTab({
								url: '../pages/index/index'
							})
						} else {
							this.$u.toast(res.msg)
						}
					})
				} else {
					create({
						...this.from,
						job_experience: this.job_experience,
						project_experience: this.project_experience,
						education_experience: this.education_experience,
						job_intention: [this.job_intention]
					}).then(res => {
						if (res.code == 1) {
							uni.switchTab({
								url: '../pages/index/index'
							})
						} else {
							this.$u.toast(res.msg)
						}
					})
				}
				uni.setStorageSync("category_industry_name", this.category_industry_name)
				uni.setStorageSync("category_job_name", this.category_job_name)
				uni.setStorageSync("is_profile", 1)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F3F3F3;
	}

	.index-page {
		overflow: hidden;
		// height: 100vh;
		background: #fff;


		.mingpianfont {
			height: 50rpx;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 50rpx;
		}

		.explain {
			margin-top: 24rpx;
			width: 528rpx;
			height: 36rpx;
			font-size: 26rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 36rpx;
		}


		//个人信息
		.personal {
			width: 750rpx;
			background: #FFFFFF;
			border-radius: 28rpx 28rpx 0rpx 0rpx;
			margin-top: -40rpx;
			position: relative;
			z-index: 99;
			padding: 40rpx 32rpx 0;
			box-sizing: border-box;
			height: 100%;
			margin-bottom: 60rpx !important;

			.body-input {
				height: 170rpx;
				border-bottom: 2rpx solid #F4F4F4;

				.input-title {
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #888888;
					margin-bottom: 20rpx;
					margin-top: 30rpx;
					box-sizing: border-box;
				}

				.input-style {
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #CACACA;
				}
			}

			.button {
				width: 686rpx;
				height: 88rpx !important;
				background: #0C66C2;
				border-radius: 12rpx;
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 88rpx;
				margin: 10rpx 0 0rpx 0;
				display: flex;
				justify-content: center;
				margin-bottom: 60rpx;
				// position: fixed;
				// bottom: 60rpx;
			}
		}

		.index-item {
			// width: 702rpx;
			// background: #FFFFFF;
			// border-radius: 20rpx;
			// margin: 20rpx auto;
			// padding: 0 20rpx 24rpx 10rpx;

			.item-down {
				text:first-child {
					font-size: 22rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #666666;
				}

				text:last-child {
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
				}
			}

			.item-gongsi {
				margin-bottom: 16rpx;

				.text2 {
					font-size: 24rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #666666;
				}

				.logo {
					width: 42rpx;
					height: 42rpx;
					border-radius: 10rpx;
					margin-right: 16rpx;
				}

				.text1 {
					max-width: 192rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #444444;
					margin-right: 12rpx;
				}
			}

			.item-label {
				margin-bottom: 20rpx;

				text {
					margin-right: 16rpx;
					line-height: 46rpx;
					background: #F7F7F7;
					border-radius: 4rpx;
					padding: 0 14rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #5F5F5F;
				}
			}

			.item-top {
				height: 88rpx;

				.text1 {
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
					margin-right: 16rpx;
				}

				.text2 {
					width: 50rpx;
					line-height: 32rpx;
					background: rgba(255, 83, 53, 0.1);
					border-radius: 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FF5335;
					margin-right: 12rpx;
				}

				.text3 {
					width: 90rpx;
					line-height: 32rpx;
					background: #FFF2E8;
					border-radius: 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FF8620;
					margin-right: 12rpx;
				}

				.text4 {
					line-height: 32rpx;
					background: #E6EFF8;
					border-radius: 4rpx;
					padding: 0 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #0C66C2;
				}

				.text5 {
					font-size: 32rpx;
					font-family: JDZhengHT-Regular, JDZhengHT;
					font-weight: 400;
					color: #0C66C2;
				}
			}
		}

		.index-navbar {
			position: sticky;
			top: 0;
			left: 0;
			width: 750rpx;
			z-index: 10;

			.header-down {
				height: 92rpx;
				padding: 20rpx 24rpx;
				box-sizing: border-box;

				.font {
					font-size: 40rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}

				.right-item {
					padding: 0 16rpx;
					height: 52rpx;
					background: #F3F3F3;
					border-radius: 4rpx;
					margin-left: 20rpx;

					.text {
						margin-right: 4rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}

				.down-left {
					.text {
						margin-right: 4rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
				}
			}

			.index-bg {
				position: absolute;
				top: 0;
				left: 0;
				z-index: -1;
				width: 750rpx;
				height: 392rpx;
			}
		}

		.index-header {
			flex: 1;
			padding: 0 32rpx;
			height: 50rpx;

			.index-search {
				width: 200rpx;
				height: 64rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				padding: 0 28rpx;

				.text1 {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					margin-left: 16rpx;
				}
			}

			.index-tabs {
				text:first-child {
					font-size: 36rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}

				text:last-child {
					width: 76rpx;
					height: 12rpx;
					background: linear-gradient(270deg, #208EFF 0%, rgba(28, 159, 227, 0) 100%);
					margin-top: -20rpx;
					border-radius: 100rpx;
				}
			}
		}
	}

	::v-deep .u-navbar__content__left {
		padding: 0 !important;
	}

	::v-deep .u-subsection {
		width: 312rpx !important;
	}
</style>