Commit 64b108a4 by Sweet Zhang

增加孩子

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