Ext.QuickTips.init();
Ext.define('erp.controller.common.Search', {
extend : 'Ext.app.Controller',
requires : ['erp.util.GridUtil', 'erp.util.BaseUtil'],
views : [ 'common.search.Viewport', 'core.trigger.DbfindTrigger', 'core.form.FtField',
'core.form.ConDateField', 'core.form.YnField',
'core.form.FtDateField', 'core.form.YearDateField',
'core.form.MonthDateField', 'core.form.FtFindField', 'core.form.FtNumberField',
'core.grid.YnColumn', 'core.grid.TfColumn',
'core.form.ConMonthDateField', 'core.trigger.TextAreaTrigger' ],
models : ['SearchTemplate'],
refs : [ {
ref : 'grid',
selector : '#querygrid'
}, {
ref: 'dataCount',
selector: '#dataCount'
} ],
init : function() {
var me = this;
me.GridUtil = Ext.create('erp.util.GridUtil');
me.BaseUtil = Ext.create('erp.util.BaseUtil');
this.control({
'button[name=find]' : {
click : function(btn) {
this.onQueryClick();
},
afterrender : function() {
Ext.defer(function(){
me.onQueryClick();
}, 500);
}
},
'button[name=group]' : {
click : function(btn) {
this.onGroupClick();
}
},
'button[name=close]' : {
click : function() {
if (parent.Ext && parent.Ext.getCmp('content-panel')) {
parent.Ext.getCmp('content-panel').getActiveTab().close();
} else {
window.close();
}
}
},
'button[name=clearcondition]' : {
click : function() {
if (this.querywin) {
var g = this.querywin.down('grid');
g.store.removeAll();
g.loadEmptyData();
}
}
},
'button[name=filter]' : {
click : function() {
}
},
'button[name=sort]' : {
click : function() {
var items = this.searchTemplate ? this.searchTemplate.items : [],
sorts = this.searchTemplate ? this.searchTemplate.st_sorts : null;
this.onSortClick(items, sorts, function(sorts){
});
}
},
'button[name=temp]' : {
click : function() {
warnMsg('保存当前设置到方案?', function(b){
if(b == 'ok' || b == 'yes') {
me.updateTemp();
}
});
}
},
'menuitem[name=exportexcel]' : {
click : function() {
this.BaseUtil.exportGrid(this.getGrid().normalGrid);
}
},
'menuitem[name=exportpdf]' : {
click : function() {
this.BaseUtil.exportPdf(this.getGrid().normalGrid);
}
},
'button[name=lock]' : {
click : function() {
this.onLockClick();
}
},
'menuitem[name=sum]' : {
click : function() {
}
},
'menuitem[name=average]' : {
click : function() {
}
},
'menuitem[name=max]' : {
click : function() {
window.open(window.location.href);
}
},
'menuitem[name=webexcel]' : {
click : function() {
window.open(basePath + 'jsps/Excel/sheet/index.jsp');
}
},
'button[name=removeformat]' : {
click : function() {
this.onClear();
}
},
'button[name=clearall]' : {
click : function() {
this.getGrid().normalGrid.store.loadData([{},{},{},{},{},{},{},{},{},{}]);
}
},
'menuitem[name=template-copy]': {
click: function(item) {
var record = item.ownerCt.record;
if (record) {
var t = record.get('st_title');
me.addTemp(t + '(新)', function(title){
me.copyTemp(title, record.get('st_id'));
});
}
}
},
'menuitem[name=template-title]': {
click: function(item) {
var record = item.ownerCt.record;
if (record) {
me.addTemp(record.get('st_title'), function(title){
me.onTempTitleChange(title, record.get('st_id'), function(){
record.set('st_title', title);
});
});
}
}
},
'menuitem[name=template-set]': {
click: function(item) {
var record = item.ownerCt.record;
if (record) {
me.onTempSet(record, record.get('items'), record.get('st_id'));
}
}
},
'menuitem[name=template-del]': {
click: function(item) {
var grid = item.ownerCt.grid, record = item.ownerCt.record;
if (record) {
warnMsg('确定删除 ' + record.get('st_title') + ' ?', function(k){
if(k == 'ok' || k == 'yes') {
me.onTempDel(record.get('st_id'), function(){
Ext.example.msg('info', '提示', record.get('st_title') + ' 删除成功', 2000);
grid.store.remove(record);
record = grid.store.first();
if(record) {
grid.selModel.select(record);
}
});
}
});
}
}
}
});
if(!window.onLinkClick)
window.onLinkClick = function(l, t, arg1, arg2){
me.onLinkClick(l, t, arg1, arg2);
};
},
onQueryClick : function() {
var me = this, win = me.querywin;
if (!win) {
var form = me.createQueryForm(), temp = me.createTempGrid();
win = me.querywin = Ext.create('Ext.window.Window', {
closeAction : 'hide',
title : '筛选',
height: 500,
width: 550,
items : [form, temp],
buttonAlign : 'center',
buttons : [{
text : $I18N.common.button.erpQueryButton,
height : 26,
handler : function(b) {
var items = temp.selModel.getSelection();
if(items.length > 0) {
me.onQuery(items[0].data);
}
b.ownerCt.ownerCt.hide();
}
},{
text : '直接导出',
iconCls: 'icon-xls',
height : 26,
handler : function(b) {
me.exportExcel(me.getGrid().normalGrid, temp.selModel.getSelection(), form.getCondition());
b.ownerCt.ownerCt.hide();
}
}, {
text : $I18N.common.button.erpCloseButton,
height : 26,
handler : function(b) {
b.ownerCt.ownerCt.hide();
}
}]
});
me.onTempLoad(function(data, lastId){
temp.store.loadData(data);
if(data.length > 0) {
var r = (lastId && temp.store.findRecord('st_id', lastId)) || temp.store.first();
temp.selModel.select(r);
form.setTitle(r.get('st_title'));
}
});
}
win.show();
},
createTempGrid : function() {
var me = this;
return Ext.create('Ext.grid.Panel', {
id: 'temp',
cls: 'custom-grid',
title: '自定义方案',
region: 'south',
height: 200,
autoScroll: true,
tools: [{
type: 'plus',
tooltip: '添加方案',
handler: function(e, el, tb, tool) {
me.addTemp();
}
}],
columns: [{
text: '日期',
dataIndex: 'st_date',
renderer: function(v) {
return Ext.Date.format(new Date(v), 'Y-m-d');
},
flex: 1
},{
text: '创建人',
dataIndex: 'st_man',
flex: 0.8
},{
text: '描述',
dataIndex: 'st_title',
flex: 3
},{
xtype: 'actioncolumn',
flex: .6,
align: 'center',
items: [{
icon: basePath + 'resource/images/16/edit.png',
tooltip: '设置',
handler: function(grid, rIdx, cIdx) {
var record = grid.store.getAt(rIdx);
me.onTempSet(record, record.get('items'), record.get('st_id'));
}
},{
icon: basePath + 'resource/images/16/delete.png',
tooltip: '删除',
handler: function(grid, rIdx, cIdx) {
var record = grid.store.getAt(rIdx);
warnMsg('确定删除 ' + record.get('st_title') + ' ?', function(k){
if(k == 'ok' || k == 'yes') {
me.onTempDel(record.get('st_id'), function(){
Ext.example.msg('info', '提示', record.get('st_title') + ' 删除成功', 2000);
grid.store.remove(record);
record = grid.store.first();
if(record) {
grid.selModel.select(record);
}
});
}
});
}
}]
}],
selModel: Ext.create('Ext.selection.CheckboxModel',{
mode: 'SINGLE',
listeners: {
select : function(sm, record, idx) {
var items = record.get('items');
if(items) {
me.formatTempSet(items, record.get('properties'), true);
}
me.defaultCondition = record.get('st_condition');
me.searchTemplate = record.data;
}
}
}),
columnLines: true,
store: new Ext.data.Store({
fields: ['st_date', 'st_man', 'st_title', 'items', 'properties', 'st_id','st_condition','st_usedtable','st_tablesql','st_sorts', 'st_limits']
}),
viewConfig: {
listeners: {
itemcontextmenu: function(view, record, item, index, e) {
me.onTempContextmenu(view, record, e);
}
}
}
});
},
/**
* 方案grid,右键菜单
*/
onTempContextmenu: function(view, record, e) {
e.preventDefault();
var menu = view.contextMenu;
if (!menu) {
menu = view.contextMenu = new Ext.menu.Menu({
items: [{
text : '复制方案',
name: 'template-copy'
},{
text : '修改描述',
name: 'template-title'
},{
text : '编辑方案',
name: 'template-set'
},{
iconCls: 'icon-remove',
text : '删除',
name: 'template-del'
}]
});
menu.grid = view.ownerCt;
}
menu.showAt(e.getXY());
menu.record = record;
},
formatTempSet : function(items, properties, load) {
var me = this, grid = this.getGrid();
var datas = new Array(), columns = new Array(), alias = new Array(),
group = null, locks = new Array(), temp = new Array(), v, w = 0.5;
Ext.Array.each(items, function(i){
var modeItems = [];
if(1 === i.stg_query) {
if (i.stg_mode && i.stg_mode != '' && properties) {// multi properties field
Ext.Array.each(properties, function(p){
if(p.stg_field == i.stg_field) {
modeItems.push({
display: p.display,
value: p.value
});
}
});
if(i.stg_mode == 'checkboxgroup' || i.stg_mode == 'radiogroup') {
var items = [];
Ext.Array.each(properties, function(p){
if(p.stg_field == i.stg_field) {
items.push({
boxLabel: p.display,
inputValue: p.value,
name: i.stg_field,
checked: (i.stg_value && (i.stg_value == p.value || i.stg_value == '$ALL'))
});
}
});
datas.push({
xtype: i.stg_mode,
fieldLabel: i.stg_text,
relativeTable: i.stg_table,
columnWidth: 1,
columns: 3,
vertical: true,
items: items
});
} else if (i.stg_mode == 'combobox') {
var store = new Ext.data.Store({
fields: ['display', 'value'],
data: Ext.Array.merge([{
display: '全部',
value: '$ALL'
},{
display: '无',
value: '$NULL'
}], modeItems)
});
datas.push({
xtype: i.stg_mode,
name: i.stg_field,
fieldLabel: i.stg_text,
relativeTable: i.stg_table,
columnWidth: .5,
store: store,
queryMode: 'local',
displayField: 'display',
valueField: 'value',
value: i.stg_value
});
}
} else {
w = .5;
v = i.stg_value;
var t = 'textfield', type = i.stg_type.toUpperCase();
if(type == 'DATE' || type == 'TIMESTAMP') {
t = 'datefield';
if(!Ext.isEmpty(v)) {
w = 1;
switch(v) {
case '今天':
t = 'condatefield';v = 1;break;
case '昨天':
t = 'condatefield';v = 2;break;
case '本月':
t = 'condatefield';v = 3;break;
case '上个月':
t = 'condatefield';v = 4;break;
case '本年度':
t = 'condatefield';v = 5;break;
case '上年度':
t = 'condatefield';v = 6;break;
case '自定义':
t = 'condatefield';v = 7;break;
default:
if(!Ext.isDate(v) && /\d{4}-\d{2}-\d{2}/.test(v)) {
v = Ext.Date.parse(v, 'Y-m-d');
}
break;
}
}
} else if(type == 'NUMBER') {
t = 'numberfield';
}
if(1 == i.stg_dbfind) {
t = 'dbfindtrigger';
}
if(1 == i.stg_double) {
w = 1;
if(t == 'numberfield') {
t = 'erpFtNumberField';
} else if (t == 'dbfindtrigger') {
t = 'ftfindfield';
} else if (t == 'datefield') {
t = 'ftdatefield';
} else if (t == 'textfield'){
t = 'erpFtField';
}
if(i.stg_format == 'Ym') {
t = 'conmonthdatefield';
}
}
datas.push({
fieldLabel: i.stg_text,
relativeTable: i.stg_table,
labelWidth: 100,
xtype: t,
name: i.stg_field,
id: i.stg_field,
value: v,
columnWidth: w
});
}
}
if(1 === i.stg_group) {
group = i.stg_alias;
}
if(1 === i.stg_lock) {
locks.push(i.stg_alias);
}
var xtype = me.getTypeByStg(i.stg_type);
if(1 === i.stg_use) {
var col = {
text: i.stg_text,
xtype: xtype,
dataIndex: i.stg_alias,
dataField: i.stg_field,
dataTable: i.stg_table,
format: (i.stg_format == 'Ym') ? null : i.stg_format,
width: i.stg_width,
summaryType: i.stg_sum == 1 ? 'sum' : null,
align: xtype == 'numbercolumn' ? 'right' : 'left'
};
if(i.stg_link) {
col.renderer = function(value, p, record) {
if(value) {
return Ext.String.format(
'{2}',
record.get(i.stg_tokencol1),
record.get(i.stg_tokencol2),
value
);
return null;
};
};
}
columns.push(col);
}
temp.push({
stg_text: i.stg_text,
stg_use: i.stg_use,
stg_field: i.stg_field,
stg_value: i.stg_value,
stg_lock: i.stg_lock == 1,
stg_group: i.stg_group == 1,
stg_sum: i.stg_sum == 1,
stg_dbfind: i.stg_dbfind == 1,
stg_double: i.stg_double == 1,
stg_query: i.stg_query == 1,
stg_width: i.stg_width,
stg_type: i.stg_type,
stg_table: i.stg_table,
stg_format: i.stg_format,
stg_formula: i.stg_formula,
stg_mode: i.stg_mode,
modeItems: i.stg_mode ? (modeItems || [{dispay:null,value:null}]) : modeItems,
type: xtype,
links: i.links,
stg_link: i.stg_link,
stg_tokentab1: i.stg_tokentab1,
stg_tokencol1: i.stg_tokencol1,
stg_tokentab2: i.stg_tokentab2,
stg_tokencol2: i.stg_tokencol2
});
});
// 加载筛选条件
if(load) {
var f = this.querywin.down('form');
f.removeAll();
f.add(datas);
var alias = Ext.Array.pluck(columns, 'dataIndex');
Ext.Array.each(temp, function(t){
if(t.stg_tokencol1 && !Ext.Array.contains(alias, t.stg_tokencol1)) {
alias.push(t.stg_tokencol1);
}
if(t.stg_tokencol2 && !Ext.Array.contains(alias, t.stg_tokencol2)) {
alias.push(t.stg_tokencol2);
}
});
Ext.suspendLayouts();
grid.reconfigure(new Ext.data.Store({
fields: alias
}), columns);
Ext.resumeLayouts(true);
// 加载分组条件
this.groupfield = group;
this.toogleGroup(group, true);
// 固定列
this.lockfields = locks;
if(locks.length > 0) {
var normal = grid.getView().normalGrid;
Ext.Array.each(locks, function(){
var column = normal.down('gridcolumn[dataIndex=' + this + ']');
if (column.locked) {
grid.unlock(column);
} else {
grid.lock(column);
}
});
}
// 加载合计
}
return temp;
},
onTempSet : function(record, items, sId) {
var me = this, win = me.tempwin, temp = me.formatTempSet(items, record.get('properties'), false);
if (!win) {
var sGrid = me.getSettingGrid();
Ext.define("Post", {
extend: 'Ext.data.Model',
proxy: {
type: 'ajax',
url : basePath + 'ma/dataDictionary/search.action',
reader: {
type: 'json',
root: 'datas',
totalProperty: 'totalCount'
},
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
},
fields: [
{name: 'desc', mapping: 'dd_description'},
{name: 'table', mapping: 'dd_tablename'}
]
});
ds = Ext.create('Ext.data.Store', {
pageSize: 10,
model: 'Post'
});
win = me.tempwin = Ext.create('Ext.window.Window', {
header: {
items: [{
xtype: 'tbtext',
id: 'set-title',
text: '方案设置',
style: 'font-weight: 700;'
}, {
xtype: 'tbtext',
id: 'set-info',
tpl: Ext.create('Ext.XTemplate',
'共 {tableCount} 个表关联,' +
'可选 {columnCount} 列 ' +
'已选 {usedCount} 列')
}]
},
closeAction : 'hide',
width : '100%',
height : '80%',
layout: 'border',
items : [{
region: 'west',
width: 400,
layout: 'accordion',
id: 'dictionary',
tbar: [{
xtype: 'combo',
store: ds,
width: 360,
displayField: 'desc',
emptyText: '查找数据字典',
typeAhead: false,
hideLabel: true,
hideTrigger:true,
minChars: 3,
listConfig: {
minHeight: 360,
maxHeight: 360,
loadingText: '查找中...',
emptyText: '
没有找到您需要的数据字典.
',
getInnerTpl: function() {
return '' +
'' +
'{desc}{table}' +
'' +
'{table}' +
'
';
}
},
pageSize: 10,
listeners: {
select: function(combo, records, opts) {
me.addDictionary(win, records[0].get('table'));
combo.reset();
}
},
getParams: function(queryString) {
var params = {},
param = this.queryParam;
if (param) {
params[param] = escape(queryString);
}
return params;
}
},'->', {
xtype: 'tool',
type: 'left',
style: {
marginRight: '5px'
},
tooltip: '收拢',
handler: function(e, el, tb, tool) {
tb.ownerCt.collapse(Ext.Component.DIRECTION_LEFT, true);
}
}]
},{
region: 'center',
layout: 'anchor',
items: [sGrid]
}],
buttonAlign : 'center',
buttons : [{
text : '保存到方案',
height : 26,
handler : function(b) {
var w = b.ownerCt.ownerCt;
me.updateTemp(function(){
w.hide();
});
}
},{
text : '作为新方案保存',
id: 'new_temp_btn',
height : 26,
hidden : (sId <= 0),
handler : function(b) {
var t = win.relativeRecord.get('st_title');
me.addTemp(t + '(新)', function(title){
var w = b.ownerCt.ownerCt;
w.hide();
me.copyTemp(title);
});
}
}, {
text : $I18N.common.button.erpCloseButton,
height : 26,
handler : function(b) {
b.ownerCt.ownerCt.hide();
}
}]
});
}
win.show();
if(sId <= 0) {
win.down('#new_temp_btn').hide();
} else {
win.down('#new_temp_btn').show();
}
var g = win.down('#grid-setting');
g.store.loadData(temp);
g.sorts = record.get('st_sorts');
g.limits = record.get('st_limits');
g.down('#st_condition').setValue(record.get('st_condition'));
// 加载数据字典
var dic = win.down('#dictionary'),
usedTabs = record.get('st_usedtable'), tabSql = record.get('st_tablesql');
if(dic.tables != usedTabs || win.relativeId != sId) {
g.down('#set-tab-info').setTooltip(me.getCodeTip({
usedTabs: usedTabs.split(','),
tabSql: tabSql,
condSql: record.get('st_condition'),
sortSql: g.sorts,
data: temp
}));
me.getDictionary(usedTabs, function(datas){
dic.tables = usedTabs;
dic.removeAll();
var c = 0;
for(var i in datas) {
dic.add(me.createDictionaryGrid(datas[i]));
c += datas[i].dataDictionaryDetails.length;
}
win.down('#set-info').update({
tableCount: datas.length,
columnCount: c,
usedCount: temp.length
});
});
}
if(win.relativeId != sId) {
win.down('#set-title').setText(record.get('st_title'));
win.relativeRecord = record;
win.relativeId = sId;
}
},
/**
* 显示方案sql的tip
*/
getCodeTip: function(config) {
var me = this, oldConf = me.templateConfig;
if(!oldConf)
oldConf = {};
me.templateConfig = config = Ext.Object.merge(oldConf, config);
return new Ext.tip.ToolTip({
target: 'set-tab-info',
cls: 'tip-custom',
autoHide: false,
hideDelay: 0,
html: me.getCodeHtml(config)
});
},
/**
* 代码html
*/
getCodeHtml: function(datas) {
return new Ext.XTemplate(
'数据字典:' +
'' +
'' +
'' +
'关联SQL:' +
'{tabSql:this.format}
' +
'排序SQL:' +
'{sortSql:this.orderBy}
' +
'条件SQL:' +
'{condSql:this.format}
' +
'查询SQL:' +
'{[this.getSearchSql(values)]}
', {
keywords : ['SELECT ', ' FROM ', ' WHERE ', ' LEFT JOIN ', ' ON ', 'ORDER BY ', ' AND ', ' DESC', ' ASC', 'TO_CHAR'],
format: function(sql) {
if(!sql) return null;
var kw = this.keywords;
for(var i in kw) {
var reg = new RegExp(kw[i], 'g');
sql = sql.replace(reg, '' + kw[i] + '');
}
sql = this.replaceQuot(sql);
return sql;
},
replaceQuot: function(sql) {
var index = 0, length = sql.length, s, e = -1, c = 0, htm = '';
while(index < length) {
if((s = sql.indexOf('\'', index)) != -1 && (e = sql.indexOf('\'', s + 1)) != -1) {
c = 1;
while(sql.substring(e + c, e + c + 1) == '\'' || c%2 == 0){
e++;
c++;
}
htm += sql.substring(index, s) + '' + sql.substring(s, e+1) +'';
index = e + 1;
} else {
htm += sql.substring(e + 1);
break;
}
}
return htm.length > 0 ? htm : sql;
},
orderBy: function(sql) {
if(!sql) return null;
return this.format('ORDER BY ' + sql);
},
getSearchSql: function(values) {
var fs = [];
Ext.Array.each(values.data, function(d){
if(d.stg_type.toLowerCase() == 'date')
fs.push('TO_CHAR(' + d.stg_table + '.' + d.stg_field +
', \'yyyy-mm-dd hh24:mi:ss\') ' + d.stg_field);
else
fs.push(d.stg_table + '.' + d.stg_field + ' ' + d.stg_field);
});
return this.format('SELECT ' + fs.join(',') + ' FROM ' + values.tabSql +
(values.condSql ? (' WHERE (' + values.condSql + ')') : '') +
(values.sortSql ? (' ORDER BY ' + values.sortSql) : ''));
}
}).apply(datas);
},
/**
* 添加数据字典
*/
addDictionary: function(win, table) {
var me = this, dic = win.down('#dictionary');
if(dic.tables && Ext.Array.indexOf(dic.tables.split(','), table) > -1) {
Ext.example.msg('warning', '警告', '不能添加已经存在的表', 4000);
return;
}
var newTabs = dic.tables ? dic.tables + ',' + table : table;
me.getTabSql(newTabs, function(sql){
me.getDictionary(table, function(datas){
dic.tables = newTabs;
var c = 0;
for(var i in datas) {
dic.add(me.createDictionaryGrid(datas[i]));
c += datas[i].dataDictionaryDetails.length;
}
Ext.each(dic.items.items, function(g){
c += g.store.getCount();
});
win.down('#set-info').update({
tableCount: dic.items.items.length,
columnCount: c
});
win.down('#set-tab-info').setTooltip(me.getCodeTip({
usedTabs: dic.tables.split(','),
tabSql: sql
}));
});
});
},
getTypeByStg: function(t) {
t = t.toUpperCase();
if(t.indexOf('NUMBER') > -1)
return 'numbercolumn';
if(t.indexOf('DATE') > -1)
return 'datecolumn';
return null;
},
/**
* 显示数据字典的grid
*/
createDictionaryGrid: function(dic) {
var id = 'grid-' + dic.dd_tablename, datas = [], me = this;
Ext.Array.each(dic.dataDictionaryDetails, function(d){
var nl = {
text: d.ddd_description,
type: me.getTypeByStg(d.ddd_fieldtype),
stg_width: 100,
stg_text: d.ddd_description,
stg_use: 1,
stg_field: d.ddd_fieldname,
stg_table: d.ddd_tablename,
stg_type: d.ddd_fieldtype,
modeItems: [],
links: d.links
};
if(d.links && d.links.length > 0) {
nl.stg_link = d.links[0].dl_link;
nl.stg_tokentab1 = d.links[0].dl_tokentab1;
nl.stg_tokencol1 = d.links[0].dl_tokencol1;
nl.stg_tokentab2 = d.links[0].dl_tokentab2;
nl.stg_tokencol2 = d.links[0].dl_tokencol2;
}
datas.push(nl);
});
return new Ext.grid.Panel({
title: dic.dd_description,
cls: 'custom-grid',
id: id,
columns: [{
text: '代码',
dataIndex: 'stg_field',
flex: 1,
filter: {
xtype : 'textfield'
}
},{
text: '描述',
dataIndex: 'stg_text',
flex: 1,
filter: {
xtype : 'textfield'
}
}],
plugins: [Ext.create('erp.view.core.grid.HeaderFilter')],
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
dragGroup: 'grid-setting',
dropGroup: 'grid-setting'
},
listeners: {
drop: function(node, data) {
// 从配置里面拖过来的,表示删除
// 重新加载数据,防止出现checkcolumn的勾选错位情况
var newData = [];
data.view.store.each(function(record){
newData.push(record.data);
});
data.view.store.loadData(newData);
}
}
},
selModel: new Ext.selection.RowModel({
mode: 'MULTI'
}),
store: new Ext.data.Store({
model: erp.model.SearchTemplate,
data: datas,
sorters: [{
property: 'stg_field',
direction: 'ASC'
}]
})
});
},
createQueryForm : function() {
var me = this;
var form = Ext.create('Ext.form.Panel', {
region: 'center',
height: 300,
title: '(未选择方案)',
layout: 'column',
autoScroll: true,
defaults: {
columnWidth: 1,
margin: '4 8 4 8'
},
bodyStyle: 'background:#f1f2f5;',
getCondition: function() {
var s = me.defaultCondition ? '(' + me.defaultCondition + ')' : '';
Ext.each(this.items.items, function(){
var v = this.getValue(), b = this.relativeTable, n = this.name, _n = b + '.' + n, t;
if(!Ext.isEmpty(v) && v != '$ALL') {
switch(this.xtype) {
case 'datefield':
t = "to_char(" + _n + ",'yyyy-mm-dd')='" + Ext.Date.format(v,'Y-m-d') + "'";break;
case 'condatefield':
t = _n + ' ' + v;break;
case 'ftdatefield':
t = _n + ' ' + this.value;break;
case 'ftfindfield':
t = _n + ' ' + this.value;break;
case 'erpFtNumberField':
t = _n + ' ' + this.value;break;
case 'checkboxgroup':
if(!Ext.Object.isEmpty(v)) {
var ks = Ext.Object.getKeys(v), k = ks[0], vs = [];
Ext.Array.each(v[k], function(c){
vs.push(k + '=\'' + c + '\'');
});
t = vs.join(' OR ');
}
break;
case 'radiogroup':
if(!Ext.Object.isEmpty(v)) {
var ks = Ext.Object.getKeys(v), k = ks[0];
t = k + '=\'' + v[k] + '\'';
}
break;
case 'conmonthdatefield':
if(!Ext.Object.isEmpty(v)) {
if(n.toUpperCase().indexOf('YM_VIEW_PARAM') > -1) {
t = ' ' + this.value;
} else {
t = _n + ' ' + this.value;
}
}
break;
default:
v = String(v);
if(v.charAt(0) == '%' || v.charAt(v.length - 1) == '%') {
t = _n + " like '" + v + "'";
} else if (v == '$NULL') {
t = "nvl(" + _n + ",' ')=' '";
} else {
t = _n + "='" + v + "'";
}
break;
}
if(t) {
t = '(' + t + ')';
s += s.length > 0 ? (' and ' + t ) : t;
}
}
});
return s.length > 0 ? s : '0=0';
}
});
return form;
},
onQuery : function(data) {
var g = this.getGrid(), q = this.querywin.down('form'), end = g.maxDataSize || 10000;
this.loadNewStore(g, {
sId: data ? data.st_id : this.$sid,
condition: q.getCondition(),
sorts: data ? data.st_sorts : this.templateConfig.sorts,
start: 1,
end: end
});
this.querywin.hide();
this.log();//记录本次选择的方案
},
onGroupClick : function() {
var me = this, win = me.groupwin;
if (!win) {
var form = me.getAliaForm();
win = me.groupwin = Ext.create('Ext.window.Window', {
title : '分组设置',
closeAction : 'hide',
width : 500,
maxHeight : 400,
items : [form],
buttonAlign : 'center',
buttons : [{
text : '取消分组',
flag : 'cancel',
height : 26,
disabled : true,
handler : function(b) {
var w = b.ownerCt.ownerCt;
me.toogleGroup(w.down('form'), false);
w.hide();
}
},{
text : $I18N.common.button.erpConfirmButton,
height : 26,
handler : function(b) {
var w = b.ownerCt.ownerCt;
me.toogleGroup(w.down('form'), true);
w.hide();
}
}, {
text : $I18N.common.button.erpCloseButton,
height : 26,
handler : function(b) {
b.ownerCt.ownerCt.hide();
}
}]
});
if(this.groupfield) {
var f = win.down('radio[inputValue=' + this.groupfield + ']');
if(f) {
f.setValue(true);
}
}
}
win.show();
var f = win.down('radio[value=true]'), b = win.down('button[flag=cancel]');
b.setDisabled(!f);
},
onLockClick : function() {
var me = this, win = me.lockwin;
if (!win) {
var form = me.getAliaForm('checkbox');
win = me.lockwin = Ext.create('Ext.window.Window', {
title : '固定列设置',
closeAction : 'hide',
width : 500,
maxHeight : 400,
items : [form],
buttonAlign : 'center',
buttons : [{
text : $I18N.common.button.erpConfirmButton,
height : 26,
handler : function(b) {
var w = b.ownerCt.ownerCt;
me.onLock(w.down('form'));
w.hide();
}
}, {
text : $I18N.common.button.erpCloseButton,
height : 26,
handler : function(b) {
b.ownerCt.ownerCt.hide();
}
}]
});
if(this.lockfields) {
Ext.Array.each(this.lockfields, function(l){
var f = win.down('checkbox[inputValue=' + l + ']');
if(f) {
f.setValue(true);
}
});
}
}
win.show();
},
onSortClick : function(source, oldSorts, callback) {
var me = this, win = me.sortwin;
var oldData = [], oldProp = [];
if(oldSorts) {
Ext.Array.each(oldSorts.split(','), function(s, i){
var p = s.split(' '), t = null, f = p[0], tx = '';
if(f.indexOf('.') > 0) {// table.field
t = f.substr(0, f.indexOf('.'));
f = f.substr(f.indexOf('.') + 1);
}
if(Ext.isArray(source)) {
var obj = Ext.Array.findBy(source, function(i){
return i.stg_field == f;
});
if (obj) tx = obj.stg_text;
} else {
tx = source.findRecord('stg_field', f).get('stg_text');
}
oldData.push({property: f, direction: p[1], number: i+1, description: tx, table: t});
oldProp.push(f);
});
}
if (!win) {
var form = me.getGridForm('checkbox', null, source, oldProp),
view = me.getSortingView(oldData);
win = me.sortwin = Ext.create('Ext.window.Window', {
title : '排序设置',
closeAction : 'hide',
width : 800,
layout: 'hbox',
defaults: {flex: 1},
items : [form, view],
buttonAlign : 'center',
buttons : [{
text : $I18N.common.button.erpConfirmButton,
height : 26,
handler : function(b) {
var w = b.ownerCt.ownerCt, sorts = [], desc = '';
view.getStore().each(function(i){
desc = i.get('property') + ' ' + i.get('direction');
if(i.get('table'))
desc = i.get('table') + '.' + desc;
sorts.push(desc);
});
callback.call(me, sorts.join(','));
w.hide();
}
}, {
text : $I18N.common.button.erpCloseButton,
height : 26,
handler : function(b) {
b.ownerCt.ownerCt.hide();
}
}]
});
} else {
var form = win.down('form'), view = win.down('dataview');
form.removeAll();
form.add(me.createFormItems(source, oldProp));
view.store.loadData(oldData);
}
win.show();
me.onSortChange(win.down('form'), win.down('dataview'));
},
/**
* 排序设置,监听字段变化
*/
onSortChange: function(form, view) {
var me = this, onDirectionChange = function() {
var d = Ext.select("td.sort-value input"), e = d.elements;
Ext.each(e, function(m) {
Ext.EventManager.on(m, {
change : function(e, el){
var record = view.getStore().findRecord('property', el.name);
record.set('direction', el.value);
},
buffer : 100
});
});
};
form.getForm().getFields().each(function(field){
field.on('change', function(scope){
view.getStore().loadData(me.getSortProperties(scope.ownerCt, view.getStore()));
onDirectionChange();
});
});
Ext.defer(onDirectionChange, 100);
},
/**
* 选中的排序字段view
*/
getSortingView: function(oldData) {
var sortStore = new Ext.data.Store({
fields: ['property', 'description', 'direction', 'number', 'table'],
sorters: [{
property: 'number',
direction: 'ASC'
}],
data: oldData
});
return Ext.create('Ext.view.View', {
cls: 'sort-view',
tpl: '' +
'' +
'' +
'' +
'- 如果直接点击列抬头来排序,将不会使用到本次排序设置
' +
'- 可以拖放选中的字段来改变排序的优先顺序
' +
'
',
itemSelector: 'div.sort',
overItemCls: 'sort-over',
selectedItemClass: 'sort-selected',
singleSelect: true,
ddGroup: 'sort',
store: sortStore,
listeners: {
render: function(v) {
v.dragZone = new Ext.dd.DragZone(v.ownerCt.el, {
ddGroup: 'sort',
getDragData: function(e) {
var sourceEl = e.getTarget(v.itemSelector, 10), d;
if (sourceEl) {
d = sourceEl.cloneNode(true);
d.id = Ext.id();
return (v.dragData = {
sourceEl: sourceEl,
repairXY: Ext.fly(sourceEl).getXY(),
ddel: d,
record: v.getRecord(sourceEl)
});
}
},
getRepairXY: function() {
return this.dragData.repairXY;
}
});
v.dropZone = new Ext.dd.DropZone(v.ownerCt.el, {
ddGroup: 'sort',
getTargetFromEvent: function(e) {
return e.getTarget('.sort .sort-over');
},
onNodeEnter: function(target, dd, e, data){
var fly = Ext.fly(target);
if(fly && typeof fly.addClass === 'function')
fly.addClass('sort-target-hover');
},
onNodeOut: function(target, dd, e, data){
var fly = Ext.fly(target);
if(fly && typeof fly.removeClass === 'function')
fly.removeClass('sort-target-hover');
},
onNodeOver: function(target, dd, e, data){
return Ext.dd.DropZone.prototype.dropAllowed;
},
onNodeDrop : function(target, dd, e, data){
var dragRec = dd.dragData.record,
dropRec = v.getRecord(target);
var i = dragRec.get('number'), j = dropRec.get('number');
dragRec.set('number', j);
dropRec.set('number', i);
v.getStore().sort('number', 'ASC');
return true;
}
});
}
}
});
},
newComboConfig: function(data) {
return {
store: Ext.create('Ext.data.Store', {
fields: ['display', 'value'],
data : data
}),
displayField: 'display',
valueField: 'value',
queryMode: 'local'
};
},
getSettingGrid : function() {
var me = this, config = {
store: Ext.create('Ext.data.Store', {
fields: ['display', 'value'],
data : [
{"display": '今天', "value": '今天'},
{"display": '昨天', "value": '昨天'},
{"display": '本月', "value": '本月'},
{"display": '上个月', "value": '上个月'},
{"display": '本年度', "value": '本年度'},
{"display": '上年度', "value": '上年度'},
{"display": '自定义', "value": '自定义'}
]
}),
displayField: 'display',
valueField: 'value',
queryMode: 'local'
};
var formatStore = new Ext.data.Store({
fields: ['display', 'value', 'type'],
data: [{
display: '0,000.00',
value: '0,000.00',
type: 'numbercolumn'
},{
display: '0,000.0000',
value: '0,000.0000',
type: 'numbercolumn'
},{
display: '0,000.000000',
value: '0,000.000000',
type: 'numbercolumn'
},{
display: '整数',
value: '0,000',
type: 'numbercolumn'
},{
display: '年-月-日',
value: 'Y-m-d',
type: 'datecolumn'
},{
display: '年-月-日 时:分:秒',
value: 'Y-m-d H:i:s',
type: 'datecolumn'
},{
display: '年-月',
value: 'Y-m',
type: 'datecolumn'
},{
display: '月-日 时:分',
value: 'm-d H:i',
type: 'datecolumn'
}]
});
return Ext.create('Ext.grid.Panel', {
id: 'grid-setting',
anchor: '100% 100%',
autoScroll : true,
cls: 'custom-grid',
border: false,
columnLines: true,
tbar: [{
text: '自定义公式',
iconCls: 'icon-fx',
handler: function(t) {
var g = t.ownerCt.ownerCt;
me.onFormulaClick(g.getStore(), null, function(formula){
g.store.add({
stg_text: '输入公式名称',
stg_use: true,
stg_field: 'COL_' + new Date().getTime(),
stg_formula: formula,
stg_width: 100,
stg_type: 'NUMBER',
stg_format: '0,000.00',
modeItems: []
});
g.selModel.select(g.store.last());
});
}
},{
text: '权限约束',
iconCls: 'icon-limit',
handler: function(t) {
var g = t.ownerCt.ownerCt;
me.onLimitClick(g.getStore(), g.limits, function(val){
g.limits = val;
});
}
},{
text: '排序设置',
iconCls: 'icon-sort',
handler: function(t) {
var g = t.ownerCt.ownerCt;
me.onSortClick(g.getStore(), g.sorts, function(sorts){
g.sorts = sorts;
g.down('#set-tab-info').setTooltip(me.getCodeTip({
sortSql: g.sorts
}));
});
}
},'->',{
xtype: 'textfield',
emptyText: 'SQL条件',
width: '66%',
id: 'st_condition'
}],
bbar: ['提示:1. 可以拖动数据字典的字段到右边;2. 字段可以拖放来调整顺序;3. 行展开设置特殊选项', '->', {
icon: basePath + 'resource/images/16/question.png',
cls: 'x-btn-icon',
text: '查看方案代码',
tooltip: '',
id: 'set-tab-info'
}],
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
dragGroup: 'grid-setting',
dropGroup: 'grid-setting'
},
listeners: {
drop: function(node, data, over) {
// 重新加载数据,防止出现checkcolumn的勾选错位情况
var newData = [];
if(over) {
over.store.each(function(record){
newData.push(record.data);
});
over.store.loadData(newData);
}
}
}
},
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners: {
beforeedit: function(editor, e, opts) {
if(e.column.dataIndex == 'stg_value') {
var isDate = ['datecolumn','datetimecolumn'].indexOf(e.record.get('type')) > -1,
isRadio = e.record.get('stg_mode') == 'radiogroup',
isMulti = ['checkboxgroup','combobox'].indexOf(e.record.get('stg_mode')) > -1,
items = e.record.get('modeItems');
if(isDate) {
e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(config, {
value: e.value
})));
} else if(isRadio) {
e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(me.newComboConfig(items), {
value: e.value
})));
} else if(isMulti) {
var _items = Ext.Array.merge([{display: '全选', value: '$ALL'}], items);
e.column.setEditor(new Ext.form.field.ComboBox(Ext.Object.merge(me.newComboConfig(_items), {
value: e.value
})));
} else {
e.column.setEditor(new Ext.form.field.Text({
value: e.value
}));
}
} else if(e.column.dataIndex == 'stg_format') {
formatStore.clearFilter(true);
formatStore.filter('type', e.record.get('type'));
}
}
}
}), {
ptype: 'rowexpander',
pluginId: 'rowexpander',
expandOnDblClick: false,
rowBodyTpl : [
'' +
'' +
'
' +
'
{stg_formula:this.formatFormula}
' +
'
' +
'' +
'
' +
'
' +
''+
'' +
'' +
'
' +
'
' +
'' +
'' +
' /> {dl_title}' +
'' +
'' +
'
' +
'
' +
'' +
'' +
'' +
'' +
'' +
'' +
'',
{
formatFormula: function(formula) {
var units = formula._split(/[\+\-\*\/%,\(\)]/), text = '', scope = this;
Ext.Array.each(units, function(unit){
if(!isNumber(unit) && (unit.indexOf('.') > 0 || unit.indexOf('COL_') == 0))
text += scope.getDesc(unit);
else
text += unit;
});
return text;
},
onFormulaEdit: function(elm) {
var store = this.owner.view.store, grid = this.owner.grid;
Ext.EventManager.on(elm, {
click: function(event, el) {
var record = grid.store.findRecord('stg_field', el.getAttribute('data-bind'));
me.onFormulaClick(store, record.get('stg_formula'), function(formula){
record.set('stg_formula', formula);
});
Ext.EventManager.stopEvent(event);
},
buffer: 50
});
},
getDesc: function(unit) {
var table = null, field = unit;
if(unit.indexOf('.') > 0) {
table = unit.substring(0, unit.indexOf('.'));
field = unit.substr(unit.indexOf('.')+1);
}
var res = this.owner.view.store.queryBy(function(record){
return record.get('stg_table') == table && record.get('stg_field') == field;
}), item = res.first();
if(item)
return item.get('stg_text');
return '';
},
linkEvent: function(eventName) {
var result = Ext.id();
Ext.defer(this.addListener, 1, this, [result, eventName]);
return result;
},
addListener: function(id, eventName) {
var elm = Ext.get(id);
elm && this[eventName].call(this, elm);
},
onModeChange: function(elm) {
var grid = this.owner.grid;
Ext.EventManager.on(elm, {
change: function(event, el) {
var record = grid.store.findRecord('stg_field', el.name);
record.set('stg_mode', el.value);
if(el.value && el.value != '') {
var items = record.get('modeItems');
if(!items || items.length == 0) {
record.set('modeItems', [{display: null,value:null}]);
}
}
Ext.EventManager.stopEvent(event);
},
buffer: 100
});
},
getViewItems: function(el) {
var p = el.parentNode.parentNode;
if(p) {
var gps = Ext.query('.mode-item', el.parentNode.parentNode), items = [];
Ext.Array.each(gps, function(els){
var e = els.childNodes, d = e[0].value, v = e[1].value;
v = (!v || v == '') ? d : v;
v = (!d || d == '') ? null : v;
items.push({display: d, value: v});
});
return items;
}
return null;
},
onModeItemAdd: function(elm) {
var grid = this.owner.grid, me = this;
Ext.EventManager.on(elm, {
click: function(event, el) {
var p = el.parentNode.parentNode;
if(p) {
var field = p.getAttribute('data-bind'),
record = grid.store.findRecord('stg_field', field),
items = me.getViewItems(el) || [];
items.push({
display: null,
value: null
});
record.set('modeItems', items);
}
Ext.EventManager.stopEvent(event);
},
buffer: 50
});
},
onModeItemDel: function(elm) {
var grid = this.owner.grid;
Ext.EventManager.on(elm, {
click: function(event, el) {
var p = el.parentNode.parentNode;
if(p) {
var field = p.getAttribute('data-bind'),
record = grid.store.findRecord('stg_field', field),
items = record.get('modeItems'), idx = Number(el.getAttribute('data-index')) - 1;
items.splice(idx, 1);
Ext.get(el.parentNode).remove();
record.set('modeItems', items);
}
Ext.EventManager.stopEvent(event);
}
});
},
onModeItemFocus: function(elm) {
var me = this;
Ext.EventManager.on(elm, {
mousedown: function(event, el) {
el.focus();
Ext.EventManager.stopEvent(event);
},
buffer: 100
});
Ext.EventManager.on(elm, {
blur: function(event, el) {
if(el.name == 'display') {
var nextEl = el.nextSibling;
if(Ext.isEmpty(el.value) || el.value == '') {
nextEl.value = null;
} else {
if(Ext.isEmpty(nextEl.value) || nextEl.value == '') {
nextEl.value = el.value;
}
}
}
},
change: function(event, el) {
var items = me.getViewItems(el);
if (items) {
var field = el.parentNode.parentNode.getAttribute('data-bind'),
grid = me.owner.grid,
record = grid.store.findRecord('stg_field', field);
record.set('modeItems', items);
}
},
buffer: 10
});
},
onLinkChange: function(elm) {
var grid = this.owner.grid;
Ext.EventManager.on(elm, {
change: function(event, el) {
var record = grid.store.findRecord('stg_field', el.getAttribute('data-bind')),
links = record.get('links'), dl = links[el.value - 1];
record.set('stg_link', dl.dl_link);
record.set('stg_tokentab1', dl.dl_tokentab1);
record.set('stg_tokencol1', dl.dl_tokencol1);
record.set('stg_tokentab2', dl.dl_tokentab1);
record.set('stg_tokencol2', dl.dl_tokencol2);
Ext.EventManager.stopEvent(event);
},
buffer: 100
});
}
}]
}],
store: new Ext.data.Store({
model: erp.model.SearchTemplate
}),
columns: [{
text: '列',
flex: 1,
columns: [{
text: '名称',
dataIndex: 'stg_text',
width: 180,
editor: {
xtype: 'textfield'
},
sortable: false,
renderer: function(val, meta, record){
var a = record.get('stg_table'), b = record.get('stg_field'),
c = record.get('stg_formula'), text = '';
a && (text += '表:' + a);
b && (text += ' 字段:' + b);
c && (text += ' 公式:' + c);
return '' + val + '';
}
},{
text: '是否
显示',
xtype: 'checkcolumn',
dataIndex: 'stg_use',
align: 'center',
headerCheckable: false,
width: 45,
sortable: false
},{
text: '宽度',
xtype: 'numbercolumn',
dataIndex: 'stg_width',
align: 'center',
width: 50,
format: '0,00',
editor: {
xtype: 'numberfield',
hideTrigger: true
},
sortable: false
},{
text: '格式转换',
dataIndex: 'stg_format',
align: 'center',
width: 90,
editor: {
xtype: 'combo',
store: formatStore,
displayField: 'display',
valueField: 'value',
queryMode: 'local'
},
sortable: false
}],
sortable: false
},{
text: '查询',
columns: [{
text: '用于
查询',
xtype: 'checkcolumn',
dataIndex: 'stg_query',
align: 'center',
width: 45,
sortable: false
},{
text: '多输
入框',
dataIndex: 'stg_double',
xtype: 'checkcolumn',
align: 'center',
width: 45,
sortable: false
},{
text: '带放
大镜',
dataIndex: 'stg_dbfind',
xtype: 'checkcolumn',
align: 'center',
width: 45,
sortable: false
},{
text: '默认值',
dataIndex: 'stg_value',
align: 'center',
flex: 1,
sortable: false,
editor: {
xtype: 'textfield'
}
}],
sortable: false
},{
text: '锁列',
dataIndex: 'stg_lock',
xtype: 'checkcolumn',
width: 40,
sortable: false
},{
text: '分组',
dataIndex: 'stg_group',
xtype: 'checkcolumn',
singleChecked: true,
width: 40,
sortable: false
},{
text: '合计',
dataIndex: 'stg_sum',
xtype: 'checkcolumn',
width: 40,
sortable: false
}]
});
},
getLimitForm: function(combo) {
return Ext.create('Ext.form.Panel', {
title: '选择字段,建立约束关系',
bodyStyle : 'background:#f1f2f5;padding:5px 5px 0',
items: [{
xtype:'fieldset',
title: '客户分配',
padding: '0 5 10 10',
name: '_L',
checkboxToggle: true,
collapsible: true,
collapsed: true,
defaultType: 'combobox',
defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
layout: 'column',
items :[Ext.Object.merge({
fieldLabel: '客户编号',
name: '_L_CU_1'
}, combo), {
xtype: 'displayfield',
value: '调取分配给你的客户的所有数据'
}, Ext.Object.merge({
fieldLabel: '业务员编号',
name: '_L_CU_2'
}, combo), {
xtype: 'displayfield',
value: '调取业务员是你的所有数据'
}],
getValue: function() {
var a = this.down('combo[name=_L_CU_1]').getValue(),
b = this.down('combo[name=_L_CU_2]').getValue();
return a ? 'CU(' + a + (b ? (',' + b) : '') + ')' : null;
}
}, {
xtype:'fieldset',
title: '供应商分配',
padding: '0 5 10 10',
name: '_L',
checkboxToggle: true,
collapsible: true,
collapsed: true,
defaultType: 'combobox',
defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
layout: 'column',
items :[Ext.Object.merge({
fieldLabel: '供应商编号',
name: '_L_VE_1'
}, combo), {
xtype: 'displayfield',
value: '调取分配给你的供应商的所有数据'
}, Ext.Object.merge({
fieldLabel: '采购员编号',
name: '_L_VE_2'
}, combo), {
xtype: 'displayfield',
value: '调取采购员是你的所有数据'
}],
getValue: function() {
var a = this.down('combo[name=_L_VE_1]').getValue(),
b = this.down('combo[name=_L_VE_2]').getValue();
return a && b ? 'VE(' + a + (b ? (',' + b) : '') + ')' : null;
}
}, {
xtype:'fieldset',
title: '个人',
padding: '0 5 10 10',
name: '_L',
checkboxToggle: true,
collapsible: true,
collapsed: true,
defaultType: 'combobox',
defaults: {columnWidth: .5, margin: '3 10 0 0', labelWidth: 80, editable: false},
layout: 'column',
items :[Ext.Object.merge({
fieldLabel: '个人编号',
name: '_L_EM_1'
}, combo)],
getValue: function() {
var a = this.down('combo[name=_L_EM_1]').getValue();
return a ? 'EM(' + a + ')' : null;
}
}]
});
},
/**
* 权限约束设置
*/
onLimitClick: function(source, oldLimits, callback) {
var me = this, win = me.limitwin, datas = [{display: '(无)', value: null}];
source.each(function(item){
if(item.get('stg_type').indexOf('VARCHAR2') == 0) {
datas.push({
display: item.get('stg_text'),
value: item.get('stg_table') + '.' + item.get('stg_field')
});
}
});
var combo = me.newComboConfig(datas);
if (!win) {
win = me.limitwin = Ext.create('Ext.window.Window', {
title : '权限约束设置',
closeAction : 'hide',
width : 500,
items : [me.getLimitForm(combo)],
buttonAlign : 'center',
buttons : [{
text : $I18N.common.button.erpConfirmButton,
height : 26,
handler : function(b) {
var w = b.ownerCt.ownerCt,
fs = w.down('form').down('fieldset[collapsed=false]'),
value = fs ? fs.getValue() : null;
callback && callback.call(me, value);
w.hide();
}
}, {
text : $I18N.common.button.erpCloseButton,
height : 26,
handler : function(b) {
b.ownerCt.ownerCt.hide();
}
}]
});
} else {
var coms = win.down('form').query('combobox');
Ext.Array.each(coms, function(com){
com.getStore().loadData(datas);
});
}
win.show();
var form = win.down('form');
if(oldLimits) {
if(oldLimits.indexOf('CU') == 0) {// 客户分配
var col1 = null, col2 = null;
if(oldLimits.indexOf(",") > -1) {
col1 = oldLimits.substring(3, oldLimits.indexOf(','));
col2 = oldLimits.substring(oldLimits.indexOf(',') + 1, oldLimits.lastIndexOf(')'));
} else {
col1 = oldLimits.substring(3, oldLimits.indexOf(')'));
}
form.down('combobox[name=_L_CU_1]').setValue(col1);
form.down('combobox[name=_L_CU_2]').setValue(col2);
form.down('combobox[name=_L_CU_1]').ownerCt.setExpanded(true);
} else if(oldLimits.indexOf('VE') == 0) {// 供应商分配
var col1 = null, col2 = null;
if(oldLimits.indexOf(",") > -1) {
col1 = oldLimits.substring(3, oldLimits.indexOf(','));
col2 = oldLimits.substring(oldLimits.indexOf(',') + 1, oldLimits.lastIndexOf(')'));
} else {
col1 = oldLimits.substring(3, oldLimits.indexOf(')'));
}
form.down('combobox[name=_L_VE_1]').setValue(col1);
form.down('combobox[name=_L_VE_2]').setValue(col2);
form.down('combobox[name=_L_VE_1]').ownerCt.setExpanded(true);
} else if(oldLimits.indexOf('EM') == 0) {// 个人
var col1 = oldLimits.substring(3, oldLimits.lastIndexOf(')'));
form.down('combobox[name=_L_EM_1]').setValue(col1);
form.down('combobox[name=_L_EM_1]').ownerCt.setExpanded(true);
}
} else {
var fs = form.down('fieldset[collapsed=false]');
fs && fs.setExpanded(false);
}
},
/**
* 公式设置用到的函数
*/
formula: function() {
var me = this;
me.formula_operator = [];
return {
log: function(oper, text, data, isfn) {
me.formula_operator.push({oper: oper, text: text, data: data, isfn: isfn});
},
getContainer: function(scope) {
return scope.up('form').down('fieldcontainer[cls~=x-screen]');
},
add: function(scope) {
var f = this.getContainer(scope);
f.add({text: scope.text, data: scope.data, isfn: scope.isfn});
if(scope.isfn) {
f.add({text: '('});
this.log(1, scope.text, null, true);
this.log(2, '(');
} else {
this.log(1, scope.text, scope.data);
}
},
del: function(scope) {
var f = this.getContainer(scope), l = f.down('button:last');
if (l) {
f.remove(l);
this.log(0, l.text, l.data, l.isfn);
}
},
back: function(scope) {
var f = this.getContainer(scope), len = me.formula_operator.length;
if(len > 0) {
var i = len - 1, o = me.formula_operator[i], oper = o.oper;
switch(oper) {
case 0:
f.add({text: o.text, data: o.data, isfn: o.isfn});
break;
case 1:
var b = f.down('button:last');
if(b && b.text == o.text)
f.remove(b);
break;
case 2:
var b = f.down('button:last');
if(b && b.text == o.text) {
f.remove(b);
f.remove(f.down('button:last'));
}
break;
case 3:
var j = 0;
for(;i > 0;i-- ) {
if(me.formula_operator[i].oper == 3) {
j = i;
} else {
break;
}
}
for(;j < len;j++ ) {
o = me.formula_operator[j];
f.add({text: o.text, data: o.data, isfn: o.isfn});
}
i++;
break;
}
me.formula_operator.splice(i);
}
},
clear: function(scope) {
var m = this, f = m.getContainer(scope), btns = f.query('button');
f.removeAll();
Ext.Array.each(btns, function(b){
m.log(3, b.text, b.data, b.isfn);
});
},
reset: function(scope, source, oldData) {
var f = this.getContainer(scope);
if(me.formula_operator.length > 0) {
f.removeAll();
f.add(f.initItems);
}
me.formula_operator = [];
}
};
},
getFormulaForm: function(source, oldData) {
var defItems = [], defBtns = "789/%456*(123-)0.+".split(""),
colItems = [], me = this, formula = me.formula();
defItems.push({
text: '←',
tooltip: '删除',
handler: function(btn) {
formula.del(btn);
}
});
defItems.push({
text: '→',
tooltip: '回退',
handler: function(btn) {
formula.back(btn);
}
});
defItems.push({text: ','});
defItems.push({
text: 'RE',
tooltip: '重置',
handler: function(btn) {
formula.reset(btn);
}
});
defItems.push({
text: 'CE',
tooltip: '清除',
handler: function(btn) {
formula.clear(btn);
}
});
Ext.Array.each(defBtns, function(b){
var o = {text: b};
if(b == '0')
o.columnWidth = .4;
defItems.push(o);
});
defItems.push({text: 'abs', isfn: true, tooltip: 'abs(x),返回x的绝对值'});
defItems.push({
text: 'round',
isfn: true,
columnWidth: .4,
tooltip: 'round(x,y),返回四舍五入到小数点右边y位的x值'
});
defItems.push({
text: 'floor',
isfn: true,
columnWidth: .4,
tooltip: 'floor(x)函数,返回小于或等于x的最大整数'
});
defItems.push({text: 'ceil', isfn: true, tooltip: 'ceil(x),返回大于或等于x的最小整数'});
source.each(function(item){
if(item.get('stg_type').indexOf('NUMBER') == 0 && item.get('stg_table')) {
colItems.push({
text: item.get('stg_text'),
data: item.data
});
}
});
var form = Ext.create('Ext.form.Panel', {
bodyStyle : 'background:#f1f2f5;padding:5px',
layout: 'vbox',
items: [{
xtype: 'fieldcontainer',
margin: '0 3 8 3',
width: '100%',
minHeight: 50,
cls: 'x-form-text x-screen',
defaultType: 'button',
defaults: {
margin: '0 0 3 0',
cls: 'x-btn-clear'
}
},{
xtype: 'container',
layout: 'hbox',
width: '100%',
defaultType: 'fieldcontainer',
defaults: {flex: 1},
items: [{
layout: 'column',
defaultType: 'button',
defaults: {
columnWidth: .2,
height: 30,
margin: '3 3 3 3'
},
items: defItems
},{
layout: 'column',
defaultType: 'button',
defaults: {
columnWidth: .5,
height: 30,
margin: '3 3 3 3'
},
items: colItems
}]
}]
});
var btns = form.query('button');
Ext.Array.each(btns, function(btn){
if(!btn.handler) {
btn.handler = function() {
formula.add(btn);
};
}
});
if(oldData) {
var container = form.down('fieldcontainer[cls~=x-screen]'),
items = me.getItemsFromFormula(source, oldData);
container.initItems = items;
container.add(items);
}
return form;
},
/**
* 解析表达式
*/
getItemsFromFormula: function(source, oldData) {
var sign = /[\+\-\*\/%,\(\)]/, units = oldData._split(sign), items = [],
fns = ['abs', 'ceil', 'floor', 'round'];
Ext.Array.each(units, function(unit){
if(isNumber(unit)) {
Ext.Array.each(unit.split(""), function(u){
items.push({text: u});
});
} else if(fns.indexOf(unit) > -1){
items.push({
text: unit,
isfn: true
});
} else if(sign.test(unit)) {
items.push({text: unit});
} else {
var table = null, field = unit;
if(unit.indexOf('.') > 0) {
table = unit.substring(0, unit.indexOf('.'));
field = unit.substr(unit.indexOf('.')+1);
}
var res = source.queryBy(function(record){
return record.get('stg_table') == table && record.get('stg_field') == field;
}), item = res.first();
if(item)
unit = item.get('stg_text');
items.push({
text: unit,
data: {stg_table: table, stg_field: field}
});
}
});
return items;
},
/**
* 自定义公式
*/
onFormulaClick: function(source, oldData, callback) {
var me = this;
var win = Ext.create('Ext.window.Window', {
title : '自定义公式',
closeAction: 'destroy',
width : 500,
items : [me.getFormulaForm(source, oldData)],
buttonAlign : 'center',
buttons : [{
text : $I18N.common.button.erpConfirmButton,
height : 26,
handler : function(b) {
var w = b.ownerCt.ownerCt,
items = w.query('fieldcontainer[cls~=x-screen] > button'),
text = '', test = '', d = 0.123;
Ext.Array.each(items, function(item){
if(item.data) {
text += item.data.stg_table + '.' + item.data.stg_field;
d = Math.pow(d, 2);
test += d;
} else {
text += item.text;
test += item.text;
}
});
try {
Ext.Test.eval(test);
callback && callback.call(me, text);
w.close();
} catch(e) {
Ext.example.msg('error', '错误', '您的公式有误,请检查并修改正确' +
'' +e + '
', 5000);
}
}
}, {
text : $I18N.common.button.erpCloseButton,
height : 26,
handler : function(b) {
var w = b.ownerCt.ownerCt;
w.close();
}
}]
});
win.show();
},
/**
* 生成form的字段
* 勾选、单选框
*/
createFormItems: function(source, oldData) {
var fields = [];
if(source) {
if(Ext.isArray(source)) {
Ext.Array.each(source, function(i){
if(i.stg_use == 1) {
var obj = {boxLabel : i.stg_text, inputValue : i.stg_field, table: i.stg_table};
if(oldData && Ext.Array.indexOf(oldData, i.stg_field) > -1)
obj.checked = true;
fields.push(obj);
}
});
} else {
source.each(function(i){
if(i.get('stg_use') == 1) {
var obj = {boxLabel : i.get('stg_text'), inputValue : i.get('stg_field'), table: i.get('stg_table')};
if(oldData && Ext.Array.indexOf(oldData, i.get('stg_field')) > -1)
obj.checked = true;
fields.push(obj);
}
});
}
} else {
var grid = this.getGrid().getView().normalGrid, columns = grid.headerCt.getGridColumns();
Ext.each(columns, function(){
if(!this.hidden && this.getWidth() > 0 && this.dataIndex) {
var obj = {boxLabel : this.text, inputValue : this.dataField, table: this.dataTable};
if(oldData && Ext.Array.indexOf(oldData, this.dataIndex) > -1)
obj.checked = true;
fields.push(obj);
}
});
}
return fields;
},
/**
* 生成form的字段
* 勾选、单选框
使用别名
*/
createAliaItems: function(oldData) {
var fields = [];
var grid = this.getGrid().getView().normalGrid, columns = grid.headerCt.getGridColumns();
Ext.each(columns, function(){
if(!this.hidden && this.getWidth() > 0 && this.dataIndex) {
var obj = {boxLabel : this.text, inputValue : this.dataIndex};
if(oldData && Ext.Array.indexOf(oldData, this.dataIndex) > -1)
obj.checked = true;
fields.push(obj);
}
});
return fields;
},
/**
*
*/
getAliaForm : function(type, itemId, oldData) {
var me = this;
return Ext.create('Ext.form.Panel', {
itemId : itemId,
autoScroll : true,
layout : 'column',
bodyStyle : 'background:#f1f2f5;',
defaults : {
xtype : type || 'radio',
name : 'gridfield',
columnWidth : .33,
margin : '3 3 3 10'
},
items : me.createAliaItems(oldData)
});
},
getGridForm : function(type, itemId, source, oldData) {
var me = this;
return Ext.create('Ext.form.Panel', {
itemId : itemId,
autoScroll : true,
layout : 'column',
bodyStyle : 'background:#f1f2f5;',
defaults : {
xtype : type || 'radio',
name : 'gridfield',
columnWidth : .33,
margin : '3 3 3 10'
},
items : me.createFormItems(source, oldData)
});
},
toogleGroup : function(f, b) {
if (!f) return;
var dx = null;
if (typeof f === 'string') {
dx = f;
} else {
var r = f.down('radio[value=true]');
if (r) {
dx = r.inputValue;
}
}
if (dx) {
var grid = this.getGrid(), c = grid.down('gridcolumn[dataIndex=' + dx + ']');
if(b) {
if(grid.store.groupField) {
var m = grid.down('gridcolumn[dataIndex=' + grid.store.groupField + ']');
if(m) {
m.summaryType = m.lastSummaryType;
m.summaryRenderer = m.lastSummaryRenderer;
}
}
if(typeof c.lastSummaryType === 'undefined') {
c.lastSummaryType = c.summaryType;
}
if(typeof c.lastSummaryRenderer === 'undefined') {
c.lastSummaryRenderer = c.summaryRenderer;
}
c.summaryType = 'count';
c.summaryRenderer = function(v) {
return '共(' + v + ')条';
};
grid.store.groupField = dx;
grid.store.group(dx, 'ASC');
} else {
c.summaryType = c.lastSummaryType;
c.summaryRenderer = c.lastSummaryRenderer;
var view = grid.lockedGrid.getView(), fe = view.getFeature('group');
if(fe) {
fe.disable();
view.refresh();
}
view = grid.normalGrid.getView(), fe = view.getFeature('group');
if(fe) {
fe.disable();
view.refresh();
}
var r = f.down('radio[value=true]');
if (r) {
r.setValue(false);
}
grid.store.groupField = null;
}
}
},
/**
* 锁定列
*/
onLock : function(form) {
var r = form.query('checkbox[value=true]');
var grid = this.getGrid(), normal = grid.getView().normalGrid;
Ext.Array.each(r, function(){
var column = normal.down('gridcolumn[dataIndex=' + this.inputValue + ']');
if (column.locked) {
grid.unlock(column);
} else {
grid.lock(column);
}
});
},
/**
* 取出排序设置
*/
getSortProperties : function(form, store) {
var r = form.query('checkbox[value=true]'), prop = [];
Ext.Array.each(r, function(c, i){
var obj = {
property: c.inputValue,
direction: 'ASC',
description: c.boxLabel,
number: i + 1,
table: c.table
};
if (store) {
var item = store.findRecord('property', c.inputValue);
if (item) {
obj.direction = item.get('direction');
}
}
prop.push(obj);
});
return prop;
},
/**
* 后台排序
*/
onSort : function(sorts) {
// var grid = this.getGrid().getView().normalGrid;
// grid.store.sort(this.getSortProperties(form));
},
/**
* 清除排序、分组等
*/
onClear : function() {
var grid = this.getGrid().getView().normalGrid;
grid.store.clearGrouping();
grid.store.clearFilter();
},
onTempLoad : function(fn) {
Ext.Ajax.request({
url: basePath + 'ma/search/temp/g.action',
params: {
caller: caller
},
callback: function(opt, s, res) {
var r = Ext.decode(res.responseText);
if(r.success && r.data) {
fn.call(null, r.data, r.lastId);
} else if(r.exceptionInfo) {
Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
}
}
});
},
addTemp : function(title, fn) {
var me = this;
var t = title || (me.BaseUtil.getActiveTab().title + '(' + em_name + ')' + Ext.Date.format(new Date(),'Y-m-d'));
var w = Ext.create('Ext.window.Window', {
width: 300,
height: 97,
title: '为方案命名',
layout: 'anchor',
items: [{
xtype: 'textfield',
allowBlank: false,
anchor: '100% 100%',
value: t
}],
buttonAlign: 'center',
buttons: [{
text : $I18N.common.button.erpConfirmButton,
height : 26,
handler : function(b) {
var w = b.ownerCt.ownerCt, f = w.down('textfield');
if(!Ext.isEmpty(f.getValue())) {
if(fn) {
fn.call(me, f.getValue());
} else {
var g = me.querywin.down('grid');
var r = g.store.add({st_id: 0, st_date: new Date().getTime(), st_man: em_name, st_title: f.getValue(), st_caller: caller});
if(r.length > 0) {
g.selModel.select(r[0]);
me.onTempSet(r[0], [], 0);
}
}
}
w.close();
}
}, {
text : $I18N.common.button.erpCloseButton,
height : 26,
handler : function(b) {
b.ownerCt.ownerCt.hide();
}
}]
});
w.show();
},
updateTemp : function(callback) {
var me = this, win = this.tempwin, g = win.down('#grid-setting'),
datas = new Array(), d, s = win.relativeId, i = 1,
c = g.down('#st_condition').getValue(),
sorts = g.sorts, limits = g.limits;
g.store.each(function(r){
d = r.data;
if(d.stg_use || d.stg_query || d.stg_group || d.stg_lock) {
d.stg_use = d.stg_use ? 1 : 0;
d.stg_query = d.stg_query ? 1 : 0;
d.stg_group = d.stg_group ? 1 : 0;
d.stg_lock = d.stg_lock ? 1 : 0;
d.stg_sum = d.stg_sum ? 1 : 0;
d.stg_double = d.stg_double ? 1 : 0;
d.stg_dbfind = d.stg_dbfind ? 1 : 0;
d.stg_stid = s;
d.stg_detno = i++;
delete d.text;
delete d.type;
delete d.links;
delete d.stg_alias;
if (d.modeItems) {
var validItems = [];
Ext.Array.each(d.modeItems, function(item, i){
if(item.display && item.display != '') {
item.num = validItems.length + 1;
item.st_id = s;
item.stg_field = d.stg_field;
item.value = (item.value == null || item.value == '') ?
item.display : item.value;
validItems.push(item);
}
});
d.modeItems = validItems;
}
datas.push(d);
}
});
var e = me.getRepeats(datas);
if(e) {
Ext.example.msg('error', '有重复选择的字段', e, 5000);
return;
}
if(s > 0) {
me.onTempUpdate(datas, c, sorts, limits, s, callback);
} else {
me.onTempSave(win.relativeRecord.get('st_title'), datas, c, sorts, limits, callback);
}
},
/**
* 判断是否有重复拖放过来的字段或重复的公式
*/
getRepeats: function(datas) {
var p = {}, k = null, e = '';
Ext.Array.each(datas, function(d, i){
k = d.stg_table + '.' + d.stg_field;
if(d.stg_formula)
k = d.stg_formula;
if(p[k])
e += '行' + (i + 1) + '的' + d.stg_text;
else
p[k] = true;
});
if(e.length > 0)
return e;
return null;
},
copyTemp: function(title, sourceId) {
if(sourceId) {
this.onTempCopy(title, sourceId);
} else {
var me = this, win = this.tempwin, g = win.down('#grid-setting'),
datas = new Array(), d, i = 1,
c = g.down('#st_condition').getValue(), sorts = g.sorts, limits = g.limits;
g.store.each(function(r){
d = r.data;
if(d.stg_use || d.stg_query || d.stg_group || d.stg_lock) {
d.stg_use = d.stg_use ? 1 : 0;
d.stg_query = d.stg_query ? 1 : 0;
d.stg_group = d.stg_group ? 1 : 0;
d.stg_lock = d.stg_lock ? 1 : 0;
d.stg_sum = d.stg_sum ? 1 : 0;
d.stg_double = d.stg_double ? 1 : 0;
d.stg_dbfind = d.stg_dbfind ? 1 : 0;
d.stg_stid = 0;
d.stg_detno = i++;
delete d.text;
delete d.type;
delete d.links;
delete d.stg_alias;
if (d.modeItems) {
var validItems = [];
Ext.Array.each(d.modeItems, function(item, i){
if(item.display && item.display != '') {
item.num = validItems.length + 1;
item.stg_field = d.stg_field;
item.value = (item.value == null || item.value == '') ?
item.display : item.value;
validItems.push(item);
}
});
d.modeItems = validItems;
}
datas.push(d);
}
});
me.onTempSave(title, datas, c, sorts, limits);
}
},
onTempUpdate : function(datas, condition, sorts, limits, id, callback) {
var me = this;
Ext.Ajax.request({
url: basePath + 'ma/search/temp/u.action',
params: {
sId: id,
caller: caller,
datas: Ext.encode(datas),
condition: condition,
sorts: sorts,
limits: limits
},
callback: function(opt, s, res) {
var r = Ext.decode(res.responseText);
if(r.success) {
callback && callback.call(me);
Ext.example.msg('info', '提示', '方案修改成功', 2000);
me.onTempLoad(function(data){
var temp = me.querywin.down('gridpanel[id=temp]'),
grid = me.querywin.down('grid');
temp.store.loadData(data);
if(data.length > 0) {
var r = temp.store.findRecord('st_id', id) || temp.store.last();
temp.selModel.select(r);
grid.setTitle(r.get('st_title'));
}
});
} else if(r.exceptionInfo) {
Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
}
}
});
},
onTempSave : function(title, datas, condition, sorts, limits, callback) {
var me = this;
Ext.Ajax.request({
url: basePath + 'ma/search/temp/s.action',
params: {
caller: caller,
title: title,
datas: Ext.encode(datas),
condition: condition,
sorts: sorts,
limits: limits
},
callback: function(opt, s, res) {
var r = Ext.decode(res.responseText);
if(r.success) {
callback && callback.call(me);
Ext.example.msg('info', '提示', '方案保存成功', 2000);
me.onTempLoad(function(data){
var temp = me.querywin.down('gridpanel[id=temp]'),
grid = me.querywin.down('grid');
temp.store.loadData(data);
if(data.length > 0) {
var r = temp.store.last();
temp.selModel.select(r);
grid.setTitle(r.get('st_title'));
}
});
} else if(r.exceptionInfo) {
Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
}
}
});
},
onTempCopy : function(title, id) {
var me = this;
Ext.Ajax.request({
url: basePath + 'ma/search/temp/c.action',
params: {
title: title,
sId: id
},
callback: function(opt, s, res) {
var r = Ext.decode(res.responseText);
if(r.success) {
Ext.example.msg('info', '提示', '方案复制成功', 2000);
me.onTempLoad(function(data){
var temp = me.querywin.down('gridpanel[id=temp]'),
grid = me.querywin.down('grid');
temp.store.loadData(data);
if(data.length > 0) {
var r = temp.store.last();
temp.selModel.select(r);
grid.setTitle(r.get('st_title'));
}
});
} else if(r.exceptionInfo) {
Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
}
}
});
},
onTempTitleChange: function(title, id, callback) {
var me = this;
Ext.Ajax.request({
url: basePath + 'ma/search/temp/t.action',
params: {
title: title,
sId: id
},
callback: function(opt, s, res) {
var r = Ext.decode(res.responseText);
if(r.success) {
Ext.example.msg('info', '提示', '修改成功', 2000);
callback && callback.call(me);
} else if(r.exceptionInfo) {
Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
}
}
});
},
onTempDel : function(id, fn) {
if(id > 0) {
Ext.Ajax.request({
url: basePath + 'ma/search/temp/d.action',
params: {
caller: caller,
sId: id
},
callback: function(opt, s, res) {
var r = Ext.decode(res.responseText);
if(r.success) {
fn.call();
} else if(r.exceptionInfo) {
Ext.example.msg('error', '失败', r.exceptionInfo, 5000);
}
}
});
} else {
fn.call();
}
},
/**
* 记录选择方案
*/
log : function() {
var grid = this.querywin.down('grid'), record = grid.selModel.lastSelected;
if (record) {
var id = record.get('st_id');
if(id && id > 0 ) {
Ext.Ajax.request({
url: basePath + 'ma/search/log.action',
params: {
caller: caller,
sId: id
},
callback: function(opt, s, res) {
var r = Ext.decode(res.responseText);
if(r.exceptionInfo) {
Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
}
}
});
}
}
},
/**
* 数据字典
*/
getDictionary: function(tableNames, callback) {
var me = this;
if(tableNames && tableNames != '') {
Ext.Ajax.request({
url: basePath + 'ma/getDataDictionaries.action',
params: {
tables: tableNames
},
callback: function(opt, s, res) {
var r = Ext.decode(res.responseText);
if(r.exceptionInfo) {
Ext.example.msg('error', '错误', r.exceptionInfo, 5000);
} else if(r.datas) {
callback.call(me, r.datas);
}
}
});
} else {
callback.call(me, []);
}
},
/**
* 重新加载数据
*/
loadNewStore : function(grid, params) {
var me = this;
grid.setLoading(true);
Ext.Ajax.request({
url : basePath + "common/search.action",
params: params,
method : 'post',
callback : function(opt, s, res){
grid.setLoading(false);
var r = Ext.decode(res.responseText);
if(r.datas) {
grid.store.loadData(r.datas);
me.getDataCount().update({count: r.datas.length});
me.getDataCount().show();
}
}
});
},
/**
* 导出excel
*/
exportExcel : function(grid, records, condition) {
var columns = grid.headerCt.getGridColumns(),
cm = new Array(), gf = grid.store.groupField;
Ext.Array.each(columns, function(c){
if(!c.hidden && (c.width > 0 || c.flex > 0) && !c.isCheckerHd) {
cm.push({
text: (Ext.isEmpty(c.text) ? ' ' : c.text.replace(/
/g, '\n')),
dataIndex: c.dataIndex,
width: c.width,
xtype: c.xtype,
format: c.format,
locked: c.locked,
summary: c.summaryType == 'sum',
group: c.dataIndex == gf
});
}
});
if (!Ext.fly('ext-grid-excel')) {
var frm = document.createElement('form');
frm.id = 'ext-grid-excel';
frm.name = frm.id;
frm.className = 'x-hidden';
document.body.appendChild(frm);
}
var record = records[0];
Ext.Ajax.request({
url: basePath + 'common/search/excel.xls',
method: 'post',
form: Ext.fly('ext-grid-excel'),
isUpload: true,
params: {
sId: record.get('st_id'),
condition: condition,
columns: unescape(Ext.encode(cm).replace(/\\/g,"%")),
sorts: record.get('st_sorts'),
title: record.get('st_title') + '----' + Ext.Date.format(new Date(), 'Y-m-d H:i:s')
}
});
},
/**
* 传入表名,获得表的关联sql
*/
getTabSql: function(tables, callback) {
var me = this;
Ext.Ajax.request({
url: basePath + 'ma/search/relation.action',
method : 'post',
params: {
tables: tables
},
callback : function(opt, s, res){
var r = Ext.decode(res.responseText);
if(r.data) {
callback && callback.call(me, r.data);
} else {
Ext.example.msg('error', '错误', '您选择的数据字典 ' + tables +
' 暂时还没有建立关联关系', 5000);
}
}
});
},
/**
* 行点击链接,打开单据界面
*/
onLinkClick: function(link, title) {
var args = encodeURI(Ext.Array.toArray(arguments, 2).join('-')).replace(/%/g,'-');
var tabPanel = this.getTabPanel(),
panel = tabPanel.down('#' + args);
// 出入库单据、工单、等按类型来获取caller,统一类型标志class
// 用于jsp页面一致,caller不同的
if(link.indexOf('class=') > -1) {
link += '&whoami=' + this.getCaller(this.getUrlParam(link, 'class'));
}
if (!panel) {
panel = tabPanel.add({
id : args,
title : title,
tag : 'iframe',
border : false,
layout : 'fit',
iconCls : 'x-tree-icon-tab-tab1',
html : '',
closable : true
});
}
tabPanel.setActiveTab(panel);
},
/**
* 主界面的tabPanel
*/
getTabPanel: function() {
var main = parent.Ext.getCmp("content-panel");
if (!main) {
main = parent.parent.Ext.getCmp("content-panel");
}
return main;
},
/**
* URL里面解析出参数值
*/
getUrlParam: function(url, param) {
var reg = new RegExp("(^|&)" + param + "=([^&]*)(&|$)"),
matchs = url.substr(url.indexOf('?') + 1).match(reg);
if (matchs)
return decodeURI(matchs[2]);
return null;
},
/**
* 按类型获取caller。用于出入库单等
*/
getCaller: function(cls) {
var call = null;
switch (cls) {
case '采购验收单':
call = 'ProdInOut!PurcCheckin';
break;
case '采购验退单':
call = 'ProdInOut!PurcCheckout';
break;
case '出货单':
call = 'ProdInOut!Sale';
break;
case '拨入单':
call = 'ProdInOut!AppropriationIn';
break;
case '销售拨出单':
call = 'ProdInOut!SaleAppropriationOut';
break;
case '销售退货单':
call = 'ProdInOut!SaleReturn';
break;
case '拨出单':
call = 'ProdInOut!AppropriationOut';
break;
case '不良品入库单':
call = 'ProdInOut!DefectIn';
break;
case '不良品出库单':
call = 'ProdInOut!DefectOut';
break;
case '委外领料单':
call = 'ProdInOut!OutsidePicking';
break;
case '委外退料单':
call = 'ProdInOut!OutsideReturn';
break;
case '委外验收单':
call = 'ProdInOut!OutsideCheckIn';
break;
case '委外验退单':
call = 'ProdInOut!OutesideCheckReturn';
break;
case '借货归还单':
call = 'ProdInOut!OutReturn';
break;
case '研发采购验收单':
call = 'ProdInOut!PurcCheckin!PLM';
break;
case '研发采购验退单':
call = 'ProdInOut!PurcCheckout!PLM';
break;
case '换货入库单':
call = 'ProdInOut!ExchangeIn';
break;
case '换货出库单':
call = 'ProdInOut!ExchangeOut';
break;
case '生产补料单':
call = 'ProdInOut!Make!Give';
break;
case '完工入库单':
call = 'ProdInOut!Make!In';
break;
case '生产退料单':
call = 'ProdInOut!Make!Return';
break;
case '生产报废单':
call = 'ProdInOut!Make!Useless';
break;
case '无订单出货单':
call = 'ProdInOut!NoSale';
break;
case '委外补料单':
call = 'ProdInOut!OSMake!Give';
break;
case '其它入库单':
call = 'ProdInOut!OtherIn';
break;
case '其它出库单':
call = 'ProdInOut!OtherOut';
break;
case '其它采购入库单':
call = 'ProdInOut!OtherPurcIn';
break;
case '其它采购出库单':
call = 'ProdInOut!OtherPurcOut';
break;
case '拆件入库单':
call = 'ProdInOut!PartitionStockIn';
break;
case '生产领料单':
call = 'ProdInOut!Picking';
break;
case '库存初始化':
call = 'ProdInOut!ReserveInitialize';
break;
case '借货出货单':
call = 'ProdInOut!SaleBorrow';
break;
case '销售拨入单':
call = 'ProdInOut!SalePutIn';
break;
case '盘亏调整单':
call = 'ProdInOut!StockLoss';
break;
case '盘盈调整单':
call = 'ProdInOut!StockProfit';
break;
case '报废单':
call = 'ProdInOut!StockScrap';
break;
case '研发退料单':
call = 'ProdInOut!YFIN';
break;
case '研发领料单':
call = 'ProdInOut!YFOUT';
break;
case 'MAKE':
call = 'Make!Base';
break;
case 'OS':
call = 'Make';
break;
case '采购收料单':
call = 'VerifyApply';
break;
case '委外收料单':
call = 'VerifyApply!OS';
break;
case '采购入库申请单':
call = 'VerifyApply';
break;
case '委外入库申请单':
call = 'VerifyApply!OS';
break;
case '冲应付款':
call = 'PayBalance!CAID';
break;
case '付款单':
call = 'PayBalance';
break;
case '应付款转销':
call = 'PayBalance!APRM';
break;
case '收款单':
call = 'RecBalance!PBIL';
break;
case '冲应收款':
call = 'RecBalance!IMRE';
break;
}
return call;
}
});