<template>
	<view style="">
		<view class="navTab">
			<view class="sintitle">
				<img src="/static/index/grxx.png" alt="">
				<p>基本信息</p>
			</view>
			<u-form :model="basicobj"  ref="basicobj" label-position='left' label-width='150'  border-bottom='false' >
				<u-form-item  label="姓名：" prop="name"  border-bottom='false' required='true'>
					<view class="sinput">
						<u-input style="width:100%;"  v-model="basicobj.name"  placeholder='输入姓名'/>
					</view>
				</u-form-item>
				
				 <u-form-item  label="所在城市：" prop="city"  border-bottom='false' required='true'>
					<!-- <view v-if="istest" class="sinput">
						<u-input style="width:100%;"   v-model="basicobj.city" placeholder='输入所在城市' /> 
					</view>v-else -->
					<view class="sinput">
						<u-input style="width:100%;"  v-model="basicobj.city" type="select"  @click="cityshow = true" placeholder='输入所在城市' />
						<u-select v-model="cityshow"  :list="cityList"  @confirm="citychange" mode="mutil-column-auto" ></u-select>
					</view>
				</u-form-item>
				
				<u-form-item  label="个人技能：" prop="testSkills"  border-bottom='false' required='true'>
					<view class="sinput">
						<u-input style="width:100%;"  v-model="basicobj.testSkills" placeholder='输入个人技能'/>
					</view>
				</u-form-item> 
				<view class="sintitle" style="margin-top:15px;margin-left: -20px;">
					<img src="/static/index/jnzs.png" alt="">
					<p style="color:#fa3534;margin-right:3px">* </p>
					<p>资格证书</p>
				</view>
				<u-form-item  prop="certificateUrl"  border-bottom='false' >
					<u-upload width='100px' height='100px'
						:action="action"
						:header="headers"
						:auto-upload="true"
						:show-progress="false"
						 max-count="1"
						:deletable="true"
						:file-list="basicobj.certificateUrl"
						@on-success="(data,index,lists) => {fielUploadSuc(data,index,lists) }"
						@on-remove="(index, lists, name)=>{deleteUpfile(index)}"
						@on-error="(data,index, lists)=>{errorUpfile(data,index, lists)}"
						>
						<view slot="addBtn" class="slot-btn" >
							<img v-if="basicobj.certificateUrl" :src="basicobj.certificateUrl"  mode="aspectFill" style="width: 100px;height: 100px;">
							  <div  v-else class="upliacla">
								  <p style="font-size: 18px;">+</p>
								  <p>选择图片</p>
								<!-- <u-icon name="arrow-upward" color="#606266" size="38"></u-icon> -->
							  </div>
						</view>
					</u-upload>
					<!-- <div v-if="basicobj.certificateUrl">
						
						<img v-if="basicobj.certificateUrl.length>35" :src="basicobj.certificateUrl" style="width: 100px;height: 100px;">
						<p class="wuploa" v-else>未上传证书</p>
					</div> -->
				</u-form-item>
			</u-form>
			
		</view>
		<view class="bottbtn"  @click="resource">保存</view>
		
		<view style="height:10px"></view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cityshow:false,
				basicobj:{name:'',city:'',testSkills:'',certificateUrl:''},
				wxUserInfo:null,
				testerdata:null,
				cityList:[],
				action: this.http.baseUrl +'/upload',
				headers:{Authorization:'Bearer '+uni.getStorageSync('accessToken')},
				certRules: {
					name: [{required: true, message: '请输入姓名', trigger: 'change',},
					{max: 4, message: '最多输入4个中文', trigger: 'change' },
					{
					  pattern:
					     /^(?:[\u4e00-\u9fa5·]{2,16})$/,
					  message: "请输入中文",
					  trigger: "blur",
					},],
					city:[{required: true, message: '请选择城市', trigger: 'change'}],
					
				},
				
			}
		},
		onShow() {
			
			this.http.quickGet(`/common/city`,).then(res=>{
				// console.log('城市数组---',res)
				this.cityList=res.data
			})
		},
		onReady(){
			this.$refs.basicobj.setRules(this.certRules);
		},
		onLoad() {
			// /tester/cert/apply/{userId}
			this.wxUserInfo = uni.getStorageSync('wxUserInfo');
			let userId=this.wxUserInfo.userId
			this.http.quickGet(`/tester/TesterInfo/resume/${this.wxUserInfo.userId}`,true).then(res=>{
				let resumedata=res.data;
				let {name,city,testSkills,certificateUrl}=resumedata;
				this.basicobj={name,city,testSkills,certificateUrl}
				console.log('简历信息---',res)
			})
		},
		computed: {
		  
		},
		methods: {
			citychange(e){
				console.log('城市回显',e,this.cityshow)
				this.basicobj.city=e[0].label+'-'+e[1].label
			},
			//文件上传成功回调
			fielUploadSuc(data,index) {
				console.log('-',data,'*',index)
				
				if (data.code === 200) {
					this.basicobj.certificateUrl=data.filePath
					console.log('技能认证',this.basicobj.certificateUrl)
				}
			},
			//移除
			deleteUpfile(index,lists){
				console.log('del技能认证',this.basicobj.certificateUrl)
				this.basicobj.certificateUrl=''
				// if(this.credentialImgList.length>0){				
				// 	let id=this.credentialImgList[0].id;
				// 	this.http.quickDelete(`/equestrianinfo/file/${id}`).then(()=>{})
				// }
			},
			errorUpfile(data,index){
				// console.log('上传失败-',data,'*',index)
				// this.$refs.uToast.show({
				// 	title: '上传失败，请您重新上传',
				// 	type: 'error',
				// })
			},
			resource(){
				console.log('basicobj',this.basicobj)
				this.$refs.basicobj.validate(valid => {
					if (valid) { 
						let certificateUrl = this.http.baseUrl + this.basicobj.certificateUrl;
						// console.log('技能证书',this.basicobj.certificateUrl)
						// if(this.basicobj.certificateUrl.indexOf('https')==0){
						// 	certificateUrl=this.basicobj.certificateUrl
						// }else{
						// 	if(this.basicobj.certificateUrl==''){
						// 		certificateUrl=''
						// 	}else{
						// 		certificateUrl='https://www.keyitest.cn/prod-api'+this.basicobj.certificateUrl
						// 	}
						// }
						let data={
							userId:this.wxUserInfo.userId,
							name:this.basicobj.name,
							city:this.basicobj.city,
							testSkills:this.basicobj.testSkills,
							certificateUrl,
						}
						console.log('基本信息',data)
						// return;
						this.http.quickPut(`/tester/TesterInfo`,data,true).then(res=>{
							console.log('更新基本信息',res)
							if(res.data.code==200){
								this.$refs.uToast.show({
									title: '保存成功',
									type: 'success',
									url:'pages/personal/personalresume/personalresume'
								})
							}else{
								
							}
						})
					}else{
						console.log('验证失败',this.basicobj)
					}
				})
			}
		}
	}
