import $ from 'jquery'
import components from './box/yzComponents';
let yzQuestion = function (cfg) {
// content里面是box组件
this.content = cfg.content || null;
this.border = parseInt(cfg.border) || 1;
this.minHeight = cfg.minHeight;
this.pNum = cfg.pNum;
this.pageNo = cfg.pageNo;
this.problemId = cfg.problemId;
this.questionId = cfg.questionId;
this.rectNo = cfg.rectNo;
this.score = cfg.score;
this.sort = cfg.sort;
this.title = cfg.title || '';
this.inDetail = cfg.inDetail;
this.isSubject = cfg.isSubject;
this.blockindex = parseInt(cfg.blockindex);
this.blocknum = parseInt(cfg.blocknum);
// 这个是组件的dom
this.contentDom = [];
this.order = parseInt(cfg.order);
this.domId = ('lsiten_question_'+Math.random()).replace('.','_');
// dom相关属性
this.vdom = null;
};
yzQuestion.prototype._mapKey = [
'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z'
];
/**
* function 生成客观题的dom
*/
yzQuestion.prototype._renderObjectiveDom = function () {
let ul = $('
');
let optionnum = parseInt(this.inDetail.split('-')[2]);
for (let i=0; i'+ this._mapKey[i] +'');
}
this.vdom.append(ul);
};
/**
* function 生成主观题的dom
* @TODO 生成content
*/
yzQuestion.prototype._renderCommonDom = function () {
let content = $('');
content.css({height: (this.minHeight - 20) + 'px'});
if (this.content) {
this.content.renderDom();
} else {
this.content = new components({
content: content
});
}
this.vdom.append(content);
// 冒泡监听事件
this.vdom.on('click', ()=>{
// 将题目和domId冒泡到顶层
this.vdom.trigger('getQuestion',[this.pNum,this.content]);
});
};
/**
* function 生成title的dom
* @TODO title可编辑
*/
yzQuestion.prototype._renderTitleDom = function () {
let title = $('');
if (!this.isSubject) {
title.html(this.pNum+this.title);
} else
{
title.addClass('next-line');
let sort = $('' + this.pNum + '
');
let subtitle = $('' + this.title + '
');
let score = $('(' + this.score + '分)
');
title.append(sort);
title.append(subtitle);
title.append(score);
}
title.css({
height: '20px',
'line-height': '20px'
});
this.vdom.append(title);
};
/**
* function 将数据转换为dom的形式
*/
yzQuestion.prototype.renderToDom = function () {
this.vdom = $('');
this.vdom.css({
minHeight: this.minHeight
})
this._renderTitleDom();
// 如果是客观题
if (!this.isSubject) {
let width = 100/this.allblock + '%';
this.vdom.css({
width: width
});
this._renderObjectiveDom();
} else {
this._renderCommonDom();
}
};
export default yzQuestion;