qa.ts
3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { DataService } from '../../providers/data-service';
import { Qa } from '../../providers/define-qa';
import { Content } from 'ionic-angular';
import { ViewChild } from '@angular/core';
import { Observable } from 'rxjs/Rx';
/*
Generated class for the Qa page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-qa',
templateUrl: 'qa.html'
})
export class QaPage {
@ViewChild(Content) content: Content;
qaList: Qa[];
qa1: Qa;
menuId: number;
unitId: number;
index: number;
title:string;
buttonDisabled: boolean;
ds: DataService;
nv: NavController;
selected: number;
result: string;
resultcolor: string;
selectstate: Array<boolean> = new Array();
subscription;
screenHeight:number;
constructor(public navCtrl: NavController, public navParams: NavParams, private dataSevice: DataService) {
this.menuId = navParams.get("menuId");
this.unitId = navParams.get("unitId");
this.title = navParams.get("title");
this.index = 0;
this.qaList = dataSevice.getQa(this.menuId, this.unitId);
this.qa1 = this.qaList[this.index];
this.buttonDisabled = null;
this.ds = dataSevice;
this.nv = navCtrl;
this.selected = -1;
for (var i = 0; i < this.qa1.choicesId.length; i++) {
this.selectstate.push(false);
}
}
ionViewDidLoad() {
console.log('ionViewDidLoad QaPage');
}
itemSelected(id: number) {
for (var i = 0; i < this.qa1.choicesId.length; i++) {
if(this.selectstate[i] == true) {
this.selectstate[i] = false;
}
}
this.selectstate[id] = true;
this.selected = id;
}
openAnswer() {
if (this.buttonDisabled == null)
{
this.result = "解答";
this.resultcolor = "dark";
if (this.selected === this.qa1.answerId) { //正解
this.result = "正解";
this.resultcolor = "danger";
}
else {
this.result = "不正解";
this.resultcolor = "primary";
}
this.buttonDisabled = true;
if (this.index >= (this.qaList.length - 1))
{
var key: string;
key = this.qa1.menuId + ":" + this.qa1.unitId;
this.dataSevice.saveInfo(key);
}
var element = document.getElementsByClassName('question-card');
this.screenHeight = element[0].clientHeight;
this.subscription = Observable.timer(300)
.subscribe(x => {
this.content.scrollTo(0, this.screenHeight, 300);
}
);
}
}
goToNext() {
this.index++;
this.buttonDisabled = null;
this.selected = -1;
this.qa1 = this.qaList[this.index];
this.selectstate = new Array();
for (var i = 0; i < this.qa1.choicesId.length; i++) {
this.selectstate.push(false);
}
this.content.scrollToTop(300);
}
backToUnit() {
this.nv.pop();
}
}