Newer
Older
import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams, ToastController} from 'ionic-angular';
import {AppService} from "../../../service/http.service";
import {message} from "../../../app/main";
import {TabsService} from "../../tabs/tabs.service";
import {CommonService} from "../../../provide/common.service";
qType; //题目类型
temp; //问卷信息
title; //标题
index = 1; //序号
quesDescList = [];
constructor(public navCtrl: NavController, public navParams: NavParams, private tabSer: TabsService,
public appService: AppService, public toastCtrl: ToastController, private commonSer: CommonService) {
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
}
ionViewDidLoad() {
this.qType = this.navParams.get('type'); //问卷信息
}
addOption() {
const option = {
comment: '', //选项文字
option: this.index
}; //序号
this.index++;
this.quesDescList.push(option);
}
removeOption(i) {
if (this.quesDescList.length > 1) {
this.quesDescList.splice(i, 1);
} else {
this.appService.popToastView('至少一个选项', 'middle', 1500);
}
}
//多选
mutiSelect(i, option) {
let op = String.fromCharCode(64 + ~~option);
if (this.correntAnswer.indexOf(op) != -1) {
this.correntAnswer = this.correntAnswer.replace(op + ';', '');
} else {
this.correntAnswer += op + ';';
}
}
//提交问卷
submit() {
if (!this.check()) {
return false;
}
if (this.qType == 1) {
const option1 = {
comment: '是',
option: '1'
}; //序号
const option2 = {
comment: '否',
option: '2'
}; //序号
this.quesDescList.push(option1);
this.quesDescList.push(option2);
}
let current;
if (this.qType == '3') {
current = this.correntAnswer;
} else {
current = String.fromCharCode(64 + ~~this.correntAnswer);
}
let arr = [];
this.quesDescList.forEach(e => {
const obj = {
comment: e.comment,
option: String.fromCharCode(64 + ~~e.option)
};
arr.push(obj);
});
const data = {
stem: this.title,
type: this.qType,
correntAnswer: current,
options: arr
};
let index = this.navCtrl.length() - 1;
this.navCtrl.remove(1, index);
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
}
}
)
}
//校验
check() {
if (!this.title) {
this.appService.popToastView('请输入标题', 'middle', 1000);
return false;
}
if (this.qType == 2 || this.qType == 3) {
if (this.quesDescList.length == 0) {
this.appService.popToastView('请输入选项', 'middle', 1000);
return false;
} else {
let index = 0;
this.quesDescList.forEach((res) => {
if (res.comment.length == 0) {
index++;
}
});
if (index > 0) {
this.appService.popToastView('请输入选项', 'middle', 1000);
return false;
}
}
}
return true;
}