extqa.ts
3.21 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
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 Extqa page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-extqa',
templateUrl: 'extqa.html'
})
export class ExtqaPage {
@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;
selectstate: Array<boolean> = new Array();
subscription;
screenHeight:number;
positiveCnt: 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.getExtqa(this.menuId, this.unitId);
this.qa1 = this.qaList[this.index];
this.buttonDisabled = null;
this.ds = dataSevice;
this.nv = navCtrl;
this.selected = -1;
this.positiveCnt = 0;
for (var i = 0; i < this.qa1.choicesId.length; i++) {
this.selectstate.push(false);
}
}
ionViewDidLoad() {
console.log('ionViewDidLoad ExtqaPage');
}
itemSelected(id: number) {
for (var i = 0; i < this.qa1.choicesId.length; i++) {
this.selectstate[i] = false;
}
this.selectstate[id] = true;
this.selected = id;
this.content.scrollToBottom(300);
}
openAnswer() {
if (this.buttonDisabled == null)
{
this.result = "解答";
if (this.selected === this.qa1.answerId) { //正解
this.result = "正解";
this.positiveCnt++;
}
else {
this.result = "不正解";
}
this.buttonDisabled = true;
if (this.index >= (this.qaList.length - 1))
{
var key: string;
var value: string;
key = this.qa1.menuId + ":" + this.qa1.unitId;
value = this.positiveCnt + ":" + this.qaList.length;
this.dataSevice.saveInfo(key, value);
}
var element = document.getElementsByClassName('question-card');
this.screenHeight = element[0].clientHeight;
this.subscription = Observable.timer(300)
.subscribe(x => {
this.content.scrollToBottom(300);
}
);
}
}
goToNext() {
this.index++;
this.qa1 = this.qaList[this.index];
this.buttonDisabled = null;
this.selected = -1;
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();
}
}