<template>
	<view>
		<u-navbar back-text="求职信息" back-icon-size="28" back-icon-color="#ffffff"
			:background="{backgroundColor: '#2795FD',}" :back-text-style="{color: '#ffffff'}"></u-navbar>
		<view class="main">
			<!-- 个人信息 -->
			<view class="person-infos">
				<view class="infos">
					<view class="name" v-if="userInfo.status==1">
						{{userInfo.realName?userInfo.realName:''}}
					</view>
					<view class="gender-age" v-if="userInfo.status==0">
						
						<text class="text">简历状态</text>
						
						<text>[未创建]</text>
						
					</view>
					<view class="gender-age" v-if="userInfo.status==1">
						<text class="text">{{userInfo.gender==1?'男':'女'}}</text>|
						<text class="text">{{userInfo.age}}岁</text>|
						<text class="text">简历状态</text>
							<text style="color:chocolate" v-if="formData.status==0">[审批中]</text>
							<text style="color: #4CAF50;" v-else-if="formData.status==1">[生效]</text>
							<text v-else >[未创建]</text>
						
					</view>
				</view>

				<view class="photo" @click="uploadPhoto">
					<u-avatar :src="src"  :gender="userInfo.gender"
					
					size="120" mode="circle"></u-avatar>
					<img class="camera" src="@/assets/img/riFill-camera-fill Copy@1x.png" alt="">

				</view>

			</view>
			
			<u-select v-model="show" value-name="value" label-name="name"
			 :list="list" @confirm="confirm"></u-select>

			<!-- 信息填写 -->
			<view class="information-group">
				<!-- 联系电话 -->
				<view class="item">
					<view class="title">
						联系电话
					</view>
					<view class="input">
						{{tel}}
					</view>
				</view>
				<!-- 意向行业 -->
				<view class="item">
					<view class="title">
						意向行业<text>*</text>
					</view>
					<view class="input"  >
						<u-input type="select" v-model="intendedIndustries" @click="popupShow=true" readonly   placeholder="请选择意向行业"></u-input>
						
					</view>
					
				</view>
				<!--意向岗位 -->
				<view class="item">
					<view class="title">
						意向岗位<text>*</text>
					</view>
					<view class="input">
						<u-input type="text" v-model="formData.intendedPosition"
						 placeholder="请填写想找的工作岗位"></u-input>
						
					</view>

				</view>
				
				<!-- 结算方式 -->
				<view class="item">
					<view class="title">
						结算方式<text>*</text>
					</view>
					<view class="input">
						<u-input type="select"  v-model="method" 
						 @click="showselect(1)" placeholder="请选择结算方式"></u-input>
						
					</view>
					
				</view>
				<!-- 期望薪资 -->
				<view class="item">
					<view class="title">
						期望薪资<text>*</text>
					</view>
					<view class="input2">
						<u-input type="number"  v-model="formData.hopeSalary"
						placeholder="请填写期望薪资"></u-input>
						
		
					</view>
					<view class="unit">
						{{getUnit(formData)}}
					</view>
				</view>
			
				<!-- 工作经验 -->
				<view class="item" v-if="false">
					<view class="title">
						工作经验
					</view>
					<view class="input">
						<u-input type="select"   v-model="workExperience" 
						 @click="showselect(2)" placeholder="请选择工作经验"></u-input>
						
						
					</view>
					 
				</view>
				<!-- 学历 -->
				<view class="item">
					<view class="title">
						学历
					</view>
					<view class="input">
						<u-input type="select"   v-model="education" 
						 @click="showselect(3)" placeholder="请选择学历"></u-input>
						
					</view>
				
				</view>
				
				<!--意向岗位 -->
				<view class="item">
					<view class="title">
						现居住地
					</view>
					<view class="input">
						<u-input type="text" v-model="formData.address"
						 placeholder="请填写您的现居住地"></u-input>
						
					</view>
				
				</view>
			</view>
		</view>


		<view class="service-description">
			<view class="title">
				<text>*</text>个人简介
			</view>
			<textarea class="textarea"  v-model="formData.serviceDesc"
			 placeholder="请填写您的个人简历，如工作年限/工作经历/擅长技能等，有助于您更快、更准确的找到工作。"></textarea>
		</view>
		<view class="main">
			<view class="information-group">
				<view class="titlesm">
					{{userInfo.status==0?'实名认证':'已实名'}}
				</view>
				<!--意向岗位 -->
				<view class="item">
					<view class="title">
						真实姓名<text class="redtext">*</text>
					</view>
					<view class="input" v-if="userInfo.status==0">
						<u-input type="text"  v-model="personalForm.realName"
						  placeholder="请填写真实姓名"></u-input>
						
					</view>
					<view  v-if="userInfo.status==1" class="input input3" >
						{{personalForm.realName}}
					</view>
				
				</view>
				<!--意向岗位 -->
				<view class="item">
					<view class="title">
						身份证号<text class="redtext">*</text>
					</view>
					<view class="input "  v-if="userInfo.status==0">
						<u-input type="text" v-model="personalForm.idCard"
						 placeholder="请填写18位身份证号"></u-input>
						
					</view>
					<view  v-if="userInfo.status==1" class="input input3" >
						{{personalForm.idCard}}
					</view>
				</view>
				<view class="item">
					<view class="title" style="width: 250rpx;">
						真实姓名保护
					</view>
					<view class="input  input4 "  >
						
						关闭<u-switch  size="40"  @change="change3" v-model="isAnonymous"></u-switch>开启
						
					</view>
					
				</view>
				<view  class="itemView">开启后，对外显示名称将展示“X女士/先生”<br/>(只修改"真实姓名保护"无需提交审批)</view>
				
			</view>
			<view class="viewradio">
				<u-radio-group v-model="valueradio">
				<u-radio name="1">阅读并同意</u-radio>
				</u-radio-group>
				
				<span v-for="(item,i) in newsList" :key="i">
					{{i==0?'':','}}<span @click="gotoUrl('pages/packages/news/articleDetail?id='+item.id)" class="spanradio" ><{{item.title}}></span>
				</span>
				
			</view>
		</view>
		
		<button class="save"  @click="submit"
		type="default">
		<span v-if="formData.status==0">提交修改</span>
		<span v-else-if="formData.status==1">提交修改</span>
		<span v-else >提交审批</span>
		</button>
		
		<!-- 筛选框 -->
		<u-popup v-model="popupShow"  @open="popupShowOpen" mode="bottom" border-radius="20" :closeable="true">
			<view class="popup-content">
				<view class="headline">
					筛选
				</view>
		
				<!-- 行业 -->
				<view class="industry">
					<view class="title">
						<u-search v-model="querypop"></u-search>
						<view>意向行业 <span style="color: #4696f6;">{{isChecked!=-1?'已选中:'+industryList[isChecked].name:''}}</span> (向下拉可滑动)</view>
						
					</view>
						<!-- 选项 -->
						
						<scroll-view  class="scrollview" scroll-y="true" style="height: 620rpx;">
						
							<view class="options">
								
									<view 
									:class="{item,checked:isChecked==index}" v-for="(item,index) in industryList"
									  v-show="item.name.indexOf(querypop)!=-1"
									 :key="index"
										@click="changeChecked(index)">
										<!-- 快递跑腿/配送/分拣 -->{{item.name}}
									</view>
								
							</view>
						</scroll-view>
					
				</view>
				<!-- 结算方式 -->
				<view class="clearing-form" v-if="false">
					<view class="title">
						结算方式
					</view>
					<!-- 选项 -->
					<view class="options">
						<view :class="{item,checked:wayChecked==index}" v-for="(item,index) in wayList" :key="index"
							@click="changeWayChecked(index)">
							{{item.name}}
						</view>
					</view>
				</view>
				<!-- 薪资形式 -->
				<view class="salary-form" v-if="false">
					<view class="title">
						薪资形式
					</view>
					<!-- 选项 -->
					<view class="options ">
						<view :class="{item,checked:saralyChecked==index}" v-for="(item,index) in salaryList"
							:key="index" @click="changeSaralyChecked(index)">
							{{item.name}}
						</view>
					</view>
				</view>
		
		
		
				<view class="button">
					<button class="reset" @click="reset()">重置</button>
					<button class="confirm" @click="queryBtn()" >确认</button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import * as API_weixin from '@/apis/weixin.js'
	import {
		checkIdCard
	} from '@/apis/utils'
	import * as API from '@/apis/pagejs/packages.js'
	export default {
		data() {
			return {
				valueradio:'',
				querypop:"",
				popupShow: false,
				isChecked: -1,
				industryList: [
				],
				personalForm:{
					realName:'',
					idCard:"",
				},
				src: '',
				tel: '15011110000',
				show: false,
				list: [],
				formData:{
					id:"",
					intendedIndustries:"",
					intendedPosition:"",
					hopeSalary:"",
					method:"",
					workExperience:"",
					education:"",
					serviceDesc:"",
					photo:"",
				},
				intendedIndustries:"",
				method:"",
				workExperience:"",
				education:"",
				sqlList:[[],[
    {
       "name": "日结",
       "value": "1",
    },
    {
        "name": "周结",
        "value": "2",
    },
    {
        
        "name": "月结",
        "value": "3",
     
    }
],[],[],[],[],[]],
				valueList:[-1,-1,-1,-1,-1,-1],
				selectIndex:0,
				form: {},
				userInfo:{},
				isAnonymous:"",
				newsList:[],
			}
		},
		onLoad(){
			this.userInfo=this.carhelp.getPersonInfo()	
			this.tel=this.userInfo.phone
			if(this.userInfo.realName){
				this.personalForm.realName=this.userInfo.realName
				this.personalForm.idCard=this.userInfo.idCard
			}
			this.isAnonymous=this.userInfo.isAnonymous
			this.myJobHunt()
			this.getNewsInfo()
		},
		methods: {
			getNewsInfo(){
				
				API.newsList({
					category:9,
					
				}).then((res) => {
					uni.hideLoading();
					
					this.newsList = res.data.data;
					
					
				}).catch(error => {
					uni.showToast({icon: 'none',
						title: error,
						icon: "none"
					})
				})
			},
			change3(index){
				this.isAnonymous=index;
				this.updateApi()
			},
			updateApi(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API.updatePerson({
					intention: this.userInfo.intention,
					isAnonymous:this.isAnonymous,
					jobStatus:this.userInfo.jobStatus
				}).then((res) => {
					uni.hideLoading();
					//this.userInfo.intention=this.intention?"1":"2";
					this.userInfo.isAnonymous=this.isAnonymous;
					//this.userInfo.jobStatus=this.jobStatus?"1":"0";
					this.carhelp.setPersonInfo(this.userInfo)
					uni.showToast({
						icon:"none",
						title:"修改成功"
					})
				}).catch(error => {
					this.showPhone = false;
					uni.hideLoading();
				})
			},
			reset() {
				this.isChecked = -1;
			
				
			},
			queryBtn(){
				this.formData.intendedIndustries=this.industryList[this.isChecked].value
				this.intendedIndustries=this.industryList[this.isChecked].name
				this.popupShow=false;
			},
			changeChecked(index) {
				this.isChecked = index;
			},
			popupShowOpen(){
				if(this.industryList.length==0){
					uni.showLoading({
						title: "加载中",
						mask: true,
					})
					API_weixin.findListByCatalogName({
						name:'意向行业',
						
					}).then((res) => {
						uni.hideLoading();
						
						this.industryList=res.data.dictionaryList
						
					}).catch(error => {
					
						uni.showToast({icon: 'none',
							title: error
						})
						//this.getPhone()
						
					})
				}
			},
			myJobHunt(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				
				API.myJobHunt().then((res) => {
					uni.hideLoading()				
					if(res.data.jobInformationInfo){
						this.valueradio=1
						this.formData = res.data.jobInformationInfo;
						var name=["intendedIndustries","method",
						"workExperience","education",]
						for(var i in  name){
							//.log(name[i]+'N')
							var test=this.formData[(name[i]+'N')]
							this[name[i]]=test?test:''
						}
						this.src= this.formData.photo
					}
					
				}).catch(error => {
					uni.showToast({icon: 'none',
						title: error,
						icon: "none"
					})
				})
			},
			submit(){
				if(!this.valueradio) {
					uni.showToast({icon: 'none',
						title: "请勾选`阅读并同意`相关协议",
						icon: "none"
					})
					return
				}
				if(!this.formData.intendedIndustries){
					uni.showToast({icon: 'none',
						title: "请选择意向行业"
					})
					return
				}
				if(!this.formData.intendedPosition){
					uni.showToast({icon: 'none',
						title: "请填写想找的工作岗位"
					})
					return
				}
				if(!this.formData.method){
					uni.showToast({icon: 'none',
						title: "请选择结算方式"
					})
					return
				}
				
				if(!this.formData.hopeSalary){
					uni.showToast({icon: 'none',
						title: "请填写期望薪资"
					})
					return
				}
				if(!this.formData.serviceDesc){
					uni.showToast({icon: 'none',
						title: "请描述个人简介"
					})
					return
				}
				
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				this.formData.photo=this.src
				
				if(this.userInfo.status==0){
					if(!this.personalForm.realName) {
						uni.showToast({icon: 'none',
							title: "请填写真实姓名",
							icon: "none"
						})
						return
					}
					if(!this.personalForm.idCard) {
						uni.showToast({icon: 'none',
							title: "请填写身份证号",
							icon: "none"
						})
						return
					}
					var checkIdCardResult = checkIdCard(this.personalForm.idCard);
					if (checkIdCardResult !== true) {
						uni.showToast({icon: 'none',
							title: checkIdCardResult,
							icon: "none"
						})
						return;
					}
					this.personalAutApi();
				}else{
					this.createJobHuntApi()
				}
				
				
			},
			personalAutApi(){
				uni.showLoading({
					title: "加载中",
					mask: true
				})
				API.createAuthentication(this.personalForm).then((res) => {
					uni.hideLoading();
					this.createJobHuntApi();
				}).catch(error => {
					uni.showToast({icon: 'none',
						title: error,
						icon: "none"
					})
				})
			},
			createJobHuntApi(){
				API.createJobHunt(this.formData).then((res) => {
					uni.hideLoading();
					
					uni.showModal({
						title: '提示',
						content: '简历审批中,请耐心等待',
						showCancel:false,
						success: function (res) {
							if (res.confirm) {
								
								uni.navigateBack()
							} else if (res.cancel) {
								//.log('用户点击取消');
							}
						}
					});
					
				}).catch(error => {
				
					uni.showToast({icon: 'none',
						title: error
					})
					//this.getPhone()
					
				})
			},
			showselect(k){
				this.selectIndex=k;
				if(this.sqlList[k].length==0){
					var name=['意向行业','结算方式','工作经验','学历']
					uni.showLoading({
						title: "加载中",
						mask: true,
					})
					API_weixin.findListByCatalogName({
						name:name[k],
						
					}).then((res) => {
						uni.hideLoading();
						this.sqlList[k]=res.data.dictionaryList
						this.list=this.sqlList[k];
						this.show= true
						
					}).catch(error => {
					
						uni.showToast({icon: 'none',
							title: error
						})
						//this.getPhone()
						
					})
				}else{
					this.list=this.sqlList[k];
					this.show= true
				}
			},
			saveRecordConfirmMethod(fileData) {

				var token = this.carhelp.getToken()

				uni.uploadFile({
					url: process.car.BASE_URL + "uploadPicture", //仅为示例，非真实的接口地址
					filePath:fileData,
					header: {
						'Authorization': token,
						//'Content-Type': 'multipart/form-data',
						'X-Requested-With': 'XMLHttpRequest',
						//	'content-type': 'multipart/form-data'
					},
					name: 'photoFile',
					formData: {
						subFolder: "headimg"
					},
					success: (uploadFileRes) => {
						
						
						var obj = JSON.parse(uploadFileRes.data)
						//.log(obj);
						this.src = obj.data;

						// uni.hideLoading();
					}
				});
			},
			confirm(e) {
				this.show = false;
				var name=["intendedIndustries","method",
				"workExperience","education",]
				this[name[this.selectIndex]]=e[0].label
				this.formData[name[this.selectIndex]]=e[0].value
				//.log(e)
			},
			uploadPhoto() {
				let _self = this;

				const crop = {
					quality: 100,
					width: 600,
					height: 600,
					resize: true
				};

				// 上传图片
				uni.chooseImage({
					count: 1,
					crop,
					success: async (res) => {
						//(res);
						let tempFile = res.tempFiles[0];

						var filePath = res.tempFilePaths[0]

						let fileData = await new Promise((callback) => {
							uni.navigateTo({
								url: './cropImage?path=' + filePath +
									`&options=${JSON.stringify(crop)}`,
								animationType: "fade-in",
								events: {
									success: url => {
										callback(url)
									}
								}
							});
						})

						this.saveRecordConfirmMethod(fileData);




					}
				});
			},
		}
	}
