Commit 82121ffd by Chao Sun

多选初始化

parents e91e49df adc478ef
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core' import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core'
@Component({ @Component({
selector: 'app-page3', selector: 'app-page3',
...@@ -20,16 +20,23 @@ export class Page3Component implements OnInit { ...@@ -20,16 +20,23 @@ export class Page3Component implements OnInit {
curQuesLen: number curQuesLen: number
//增加孩子点击次数 //增加孩子点击次数
addChildCount: number addChildCount: number
curQuestionSelecte:string; curQuestionSelecte: string;
constructor() {} questions: Array<any>;
constructor() {
this.questions = [];
}
ngOnInit() { ngOnInit() {
this.curQues = {} this.curQues = {}
this.curAllQues = {} this.curAllQues = {}
this.curQuesLen = this.curPageData['questions'].length this.curQuesLen = this.curPageData['questions'].length
//初始化增加孩子按钮可以点2次 //初始化增加孩子按钮可以点2次
this.addChildCount = 2 this.addChildCount = 2;
// console.log(this.curPageData)
this.selectedOptions();
} }
showToast(question, idx) { showToast(question, idx) {
this.isShow = true this.isShow = true
this.curQues = question this.curQues = question
...@@ -38,28 +45,107 @@ export class Page3Component implements OnInit { ...@@ -38,28 +45,107 @@ export class Page3Component implements OnInit {
this.curQuestionSelecte = question.name this.curQuestionSelecte = question.name
} }
closeToast() { closeToast() {
this.isShow = false this.isShow = false
} }
getAnswer(option) {
const questionId = this.curQues['questionId'] // getAnswer(option) {
this.curAllQues[questionId] = option // const questionId = this.curQues['questionId']
console.log(this.curAllQues) // this.curAllQues[questionId] = option
const questions = Object.keys(this.curAllQues).map(questionId => { // const questions = Object.keys(this.curAllQues).map(questionId => {
return { questionId, options: [this.curAllQues[questionId]] } // return {questionId, options: [this.curAllQues[questionId]]}
}) // })
// const ret = {
const ret = { // pageId: 3,
pageId: 3, // questions
questions // }
} // console.log(ret);
this.getAllAnswer.emit(ret) // this.getAllAnswer.emit(ret)
} // }
changeStyle(options, optionId) { changeStyle(options, optionId) {
//当前选中项 //当前选中项
this.curPageData['questions'][this.curQuesIndex]['name'] = this.curPageData['questions'][this.curQuesIndex]['name'] =
options.optionName options.optionName
this.curPageData['questions'][this.curQuesIndex]['optionId'] =
options.optionId
}
// 保存用户选择的信息
selectedOptions() {
if (this.curPageData['questions'].length > 0) {
for (let i = 0; i < this.curPageData['questions'].length; i++) {
if (!this.curPageData['questions'][i]['name']) {
return;
}
let option = {};
let question = {
questionId: '',
options: []
};
question.questionId = this.curPageData['questions'][i].questionId;
option = {
customerInput: null,
optionId: this.curPageData['questions'][i]['optionId'],
optionName: this.curPageData['questions'][i]['name'],
optionOrder: 2,
selected: true
};
question.options.push(option);
this.questions.push(question);
}
}
const ret = {
pageId: 3,
questions: this.questions
}
console.log(ret);
this.getAllAnswer.emit(ret);
}
getAnswer(questionId, option) {
debugger;
if (this.curPageData['questions'].length > 0) {
for (let i = 0; i < this.curPageData['questions'].length; i++) {
let oldOption = {};
let question = {
questionId: '',
options: []
};
question.questionId = this.curPageData['questions'][i].questionId;
oldOption = {
customerInput: null,
optionId: this.curPageData['questions'][i]['optionId'],
optionName: this.curPageData['questions'][i]['name'],
optionOrder: 2,
selected: true
};
if (this.curPageData['questions'][i]['optionId']) {
question.options.push(oldOption);
this.questions.push(question);
}
for (let j = 0; j < this.questions.length; j++) {
if (this.questions[j].questionId == questionId) {
this.questions[j].options[0] = option;
} else {
const questions = {
questionId: '',
options: [option]
};
this.questions.push(questions);
}
}
}
}
const ret = {
pageId: 3,
questions: this.questions
}
console.log(ret);
this.getAllAnswer.emit(ret);
} }
......
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