Commit daeaf70b by Sweet Zhang

保存上一页的数据

parent 5a811422
......@@ -14,12 +14,13 @@ export class AgeComponent implements OnInit {
isShow: boolean;
curQues: any;
curQuesIndex: number;
curQuestionSelecte: string;
pageAnswers: any;
// 可添加的孩子总个数
totalChildLimitCount: number;
questionSubId: number;
question: any;
// 上一次的答案
lastQuestions: Array<any>;
constructor(private commonService: CommonService, private router: Router, private route: ActivatedRoute) {
/**
......@@ -39,6 +40,7 @@ export class AgeComponent implements OnInit {
}
ngOnInit() {
this.lastQuestions = this.commonService.todosCopy.filter(item => item.pageId == 3).pop();
this.commonService.surveyInfo().then(res => {
this.curPageData = res['data']['survey']['pages'].filter(item => item.pageId === 3).pop();
this.pageAnswers.pageId = this.curPageData['pageId'];
......
......@@ -22,7 +22,9 @@ export class CommonService {
'X-Authorization': ''
})
};
if (sessionStorage.getItem('todos')) {
this.todos = JSON.parse(sessionStorage.getItem('todos'));
}
}
/**
......@@ -125,8 +127,13 @@ export class CommonService {
}
}
this.todos.push(todo);
sessionStorage.setItem('todos', JSON.stringify(this.todos));
this.todosSource.next(this.todos);
return this;
}
get todosCopy() {
return this.todos;
}
}
......@@ -10,6 +10,8 @@ export class FamilyComponent implements OnInit {
curPageData: Array<any>;
pageAnswers: any;
selectedOptionId: any;
// 上一次的答案
lastQuestions: Array<any>;
constructor(private commonService: CommonService, private router: Router) {
this.pageAnswers = {
......@@ -23,8 +25,22 @@ export class FamilyComponent implements OnInit {
}
ngOnInit() {
this.lastQuestions = this.commonService.todosCopy.filter(item => item.pageId == 2).pop();
this.commonService.surveyInfo().then(res => {
this.curPageData = res['data']['survey']['pages'].filter(item => item.pageId === 2).pop();
for (let i = 0; i < this.lastQuestions['questions'].length; i++) {
for (let j = 0; j < this.curPageData['questions'].length; j++) {
if (this.lastQuestions['questions'][i].questionId == this.curPageData['questions'][j].questionId) {
for (let m = 0; m < this.lastQuestions['questions'][i].options.length; m++) {
for (let n = 0; n < this.curPageData['questions'][i].options.length; n++) {
if (this.lastQuestions['questions'][i].options[m].optionId == this.curPageData['questions'][i].options[n].optionId) {
this.selectedFamily(this.curPageData['questions'][i].options[n]);
}
}
}
}
}
}
// console.log(this.curPageData)
});
}
......@@ -32,7 +48,7 @@ export class FamilyComponent implements OnInit {
// 选择家庭结构
selectedFamily(option) {
this.selectedOptionId = option.optionId;
const options = this.curPageData['questions'][0]['options']
const options = this.curPageData['questions'][0]['options'];
for (let i = 0; i < options.length; i++) {
if (option['optionId'] == options[i]['optionId']) {
options[i]['selected'] = true;
......@@ -49,7 +65,7 @@ export class FamilyComponent implements OnInit {
}],
};
this.commonService.addAnswer(this.pageAnswers);
console.log(this.pageAnswers)
// console.log(this.pageAnswers)
}
// 下一步
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment