<template>
	<view class="container">
		<view class="page">
			<text class="num actived pass">1</text>
			<text class="line line_pass"></text>
			<text class="num actived pass">2</text>
			<text class="line line_pass"></text>
			<text class="num actived pass">3</text>
			<text class="line line_pass"></text>
			<text class="num actived">4</text>
			<text class="line"></text>
			<text class="num">5</text>
			<text class="line"></text>
			<text class="num">6</text>
			<text class="line"></text>
			<text class="num">7</text>
			<text class="line"></text>
			<text class="num">8</text>
		</view>
		<view class="wrapper">
			<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" :disabled="this.applyParam.approvalStatus!= 0 && this.applyParam.approvalStatus != 2">
						 <view class="uni-input">{{educationLevelList[educationIdx]['name']}}
							 <text class="iconfont icon-youjiantou"></text>
						 </view>
					 </picker>
			       </view>
			       <view class="contentItem">
			         <text>毕业学校</text>
			         <input type="text" class="form-control" v-model="applyParam.lastGraduateSchool" 
					 :disabled="this.applyParam.approvalStatus!= 0 && this.applyParam.approvalStatus != 2"/>
			       </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>
		<view class="fixed" @click="saveInfo()">
			{{(this.applyParam.approvalStatus== 0 || this.applyParam.approvalStatus == 2)?'保存并下一步':'下一步'}}
		</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:'',
					approvalStatus:''
				},
				dataForm:{
					loginId: uni.getStorageSync('cffp_userId'),
					targetType: "5",
					targetId: '',
					targetNo: "4",
					targetUseFor: "12",
					targetSeq: "0"
				}
			}
		},
		components:{},
		onLoad(options){
			this.educationLevelQuery();
			setTimeout(()=>{
				if(uni.getStorageSync('applyId')){
					this.queryById(uni.getStorageSync('applyId'),null)
				}else if(options.shareId){
					this.queryById(options.shareId,null)
				}else{
					this.queryById(null,uni.getStorageSync('cffp_userId'))
				}
			},500)
		},
		methods:{
			educationLevelQuery(){
				api.educationLevelQuery().then((res)=>{
					console.log(res)
					if(res['success']){
						this.educationLevelList = this.educationLevelList.concat(res['data']['educationLevelList']);
					}
				})
			},
			queryById(id,userId){
				api.queryById({id:id,userId:userId}).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){
				if(this.applyParam.approvalStatus== 0 || this.applyParam.approvalStatus == 2){
					this.dataForm.targetId = this.applyParam.id
					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.approvalStatus== 0 || this.applyParam.approvalStatus == 2){
					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,
							operatStep:4,
					}
					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;
						}
					})
				}else{
					uni.navigateTo({
						// url:`bank-card?id=${res['data']['id']}`
						url:`bank-card`
					});
				}
			}
		}
	}
</script>

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