<template>
	<view class="dangerbig-details">
		<view class="fixedheader">
			<headers :themeType="true" :showBack="true">
				<view class="headerName">
					培训详情
				</view>
			</headers>
		</view>
		<view :style="{ 'padding-top': (statusBarHeight + 45) * 1.5 + 'rpx' }">
			<view class="detail-content">
					<view class="list">
						<view class="list-info">
							培训计划名称：<text class="detail-data">{{detailData.name}}</text>
						</view>
						<view class="list-info">
							科目类型：<text class="detail-data">{{detailData.subjectName}}</text>
						</view>
						<view class="list-info">
							课件名称：<text class="detail-data">{{detailData.courseName}}</text>
						</view>
						<view class="list-info">
							教育主题：<text class="detail-data">{{detailData.title}}</text>
						</view>
						<view class="list-info">
							考试试卷：<text class="detail-data">{{detailData.paperName}}</text>
						</view>
						<view class="list-info">
							培训有效时间：<text style="font-size: 24rpx;">{{detailData.trainBeginTime}}-{{detailData.trainEndTime}}</text>
						</view>
					</view>

					<view class="detail-nav" v-if="COMPANY != 'longguang'">
						<scroll-view class="scrollx-wrap" scroll-x>
							<view class="nav-list">
								<view class="nav-item"
									:class="{'active-nav': activeIndex == item.id}"
									v-for="(item,index) in navList" :key="index"
									@click="checkNav(item)">
									{{item.name}}
								</view>
							</view>
						</scroll-view>
						<view class="detail-wrap">
							<view class="study-detail-list" >
								<view class="study-detail-item" v-for="(item,index) in listData" :key="index">
									<view>
										<text>姓名：</text>
										<text>{{item.workerName}}</text>
									</view>
									<view>
										<text>身份证号：</text>
										<text>{{item.workerCard}}</text>
									</view>
									<view v-if="activeIndex == 1">
										<text>开始学习时间：</text>
										<text>{{item.beginTime}}</text>
									</view>
									<view v-if="activeIndex == 1">
										<text>结束学习时间：</text>
										<text>{{item.endTime}}</text>
									</view>
									<view v-if="activeIndex == 3">
										<text>开始考试时间：</text>
										<text>{{item.startExamTime}}</text>
									</view>
									<view v-if="activeIndex == 3">
										<text>作答时长：</text>
										<text>{{item.duration}}</text>
									</view>
									<view v-if="activeIndex == 3">
										<text>考试结果：</text>
										<text>{{item.isPass == 1?'合格':'不合格'}}</text>
									</view>
									<view v-if="activeIndex == 3">
										<text>考试总分：</text>
										<text>{{item.score}}</text>
									</view>
									<view v-if="activeIndex == 3 || activeIndex == 4">
										<text>剩余重考次数：</text>
										<text>{{item.examCount}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
					<!-- <view class="add-btn" v-if="activeIndex != 7 && activeIndex != 2 && !(activeIndex == 1 && detailData.engineeringState == 3) -->
					<view class="add-btn" v-if="activeIndex != 7 && activeIndex != 2 
					&& COMPANY != 'longguang' && detailData.finalAcceptanceStatus !== 2 && isShowBtn"
					@click="addForm">
						<uni-icons2 v-if="activeIndex == 5" type="camera" size="30" color="#fff"></uni-icons2>
						<uni-icons2 v-else type="plusempty" size="30" color="#fff"></uni-icons2>
						<span>+</span>
					</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				statusBarHeight: 0,
				isShow: true,
				componentName: "planList",
				navList:[{
					id: 1,
					name: "学习记录"
				},{
					id: 2,
					name: "未学习统计"
				},{
					id: 3,
					name: "考试记录"
				},{
					id: 4,
					name: "未考试统计"
				}
				],
				activeIndex: 1,
				detailId: "",
				detailData:{},
				isShowBtn: null,
				listData: []
			}
		},
		onReachBottom() {
			console.log(1,this.$refs['list'])
		},
		onPullDownRefresh() {
			console.log(2)
		},
		onShow(){
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
		},
		onLoad(val){
			this.detailData = JSON.parse(val.obj)
			console.log(this.detailData)
			this.getListData();
		},
		mounted() {
		},
		methods:{
			getListData(){
				let that = this;
				let url = ""
				let requestData = {
					trainId: this.detailData.id
				}
				if(this.activeIndex == 1){
					requestData.number = 1
					url = "exam/courseRecord/list"
				} else if(this.activeIndex == 2){
					requestData.number = 0
					url = "exam/courseRecord/list"
				} else if(this.activeIndex == 3){
					requestData.examNum = 1
					url = "exam/trainRecord/examRecordList"
				} else if(this.activeIndex == 4){
					requestData.examNum = 0
					url = "exam/trainRecord/examRecordList"
				}
				this.sendRequest({
					url: url,
					data: requestData,
					header: {},
					method: 'post',
					success(res) {
						if(res.code == 200){
							that.listData = res.result;
							that.listData.map(item => {
								let str = "*************"
								item.workerCard = item.workerCard.substring(0,3)+str+item.workerCard.substring(14)
							})
						}
					}
				})
			},
			initData(){
				this.sendRequest({
					url:'xmgl/dangerousEngineeringRecord/queryById',
					method:'post',
					data:{id:this.detailId},
					success:res=>{
						uni.hideLoading()
						// if(res.code==200){
						// 	this.listData = res.result.records
						// }
						this.detailData =  res.result
						let str = '';
						if(res.result.chooseTypeDescribeList){
							this.detailData.describeName
							res.result.chooseTypeDescribeList.map((item,index) => {
								if(index == res.result.chooseTypeDescribeList.length - 1){
									str = str + item.describeName
								} else {
									str = str + item.describeName + ','
								}
							})
							console.log(str,123456789)
							this.detailData.describeName = str;
						}
						console.log(this.detailData)
						this.getApply()
					}
				})
			},
			getApply(){
				console.log("=====================================================detail");
				console.log(this.detailData);
				this.sendRequest({
					url:'xmgl/xzDangerousEngineeringAcceptance/list',
					method:'get',
					data:{
						engineeringId: this.detailData.id,
						projectSn: JSON.parse(uni.getStorageSync('projectDetail')).projectSn,
						type:1
					},
					success:res=>{
						uni.hideLoading()
						console.log("xmgl/xzDangerousEngineeringAcceptance/list",res);
						let result = res.result
						if(res.result.length>0){
							if(res.result[0].acceptanceResult === null) this.isShowBtn = false
							if(res.result[0].acceptanceResult === 1) this.isShowBtn = false
							if(res.result[0].acceptanceResult === 2) this.isShowBtn = true
						}else{
							this.isShowBtn = true
						}
					}
				})
			},
			checkNav(val){
				this.activeIndex = val.id
				this.getListData();
			},
			addForm(){
				if(this.activeIndex == 1){
					uni.navigateTo({
						url:'./addPlan?id='+this.detailId
					})
				} else if(this.activeIndex == 3){
					uni.navigateTo({
						url:'./addOrdinaryAcceptance?id='+this.detailId
					})
				}	else if(this.activeIndex == 4){
					uni.navigateTo({
						url:'./addVerifyForm?id='+this.detailId
					})
				} else if(this.activeIndex == 5){
					if(uni.getStorageSync('dangerData')){
						uni.removeStorageSync('dangerData');
					}
					if(uni.getStorageSync('detailData')){
						uni.removeStorageSync('detailData');
					}
					uni.navigateTo({
						// url:'../safeManage/addExamine?type=1&engineeringId='+this.detailId + '&moduleType=safeCheck'
						url:'../safeSame/addIssue?type=1&engineeringId='+this.detailId + '&moduleType=safeCheck'
					})
				} else if(this.activeIndex == 6){
					uni.navigateTo({
						url:'./addConstructionStation?id='+this.detailId
					})
				}
				else if(this.activeIndex == 8){
					if(this.isShowBtn){
						uni.navigateTo({
							url:'./addFinallyAcceptance?id='+this.detailId+'&name='+this.detailData.engineeringName
						})
					}else{
						uni.showToast({
							title: '请勿重复操作',
							icon: "none",
							duration: 2000
						});
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.dangerbig-details{
	min-height: 100%;
	background: #F6F6F6;
	.fixedheader{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 2;
	}
	.detail-content{
		padding-top: 20rpx;
	}
	.list{
		margin-bottom: 20rpx;
	}
	.list-info{
		background: #fff;
		border-bottom: 1px solid #F6F6F6;
		font-size: 28rpx;
		padding: 20rpx;
	}
	.more-btn{
		text-align: center;
		font-size: 28rpx;
		height: 50rpx;
		background: #F1F7FE;
		line-height: 50rpx;
	}
	.nav-list{
		display: flex;
		height: 80rpx;
		align-items: center;
		justify-content: space-between;
		padding: 0 20rpx;
		.nav-item{
			white-space: nowrap;
			padding: 0 20rpx;
			height: 80rpx;
			box-sizing: border-box;
			line-height: 80rpx;
			font-size: 28rpx;
		}
		.active-nav{
			border-bottom: 4rpx solid #4396E7;
		}
	}
	.detail-wrap{
		padding: 30rpx 18rpx;
		.study-detail-list{
			.study-detail-item{
				background: linear-gradient( 180deg, rgba(255,255,255,0.1) 0%, rgba(198,220,255,0.2) 100%);
				box-shadow: 0px 8rpx 32rpx -8rpx rgba(42,60,106,0.24);
				border-radius: 34rpx;
				padding: 18rpx 30rpx;
				>view{
					text{
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: 400;
						font-size: 28rpx;
						color: #000000;
					}
				}
				>view:not(:last-child){
					margin-bottom: 15rpx;
				}
			}
			.study-detail-item:not(:last-child){
				margin-bottom: 30rpx;
			}
		}
	}
	.detail-nav{
		width: 100%;
	}
	.scrollx-wrap{
		width: 100%;
		background: #fff;
	}
	.add-btn{
		background: #4181FE;
		width: 96rpx;
		height: 96rpx;
		border-radius: 50%;
		text-align: center;
		line-height: 96rpx;
		position: fixed;
		bottom: 40rpx;
		right: 40rpx;
		span{
			font-size: 60rpx;
			    line-height: 90rpx;
			    color: #fff;
		}
	}
}
</style>
