Commit c0cfab8a by Chao Sun

吸烟

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