123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- Ext.define('erp.view.common.query.Form',{
- extend: 'Ext.form.Panel',
- alias: 'widget.erpQueryFormPanel',
- id: 'queryform',
- region: 'north',
- frame : true,
- layout : 'column',
- header: false,////不显示title
- autoScroll : true,
- defaultType : 'textfield',
- labelSeparator : ':',
- buttonAlign : 'center',
- fieldDefaults : {
- margin : '2 2 2 2',
- fieldStyle : "background:#FFFAFA;color:#515151;",
- labelAlign : "right",
- blankText : $I18N.common.form.blankText
- },
- FormUtil: Ext.create('erp.util.FormUtil'),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- prevTime:null,
- tbar: [{
- id:'query',
- name: 'query',
- text: $I18N.common.button.erpQueryButton,
- iconCls: 'x-button-icon-query',
- cls: 'x-btn-gray',
- handler: function(btn){
- //限制点击筛选时间间隔不能超过2秒
- var form=btn.ownerCt.ownerCt;
- if(form.prevTime==null){
- form.prevTime=new Date().getTime();
- form.onQuery();
- }else {
- var nowtime=new Date().getTime();
- if((nowtime-form.prevTime)/1000<2){
- showError('请控制筛选时间间隔不能小于2秒!');
- return;
- }else {
- form.prevTime=nowtime;
- form.onQuery();
- }
- }
-
- }
- }, '->', {
- name: 'export',
- text: $I18N.common.button.erpExportButton,
- iconCls: 'x-button-icon-excel',
- cls: 'x-btn-gray',
- handler: function(btn){
- var grid = Ext.getCmp('querygrid');
- if(grid.xtype == 'erpQueryGridPanel') {
- var condition = grid.defaultCondition || '';
- condition = btn.ownerCt.ownerCt.spellCondition(condition);
- if(Ext.isEmpty(condition)) {
- condition = grid.emptyCondition || '1=1';
- }
- grid.BaseUtil.createExcel(caller, 'detailgrid', condition);
- } else if(grid.xtype == 'erpDatalistGridPanel') {
- var condition = grid.getCondition() || '';
- condition = btn.ownerCt.ownerCt.spellCondition(condition);
- if(Ext.isEmpty(condition)) {
- condition = '1=1';
- }
- if(typeof grid.getCondition === 'function') {
- condition += ' and ' + grid.getCondition();
- }
- grid.BaseUtil.createExcel(caller, 'datalist', condition);
- } else {
- btn.ownerCt.ownerCt.BaseUtil.exportGrid(grid);
- }
- }
- }, '-',{
- name: 'refresh',
- text: $I18N.common.button.erpRefreshButton,
- iconCls: 'x-button-icon-check',
- cls: 'x-btn-gray'
- }, {
- text: $I18N.common.button.erpCloseButton,
- iconCls: 'x-button-icon-close',
- cls: 'x-btn-gray',
- id:'close',
- handler: function(){
- var main = parent.Ext.getCmp("content-panel");
- main.getActiveTab().close();
- }
- }],
- initComponent : function(){
- this.getItemsAndButtons();
- this.callParent(arguments);
- this.addKeyBoardEvents();
- },
- onQuery: function() {
- var grid = Ext.getCmp('querygrid');
- if(!grid){
- grid = Ext.getCmp('grid');
- }
- var form = this;
- var condition = grid.defaultCondition || '';
- condition = form.spellCondition(condition);
- if(Ext.isEmpty(condition)) {
- condition = grid.emptyCondition || '1=1';
- }
- form.beforeQuery(caller, condition);//鎵ц鏌ヨ鍓嶉�杈�
- var gridParam = {caller: caller, condition: condition, start: 1, end: getUrlParam('_end')||1000};
- grid.GridUtil.loadNewStore(grid, gridParam);
- },
- spellCondition: function(condition){
- var form = this;
- Ext.each(form.items.items, function(f){
- if(f.logic != null && f.logic != ''){
- if(f.xtype == 'checkbox' && f.value == true){
- if(condition == ''){
- condition += f.logic;
- } else {
- condition += ' AND ' + f.logic;
- }
- } else if(f.xtype == 'datefield' && f.value != null){
- var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
- if(condition == ''){
- condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
- } else {
- condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
- }
- } else if(f.xtype == 'datetimefield' && f.value != null){
- var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
- if(condition == ''){
- condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
- } else {
- condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
- }
- } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
- if(condition == ''){
- condition += f.logic + '=' + f.value;
- } else {
- condition += ' AND ' + f.logic + '=' + f.value;
- }
- } else if(f.xtype == 'yeardatefield' && f.value != null && f.value != ''){
- if(condition == ''){
- condition += f.logic + '=' + f.value;
- } else {
- condition += ' AND ' + f.logic + '=' + f.value;
- }
- }else if(f.xtype == 'combo' && f.value == '$ALL'){
- if(f.store.data.length > 1) {
- if(condition == ''){
- condition += '(';
- } else {
- condition += ' AND (';
- }
- var _a = '';
- f.store.each(function(d, idx){
- if(d.data.value != '$ALL') {
- if(_a == ''){
- _a += f.logic + "='" + d.data.value + "'";
- } else {
- _a += ' OR ' + f.logic + "='" + d.data.value + "'";
- }
- }
- });
- condition += _a + ')';
- }
- } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
- if(condition == ''){
- condition += f.logic + ' in (' ;
- } else {
- condition += ' AND ' + f.logic + ' in (';
- }
- var str=f.value,constr="";
- for(var i=0;i<str.split("#").length;i++){
- if(i<str.split("#").length-1){
- constr+="'"+str.split("#")[i]+"',";
- }else constr+="'"+str.split("#")[i]+"'";
- }
- condition +=constr+")";
- }else if(f.xtype=='condatehourminutefieldq' && f.firstValue != null && f.firstValue != '' && f.secondvalue != null && f.secondvalue != ''){
- var v1 = Ext.Date.format(new Date(f.firstValue), 'Y-m-d H:i:s');
- var v2 = Ext.Date.format(new Date(f.secondvalue), 'Y-m-d H:i:s');
- if(condition == ''){
- condition += f.logic + " BETWEEN to_date('" + v1+ "','yyyy-MM-dd HH24:mi:ss') AND to_date('"
- +v2+"','yyyy-MM-dd HH24:mi:ss')";
- } else {
- condition += ' AND ' + f.logic + " BETWEEN to_date('" + v1+ "','yyyy-MM-dd HH24:mi:ss') AND to_date('"
- +v2+"','yyyy-MM-dd HH24:mi:ss')";
- }
-
- } else {
- if(f.value != null && f.value != ''){
- var val = String(f.value);
- if(contains(val, 'BETWEEN', true) && contains(val, 'AND', true)){
- if(condition == ''){
- condition += f.logic + " " + f.value;
- } else {
- condition += ' AND (' + f.logic + " " + f.value + ")";
- }
- } else if(f.logic == 'ym_view_param') {
- if(condition == ''){
- condition += " " + f.value;
- } else {
- condition += ' AND (' + f.value + ")";
- }
- } else if(contains(val, '||', true)){
- var str = '';
- Ext.each(f.value.split('||'), function(v){
- if(v != null && v != ''){
- if(str == ''){
- str += f.logic + "='" + v + "'";
- } else {
- str += ' OR ' + f.logic + "='" + v + "'";
- }
- }
- });
- if(condition == ''){
- condition += str;
- } else {
- condition += ' AND (' + str + ")";
- }
- } else {
- if(f.value)f.value=f.value.replace(/\'/g,"''");
- if(val.indexOf('%') >= 0) {
- if(condition == ''){
- condition += f.logic + " like '" + f.value + "'";
- } else {
- condition += ' AND (' + f.logic + " like '" + f.value + "')";
- }
- } else {
- if(f.logic=='CONDITION'){
- if(condition == ''){
- condition += f.value ;
- } else {
- condition += ' AND ' + f.value;
- }
- }else{
- if(condition == ''){
- condition += f.logic + "='" + f.value + "'";
- } else {
- condition += ' AND (' + f.logic + "='" + f.value + "')";
- }
- }
-
- }
- }
- }
- }
- }
- });
- return condition;
- },
- _noc: 0,
- getItemsAndButtons: function(){
- var me = this;
- this.setLoading(true);
- Ext.Ajax.request({//鎷垮埌form鐨刬tems
- url : basePath + 'common/singleFormItems.action',
- params: {
- caller: caller,
- condition: '',
- _noc: (getUrlParam('_noc') || me._noc)
- },
- method : 'post',
- callback : function(options,success,response){
- me.setLoading(false);
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo != null){
- showError(res.exceptionInfo);return;
- }
- me.fo_keyField = res.fo_keyField;
- me.tablename = res.tablename;
- me.fo_id=res.fo_id;
- if(res.keyField){
- me.keyField = res.keyField;
- }
- if(res.dealUrl){
- me.dealUrl = res.dealUrl;
- }
- me.fo_detailMainKeyField = res.fo_detailMainKeyField;
- Ext.each(res.items, function(item){
- if(screen.width < 1280){//鏍规嵁灞忓箷瀹藉害锛岃皟鏁村垪鏄剧ず瀹藉害
- if(item.columnWidth > 0 && item.columnWidth <= 0.25){
- item.columnWidth = 1/3;
- } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
- item.columnWidth = 2/3;
- } else if(item.columnWidth >= 1){
- item.columnWidth = 1;
- }
- } else {
- if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
- item.columnWidth = 2/3;
- }
- }
- if(item.xtype == 'hidden') {
- item.columnWidth = 0;
- }
- });
- me.add(res.items);
- me.fireEvent('alladded', me);
- //瑙f瀽buttons瀛楃涓诧紝骞舵嫾鎴恓son鏍煎紡
- var buttonString = res.buttons;
- if(buttonString != null && buttonString != ''){
- if(contains(buttonString, '#', true)){
- Ext.each(buttonString.split('#'), function(b, index){
- if(!Ext.getCmp(b)){
- var btn = Ext.getCmp('erpVastDealButton');
- if(btn){
- btn.ownerCt.insert(2, {
- xtype: b
- });
- }
- } else {
- Ext.getCmp(b).show();
- }
- });
- } else {
- if(Ext.getCmp(buttonString)){
- Ext.getCmp(buttonString).show();
- } else {
- var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
- if(btn){
- btn.setText($I18N.common.button[buttonString]);
- btn.show();
- }
- }
- }
- }
- }
- });
- },
- /**
- * 监听一些事件
- * <br>
- * Ctrl+Alt+S 单据配置维护
- * Ctrl+Alt+P 参数、逻辑配置维护
- */
- addKeyBoardEvents: function(){
- var me = this;
- Ext.EventManager.addListener(document.body, 'keydown', function(e){
- if(e.altKey && e.ctrlKey) {
- if(e.keyCode == Ext.EventObject.S) {
- var url = "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id + "&gridCondition=fd_foidIS" + me.fo_id,
- forms = Ext.ComponentQuery.query('form'),
- grids = Ext.ComponentQuery.query('gridpanel'),
- formSet = [], gridSet = [];
- if(forms.length > 0) {
- Ext.Array.each(forms, function(f){
- f.fo_id && (formSet.push(f.fo_id));
- });
- }
- if(grids.length > 0) {
- Ext.Array.each(grids, function(g){
- if(g.xtype.indexOf('erpQueryGridPanel') > -1)
- gridSet.push(window.caller);
- else if(g.caller)
- gridSet.push(g.caller);
- });
- }
- if(formSet.length > 0 || gridSet.length > 0) {
- url = "jsps/ma/multiform.jsp?formParam=" + formSet.join(',') + '&gridParam=' + gridSet.join(',');
- }
- me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', url);
- } else if(e.keyCode == Ext.EventObject.P) {
- me.FormUtil.onAdd('configs-' + caller, '逻辑配置维护(' + caller + ')', "jsps/ma/logic/config.jsp?whoami=" + caller);
- }
- }
- });
- },
- beforeQuery: function(call, cond) {
- Ext.Ajax.request({
- url: basePath + 'common/form/beforeQuery.action',
- params: {
- caller: call,
- condition: cond
- },
- async: false,
- callback: function(opt, s, r) {
- var rs = Ext.decode(r.responseText);
- if(rs.exceptionInfo) {
- showError(rs.exceptionInfo);
- }
- }
- });
- }
- });
|