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 = $('
') 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 = '
' + '
' + '
' + '
'; 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 = ''; var labelName = '
'+ column.dispName +':
'; 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; });