<template>
	<view class="container">
		<view class="title">
		   <view>
				<text class="line"></text>学历信息
			</view>
		   <text class="page_mark">4/8</text>
		 </view>
		 <view class="content">
		     <view class="contentDetail employ">
		       <view class="contentItem">
		         <text>最高学历：如本科、专科、硕士</text>
				 <picker @change="changeEducation" :value="educationIdx" :range="educationLevelList"
				 range-key="name">
					 <view class="uni-input">{{educationLevelList[educationIdx]['name']}}
						 <text class="iconfont icon-youjiantou"></text>
					 </view>
				 </picker>
		       </view>
		       <view class="contentItem">
		         <text>毕业学校</text>
		         <input class="form-control" v-model="applyParam.lastGraduateSchool"/>
		       </view>
		       <view class="contentItem" style="border:none;">
		         <text>毕业证</text>
		         <view></view>
		       </view>
		     </view>
		     <view class="photo_wrapper" v-if="!applyParam.lastGraduateCertificationOssPath" @click="upLoadPhoto()">
		       <text class="iconfont icon-weibiaoti553"></text>
		       <view style="margin-top: 10px;" >点击添加毕业证照片</view>
		     </view>
		     <image :src="applyParam.lastGraduateCertificationOssPath" v-if="applyParam.lastGraduateCertificationOssPath"
			 @click="upLoadPhoto()" mode="widthFix"></image>
		     <view class="tips">
		       <view>（jpg,png 文件大小不大于1mb）</view>
		     </view>
		   </view>
		 <view class="fixed" @click="saveInfo()">
		   保存并下一步
		 </view>
	</view>
</template>

<script>
	import api from '../../api/api';
	import { CommonUpload } from '@/util/uploaderFile';
	export default{
		data(){
			return {
				educationLevelList:[{id:null,name:'请选择'}],
				educationIdx:0,
				applyParam:{
					lastGraduateGrade:'',
					lastGraduateSchool:'',
					lastGraduateCertificationOssPath:'',
				},
				dataForm:{
					loginId: uni.getStorageSync('cffp_userId'),
					targetType: "5",
					targetId: uni.getStorageSync('cffp_userId'),
					targetNo: "4",
					targetUseFor: "12",
					targetSeq: "0"
				}
			}
		},
		components:{},
		onLoad(){
			this.educationLevelQuery();
			if(uni.getStorageSync('applyId')){
				this.queryById(uni.getStorageSync('applyId'))
			}
		},
		methods:{
			educationLevelQuery(){
				api.educationLevelQuery().then((res)=>{
					console.log(res)
					if(res['success']){
						this.educationLevelList = this.educationLevelList.concat(res['data']['educationLevelList']);
					}
				})
			},
			queryById(id){
				api.queryById(id).then((res)=>{
					console.log(res)
					if(res['success']){
						this.applyParam = res['data']['data'];
						for(let i=0;i<this.educationLevelList.length;i++){
							if(this.applyParam.lastGraduateGrade == this.educationLevelList[i].name){
								this.educationIdx = i;
							}
						}
					}
				})
			},
			upLoadPhoto(event){
				CommonUpload(this.dataForm).then(res => {
					this.applyParam.lastGraduateCertificationOssPath = res.data.filePath;
				});
			},
			changeEducation:function(e){
				this.educationIdx = e.detail.value;
				this.applyParam.lastGraduateGrade = this.educationLevelList[this.educationIdx]['name'];
			},
			saveInfo(){
				if(!this.applyParam.lastGraduateGrade){
					uni.showToast({
						title: '请选择最高学历',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				if(!this.applyParam.lastGraduateSchool){
					uni.showToast({
						title: '请输入毕业学校',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				if(!this.applyParam.lastGraduateCertificationOssPath){
					uni.showToast({
						title: '请上传毕业证书',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				this.applyParam = {
						...this.applyParam,
						applyType:2,
						operatStep:4,
						// userId:uni.getStorageSync('cffp_userId'),
						userId:42,
						id:17,
				}
				api.saveApplyInfo(this.applyParam).then((res)=>{
					if(res['success']){
						uni.navigateTo({
							// url:`bank-card?id=${res['data']['id']}`
							url:`bank-card`
						});
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'
						})
						return;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import 'applyCommon.scss';
</style>