</script>
<style>
	page {
		background: #F0F0F2;
		padding-bottom: 150px;
	}
</style>
<style lang="scss" scoped>
	.main {
		margin: 24rpx 32rpx;
		background-color: #fff;
		padding: 40rpx 32rpx 0;
		border-radius: 12px;
		.redtext{
			color:red;
		}
		.titlesm {
			color: #333333;
			font-size: 18px;
			font-family: 'PingFangSC-medium';
			
		}
		.person-infos {
			display: flex;
			justify-content: space-between;

			.infos {
				.name {
					color: rgba(51, 51, 51, 1);
					font-size: 20px;
					font-family: 'PingFangSC-medium';
				}

				.gender-age {
					color: rgba(119, 119, 119, 1);
					margin-top: 8rpx;

					.text {
						margin: 0 8rpx;
					}

					.text:nth-of-type(1) {
						margin-left: 0;
					}
				}

			}
			.photo::before {
				content: "";
				border-radius: 100rpx;
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				background-color: rgba(104,101,101,0.25);
				z-index: 1;
			}
			.photo img {
				position: relative;
				z-index: 2;
			}
			.photo {
				position: relative;
				display: inline-block;
				img {
					width: 60px;
					height: 60px;
				}

				.camera {
					width: 48rpx;
					height: 48rpx;
					position: absolute;
					top: 36rpx;
					left: 36rpx;
					z-index: 999;
				}

			}


		}

		.information-group {
			.itemView{
				padding-bottom:20px ;
			}
			.item {
				display: flex;
				align-items: center;
				padding: 12rpx 0;
				border-bottom: 1px solid #f1f1f1;

				.title {
					color: rgba(51, 51, 51, 1);
					font-size: 32rpx;
					width: 150rpx;
					text {
						color: #FF0000;
					}
				}
				.input4{
					    display: flex;
					    align-items: center;
					
				}
				.input3{
					padding: 16rpx 0;
				}
				.input2 {
					width: 360rpx;
					margin-left: 24rpx;
					
					/deep/.uni-input-input {
						color: rgba(51, 51, 51, 1);
					}
				}
				.input {
					width: 460rpx;
					margin-left: 24rpx;

					/deep/.uni-input-input {
						color: rgba(51, 51, 51, 1);
					}
				}

				.icon {
					margin-left: auto;
				}

				.unit {
					margin-left: auto;
					color: #333333;
					font-size: 24rpx;
				}
			}
		}

	}

	// 服务描述
	.service-description {
		margin: 24rpx 32rpx;
		background-color: #fff;
		border-radius: 12px;
		padding: 24rpx 32rpx;

		.title {
			color: #333333;
			font-size: 18px;
			font-family: 'PingFangSC-medium';
		}

		text {
			color: #FF0000;
		}

		.textarea {
			margin-top: 24rpx;
			line-height: 40rpx;
			width: 100%;
			height: 240rpx;

		}

	}

	.save {
		background-color: rgba(34, 149, 255, 1);
		color: rgba(241, 241, 241, 1);
		font-size: 18px;
		height: 96rpx;
		line-height: 96rpx;
		border-radius: 50px;
		position: fixed;
		left: 32rpx;
		right: 32rpx;
		bottom: 20rpx;
		z-index: 999;
	}
	// 筛选框
	.popup-content {
		padding: 32rpx;
	
		.headline {
			color: #101010;
			font-size: 40rpx;
			text-align: center;
		}
	
		//行业
		.industry,
		.clearing-form,
		.salary-form {
			margin-top: 16rpx;
		
			.title {
				font-size: 32rpx;
				color: #111111;
			}
	
			// 选项
			.options {
				display: flex;
				
				flex-wrap: wrap;
				margin-top: 24rpx;
	
				.item {
					height: 56rpx;
					line-height: 56rpx;
					min-width: 210rpx;
					text-align: center;
					margin-bottom: 16rpx;
					margin-right: 16rpx;
					color: #999999;
					background-color: #F3F3F4;
					border-radius: 4px;
					padding: 0 6rpx;
				}
	
				.checked {
					background-color: #2795FD;
					color: #fff;
				}
			}
		}
	
		.button {
			display: flex;
	
			margin-top: 8rpx;
			.reset:after{
					border:0
			}
			.reset {
				color: #999999;
				background-color: #F3F3F4;
				width: 200rpx;
				height: 72rpx;
				line-height: 72rpx;
				border-radius: 8px;
				
			}
	
			.confirm {
				width: 440rpx;
				background-color: #2795FD;
				color: #fff;
				height: 72rpx;
				line-height: 72rpx;
				border-radius: 8px;
			}
		}
	}
	
	.salary-form,
	.clearing-form {
		.options {
			justify-content: start !important;
		}
	
		.item {
			margin-right: 24rpx;
		}
	}
	.scrollview{
		border: 1px #101010 dashed;
	}
	.viewradio{
		display: flex;
		    flex-wrap: wrap;
		    align-items: center;
		background-color: #fff;
		.spanradio{
			color:#4496f8
		}
	}
</style>