|
|
|
|
/*
|
|
|
|
|
create by yangjinhua
|
|
|
|
|
date:2016-11-07
|
|
|
|
|
* 2017-10-09 zhangzemu ERPT-94 参照参数错误处理
|
|
|
|
|
*/
|
|
|
|
|
define(function(require, exports, module) {
|
|
|
|
|
var Window = require('../window/window');
|
|
|
|
|
var tpl = require('./refwindow.tpl');
|
|
|
|
|
var toolbarAdapter = require('../../../adapter/toolbarAdapter');
|
|
|
|
|
var GridAdapter = require('../../../adapter/datagridAdapter');
|
|
|
|
|
var PaginationAdapter = require('../../../adapter/paginationAdapter');
|
|
|
|
|
var QueryPanelAdapter = null;
|
|
|
|
|
var _totalRows = 0;
|
|
|
|
|
require('./refwindow.css');
|
|
|
|
|
|
|
|
|
|
function RefWindow(args) {
|
|
|
|
|
var self = this;
|
|
|
|
|
QueryPanelAdapter = require('../../../adapter/querypanelAdapter')
|
|
|
|
|
this.options = {
|
|
|
|
|
title: '参照窗体',
|
|
|
|
|
content: tpl,
|
|
|
|
|
width: 800,
|
|
|
|
|
height: 600,
|
|
|
|
|
top: window.screen.width > 1024 ? 100 : 20,
|
|
|
|
|
modal: true,
|
|
|
|
|
closed: true,
|
|
|
|
|
closable: true,
|
|
|
|
|
minimizable: false,
|
|
|
|
|
maximizable: false,
|
|
|
|
|
collapsible: false,
|
|
|
|
|
resizable: false,
|
|
|
|
|
draggable: true,
|
|
|
|
|
data: null,
|
|
|
|
|
onBeforeClose: function() {
|
|
|
|
|
if (!self.selectItem && self.args.callback) {
|
|
|
|
|
self.args.callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.id = createGuid();
|
|
|
|
|
|
|
|
|
|
this.args = args;
|
|
|
|
|
this.paginited = false;
|
|
|
|
|
//判断是否多选
|
|
|
|
|
this.singleSelect = true;
|
|
|
|
|
if (this.args.rptRefType === '5') {
|
|
|
|
|
this.singleSelect = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.pageSize = args.refWinPageSize || 15;
|
|
|
|
|
|
|
|
|
|
this.callback = args.callback;
|
|
|
|
|
Window.call(this, this.options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inherits(RefWindow, Window);
|
|
|
|
|
|
|
|
|
|
RefWindow.prototype.init = function() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefWindow.prototype.initDataManager = function() {
|
|
|
|
|
var options = {
|
|
|
|
|
rptId: this.args.rptId,
|
|
|
|
|
rptFormatId: this.args.rptFormatId
|
|
|
|
|
};
|
|
|
|
|
this.dataManager = new DataManager(options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefWindow.prototype.customerize = function() {
|
|
|
|
|
// this.initToolbar();
|
|
|
|
|
this.initSchema();
|
|
|
|
|
this.setTitle();
|
|
|
|
|
this.doOp();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RefWindow.prototype.setTitle = function() {
|
|
|
|
|
var title = this.args.dispName || '参照窗体';
|
|
|
|
|
this.getElement('.fdpr-refwindow-title span:eq(0)').text(title);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化toobar按钮
|
|
|
|
|
* @return {[type]} [description]
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.initToolbar = function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
this.toolbarArgs = {
|
|
|
|
|
pageId: self.id,
|
|
|
|
|
container: self.getElement('.fdpr-refwindow-tool'),
|
|
|
|
|
buttons: [
|
|
|
|
|
{
|
|
|
|
|
fieldname: 'refresh',
|
|
|
|
|
dispname: '刷新',
|
|
|
|
|
icon: 'icon-refresh',
|
|
|
|
|
class: '',
|
|
|
|
|
hint: '刷新',
|
|
|
|
|
opcode: 'refresh'
|
|
|
|
|
}],
|
|
|
|
|
menuButtons: [],
|
|
|
|
|
// menuButtons: [{
|
|
|
|
|
// fieldname: 'fitcolumnRef',
|
|
|
|
|
// dispname: '表格自适应',
|
|
|
|
|
// icon: 'icon-print',
|
|
|
|
|
// class: '',
|
|
|
|
|
// hint: '表格自适应',
|
|
|
|
|
// opcode: 'fitcolumnRef',
|
|
|
|
|
// subButtons: [{
|
|
|
|
|
// fieldname: 'fitcolumnautoRef',
|
|
|
|
|
// dispname: '自动铺满',
|
|
|
|
|
// icon: 'icon-print',
|
|
|
|
|
// class: '',
|
|
|
|
|
// hint: '自动铺满',
|
|
|
|
|
// opcode: 'fitcolumnautoRef'
|
|
|
|
|
// }, {
|
|
|
|
|
// fieldname: 'fitcolumnsetRef',
|
|
|
|
|
// dispname: '按后台设置',
|
|
|
|
|
// icon: 'icon-print',
|
|
|
|
|
// class: '',
|
|
|
|
|
// hint: '按后台设置',
|
|
|
|
|
// opcode: 'fitcolumnsetRef'
|
|
|
|
|
// }]
|
|
|
|
|
// }],
|
|
|
|
|
actions: {
|
|
|
|
|
click: function(opCode) {
|
|
|
|
|
if (opCode === 'refresh') {
|
|
|
|
|
self.getData({
|
|
|
|
|
pageIndex: 0,
|
|
|
|
|
isSearch: 1
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (opCode === 'fitcolumnautoRef') {
|
|
|
|
|
// self.gridadp.fitColumns();
|
|
|
|
|
// if (!self.paginited) return;
|
|
|
|
|
// self.getData({
|
|
|
|
|
// pageIndex: 0,
|
|
|
|
|
// isSearch: 1
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (opCode === 'fitcolumnsetRef') {
|
|
|
|
|
// self.gridadp.resetColumns()
|
|
|
|
|
// if (!self.paginited) return;
|
|
|
|
|
// self.getData({
|
|
|
|
|
// pageIndex: 0,
|
|
|
|
|
// isSearch: 1
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.toobar = new toolbarAdapter(this.toolbarArgs);
|
|
|
|
|
this.toobar.init();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化gird列结构
|
|
|
|
|
* @return {[type]} [description]
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.initSchema = function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
this.schemeParams = {
|
|
|
|
|
'rptRefType': self.args.rptRefType,
|
|
|
|
|
'refObj': self.args.refObj,
|
|
|
|
|
'refWinQueryCols': self.args.refWinQueryCols,
|
|
|
|
|
'refWinDispCols': self.args.refWinDispCols,
|
|
|
|
|
'keyboardType': self.args.keyboardType
|
|
|
|
|
};
|
|
|
|
|
ER.services.refSchema(this.schemeParams, function(isok, data) {
|
|
|
|
|
if (isok) {
|
|
|
|
|
self.addQueryPanel(data);
|
|
|
|
|
self.addDataGrid(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取数据
|
|
|
|
|
* @param {[type]} options [description]
|
|
|
|
|
* @return {[type]} [description]
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.getData = function(options) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var searchParams = this.getSearchParams();
|
|
|
|
|
var isSearch = options.isSearch;
|
|
|
|
|
this.dataParams = {
|
|
|
|
|
'rptRefType': self.args.rptRefType,
|
|
|
|
|
'refObj': self.args.refObj,
|
|
|
|
|
'pageIndex': options.pageIndex,
|
|
|
|
|
'pageSize': self.pageSize,
|
|
|
|
|
'queryParams': {
|
|
|
|
|
'refQuery': {
|
|
|
|
|
'rptId': self.args.rptId,
|
|
|
|
|
'rptFormatId': self.args.rptFormatId,
|
|
|
|
|
'fieldName': self.args.fieldName
|
|
|
|
|
},
|
|
|
|
|
'colQuery': {
|
|
|
|
|
//参照窗体查询方案
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.dataParams['queryParams']['colQuery'] = searchParams;
|
|
|
|
|
ER.services.refSearch(this.dataParams, function(isok, data) {
|
|
|
|
|
if (isok) {
|
|
|
|
|
_totalRows = data.totalRows;
|
|
|
|
|
self.gridadp.loadData(data);
|
|
|
|
|
self.intiPagination(_totalRows);
|
|
|
|
|
//如果是刷新,则不重新加载分页器,只是重置页码
|
|
|
|
|
if (isSearch === 1) {
|
|
|
|
|
self.pagepanel.setRefreshPages(0, self.pageSize, _totalRows);
|
|
|
|
|
} else {
|
|
|
|
|
self.pagepanel.setRefreshPages(options.pageIndex, self.pageSize, _totalRows);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化Grid高度
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.initGridHeight = function() {
|
|
|
|
|
var toobarHeight = this.getElement('.fdpr-refwindow-tool').outerHeight(true);
|
|
|
|
|
var queryHeight = this.getElement('.fdpr-refwindow-querypanel').outerHeight(true);
|
|
|
|
|
// var paginationHeight = this.getElement('.fdpr-refwindow-pagination').outerHeight(true);
|
|
|
|
|
// var btnHeight = this.getElement('.fdpr-refwindow-btn').outerHeight(true);
|
|
|
|
|
var gridHeight = this.options.height - toobarHeight - queryHeight - 112;
|
|
|
|
|
// $('.fdpr-refwindow-datagrid').height(gridHeight);
|
|
|
|
|
return gridHeight;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取查询参数
|
|
|
|
|
* @return {[type]} [description]
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.getSearchParams = function() {
|
|
|
|
|
return this.qpanel.getQueryParams();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化分页器信息
|
|
|
|
|
* @param {[type]} 总条数 [description]
|
|
|
|
|
* @return {[type]} [description]
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.intiPagination = function(_totalRows) {
|
|
|
|
|
var self = this;
|
|
|
|
|
if (this.paginited) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
this.paginited = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.paginationParams = {
|
|
|
|
|
pageSize: this.pageSize,
|
|
|
|
|
totalRows: _totalRows,
|
|
|
|
|
container: this.getElement('.fdpr-refwindow-pagination'),
|
|
|
|
|
actions: {
|
|
|
|
|
click: function(opcode, pageIndex) {
|
|
|
|
|
self.pageopRouter(opcode, pageIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.pagepanel = new PaginationAdapter(this.paginationParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 翻页按钮事件
|
|
|
|
|
* @param {[type]} 按钮编码 [description]
|
|
|
|
|
* @param {[type]} 当前页码(从0开始) [description]
|
|
|
|
|
* @return {[type]} [description]
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.pageopRouter = function(opcode, pageIndex) {
|
|
|
|
|
var self = this;
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
case 'firstPage':
|
|
|
|
|
case 'prevPage':
|
|
|
|
|
case 'nextPage':
|
|
|
|
|
case 'lastPage':
|
|
|
|
|
case 'linkPage':
|
|
|
|
|
self.getData({
|
|
|
|
|
pageIndex: pageIndex,
|
|
|
|
|
isSearch: 0
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化grid
|
|
|
|
|
* @param {[type]} 数据 [description]
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.addDataGrid = function(data) {
|
|
|
|
|
var gridHeight = this.initGridHeight();
|
|
|
|
|
this.gridadp = new GridAdapter({
|
|
|
|
|
id: this.id,
|
|
|
|
|
name: '',
|
|
|
|
|
opts: {},
|
|
|
|
|
data: {
|
|
|
|
|
columns: data.columns
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.gridadp.makeGridRowStyler();
|
|
|
|
|
this.gridadp.makeGridProperties({
|
|
|
|
|
singleSelect: this.singleSelect,
|
|
|
|
|
height: gridHeight
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.gridadp.init(this.getElement('.fdpr-refwindow-datagrid'));
|
|
|
|
|
// this.gridadp.fitColumns();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化查询panel
|
|
|
|
|
* @param {[type]} data [description]
|
|
|
|
|
*/
|
|
|
|
|
RefWindow.prototype.addQueryPanel = function(data) {
|
|
|
|
|
var refColumns = [];
|
|
|
|
|
var refWinQueryCols = this.args.refWinQueryCols;
|
|
|
|
|
if (refWinQueryCols !== null) {
|
|
|
|
|
refWinQueryCols = refWinQueryCols.toLowerCase();
|
|
|
|
|
_.each(data.columns, function(column, index) {
|
|
|
|
|
if (refWinQueryCols.indexOf(column.fieldName) >= 0) {
|
|
|
|
|
//参照窗体默认显示格式均为文本
|
|
|
|
|
column.dispStyle = '00';
|
|
|
|
|
refColumns.push(column);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.qpanel = new QueryPanelAdapter({
|
|
|
|
|
pageId: this.id,
|
|
|
|
|
container: this.getElement('.fdpr-refwindow-querypanel'),
|
|
|
|
|
data: refColumns,
|
|
|
|
|
opts: {
|
|
|
|
|
needFilter: false,
|
|
|
|
|
selfWidth: true
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RefWindow.prototype.doOp = function() {
|
|
|
|
|
var isHandled = false;
|
|
|
|
|
var self = this;
|
|
|
|
|
this.getElement('.fdpr-cancel').on('click', function() {
|
|
|
|
|
self.close();
|
|
|
|
|
})
|
|
|
|
|
this.getElement('.fdpr-refwindow-tool').on('click', function() {
|
|
|
|
|
self.getData({
|
|
|
|
|
pageIndex: 0,
|
|
|
|
|
isSearch: 1
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
this.getElement('.fdpr-sure').on('click', function() {
|
|
|
|
|
var rptRefType = self.args.rptRefType;
|
|
|
|
|
var rows = [];
|
|
|
|
|
var value = '';
|
|
|
|
|
if (rptRefType === '2') {
|
|
|
|
|
rows = self.gridadp.getSelected();
|
|
|
|
|
if (rows === null) {
|
|
|
|
|
self.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
value = rows[self.args.refField.toLowerCase()];
|
|
|
|
|
if(self.args.refFieldName) {
|
|
|
|
|
value = value + self.args.refSeparator + rows[self.args.refFieldName.toLowerCase()];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rows = self.gridadp.getSelections();
|
|
|
|
|
if (rows === null) {
|
|
|
|
|
self.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (rows.length === 1) {
|
|
|
|
|
value = rows[0][self.args.refField.toLowerCase()];
|
|
|
|
|
if(self.args.refFieldName) {
|
|
|
|
|
value = value + self.args.refSeparator + rows[0][self.args.refFieldName.toLowerCase()];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_.each(rows, function(row, index) {
|
|
|
|
|
value += row[self.args.refField.toLowerCase()] + ',';
|
|
|
|
|
});
|
|
|
|
|
value = value.substring(0, value.length - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (self.args.callback) {
|
|
|
|
|
self.args.callback(value);
|
|
|
|
|
}
|
|
|
|
|
self.close();
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RefWindow.prototype.open = function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
Window.prototype.open.call(self);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return RefWindow;
|
|
|
|
|
});
|