</script>

<style>
	page{
		background: #FFFFFF!important;
	}
	.navTab{
		padding:13px 20px 13px 20px;
		
	}
	.sinput{
		display: flex;
		align-items: center;
		/* height: 50px; */
	}
	.u-form-left__content__label{
		color:#808080!important;
	}
	.sintitle{
		display: flex;
		align-items: center;
		/* height: 50px; */
		background: #F2F4F7;
		/* background:#20529c; */
		border-radius: 4rpx;
		padding:7px 15px; 
	}
	.sintitle img{
		width:20px;
		height:18px;
		margin-right:5px;
	}
	.sintitle p{
		font-size: 15px;
		color:#000000;
		font-weight: bold;
	}
	.sinput .u-input{
		
		height:35px;
		border-bottom: 1px solid #EBEBEB!important;
		
		
	}
	.sinput p{
		color: #808080;
	}
	.bottbtn{
		width:94vw;
		margin:30px 3vw 15px 3vw;
		height:75rpx;	
		background: linear-gradient(90deg, #5EA6FD, #1A81F9);
		border-radius:43rpx;
		text-align: center;
		line-height:75rpx;
		color: #FFFFFF;
		font-size: 33rpx;
		/* margin-left:13px; */
	}
	.sinputrt{
		display: flex;
		/* align-items: center; */
		/* height: 50px; */
		padding: 10px 0px;
	}
	.sinputrt .u-input{
		/* width:75vw; */
		height:100px;
		border: 1px solid #E6E6E6;
		background: #FFFFFF;
		border-radius: 10rpx 10rpx 0rpx 0rpx;
		padding-left: 10px!important;
	}
	.u-list-item{
		margin:0!important;
		zIndex:0!important;
	}
	.slot-btn {
		width:200rpx;
		height:0rpx;
		zIndex:99;
		/* display: flex;
		justify-content: center;
		align-items: center;
		background: rgb(244, 245, 246);
		border-radius: 10rpx; */
	}

	.slot-btn__hover {
		background-color: rgb(235, 236, 238);
	}
	.u-form-item{
		margin-bottom:-5px;
		color: #808080!important;
	}
	.u-form{
		margin-left: 20px;
	}
	.u-list-item{
		margin: 0 !important;
		background: transparent!important;
		color:transparent!important;
	}
		
		.upliacla{
			width: 100px;
			height: 100px;
			/* line-height:100px; */
			border-radius: 4px;
			background: #f4f5f6;
			color:#606266;
			display:flex;
			flex-direction: column;
			
			align-items: center;
			justify-content: center;
			
		}
		.wuploa{
			/* width: 100px;
			height: 100px;
			line-height: 100px;
			font-size: 12px;
			border: 1px solid #E6E6E6;
			text-align: center;
			border-radius: 4px; */
		}
</style>
