12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.common.Datalist', {
- extend: 'Ext.app.Controller',
- requires: ['erp.util.BaseUtil', 'erp.util.FormUtil', 'erp.util.RenderUtil'],
- views:[
- 'common.datalist.Viewport','common.datalist.GridPanel','common.datalist.Toolbar','core.button.VastAudit','core.button.VastDelete',
- 'core.button.VastPrint','core.button.VastReply','core.button.VastSubmit','core.button.ResAudit','core.form.FtField',
- 'core.grid.TfColumn','core.grid.YnColumn','core.trigger.DbfindTrigger','core.form.FtDateField','core.form.FtFindField',
- 'core.form.FtNumberField', 'core.form.MonthDateField','core.grid.NtColumn'
- ],
- init:function(){
- this.BaseUtil = Ext.create('erp.util.BaseUtil');
- this.FormUtil = Ext.create('erp.util.FormUtil');
- this.GridUtil = Ext.create('erp.util.GridUtil');
- this.control({
- 'erpDatalistGridPanel': {
- itemclick: this.onGridItemClick
- },
- 'erpVastDeleteButton': {
- click: function(btn){
- var dlwin = new Ext.window.Window({
- id : 'dlwin',
- title: btn.text,
- height: "100%",
- width: "80%",
- maximizable : true,
- buttonAlign : 'center',
- layout : 'anchor',
- items: [{
- tag : 'iframe',
- frame : true,
- anchor : '100% 100%',
- layout : 'fit',
- html : '<iframe id="iframe_dl_'+caller+'" src="'+basePath+'jsps/common/vastDatalist.jsp?urlcondition='+condition+'&whoami='+caller+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
- }],
- buttons : [{
- text: btn.text,
- iconCls: btn.iconCls,
- cls: 'x-btn-gray-1',
- handler: function(){
- }
- },{
- text : '关 闭',
- iconCls: 'x-button-icon-close',
- cls: 'x-btn-gray',
- handler : function(){
- Ext.getCmp('dlwin').close();
- }
- }]
- });
- dlwin.show();
- }
- },
- 'button[id=searchlist]': {
- click: function(){
- this.showSearchListWin();
- }
- },
- 'button[id=customize]': {
- click: function(){
- this.showCustomizeWin();
- }
- },
- 'dbfindtrigger[name=sl_label]': {
- afterrender: function(t){
- t.dbBaseCondition = 'sl_caller=\'' + caller + '\'';
- }
- }
- });
- },
- onGridItemClick: function(selModel, record){//grid行选择
- if(typeof parentDoc !== 'undefined' && parentDoc) {
- var doc = parent.Ext.getCmp(parentDoc);
- if(doc) {
- doc.fireEvent('itemselect', doc, record.data);
- }
- } else {
- if(keyField != null && keyField != ''){//有些datalist不需要打开明细表,这些表在datalist表里面不用配dl_keyField
- if(keyField.indexOf('+') > 0) {//多条件传入查询界面//vd_vsid@vd_id+vd_class@vd_class
- this.openQueryUrl(record);
- } else {
- this.openUrl(record);
- }
- }
- }
- },
- openUrl: function(record) {
- var me = this, value = record.data[keyField];
- var formCondition = keyField + "IS" + value;
- if(caller == 'BOMStep'){
- var valuePro = record.data['pr_id'];
- var valueCraft = record.data['cr_code'];
- var valueStep = record.data['cd_stepcode'];
- if(value == null || value == 0 || value == '0'){
- formCondition = 'pr_id' + "IS" + valuePro + ' and cr_code' + "IS'"+ valueCraft +"'"+' and cd_stepcode' + "IS'"+ valueStep +"'";
- }else{
- formCondition = 'pr_id' + "IS" + valuePro +' and cr_code' + "IS'"+ valueCraft +"'"+' and '+ keyField + "IS" + value +' and cd_stepcode' + "IS'"+ valueStep +"'";
- }
- }
- if(caller =='saleSnRule'){
- formCondition = keyField + "IS" + "'"+value+"' and sd_prodcode IS '"+record.data['sd_prodcode']+"'";
- }
- var gridCondition = pfField + "IS" + value;
- var newmaster = record.data['CURRENTMASTER'];
- if(!Ext.isEmpty(pfField) && pfField.indexOf('+') > -1) {//多条件传入维护界面//vd_vsid@vd_id+vd_class@vd_class
- var arr = pfField.split('+'),ff = [],k = [];
- Ext.Array.each(arr, function(r){
- ff = r.split('@');
- k.push(ff[0] + 'IS\'' + record.get(ff[1]) + '\'');
- });
- gridCondition = k.join(' AND ');
- }
- var panelId = caller + keyField + "_" + value + gridCondition;
- var panel = Ext.getCmp(panelId);
- var main = parent.Ext.getCmp("content-panel");
- if(!main){
- main = parent.parent.Ext.getCmp("content-panel");
- }
- if(!panel){
- var title = "";
- if (value.toString().length>4) {
- title = value.toString().substring(value.toString().length-4);
- } else {
- title = value;
- }
- var myurl = '';
- if(me.BaseUtil.contains(url, '?', true)){
- myurl = url + '&formCondition='+formCondition+'&gridCondition='+gridCondition;
- } else {
- myurl = url + '?formCondition='+formCondition+'&gridCondition='+gridCondition;
- }
- myurl += "&datalistId=" + main.getActiveTab().id;
- if( newmaster ){
- // myurl += "&newMaster=" + newmaster;
- var currentMaster = parent.window.sob;
- if ( currentMaster && currentMaster != newmaster) {// 与当前账套不一致
- me.openModalWin(newmaster, currentMaster, myurl);return;
- }
- }
- main.getActiveTab().currentStore = me.getCurrentStore(value);//用于单据翻页
- main.getActiveTab().currentRecord=record;
- if(main._mobile) {
- main.addPanel(me.BaseUtil.getActiveTab().title+'('+title+')', myurl, panelId);
- } else {
- panel = {
- title : me.BaseUtil.getActiveTab().title+'('+title+')',
- tag : 'iframe',
- tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'('+keyField + "=" + value+')'},
- border : false,
- layout : 'fit',
- iconCls : 'x-tree-icon-tab-tab1',
- html : '<iframe id="iframe_maindetail_'+caller+"_"+value+'" src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
- closable : true,
- listeners : {
- close : function(){
- if(!main){
- main = parent.parent.Ext.getCmp("content-panel");
- }
- main.setActiveTab(main.getActiveTab().id);
- }
- }
- };
- this.openTab(panel, panelId);
- }
- }else{
- main.setActiveTab(panel);
- }
- },
- openQueryUrl: function(record) {
- var me = this, arr = keyField.split('+'),ff = [],k = [];//vd_vsid@vd_id+vd_class@vd_class
- Ext.Array.each(arr, function(r){
- ff = r.split('@');
- var val = record.get(ff[1]);
- if(val instanceof Date)
- val = Ext.Date.format(val, 'Y-m-d');
- k.push(ff[0] + '=' + val);
- });
- var myurl = k.join('&');
- var panelId = caller + "_" + myurl;
- var panel = Ext.getCmp(panelId);
- var main = parent.Ext.getCmp("content-panel");
- if(!main){
- main = parent.parent.Ext.getCmp("content-panel");
- }
- if(!panel){
- var title = me.BaseUtil.getActiveTab().title + '-查询';
- if(contains(url, '?', true)){
- myurl = url + '&' + myurl;
- } else {
- myurl = url + '?' + myurl;
- }
- if (main._mobile) {
- main.addPanel(title, myurl, panelId);
- } else {
- panel = {
- title : title,
- tag : 'iframe',
- tabConfig: {tooltip: title},
- border : false,
- layout : 'fit',
- iconCls : 'x-tree-icon-tab-tab1',
- html : '<iframe src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
- closable : true,
- listeners : {
- close : function(){
- if(!main){
- main = parent.parent.Ext.getCmp("content-panel");
- }
- main.setActiveTab(main.getActiveTab().id);
- }
- }
- };
- this.openTab(panel, panelId);
- }
- } else {
- main.setActiveTab(panel);
- }
- },
- openTab : function (panel,id){
- var o = (typeof panel == "string" ? panel : id || panel.id);
- var main = parent.Ext.getCmp("content-panel");
- /*var tab = main.getComponent(o); */
- if(!main) {
- main =parent.parent.Ext.getCmp("content-panel");
- }
- var tab = main.getComponent(o);
- if (tab) {
- main.setActiveTab(tab);
- } else if(typeof panel!="string"){
- panel.id = o;
- var p = main.add(panel);
- main.setActiveTab(p);
- }
- },
- openModalWin: function(master, current, url) {
- if (parent.Ext) {
- Ext.Ajax.request({
- url: basePath + 'common/changeMaster.action',
- params: {
- to: master
- },
- callback: function(opt, s, r) {
- if (s) {
- var win = parent.Ext.create('Ext.Window', {
- width: '100%',
- height: '100%',
- draggable: false,
- closable: false,
- modal: true,
- id:'modalwindow',
- historyMaster:current,
- title: '创建到账套' + master + '的临时会话',
- html : '<iframe src="' + url + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
- buttonAlign: 'center',
- buttons: [{
- text: $I18N.common.button.erpCloseButton,
- cls: 'x-btn-blue',
- id: 'close',
- handler: function(b) {
- Ext.Ajax.request({
- url: basePath + 'common/changeMaster.action',
- params: {
- to: current
- },
- callback: function(opt, s, r) {
- if (s) {
- b.up('window').close();
- } else {
- alert('切换到原账套失败!');
- }
- }
- });
- }
- }]
- });
- win.show();
- } else {
- alert('无法创建到账套' + master + '的临时会话!');
- }
- }
- });
- }
- },
- getCurrentStore: function(value){
- var grid = Ext.getCmp('grid');
- var items = grid.store.data.items;
- var array = new Array();
- var o = null;
- Ext.each(items, function(item, index){
- o = new Object();
- o.selected = false;
- if(index == 0){
- o.prev = null;
- } else {
- o.prev = items[index-1].data[keyField];
- }
- if(index == items.length - 1){
- o.next = null;
- } else {
- o.next = items[index+1].data[keyField];
- }
- var v = item.data[keyField];
- o.value = v;
- if(v == value)
- o.selected = true;
- array.push(o);
- });
- return array;
- },
- showSearchListWin: function(){
- var me = this, win = this.searchWin;
- if (!win){
- win = this.searchWin = Ext.create('Ext.window.Window', {
- title: '高级查询',
- height: screen.height*0.7*0.8,
- width: screen.width*0.7*0.6,
- maximizable : true,
- closable: false,
- buttonAlign : 'center',
- layout : 'border',
- bodyStyle: 'background:#f1f1f1;',
- tools: [{
- type: 'close',
- handler: function(e, el, header, tool){
- tool.ownerCt.ownerCt.down('grid').setEffectData();//保留已选择的条件
- tool.ownerCt.ownerCt.hide();
- }
- }],
- items: [{
- xtype: 'form',
- region: 'north',
- layout: 'column',
- bodyStyle: 'background:#f1f1f1;',
- maxHeight: 100,
- buttonAlign: 'center',
- buttons: [{
- name: 'query',
- id: 'query',
- text: $I18N.common.button.erpQueryButton,
- iconCls: 'x-button-icon-query',
- cls: 'x-btn-gray',
- handler: function(btn){
- Ext.getCmp('grid').getCount(caller);
- btn.ownerCt.ownerCt.ownerCt.hide();
- }
- },{
- cls: 'x-btn-gray',
- text: '清空',
- handler: function(btn){
- btn.ownerCt.ownerCt.ownerCt.down('grid').store.loadData([{},{},{},{},{},{},{},{},{},{}]);
- Ext.getCmp('grid').getCount(caller);
- }
- },{
- cls: 'x-btn-gray',
- text: '关闭',
- handler: function(btn){
- btn.ownerCt.ownerCt.ownerCt.down('grid').setEffectData();
- btn.ownerCt.ownerCt.ownerCt.hide();
- }
- },{
- xtype: 'radio',
- name: 'separator',
- boxLabel: '与',
- checked: true,
- inputValue: 'AND',
- getCheckValue: function(){
- return this.checked ? 'AND' : 'OR';
- }
- },{
- xtype: 'radio',
- name: 'separator',
- boxLabel: '或',
- inputValue: 'OR'
- }]
- }, me.getSearchListGrid(), me.getTemplateForm() ]
- });
- Ext.getCmp('grid').searchGrid = win.down('grid');
- Ext.getCmp('grid').tempalteForm = win.down('form[name=template]');
- this.getTemplates(caller);
- }
- win.show();
- win.down('grid').loadData();
- },
- showCustomizeWin:function(){
- var me = this, win = this.CustomizeWin, grid = Ext.getCmp('grid');
- if(!win){
- var ablecolumns=new Array(),unselectcolumns=grid.basecolumns;
- Ext.Array.each(grid.columns,function(item){
- if(item.text && item.text.indexOf(' ')<0){
- ablecolumns.push(item);
- }
- });
- unselectcolumns.splice(0,ablecolumns.length);
- this.CustomizeWin=win = Ext.create('Ext.window.Window', {
- title: '<div align="center">个性设置</div>',
- height: screen.height*0.7,
- width: screen.width*0.7*0.9,
- layout:'border',
- closeAction:'hide',
- items:[{
- region:'center',
- layout:{
- type: 'hbox',
- align: 'stretch',
- padding: 5
- },
- defaults : { flex : 1 },
- items:[{
- xtype:'grid',
- multiSelect: true,
- id: 'fromgrid',
- title:'可选项',
- flex:0.7,
- cls: 'custom-grid',
- store:Ext.create('Ext.data.Store', {
- fields: [{name:'dataIndex',type:'string'},{name:'text',type:'string'},{name:'width',type:'number'}],
- data: unselectcolumns,
- filterOnLoad: false
- }),
- plugins: [Ext.create('erp.view.core.grid.HeaderFilter')],
- viewConfig: {
- plugins: {
- ptype: 'gridviewdragdrop',
- dragGroup: 'togrid',
- dropGroup: 'togrid'
- }
- },
- stripeRows: false,
- columnLines:true,
- columns:[{
- dataIndex:'dataIndex',
- cls :"x-grid-header-1",
- text:'字段名称',
- width:120,
- filter: {
- xtype : 'textfield'
- }
- },{
- dataIndex:'text',
- text:'描述',
- cls :"x-grid-header-1",
- flex:1,
- filter: {
- xtype : 'textfield'
- }
- },{
- dataIndex:'width',
- text:'宽度',
- width:60,
- cls :"x-grid-header-1",
- align:'right',
- editor: {
- xtype: 'numberfield',
- format:0
- },
- filter: {
- xtype : 'textfield'
- }
- }]
- },{
- xtype:'grid',
- multiSelect: true,
- id: 'togrid',
- stripeRows: true,
- columnLines:true,
- title:'显示项',
- store:Ext.create('Ext.data.Store', {
- fields: [{name:'dataIndex',type:'string'},{name:'text',type:'string'},{name:'width',type:'number'},
- {name:'orderby',type:'string'},{name:'priority',type:'string'}],
- data:ablecolumns,
- filterOnLoad: false
- }),
- necessaryField:'dataIndex',
- plugins: [Ext.create('erp.view.core.grid.HeaderFilter'),
- Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1
- })],
- viewConfig: {
- plugins: {
- ptype: 'gridviewdragdrop',
- dragGroup: 'togrid',
- dropGroup: 'togrid'
- }
- },
- columns:[{
- dataIndex:'dataIndex',
- text:'字段名称',
- cls :"x-grid-header-1",
- width:120,
- filter: {
- xtype : 'textfield'
- }
- },{
- dataIndex:'text',
- text:'描述',
- cls :"x-grid-header-1",
- flex:1,
- filter: {
- xtype : 'textfield'
- }
- },{
- dataIndex:'width',
- text:'宽度',
- width:60,
- xtype:'numbercolumn',
- align:'right',
- cls :"x-grid-header-1",
- filter: {
- xtype : 'textfield'
- },
- editable:true,
- format: '0',
- editor: {
- xtype: 'numberfield',
- hideTrigger: true
- },
- },
- {
- dataIndex:'orderby',
- text:'排序',
- width:60,
- xtype:'combocolumn',
- cls :"x-grid-header-1",
- filter: {
- xtype : 'textfield'
- },
- renderer:function(val){
- if(val=='ASC'){
- return '<img src="' + basePath + 'resource/images/16/up.png">' +
- '<span style="color:red;padding-left:2px">升序</span>';
- } else if(val=='DESC') {
- return '<img src="' + basePath + 'resource/images/16/down.png">' +
- '<span style="color:red;padding-left:2px">降序</span>';
- }
- },
- editor:{
- xtype:'combo',
- queryMode: 'local',
- displayField: 'display',
- valueField: 'value',
- store:Ext.create('Ext.data.Store', {
- fields: ['value', 'display'],
- data : [{value:"ASC", display:"升序"},
- {value:"DESC", display:"降序"}]
- })
- }
- },{
- dataIndex:'priority',
- text:'优先级',
- width:60,
- align:'right',
- cls :"x-grid-header-1",
- filter: {
- xtype : 'textfield'
- },
- editor:{
- xtype:'combo',
- queryMode: 'local',
- displayField: 'display',
- valueField: 'value',
- store:Ext.create('Ext.data.Store', {
- fields: ['value', 'display'],
- data : [{value:"1", display:"1"},
- {value:"2", display:"2"},
- {value:"3", display:"3"},
- {value:"4", display:"4"},
- {value:"5", display:"5"},
- {value:"6", display:"6"},
- {value:"7", display:"7"},
- {value:"8", display:"8"},
- {value:"9", display:"9"},]
- })
- }
- }]
- }]
- }],
- buttonAlign:'center',
- buttons:['->',{
- text:'重置',
- scope:this,
- handler:function(btn){
- warnMsg('重置列表将还原配置,确认重置吗?', function(btn){
- if(btn == 'yes'){
- Ext.Ajax.request({
- url : basePath + 'common/resetEmpsDataListDetails.action?_noc=1',
- params: {
- caller:caller
- },
- method : 'post',
- callback : function(options,success,response){
- var localJson = new Ext.decode(response.responseText);
- if(localJson.success){
- showMessage('提示','重置成功!',1000);
- window.location.reload();
- } else {
- if(localJson.exceptionInfo){
- var str = localJson.exceptionInfo;
- if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
- str = str.replace('AFTERSUCCESS', '');
- showError(str);
- } else {
- showError(str);return;
- }
- }
- }
- }
- });
- }
- });
- }
- },{
- style:'margin-left:5px;',
- text:'保存',
- scope:this,
- handler:function(btn){
- var grid=Ext.getCmp('togrid'),fromgrid=Ext.getCmp('fromgrid');
- var jsonGridData = new Array(),datas=new Array();
- var form = Ext.getCmp('form');
- grid.getStore().each(function(item){//将grid里面各行的数据获取并拼成jsonGridData
- var data = {
- dde_field:item.data.dataIndex,
- dde_width:item.data.width,
- dde_orderby:item.data.orderby,
- dde_priority:item.data.priority
- };
- item.dirty=false;
- jsonGridData.push(Ext.JSON.encode(data));
- datas.push(item.data);
- });
- Ext.Ajax.request({
- url : basePath + 'common/saveEmpsDataListDetails.action?_noc=1',
- params : {
- caller:caller,
- data:unescape(jsonGridData.toString())
- },
- method : 'post',
- callback : function(options,success,response){
- var localJson = new Ext.decode(response.responseText);
- if(localJson.success){
- showMessage('提示','保存成功!',1000);
- window.location.reload();
- }
- }
- });
-
- }
- },{
- style:'margin-left:5px;',
- text:'关闭',
- handler:function(btn){
- btn.ownerCt.ownerCt.hide();
- }
- },'->']
- });
- }
- win.show();
- },
- getFilterCondition: function(){
- var fields = Ext.getCmp('grid').plugins[0].fields;
- var items = new Array();
- Ext.each(Ext.Object.getKeys(fields), function(key){
- var item = fields[key];
- if(item.value != null && item.value.toString().trim() != ''){
- items.push({
- xtype: item.xtype,
- id: item.itemId,
- fieldLabel: item.fieldLabel,
- fieldStyle: item.fieldStyle,
- value: item.value,
- columnWidth: 0.5,
- cls: 'form-field-border',
- listeners: {
- change: function(f){
- Ext.getCmp(item.id).setValue(f.value);
- }
- }
- });
- }
- });
- return items;
- },
- getGridColumns : function() {
- var grid = Ext.getCmp('grid'), columns = grid.headerCt.getGridColumns(), data = [];
- Ext.each(columns, function(){
- if(this.dataIndex && this.getWidth() > 0) {
- data.push({
- display : this.text,
- value : this.text,
- column : this
- });
- }
- });
- return data;
- },
- getSearchListGrid: function(){
- var data = this.getGridColumns();
- var grid = Ext.create('Ext.grid.Panel', {
- maxHeight: 350,
- region: 'center',
- store: Ext.create('Ext.data.Store', {
- fields:[{
- name: 'sl_label',
- type: 'string'
- },{
- name: 'sl_field',
- type: 'string'
- },{
- name: 'sl_type',
- type: 'string'
- },{
- name: 'sl_dbfind',
- type: 'string'
- },{
- name: 'union',
- type: 'string'
- },{
- name: 'value'
- }],
- data: []
- }),
- columns: [{
- text: '条件',
- flex: 2,
- dataIndex: 'sl_label',
- editor: {
- xtype: 'combo',
- store : Ext.create('Ext.data.Store', {
- fields : [ 'display', 'value', 'column' ],
- data : data
- }),
- editable: false,
- displayField : 'display',
- valueField : 'value',
- queryMode : 'local'
- },
- renderer : function(val, meta, record, x, y, store, view) {
- if (val) {
- var column = view.ownerCt.headerCt.getHeaderAtIndex(y);
- if(column && typeof column.getEditor != 'undefined') {
- var editor = column.getEditor(record);
- if (editor && editor.lastSelection.length > 0) {
- var cm = editor.lastSelection[0].get('column'),
- field = cm.dataIndex;
- if (record.get('sl_field') != field)
- record.set('sl_field', field);
- var t = 'S';
- if(cm.xtype == 'datecolumn' || cm.xtype == 'datetimecolumn') {
- t = 'D';
- } else if(cm.xtype == 'numbercolumn') {
- t = 'N';
- }
- if (record.get('sl_type') != t)
- record.set('sl_type', t);
- }
- }
- } else {
- if (record.get('sl_field')) {
- record.set('sl_field', null);
- }
- }
- return val;
- },
- processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
- if (type == 'click' || type == 'dbclick') {
- return true;
- }
- return false;
- }
- },{
- text: '',
- hidden: true,
- dataIndex: 'sl_field',
- processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
- return false;
- }
- },{
- text: '',
- hidden: true,
- dataIndex: 'sl_type',
- processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
- return false;
- }
- },{
- text: '关系',
- flex: 1,
- dataIndex: 'union',
- xtype:'combocolumn',
- editor: {
- xtype: 'combo',
- store: Ext.create('Ext.data.Store', {
- fields: ['display', 'value'],
- data : [{"display": '等于', "value": '='},
- {"display": '大于', "value": '>'},
- {"display": '大于等于', "value": '>='},
- {"display": '小于', "value": '<'},
- {"display": '小于等于', "value": '<='},
- {"display": '不等于', "value": '<>'},
- {"display": '介于', "value": 'Between And'},
- {"display": '包含', "value": 'like'},
- {"display": '不包含', "value": 'not like'},
- {"display": '开头是', "value": 'begin like'},
- {"display": '开头不是', "value": 'begin not like'},
- {"display": '结尾是', "value": 'end like'},
- {"display": '结尾不是', "value": 'end not like'}]
- }),
- displayField: 'display',
- valueField: 'value',
- queryMode: 'local',
- editable: false,
- value: 'like'
- },
- /* renderer : function(v) {
- var r = v;
- switch(v) {
- case 'like':
- r = 'Like';break;
- case '=':
- r = '等于';break;
- case '>':
- r = '大于';break;
- case '>=':
- r = '大于等于';break;
- case '<':
- r = '小于';break;
- case '<=':
- r = '小于等于';break;
- case '<>':
- r = '不等于';break;
- case 'Between And':
- r = '介于';break;
- }
- return r;
- },*/
- processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
- if (type == 'click' || type == 'dbclick') {
- return true;
- }
- return false;
- }
- },{
- text: '值',
- flex: 3,
- dataIndex: 'value',
- renderer: function(val){
- if(Ext.isDate(val)){
- return Ext.Date.format(val, 'Y-m-d');
- }
- return val;
- },
- processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
- if (type == 'click' || type == 'dbclick') {
- var s = view.ownerCt.selModel, m = s.getSelection(), n = [];
- Ext.Array.each(m, function(){
- n.push(this);
- });
- n.push(view.ownerCt.store.getAt(recordIndex));
- s.select(n);
- return true;
- }
- return false;
- }
- }],
- columnLines: true,
- plugins: Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1,
- listeners: {
- beforeedit: function(e){
- if(e.field == 'value'){
- var record = e.record;
- var column = e.column;
- if(record.data['union'] == null || record.data['union'] == ''){
- record.set('union', 'like');
- }
- var f = record.data['sl_field'];
- switch(record.data['sl_type']){
- case 'D':
- switch(record.data['union']){
- case 'Between And':
- column.setEditor(new erp.view.core.form.FtDateField({
- id: f,
- name: f
- }));break;
- default:
- column.setEditor(new Ext.form.field.Date({
- id: f,
- name: f
- }));break;
- }
- break;
- case 'S':
- switch(record.data['union']){
- case 'Between And':
- column.setEditor(new erp.view.core.form.FtField({
- id: f,
- name: f,
- value: e.value
- }));break;
- default:
- column.setEditor(new Ext.form.field.Text({
- id: f,
- name: f
- }));break;
- }
- break;
- case 'N':
- switch(record.data['union']){
- case 'Between And':
- column.setEditor(new erp.view.core.form.FtNumberField({
- id: f,
- name: f
- }));break;
- default:
- column.setEditor(new Ext.form.field.Number({
- id: f,
- name: f
- }));break;
- }
- break;
- case 'T':
- column.dbfind = record.get('sl_dbfind');
- switch(record.data['union']){
- case 'Between And':
- column.setEditor(new erp.view.core.form.FtFindField({
- id: f,
- name: f
- }));break;
- default:
- column.setEditor(new erp.view.core.trigger.DbfindTrigger({
- id: f,
- name: f
- }));break;
- }
- break;
- default:
- column.setEditor(null);
- }
- }
- }
- }
- }),
- selModel: Ext.create('Ext.selection.CheckboxModel',{
- }),
- setEffectData: function(){
- var me = this;
- var datas = new Array();
- Ext.each(me.selModel.getSelection(), function(item){
- var data = item.data;
- if(!Ext.isEmpty(data.sl_label) && !Ext.isEmpty(data.union) && !Ext.isEmpty(data.value)){
- datas.push(data);
- }
- });
- me.effectdata = datas;
- },
- getEffectData: function(){
- return this.effectdata || new Array();
- },
- loadData: function(){
- if(!this.effectdata) {
- this.store.add([{},{},{},{},{},{},{},{},{},{}]);
- }
- },
- /**
- * 将数据拼成Sql条件语句
- */
- getCondition: function(){
- this.setEffectData();
- var condition = '';
- var separator = this.up('window').down('form').down('radio').getCheckValue();
- Ext.each(this.effectdata, function(data){
- if(data.union == 'Between And'){
- var v1 = data.value.split('~')[0];
- var v2 = data.value.split('~')[1];
- if(data.sl_type == 'D'){
- if(condition == ''){
- condition = '(' + data.sl_field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
- + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
- } else {
- condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
- + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
- }
- } else if(data.sl_type == 'N'){
- if(condition == ''){
- condition = '(' + data.sl_field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
- } else {
- condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
- }
- } else{
- if(condition == ''){
- condition = '(' + data.sl_field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
- } else {
- condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
- }
- }
- } else {
- if(data.sl_type == 'D'){
- var v = data.value, field = data.sl_field;
- if(Ext.isDate(v)) {
- v = Ext.Date.format(v, 'Y-m-d');
- }
- if(data.union == '<' || data.union == '<=' || data.union == '>' || data.union == '>='){
- v = "to_date('" + v + "','yyyy-MM-dd')";
- }else {
- v = Ext.Date.format(data.value, 'Ymd');
- field = "to_char(" + field + ",'yyyymmdd')";
- }
- if(condition == ''){
- condition = '(' + field + data.union + v + ') ';
- } else {
- condition += ' ' + separator +' (' + field + data.union + v + ') ';
- }
- } else {
- var v = data.value;
- if(data.union == 'like' || data.union=='not like'){
- v = " '%" + data.value + "%'";
- }else if(data.union =='begin like' || data.union =='begin not like'){
- v = " '" + data.value + "%'";
- data.union=data.union.substring(5);
- }else if(data.union =='end like' || data.union=='end not like'){
- v = " '%" + data.value + "'";
- data.union=data.union.substring(3);
- }else {
- v = " '" + data.value + "'";
- }
- if(condition == ''){
- condition = '(' + data.sl_field + " " + data.union + v + ") ";
- } else {
- condition += ' ' + separator +' (' + data.sl_field + " " + data.union + v + ") ";
- }
- }
- }
- });
- return condition;
- }
- });
- return grid;
- },
- getTemplateForm : function() {
- var me = this;
- return Ext.create('Ext.form.Panel', {
- minHeight : 150,
- region : 'south',
- layout : 'column',
- name : 'template',
- bodyStyle : 'background:#f1f2f5;',
- items : [{
- xtype : 'fieldcontainer',
- columnWidth : .75,
- defaults : {
- xtype : 'radio',
- flex : 1,
- margin : '5 0 5 15',
- labelAlign : 'right'
- },
- items : [{
- name : 'export-type',
- boxLabel : '全部列',
- checked : true
- }]
- }, {
- xtype : 'fieldcontainer',
- columnWidth : .25,
- items : [{
- xtype : 'button',
- cls : 'x-btn-gray',
- iconCls : 'x-button-icon-excel',
- flex : 1,
- margin : '15 0 5 0',
- width : 80,
- text : '导 出',
- handler : function(b) {
- var grid = Ext.getCmp('grid'),
- tb = grid.down('erpDatalistToolbar'),
- r = b.ownerCt.ownerCt.down('radio[checked=true]');
- if (r.fields)
- tb.exportData(grid, b, r.boxLabel, r.fields);
- else
- tb.exportData(grid, b);
- }
- }
- //已存在个性化设置列功能
- /*,{
- xtype : 'button',
- cls : 'x-btn-gray',
- flex : 1,
- margin : '5 0 10 0',
- width : 80,
- text : '新建模板',
- handler : function(b, e) {
- var grid = Ext.getCmp('grid');
- me.addTemplate(grid);
- }
- }*/
- ]
- }]
- });
- },
- /* addTemplate : function(grid) {
- var me = this, panel = grid.templatePanel;
- if (!panel) {
- var columns = grid.headerCt.getGridColumns(), data = [];
- Ext.each(columns, function(){
- if(this.dataIndex && this.getWidth() > 0) {
- data.push({
- boxLabel : this.text,
- inputValue : this.dataIndex,
- checked : true
- });
- }
- });
- data.push({
- columnWidth : .8,
- labelWidth : 60,
- fieldLabel : '描述',
- name : 'desc',
- xtype : 'textfield',
- allowBlank : false,
- value : this.BaseUtil.getActiveTab().title + '(模板)-' + em_name
- + '-' + Ext.Date.format(new Date(),'Ymd')
- });
- panel = grid.templatePanel = Ext.create('Ext.panel.Panel', {
- floating : true,
- shadow : 'frame',
- layout : 'column',
- width : 700,
- bodyStyle : 'background:#f1f2f5;z-index:9999;',
- defaults : {
- xtype : 'checkbox',
- margin : '5 5 15 15',
- columnWidth : .25
- },
- items : data,
- buttonAlign : 'center',
- buttons : [{
- text : '确认',
- handler : function(b) {
- var items = panel.query('checkbox[checked=true]'), fs = [];
- Ext.each(items, function(){
- fs.push(this.inputValue);
- });
- me.onTemplateAdd(panel, caller, fs.join(','), panel.down('textfield[name=desc]').value);
- }
- },{
- text : '取消',
- handler : function() {
- panel.hide();
- }
- }]
- });
- }
- panel.show();
- panel.center();
- },*/
- onTemplateAdd : function(panel, caller, fields, desc) {
- warnMsg('确定添加新模板:' + desc + '?', function(b){
- if (b == 'ok' || b == 'yes') {
- Ext.Ajax.request({
- url : basePath + 'common/template/save.action',
- params : {
- _noc : 1,
- caller : caller,
- fields : fields,
- desc : desc
- },
- callback : function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if (r.success) {
- alert('添加成功!');
- panel.hide();
- var form = Ext.getCmp('grid').tempalteForm;
- form.down('radio[value=true]').setValue(false);
- form.items.first().add({
- name : 'export-type',
- boxLabel : desc,
- fields : fields,
- checked : true
- });
- }
- }
- });
- }
- });
- },
- getTemplates : function(caller) {
- Ext.Ajax.request({
- url : basePath + 'common/getFieldsDatas.action',
- async: false,
- params: {
- caller: 'DataTemplate',
- fields: 'dt_desc,dt_fields',
- condition: 'dt_caller=\'' + caller + '\''
- },
- method : 'post',
- callback : function(opt, s, res){
- var r = new Ext.decode(res.responseText);
- if(r.exceptionInfo){
- showError(r.exceptionInfo);return;
- }
- if (r.success && r.data) {
- var f = [], dd = Ext.decode(r.data);
- if(dd.length > 0) {
- Ext.each(dd, function(){
- f.push({
- name : 'export-type',
- boxLabel : this.DT_DESC,
- fields : this.DT_FIELDS
- });
- });
- var form = Ext.getCmp('grid').tempalteForm;
- form.items.first().add(f);
- }
- }
- }
- });
- },
- indexOf: function(array, item, from) {
- if (supportsIndexOf) {
- return array.indexOf(item, from);
- }
- var i, length = array.length;
- for (i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++) {
- if (array[i] === item) {
- return i;
- }
- }
- return -1;
- },
- });
|