import { Component, OnInit } from '@angular/core';
import { Storage } from '@ionic/storage';
import { Router } from '@angular/router';
import { InterceptorService } from 'src/app/shared/providers/interceptor.service';
import { url } from 'inspector';
@Component({
selector: 'app-release-question',
templateUrl: './release-question.page.html',
styleUrls: ['./release-question.page.scss'],
})
export class ReleaseQuestionPage implements OnInit {
/*---------------------------------变量声明区------------------------------------- */
// 班级信息
classLabel = [];
// 模板ID
templateId = '';
// 上课班ID集合
classIdList = [];
// 复选框是否选中
checkList = [];
// 未选中的复选框个数
checkOutSum = 0;
// 考试名称
examineeName = '';
/*---------------------------------变量声明区------------------------------------- */
constructor(
public router: Router,
public http: InterceptorService,
public storage: Storage
) { }
/*---------------------------------方法区------------------------------------- */
ngOnInit() {
this.queryClass();
}
/**
* 查询班级信息
* @author 郭满亮
* @since 2019年1月30日19:59:48
*/
queryClass() {
this.templateId = localStorage.getItem('templateId');
this.storage.get('userId').then((val) => {
const classUrl = 'exam-web/teacherTeachClass/findByTeacherId/' + val + '/' + this.templateId;
this.http.get(classUrl).subscribe(
res => {
if (res.json().code === '0000') {
this.classLabel = res.json().data;
}
});
});
}
/**
* 获取班级ID
* @author 郭满亮
* @since 2019年1月30日20:00:13
*/
getClass(classId: string, index: number) {
if (this.checkList[index] === true) {
this.classIdList[index] = classId;
} else {
this.classIdList[index] = '';
}
}
/**
* 发布小练
* @author 郭满亮
* @since 2019年1月30日20:33:19
*/
okRelease() {
for (let j = 0 ; j < this.checkList.length ; j++) {
if (this.checkList[j] === false) {
this.checkOutSum += 1;
}
}
// 考试名称 上课班id 模板id
for (let i = 0; i < this.classIdList.length; i++) {
if (this.classIdList[i] !== '' && this.classIdList[i] !== null && this.classIdList[i] !== undefined) {
const releaseUrl = 'exam-web/studentTeachClass/savePractice/'
+ this.examineeName + '/' + this.classIdList[i] + '/' + localStorage.getItem('templateId');
this.http.post(releaseUrl).subscribe(
res => {
if (res.json().code === '0000') {
alert('发布小练成功');
this.router.navigateByUrl('tabs/home/teacher-main/released-practice');
}
});
}
}
// 若所有班级都发布,则修改模版状态
if (this.checkOutSum === 0) {
const urlState = '';
this.http.post(urlState).subscribe();
}
}
/*---------------------------------方法区------------------------------------- */
}
发布小练
最新推荐文章于 2022-01-20 18:20:14 发布