Commit 64b108a4 by Sweet Zhang

增加孩子

parent fc6ff67b
......@@ -10,7 +10,7 @@
display: flex;
justify-content: space-between;
}
.ageContent li span b {
margin-left: 10px;
}
......@@ -42,4 +42,6 @@
line-height: 38px;
margin: 3% 10% 0 10%;
}
\ No newline at end of file
.disabled{
opacity: 0.5;
}
......@@ -5,15 +5,14 @@
<li *ngFor="let optionsList of this.curPageData?.questions; index as i">
<div>{{ optionsList.questionName }}</div>
<b (click)="showToast(optionsList, i)" style="width:35%;text-align: center;float: right">
<span style="width:20%;text-align: center;">{{ optionsList.name }}</span
>
<span style="width:20%;text-align: center;">{{ optionsList.optionName}}</span>
<span style="width:10%;text-align: center;float: right">&gt;</span>
</b>
</li>
</ul>
</div>
<div class="addChild"
(click)="addChild()">
<div class="addChild" (click)="addChild()" *ngIf="!(type==1||type==2)"
[ngClass]="{'disabled':totalChildLimitCount<=0}">
<div class="icon">+</div>
<div data-toggle="modal">增加孩子年龄</div>
</div>
......@@ -28,10 +27,11 @@
<div class="toastContent" *ngIf="isShow">
<ul>
<li
[ngClass]="{ selected: this.curQuestionSelecte === options.optionName}"
*ngFor="let options of curQues.options"
(click)="selectedAge(curQues,options);">
[ngClass]="{ selected: options['selected']}"
(click)="selectedAge(options);">
{{ options.optionName }}
</li>
</ul>
<!--<div>{{curQues|json}}</div>-->
</div>
......@@ -16,6 +16,10 @@ export class AgeComponent implements OnInit {
curQuesIndex: number;
curQuestionSelecte: string;
pageAnswers: any;
// 可添加的孩子总个数
totalChildLimitCount: number;
questionSubId: number;
question: any;
constructor(private commonService: CommonService, private router: Router, private route: ActivatedRoute) {
/**
......@@ -26,7 +30,8 @@ export class AgeComponent implements OnInit {
* @type {any}
*/
this.type = this.route.snapshot.queryParams['type'];
console.log(this.type);
this.totalChildLimitCount = 2;
this.questionSubId = 0;
this.pageAnswers = {
pageId: '',
questions: [],
......@@ -37,25 +42,51 @@ export class AgeComponent implements OnInit {
this.commonService.surveyInfo().then(res => {
this.curPageData = res['data']['survey']['pages'].filter(item => item.pageId === 3).pop();
this.pageAnswers.pageId = this.curPageData['pageId'];
if (this.type == 1) {
this.handleData([3, 4]);
} else if (this.type == 2) {
this.handleData([4]);
} else if (this.type == 3) {
this.handleData([3]);
} else {
this.handleData([]);
}
console.log(this.curPageData)
});
}
// 选择年龄
selectedAge(curQues, options) {
selectedAge(options) {
// debugger;
// console.log(this.curQues);
// console.log(options);
const question = {
questionId: curQues.questionId,
questionName: curQues.questionName,
questionId: this.curQues.questionId,
questionSubId: this.curQues.questionSubId,
questionName: this.curQues.questionName,
options: [options]
};
for (let j = 0; j < this.curPageData['questions'].length; j++) {
if (this.curPageData['questions'][j].questionId == this.curQues.questionId) {
// 如果有孩子,需要考虑是孩子几的年龄
if (this.curPageData['questions'][j]['questionSubId'] == this.curQues.questionSubId) {
this.curPageData['questions'][j].optionName = options.optionName;
}
}
}
// 答案去重
for (let i = 0; i < this.pageAnswers.questions.length; i++) {
if (this.pageAnswers.questions[i].questionId == curQues.questionId) {
const index = this.pageAnswers.questions.indexOf(this.pageAnswers.questions[i]);
this.pageAnswers.questions.splice(index, 1);
if (this.pageAnswers.questions[i].questionId == this.curQues.questionId) {
if (this.pageAnswers.questions[i]['questionSubId'] == this.curQues.questionSubId) {
const index = this.pageAnswers.questions.indexOf(this.pageAnswers.questions[i]);
this.pageAnswers.questions.splice(index, 1);
}
}
}
this.pageAnswers.questions.push(question);
// console.log(this.pageAnswers);
// console.log(this.curPageData);
this.commonService.addAnswer(this.pageAnswers);
console.log(this.commonService.todos)
this.closeToast();
}
......@@ -63,16 +94,40 @@ export class AgeComponent implements OnInit {
this.isShow = true;
this.curQues = question;
this.curQuesIndex = idx;
this.curQuestionSelecte = question.name;
}
closeToast() {
this.isShow = false;
}
// 增加孩子
addChild() {
this.totalChildLimitCount--;
if (this.totalChildLimitCount < 0) {
return;
}
// 增加问题,添加questionSubId区分孩子
this.question = Object.assign({}, this.curPageData['questions'].filter(item => item.questionId == 4).pop());
this.question.questionSubId = ++this.questionSubId;
this.question.optionName = null;
this.question.questionName = '孩子' + this.questionSubId + '年龄';
this.curPageData['questions'].push(this.question);
}
// 根据家庭结构处理展示数据
handleData(questionId) {
for (let m = 0; m < this.curPageData['questions'].length; m++) {
for (let n = 0; n < questionId.length; n++) {
if (this.curPageData['questions'][m].questionId == questionId[n]) {
const index = this.curPageData['questions'].indexOf(this.curPageData['questions'][m]);
this.curPageData['questions'].splice(index, 1);
}
}
}
}
// 下一步
next() {
this.router.navigate(['/job']);
this.router.navigate(['/job'], {queryParams: {type: this.type}});
}
}
......@@ -25,7 +25,7 @@ export class FamilyComponent implements OnInit {
ngOnInit() {
this.commonService.surveyInfo().then(res => {
this.curPageData = res['data']['survey']['pages'].filter(item => item.pageId === 2).pop();
console.log(this.curPageData)
// console.log(this.curPageData)
});
}
......@@ -42,6 +42,7 @@ export class FamilyComponent implements OnInit {
}],
};
this.commonService.addAnswer(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