Authored by yyq

支持多项关联问题

... ... @@ -14,6 +14,24 @@ const _fillQuestionContents = data => {
return data;
};
const _handelSubQuestion = (qs, jid) => {
if (qs) {
qs = _.concat([], qs);
_.forEach(qs, value => {
Object.assign(value, {
subQs: true,
jid: jid
});
_fillQuestionContents(value);
});
}
return qs;
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ... @@ -62,15 +80,17 @@ module.exports = class extends global.yoho.BaseModel {
let data = _.get(result, '[1].data', {});
if (data.questions) {
_.forEach(data.questions, value => {
_.forEach(data.questions, (value, key) => {
if (!_.isEmpty(value.questionContents)) {
_.forEach(value.questionContents, subval => {
_fillQuestionContents(subval.jumpQuestion);
if (subval.jumpQuestion) {
value.hasSub = true;
_.set(subval, 'jumpQuestion.subQs', true);
_.forEach(value.questionContents, (subval, subkey) => {
if (!subval.jumpQuestion) {
return;
}
value.hasSub = true;
subval.jid = `${key}-${subkey}`;
subval.jumpQuestion = _handelSubQuestion(subval.jumpQuestion,
subval.jid);
});
}
... ...
<dl class="{{#if subQs}}sub-qs-item sub-qs{{questionIndex}} hide{{^}}qs-item{{/if}}" data-index="{{questionIndex}}" data-type="{{questionType}}">
<dl class="{{#if subQs}}sub-qs-item sub-{{jid}} hide{{^}}qs-item{{/if}}" data-index="{{questionIndex}}" data-type="{{questionType}}">
<dt>{{questionTitle}}</dt>
{{#isEqualOr questionType 1}}
{{# questionContents}}
<dd class="radio-option" data-index="{{@index}}"{{# jumpQuestion}} data-jid="{{questionIndex}}"{{/ jumpQuestion}}>
<dd class="radio-option" data-index="{{@index}}"{{#if jid}} data-jid="{{jid}}"{{/if}}>
<span class="iconfont">&#xe6ea;</span>
<div class="option-box">{{{option}}}</div>
{{#if addon}}
... ... @@ -14,7 +14,7 @@
{{#isEqualOr questionType 2}}
{{# questionContents}}
<dd class="check-option" data-index="{{@index}}"{{# jumpQuestion}} data-jid="{{questionIndex}}"{{/ jumpQuestion}}>
<dd class="check-option" data-index="{{@index}}"{{#if jid}} data-jid="{{jid}}"{{/if}}>
<span class="iconfont">&#xe6ea;</span>
<div class="option-box">{{{option}}}</div>
{{#if addon}}
... ...
... ... @@ -96,7 +96,7 @@ let question = {
for (i = 0; i < ids.length; i++) {
if (ids[i]) {
$wrap.find('.sub-qs' + ids[i]).removeClass('hide');
$wrap.find('.sub-' + ids[i]).removeClass('hide');
}
}
$wrap.slideDown();
... ...