Commit c0cfab8a by Chao Sun

吸烟

parent f16774c7
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<li <li
*ngFor="let options of this.options" *ngFor="let options of this.options"
[ngClass]="{ selected: options['selected'] == true }" [ngClass]="{ selected: options['selected'] == true }"
(click)="checkFun(options)" (click)="checkFun(options,false)"
> >
{{ options.optionName }} {{ options.optionName }}
</li> </li>
......
...@@ -14,7 +14,7 @@ export class DiseaseComponent implements OnInit { ...@@ -14,7 +14,7 @@ export class DiseaseComponent implements OnInit {
nextBtn: boolean; nextBtn: boolean;
options: Array<any>; options: Array<any>;
questions: Array<any> = []; questions: Array<any> = [];
lastQuestions: Array<any>;
constructor(private commonService: CommonService, constructor(private commonService: CommonService,
private router: Router, private router: Router,
private route: ActivatedRoute) { private route: ActivatedRoute) {
...@@ -31,44 +31,42 @@ export class DiseaseComponent implements OnInit { ...@@ -31,44 +31,42 @@ export class DiseaseComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.nextBtn = false; this.nextBtn = false;
this.surveyInfo() this.lastQuestions = this.commonService.todosCopy.filter(item => item.pageId == 14).pop();
this.surveyInfo();
} }
surveyInfo() { surveyInfo() {
this.commonService.surveyInfo().then(res => { this.commonService.surveyInfo().then(res => {
if (res['success']) { if (res['success']) {
this.curPageData = res['data']['survey'].pages['13'] this.curPageData = res['data']['survey'].pages['13']
/** //过滤页面数据
* 1:单身贵族 this.filterOptions(this.type)
* 2:二人世界 if(this.lastQuestions){
* 3:独立带娃 for (let i = 0; i < this.lastQuestions['questions'].length; i++) {
* 4:多口之家 for (let j = 0; j < this.curPageData['questions'].length; j++) {
* @type {any} if (this.lastQuestions['questions'][i].questionId == this.curPageData['questions'][j].questionId) {
*/ this.lastQuestions['questions'][i]['options'].forEach(option => {
// 过滤选项 if (Object.keys(option).indexOf('optionId') > -1) {
if (this.type == 1) { const targetObj = option;
this.options = this.curPageData['questions']['0']['options'] this.curPageData['questions'][j]['options'].forEach(option => {
this.options = this.options.filter(option => { if (targetObj['optionId'] == option['optionId']) {
return option.optionId == 106 || option.optionId == 107 this.curPageData['questions'][j]['options'][this.curPageData['questions'][j]['options'].indexOf(option)] = targetObj;
}) // 过滤选项
} this.filterOptions(this.type)
if (this.type == 2) { // console.log(targetObj)
this.options = this.curPageData['questions']['0']['options'] }
this.options = this.options.filter(option => { });
return option.optionId == 108 || option.optionId == 109 || option.optionId == 111 if (this.type == 1) {
}) this.getOneAnswer(targetObj)
} } else {
if (this.type == 3) { console.log(targetObj)
this.options = this.curPageData['questions']['0']['options'] this.getManyAnswer(targetObj,true)
this.options = this.options.filter(option => { }
return option.optionId == 108 || option.optionId == 110 || option.optionId == 111 }
}) });
} }
if (this.type == 4) { }
this.options = this.curPageData['questions']['0']['options'] }
this.options = this.options.filter(option => {
return option.optionId == 108 || option.optionId == 109 || option.optionId == 110 || option.optionId == 111
})
} }
} }
}) })
...@@ -103,8 +101,10 @@ export class DiseaseComponent implements OnInit { ...@@ -103,8 +101,10 @@ export class DiseaseComponent implements OnInit {
} }
} }
getManyAnswer(option) { getManyAnswer(option,lastFlag) {
option['selected'] = !option['selected']; if (lastFlag === false) {
option['selected'] = !option['selected'];
}
this.questions = []; this.questions = [];
for (let i = 0; i < this.curPageData['questions'][0]['options'].length; i++) { for (let i = 0; i < this.curPageData['questions'][0]['options'].length; i++) {
if (option.optionId == 111 && option['selected']) { if (option.optionId == 111 && option['selected']) {
...@@ -148,7 +148,7 @@ export class DiseaseComponent implements OnInit { ...@@ -148,7 +148,7 @@ export class DiseaseComponent implements OnInit {
if (this.type == 1) { if (this.type == 1) {
this.getOneAnswer(option) this.getOneAnswer(option)
} else { } else {
this.getManyAnswer(option) this.getManyAnswer(option,false)
} }
} }
...@@ -160,6 +160,33 @@ export class DiseaseComponent implements OnInit { ...@@ -160,6 +160,33 @@ export class DiseaseComponent implements OnInit {
} }
} }
//过滤页面选项
filterOptions(type){
if (type == 1) {
this.options = this.curPageData['questions']['0']['options']
this.options = this.options.filter(option => {
return option.optionId == 106 || option.optionId == 107
})
}
if (type == 2) {
this.options = this.curPageData['questions']['0']['options']
this.options = this.options.filter(option => {
return option.optionId == 108 || option.optionId == 109 || option.optionId == 111
})
}
if (type == 3) {
this.options = this.curPageData['questions']['0']['options']
this.options = this.options.filter(option => {
return option.optionId == 108 || option.optionId == 110 || option.optionId == 111
})
}
if (type == 4) {
this.options = this.curPageData['questions']['0']['options']
this.options = this.options.filter(option => {
return option.optionId == 108 || option.optionId == 109 || option.optionId == 110 || option.optionId == 111
})
}
}
// 上一步 // 上一步
before() { before() {
this.commonService.before(); this.commonService.before();
......
...@@ -34,6 +34,7 @@ export class FamilyComponent implements OnInit { ...@@ -34,6 +34,7 @@ export class FamilyComponent implements OnInit {
this.commonService.surveyInfo().then(res => { this.commonService.surveyInfo().then(res => {
this.curPageData = res['data']['survey']['pages'].filter(item => item.pageId === 2).pop(); this.curPageData = res['data']['survey']['pages'].filter(item => item.pageId === 2).pop();
if (this.lastQuestions) { if (this.lastQuestions) {
this.lastSelectedOptionId = this.lastQuestions['questions'][0]['options'][0]['optionId']
for (let i = 0; i < this.lastQuestions['questions'].length; i++) { for (let i = 0; i < this.lastQuestions['questions'].length; i++) {
for (let j = 0; j < this.curPageData['questions'].length; j++) { for (let j = 0; j < this.curPageData['questions'].length; j++) {
if (this.lastQuestions['questions'][i].questionId == this.curPageData['questions'][j].questionId) { if (this.lastQuestions['questions'][i].questionId == this.curPageData['questions'][j].questionId) {
...@@ -41,7 +42,6 @@ export class FamilyComponent implements OnInit { ...@@ -41,7 +42,6 @@ export class FamilyComponent implements OnInit {
if (Object.keys(option).indexOf('optionId') > -1) { if (Object.keys(option).indexOf('optionId') > -1) {
this.targetObj = option; this.targetObj = option;
} }
console.log(this.targetObj)
this.selectedFamily(this.targetObj); this.selectedFamily(this.targetObj);
}); });
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<li <li
*ngFor="let options of this.options" *ngFor="let options of this.options"
[ngClass]="{ selected: options['selected'] == true }" [ngClass]="{ selected: options['selected'] == true }"
(click)="checkFun(options)" (click)="checkFun(options,false)"
> >
{{ options.optionName }} {{ options.optionName }}
</li> </li>
......
...@@ -14,6 +14,7 @@ export class SmokingComponent implements OnInit { ...@@ -14,6 +14,7 @@ export class SmokingComponent implements OnInit {
pageAnswers: any; pageAnswers: any;
options: Array<any>; options: Array<any>;
questions: Array<any> = []; questions: Array<any> = [];
lastQuestions: Array<any>;
constructor(private commonService: CommonService, constructor(private commonService: CommonService,
private router: Router, private router: Router,
...@@ -31,6 +32,7 @@ export class SmokingComponent implements OnInit { ...@@ -31,6 +32,7 @@ export class SmokingComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.nextBtn = false; this.nextBtn = false;
this.lastQuestions = this.commonService.todosCopy.filter(item => item.pageId == 15).pop();
this.surveyInfo(); this.surveyInfo();
} }
...@@ -38,37 +40,32 @@ export class SmokingComponent implements OnInit { ...@@ -38,37 +40,32 @@ export class SmokingComponent implements OnInit {
this.commonService.surveyInfo().then(res => { this.commonService.surveyInfo().then(res => {
if (res['success']) { if (res['success']) {
this.curPageData = res['data']['survey'].pages['14']; this.curPageData = res['data']['survey'].pages['14'];
/** this.filterOptions(this.type)
* 1:单身贵族 if(this.lastQuestions){
* 2:二人世界 for (let i = 0; i < this.lastQuestions['questions'].length; i++) {
* 3:独立带娃 for (let j = 0; j < this.curPageData['questions'].length; j++) {
* 4:多口之家 if (this.lastQuestions['questions'][i].questionId == this.curPageData['questions'][j].questionId) {
* @type {any} this.lastQuestions['questions'][i]['options'].forEach(option => {
*/ if (Object.keys(option).indexOf('optionId') > -1) {
//过滤选项 const targetObj = option;
if (this.type == 1) { this.curPageData['questions'][j]['options'].forEach(option => {
this.options = this.curPageData['questions']['0']['options']; if (targetObj['optionId'] == option['optionId']) {
this.options = this.options.filter(option => { this.curPageData['questions'][j]['options'][this.curPageData['questions'][j]['options'].indexOf(option)] = targetObj;
return option.optionId == 112 || option.optionId == 113; // 过滤选项
}) this.filterOptions(this.type)
} // console.log(targetObj)
if (this.type == 2) { }
this.options = this.curPageData['questions']['0']['options']; });
this.options = this.options.filter(option => { if (this.type == 1) {
return option.optionId == 114 || option.optionId == 115 || option.optionId == 117; this.getOneAnswer(targetObj)
}) } else {
} this.getManyAnswer(targetObj,true)
if (this.type == 3) { }
this.options = this.curPageData['questions']['0']['options']; }
this.options = this.options.filter(option => { });
return option.optionId == 114 || option.optionId == 116 || option.optionId == 117; }
}) }
} }
if (this.type == 4) {
this.options = this.curPageData['questions']['0']['options'];
this.options = this.options.filter(option => {
return option.optionId == 114 || option.optionId == 115 || option.optionId == 116 || option.optionId == 117;
})
} }
} }
}) })
...@@ -103,8 +100,10 @@ export class SmokingComponent implements OnInit { ...@@ -103,8 +100,10 @@ export class SmokingComponent implements OnInit {
} }
} }
getManyAnswer(option) { getManyAnswer(option,lastFlag) {
option['selected'] = !option['selected']; if (lastFlag === false) {
option['selected'] = !option['selected'];
}
this.questions = []; this.questions = [];
for (let i = 0; i < this.curPageData['questions'][0]['options'].length; i++) { for (let i = 0; i < this.curPageData['questions'][0]['options'].length; i++) {
if (option.optionId == 117 && option['selected']) { if (option.optionId == 117 && option['selected']) {
...@@ -147,7 +146,7 @@ export class SmokingComponent implements OnInit { ...@@ -147,7 +146,7 @@ export class SmokingComponent implements OnInit {
if (this.type == 1) { if (this.type == 1) {
this.getOneAnswer(option); this.getOneAnswer(option);
} else { } else {
this.getManyAnswer(option); this.getManyAnswer(option,false);
} }
} }
...@@ -158,7 +157,33 @@ export class SmokingComponent implements OnInit { ...@@ -158,7 +157,33 @@ export class SmokingComponent implements OnInit {
return; return;
} }
} }
filterOptions(type){
//过滤选项
if (type == 1) {
this.options = this.curPageData['questions']['0']['options'];
this.options = this.options.filter(option => {
return option.optionId == 112 || option.optionId == 113;
})
}
if (type == 2) {
this.options = this.curPageData['questions']['0']['options'];
this.options = this.options.filter(option => {
return option.optionId == 114 || option.optionId == 115 || option.optionId == 117;
})
}
if (type == 3) {
this.options = this.curPageData['questions']['0']['options'];
this.options = this.options.filter(option => {
return option.optionId == 114 || option.optionId == 116 || option.optionId == 117;
})
}
if (type == 4) {
this.options = this.curPageData['questions']['0']['options'];
this.options = this.options.filter(option => {
return option.optionId == 114 || option.optionId == 115 || option.optionId == 116 || option.optionId == 117;
})
}
}
// 上一步 // 上一步
before() { before() {
this.commonService.before(); this.commonService.before();
......
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