import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; import { ActivatedRoute } from '@angular/router'; import { CanvasShareDataService } from 'src/app/canvas-share-data.service'; @Component({ selector: 'app-examination-details', templateUrl: './examination-details.component.html', styleUrls: ['./examination-details.component.scss'] }) export class ExaminationDetailsComponent implements OnInit { constructor(public canvasData:CanvasShareDataService, public http:HttpClient,public dialog: MatDialog,public snackBar: MatSnackBar,public route:ActivatedRoute) { } async ngOnInit(): Promise { await this.getTestInfo() this.getUnitPlans()//将试卷的预案考题放进数据中 } paperId:any = this.route.snapshot.queryParams.paperId //试卷id paperData:any //试卷信息 paperCompanyData:any = []; //考生具体考卷 selectPaper:any = {id:null}; //选择当前考卷 selectPaperType:string = '1'; //选择当前考卷内容 基本信息/作战部署 surplusTime:number = 3600; //考试剩余时间 //倒计时 处理时间格式 formatDate (e) { let hours = parseInt( (e.date / (1000 * 60 * 60)).toString() ) var minutes = parseInt( ((e.date % (1000 * 60 * 60)) / (1000 * 60)).toString() ); var seconds = (e.date % (1000 * 60)) / 1000; return `${hours} : ${minutes} : ${seconds}` } //基本信息表格 是否展示当前行 rowIsShow (children,tag) { let isShow:boolean = false children.forEach(element => { element.result == tag? isShow = true : null }); return isShow } //获取考卷 async getTestInfo () { await new Promise((resolve, reject) => { this.http.get(`/api/Papers/${this.paperId}`).subscribe((data:any)=>{ let now = (new Date()).getTime() let endTime = (new Date(data.endTime)).getTime() let surplusTime = Math.floor( (endTime - now) / 1000 ); //考试剩余时间 surplusTime >=0? this.surplusTime = surplusTime : this.surplusTime = 0 this.paperData = data this.paperData.paperDataInfo.forEach(element => { element.adjoinData? element.adjoinData = JSON.parse(element.adjoinData) : null element.basicInfoData? element.basicInfoData = JSON.parse(element.basicInfoData) : null element.facilityData? element.facilityData = JSON.parse(element.facilityData) : null element.functionalDivisionData? element.functionalDivisionData = JSON.parse(element.functionalDivisionData) : null element.importLocationData? element.importLocationData = JSON.parse(element.importLocationData) : null }); this.paperCompanyData = JSON.parse( JSON.stringify(data.paperDataInfo) ) //具体考卷 this.selectPaper = this.paperCompanyData[0] || {id:null} //当前选择考卷 resolve(1) }) }) } //切换 选择考卷 togglePaper (e) { if (this.selectPaper.id != e.id) { this.selectPaper = e console.log(this.selectPaper) } } //考试倒计时 handleEvent (e) { if (e.left == 600000) { //距离考试结束 剩余10分钟 const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 5000 this.snackBar.open('注: 距离考试结束还剩10分钟!','确定',config); } else if (e.left == 0) {//考试结束 this.uploadPaper() //交卷 } } //切换 选择考卷内容 togglePaperType (e) { if (this.selectPaperType != e) { this.selectPaperType = e } } //获得单位预案设定 async getUnitPlans(){ for (let index = 0; index < this.paperCompanyData.length; index++) { const item = this.paperCompanyData[index]; let params = { paperId : item.paperId, companyId : item.companyInfo.id } await new Promise((resolve,reject)=>{ this.http.get(`/api/PaperPlans`,{params:params}).subscribe(data => { item.planList = [] item.planList = data resolve(1) }) }) } this.calculateScore() } examScore:any = 0//整个试卷的总分 //计算分数 calculateScore(){ let examScore = 0 let examScore2 = 0 this.paperCompanyData.forEach(item => { //计算每个单位基本信息部分总分 item.score = item.basicInfoScore + item.adjoinScore + item.importLocationScore + item.functionalDivisionScore + item.facilityScore //计算整个试卷基本信息总分 examScore += item.score //计算整个试卷预案试题总分 let x = 0 if(item.planList){ item.planList.forEach(i => { x += i.score }) } item.planScore = x examScore2 += x }) //计算总分 this.examScore = examScore + examScore2 } //交卷 uploadPaper () { // let body = { // id: this.route.snapshot.queryParams.examId, // // name: null, // // serverTime: null, // // startTime: null, // // endTime: null, // // deadline: null, // // isMarked: null, // // totalScore: null, // // examineeId: null, // // examineeName: null, // // paperId: null, // // paperEndTime: null, // examinationDataInfo: [] // } // let uploadPaper = JSON.parse( JSON.stringify(this.paperCompanyData) ) // uploadPaper.forEach(element => { // delete element.score // delete element.planScore // delete element.planList // delete element.id // delete element.paperId // element.examinationId = this.route.snapshot.queryParams.examId // element.adjoinData = JSON.stringify( element.adjoinData || [] ) // element.basicInfoData = JSON.stringify( element.basicInfoData || [] ) // element.facilityData = JSON.stringify( element.facilityData || [] ) // element.functionalDivisionData = JSON.stringify( element.functionalDivisionData || [] ) // element.importLocationData = JSON.stringify( element.importLocationData || [] ) // }); // console.log(body) // body.examinationDataInfo = uploadPaper // this.http.put(`/api/Examinations/UpdateExaminationData/${this.route.snapshot.queryParams.examId}`,body).subscribe(data=>{ // console.log(data) // }) const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.snackBar.open('试卷提交成功! 本页面即将关闭','确定',config); // window.setTimeout(()=>{ // window.close() // },10000) } //进入作战部署 考卷 enterExam(item){ sessionStorage.setItem('companyName',this.selectPaper.companyInfo.name) sessionStorage.setItem('planId',item.planComponentId) sessionStorage.setItem('buildingTypeId',this.selectPaper.companyInfo.buildingTypes[0].id) sessionStorage.setItem('companyId',this.selectPaper.companyInfo.id) let openType item.examPlanType == 0 ? openType = 1 : openType = 2 window.open(`/canvasToolExaminee?planName=${item.title}&paperplanId=${item.id}&openType=${openType}&paperId=${this.paperId}&examId=${this.route.snapshot.queryParams.examId}&planComponentId=${item.planComponentId}`) } }