Newer
Older
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
121
122
123
124
125
126
127
128
129
130
131
import {Component, ViewChild} from '@angular/core';
import {IonicPage, Navbar, NavController, NavParams} from 'ionic-angular';
import {AppService} from "../../../../service/http.service";
@IonicPage()
@Component({
selector: 'page-survey-write',
templateUrl: 'survey-write.html',
})
export class SurveyWritePage {
@ViewChild(Navbar) navbar:Navbar;
isans;
isansName;
item;
temp;
ansArr = [];
constructor(public navCtrl: NavController, public navParams: NavParams,
public appService: AppService) {
}
ionViewDidLoad() {
this.navbar.backButtonClick= ()=>{
this.appService.alert("是否退出当前问卷调查?"),()=>{
this.navCtrl.pop()
}
}
this.item = this.navParams.get('item');
this.getDetail();
}
getDetail() {
const id = '';
this.appService.ObserverHttpGetAdd('/wisdomgroup/modules/question/edit/', this.item.id)
.subscribe((res) => {
this.temp = res.json().data.ques.datalist;
this.isansName = res.json().data.isansName;
if(res.json().isans == 1){
this.isans = true
}else{
this.isans = false;
}
for (let i = 0; i < this.temp.length; i++) {
const data = {
'questionId': this.temp[i].questionId,
'questionQueId': this.temp[i].id,
'answerdesc': '',
'quesType': this.temp[i].quesType,
'title': this.temp[i].title,
'quesDesc': JSON.parse(this.temp[i].quesDesc),
'isAns': this.temp[i].isAns
};
this.ansArr.push(data);
}
})
}
//多选
mutiSelect(i, index) {
if (this.ansArr[i].answerdesc.indexOf(index) != -1) {
this.ansArr[i].answerdesc = this.ansArr[i].answerdesc.replace(',' + index, '');
} else {
this.ansArr[i].answerdesc += "," + index;
}
}
confirm(){
this.appService.alert('确定提交问卷?',res=>{
this.submit();
});
}
submit() {
if (!this.check()) {
return false;
}
let arrData = [];
if(this.isans){
this.isans = 1;
}else{
this.isans = 2;
}
for (let i = 0; i < this.ansArr.length; i++) {
if (this.ansArr[i].quesType == 3) {
let length = this.ansArr[i].answerdesc.length;
this.ansArr[i].answerdesc = this.ansArr[i].answerdesc.substr(1, length - 1);
}
const data = {
'questionId': this.ansArr[i].questionId,
'questionQueId': this.ansArr[i].questionQueId,
'answerdesc': this.ansArr[i].answerdesc,
'isans': this.isans
};
arrData.push(data);
}
const qData = {
'array': JSON.stringify(arrData)
};
this.appService.ObserverHttpPost('/wisdomgroup/modules/question/create/quesuser', qData)
.subscribe((res) => {
this.navCtrl.pop();
})
}
check() {
let count = 0;
for (let i = 0; i < this.ansArr.length; i++) {
if (this.ansArr[i].isAns == 1) {
if (this.ansArr[i].answerdesc == "") {
this.appService.popToastView('有必答题未答', 'middle', 1500);
count++;
break;
}
}
}
if (count > 0) {
return false;
}
return true;
}
}