Newer
Older
import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {AppService} from "../../../../service/appHttpService";
constructor(public navCtrl: NavController, public navParams: NavParams,
public appService: AppService) {
}
ionViewDidLoad() {
this.item = this.navParams.get('item');
this.getDetail();
}
this.appService.ObserverHttpGetAdd('/wisdomgroup/modules/question/edit/', this.item.id)
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);
}
console.log(this.ansArr);
})
}
//多选
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 = [];
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,
};
arrData.push(data);
}
const qData = {
'array': JSON.stringify(arrData)
this.appService.ObserverHttpPost('/wisdomgroup/modules/question/create/quesuser', qData)
.subscribe((res) => {
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;
}