You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.5 KiB

define(function(require, exports, module) {
require('./querypanel.css');
var EditorHandler = require('../../editors/handler');
var self = null;
function QueryPanel(args) {
self = this;
this.args = args;
this.editors = {};
this.container = $('<div class="querypanel-container"></div>')
args.container.append(this.container)
this.columns = args.columns;
this.init();
}
QueryPanel.prototype.init = function() {
makeEditors(this.editors, this.columns, this.container);
$.parser.parse(this.container[0]);
};
function makeEditors(editors, columns, container) {
for (var i = 0; i < columns.length; i++) {
var editor = createEditor(columns[i], editors, container);
}
}
function createEditor(column, editors, container) {
var editorWrapper = createEditorWrapper(column);
var label = createEditorLabel(column);
editorWrapper.children('.editor-label').append(label);
container.append(editorWrapper);
//待处理 start
var args = EditorHandler.getEditorArgs(editorWrapper.children('.editor-input'), column);
args.isEdit = false;
var editor = null;
if ( column.dispStyle === '06') {
editor = EditorHandler.getEditorInstance('14', args);
} else {
editor = EditorHandler.getEditorInstance(column.dispStyle, args);
}
// setColumnDefaultValue(column);
editor.loadValue(column);
//待处理 end
var column_key = column.fieldName;
editors[column_key] = editor;
}
function createEditorWrapper(column) {
var editorWrapper = '<div class="editorWrapper">' +
'<div class="editor-label"></div>' +
'<div class="editor-input"></div>' +
'</div>';
var $editorWrapper = $(editorWrapper);
var editorInput = $editorWrapper.children('.editor-input');
var editorLabel = $editorWrapper.children('.editor-label');
editorLabel.css({
// 'text-align': 'right'
});
//复选框特殊样式处理
if (column.dispStyle === '03') {
editorLabel.css('float', 'right');
editorInput.css('text-align', 'right');
}
if (column.dispStyle === '04' || column.dispStyle === '05' || column.dispStyle === '06') {
editorInput.css({
'display': 'flex',
'flex-direction': 'row',
'justify-content': 'center'
})
} else {
// editorInput.width(parseInt(column.dispWidth) || 100);
}
if ( self.args.opts.selfWidth ) {
var labelContent = column.dispName;
var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
var ratio = 14;
//检查是否含有中文
if (!reg.test(labelContent)) {
ratio = 7;
}
// editorLabel.width(ratio * (parseInt(labelContent.length) + 1));
editorLabel.width(90);
if (column.dateRange) {
// editorInput.width(450);
} else {
editorInput.width(parseInt(column.dispWidth));
}
} else {
editorLabel.width(column.labelWidth);
if (column.dateRange) {
// editorInput.width(450);
} else {
editorInput.width(parseInt(column.dispWidth));
}
}
return $editorWrapper;
}
function createEditorLabel(column) {
var label = '<label for="' + column.fieldName + '"></label>';
var labelName = '<div>'+ column.dispName +':</div>';
var $label = $(label);
var $labelName = $(labelName);
var labelContent = column.dispName;
var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
var ratio = 14;
//检查是否含有中文
if (!reg.test(labelContent)) {
ratio = 7;
}
// $labelName.width(ratio * (parseInt(labelContent.length) + 1));
// $labelName.width(column.labelWidth);
if (column.isRequired) {
$labelName.css('font-weight', 'bold');
} else {
$labelName.css('font-weight', 'normal');
}
//复选框特殊样式处理
if (column.dispStyle === '03') {
$labelName.css('text-align', 'left');
}
$label.append($labelName);
return $label;
}
QueryPanel.prototype.getQueryParams = function() {
var values = {};
for (key in this.editors) {
var editor = this.editors[key];
var value = editor.getValue();
if (value) {
values[key] = value;
}
}
return values;
};
QueryPanel.prototype.getAllQueryParams = function() {
var values = {};
for (key in this.editors) {
var editor = this.editors[key];
var value = editor.getValue();
values[key] = value;
}
return values;
};
QueryPanel.prototype.checkRequiredEditors = function() {
for (key in this.editors) {
var editor = this.editors[key];
if (editor.checkNotPass) {
// ER.messager.err(editor.args.column.dispName + '严格参照');
return false;
}
var value = editor.getValue();
if (!value && editor.args.column.isRequired) {
ER.messager.err(editor.args.column.dispName + '必填!');
return false;
}
}
return true;
};
return QueryPanel;
});