<template>
	<view class="page">
		<view >
			<view class="">
				<view class="pd">
					<view class="current">应聘人姓名: {{formData.candidateName}}</view>
				</view>
				<view class="myContainer myContentBox">
					<view class="top_container">面试记录</view>
					<view class="list_item">
						<view class="list_item_name">面试阶段：</view>
						<view class="list_item_content content_right">第{{this.thisIndex}}轮</view>
					</view>
					<view class="list_item">
						<view class="list_item_name">面试官：</view>
						<view class="list_item_content content_right">{{this.interviewerName}}</view>
					</view>
					<view class="list_item">
						<view class="list_item_name">面试时间：</view>
						<view class="list_item_content content_right">{{this.interviewDate}}</view>
					</view>
					
					<view class="pd">
						<view class="report_status">
							<text class="magtext redMi">面试结果</text>
						</view>
						<view> 
							<view class="btn" :class="[result_btn==422?'btn_':'']" @click="result_btn=422">通过</view>
							<view class="btn" :class="[result_btn==423?'btn_':'']" @click="result_btn=423">不通过</view>
						</view>
						<view class="item item_line item_textarea">
							<view class="itemname redMi">面试意见</view>
							<textarea class="textarea" placeholder="请填写面试意见" v-model="interviewOpinion"></textarea>
						</view>
						<view>
							<view class="list_item">
								<view class="list_item_name">操作：</view> 
								<view class="buttonstyle"><button type="primary" @click="checkNextStep()" style="width: 100%;font-size: 12px;">进入下一轮</button></view>
							</view>
						</view>
					</view>
				</view>
			</view>
			
			<!-- <view>
				<view class="report_status">
					<text class="magtext">最终面试结果</text> 
				</view>
				<view> 
					<view class="btn" :class="[final_result_btn==422?'btn_':'']" @click="final_result_btn=422">通过</view>
					<view class="btn" :class="[final_result_btn==423?'btn_':'']" @click="final_result_btn=423">不通过</view>
				</view>
				<view class="item item_line item_textarea">
					<view class="itemname">备注信息</view>
					<textarea class="textarea" placeholder="请填写备注信息" v-model="remarks"></textarea>
				</view>
			</view> -->
		</view>
		<tingycModal @cancelModal="cancelModal" @okModal="okModal" :showModal="isShow" modalTitle="提示" note="检查是否能进入下一步面试流程?"></tingycModal> 
		
		<view class="fixMargin"></view>
		<view class="goHome" @click='goMain("workInfo")'>
			<img src="../../static/img/gohome.png">
		</view>
		<view class="fixBottom">
			<view class="uni-flex uni-row">
				<view style="-webkit-flex:1;flex: 1;">
					<button type="primary"  style="width: 100%;"  @click="submit()">确认提交</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		config
	} from '../../request/js/config.js'
	import tingycModal from '@/components/tingyc-modal/tingyc-modal.vue' 
	export default {
		components: {
			tingycModal
		},
		data() {
			return {
				config:config,
				recordId:'',
				id:'',
				formData:{},
				initFileList:[],
				thisIndex:'',
				interviewerName: '',
				interviewer:'',
				interviewDate:'',
				interviewOpinion:'',
				// remarks:'',
				result_btn:422,
				final_result_btn:'',
				filterResult:{},
				canModify: '',
				isShow:false
			}
		},
		onLoad(option) {
			  this.recordId=option.id;
			   var _this = this;
			   this.$http.request({
			     url: '/apis/interviewRecord/detail/'+option.id,
				 method:'GET',
			   }).then(res=>{
					if(res.data.code == 0){
						this.formData=res.data.headInfo;
						this.initFileList = res.data.bodyInfo;
						for (var i= 0; i < this.initFileList.length; i++) { 
						    if(this.initFileList[i].canModify ==true) {
								this.thisIndex = i+1
								this.interviewerName = this.initFileList[i].interviewerName
								this.interviewDate = this.initFileList[i].interviewDate
								this.id = this.initFileList[i].id
								this.canModify = this.initFileList[i].canModify
								this.interviewer = this.initFileList[i].interviewer
							}
						 }
					} 
			   })
			
		},
		methods: {
			// 检查是否进入下一轮
			checkNextStep() {
				let obj = {
					recordId:this.recordId,
					id:this.id,
					interviewDate:this.interviewDate,
					interviewOpinion:this.interviewOpinion ,
					interviewResults:this.result_btn,
					interviewer:this.interviewer,
					interviewStage:"第"+this.thisIndex+"轮",
				}
				console.log(obj)
				let detailList = []
				detailList.push(obj)
				this.filterResult.detail = detailList
				this.filterResult.advertiseId = this.formData.advertiseId
				this.filterResult.candidateId = this.formData.id,
				this.filterResult.candidateName = this.formData.candidateName,
				this.filterResult.id = this.recordId
				this.isShow = true
				// this.okModal()
		
			},
			cancelModal() {
				this.isShow = false
			},
			okModal() {
				this.isShow = false
				//检验下一轮
				this.$http.request({
				  url: '/apis/interviewRecord/checkNextStep',
				  paramsBody:this.filterResult
				}).then(res=>{
					if(res.data.code == 0){
						uni.showToast({
							title: '操作成功',
							duration: 	1000,
							icon:"none"
						});
						this.nextStep()
					}else{
						uni.showToast({
							title: res.data.msg,
							duration: 	2000,
							icon:"none"
						});
					}
				}).catch(err=>{
					uni.showToast({
						title: '操作失败',
						duration: 	2000,
						icon:"none"
					});
				});
			},
			
			// 下一轮
			nextStep() {
				this.$http.request({
				  url: '/apis/interviewRecord/nextStep',
				  paramsBody:this.filterResult
				}).then(res=>{
					if(res.data.code == 0){
						uni.showToast({
							title: '操作成功',
							duration: 	1000,
							icon:"none"
						});
					}else{
						uni.showToast({
							title: res.data.msg,
							duration: 	2000,
							icon:"none"
						});
					}
				}).catch(err=>{
					uni.showToast({
						title: '操作失败',
						duration: 	2000,
						icon:"none"
					});
				});
			},
			
			submit(){
					if(!(this.interviewOpinion)){
						uni.showToast({
							    title: '请填写面试意见',
							    duration: 2000,
								icon:"none"
							});
						return false;
					}
					// if(this.interviewResults) {
					// 	this.filterResult.interviewResults = this.interviewResults
					// }
					// if(this.remarks) {
					// 	this.filterResult.remarks = this.remarks
					// }
					let obj = {
						recordId:this.recordId,
						id:this.id,
						interviewDate:this.interviewDate,
						interviewOpinion:this.interviewOpinion ,
						interviewResults:this.result_btn,
						interviewer:this.interviewer,
						interviewStage:"第"+this.thisIndex+"轮",
					}
					let detailList = []
					detailList.push(obj)
					this.filterResult.detail = detailList
					this.filterResult.advertiseId = this.formData.advertiseId
					this.filterResult.candidateId = this.formData.id,
					this.filterResult.candidateName = this.formData.candidateName,
					this.filterResult.id = this.recordId
				//提交审批接口。
				this.$http.request({
				  url: '/apis/interviewRecord/saveRecord',
				  paramsBody:this.filterResult
				}).then(res=>{
					if(res.data.code == 0){
						uni.showToast({
							title: '操作成功',
							duration: 	1000,
							icon:"none"
						});
						setTimeout( function(){
							uni.navigateTo({
							    url: 'interview'
							});
						},1000)
					}else{
						uni.showToast({
							title: res.data.msg,
							duration: 	2000,
							icon:"none"
						});
					}
				}).catch(err=>{
					uni.showToast({
						title: '操作失败',
						duration: 	2000,
						icon:"none"
					});
				});
			}
		}
	}
</script>


<style scoped>
	.btn {
		width: 138upx;
		height: 58upx;
		border-radius: 8upx;
		float:left;
		margin-right: 20upx;
		line-height: 58upx;
		text-align: center;
		background-color: #D7E6FF;
		border: 1px solid #3382FF;
		box-sizing: border-box;
		color: #3382FF;
		font-size: 26upx;
		margin-top: 20upx;
	}
	
	.btn_ {
		background-color: #3382FF;
		color: #fff;
		border: none;
	}
	.buttonstyle {
		float: right;
	}
	.pd {
		padding: 14upx;
	}
	.current:after {
	    position: absolute;
	    content: '';
	    width: 0px;
	    height: 0px;
	    /* background-color: #3382FF; */
	    /* bottom: 4px; */
	    left: 10px;
	    border-radius: 4px;
	}
</style>
