Datalist.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.Datalist', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil', 'erp.util.FormUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'common.datalist.Viewport','common.datalist.GridPanel','common.datalist.Toolbar','core.button.VastAudit','core.button.VastDelete',
  7. 'core.button.VastPrint','core.button.VastReply','core.button.VastSubmit','core.button.ResAudit','core.form.FtField',
  8. 'core.grid.TfColumn','core.grid.YnColumn','core.trigger.DbfindTrigger','core.form.FtDateField','core.form.FtFindField',
  9. 'core.form.FtNumberField', 'core.form.MonthDateField','core.grid.NtColumn'
  10. ],
  11. init:function(){
  12. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  13. this.FormUtil = Ext.create('erp.util.FormUtil');
  14. this.GridUtil = Ext.create('erp.util.GridUtil');
  15. this.control({
  16. 'erpDatalistGridPanel': {
  17. itemclick: this.onGridItemClick
  18. },
  19. 'erpVastDeleteButton': {
  20. click: function(btn){
  21. var dlwin = new Ext.window.Window({
  22. id : 'dlwin',
  23. title: btn.text,
  24. height: "100%",
  25. width: "80%",
  26. maximizable : true,
  27. buttonAlign : 'center',
  28. layout : 'anchor',
  29. items: [{
  30. tag : 'iframe',
  31. frame : true,
  32. anchor : '100% 100%',
  33. layout : 'fit',
  34. 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>'
  35. }],
  36. buttons : [{
  37. text: btn.text,
  38. iconCls: btn.iconCls,
  39. cls: 'x-btn-gray-1',
  40. handler: function(){
  41. }
  42. },{
  43. text : '关 闭',
  44. iconCls: 'x-button-icon-close',
  45. cls: 'x-btn-gray',
  46. handler : function(){
  47. Ext.getCmp('dlwin').close();
  48. }
  49. }]
  50. });
  51. dlwin.show();
  52. }
  53. },
  54. 'button[id=searchlist]': {
  55. click: function(){
  56. this.showSearchListWin();
  57. }
  58. },
  59. 'button[id=customize]': {
  60. click: function(){
  61. this.showCustomizeWin();
  62. }
  63. },
  64. 'dbfindtrigger[name=sl_label]': {
  65. afterrender: function(t){
  66. t.dbBaseCondition = 'sl_caller=\'' + caller + '\'';
  67. }
  68. }
  69. });
  70. },
  71. onGridItemClick: function(selModel, record){//grid行选择
  72. if(typeof parentDoc !== 'undefined' && parentDoc) {
  73. var doc = parent.Ext.getCmp(parentDoc);
  74. if(doc) {
  75. doc.fireEvent('itemselect', doc, record.data);
  76. }
  77. } else {
  78. if(keyField != null && keyField != ''){//有些datalist不需要打开明细表,这些表在datalist表里面不用配dl_keyField
  79. if(keyField.indexOf('+') > 0) {//多条件传入查询界面//vd_vsid@vd_id+vd_class@vd_class
  80. this.openQueryUrl(record);
  81. } else {
  82. this.openUrl(record);
  83. }
  84. }
  85. }
  86. },
  87. openUrl: function(record) {
  88. var me = this, value = record.data[keyField];
  89. var formCondition = keyField + "IS" + value;
  90. if(caller == 'BOMStep'){
  91. var valuePro = record.data['pr_id'];
  92. var valueCraft = record.data['cr_code'];
  93. var valueStep = record.data['cd_stepcode'];
  94. if(value == null || value == 0 || value == '0'){
  95. formCondition = 'pr_id' + "IS" + valuePro + ' and cr_code' + "IS'"+ valueCraft +"'"+' and cd_stepcode' + "IS'"+ valueStep +"'";
  96. }else{
  97. formCondition = 'pr_id' + "IS" + valuePro +' and cr_code' + "IS'"+ valueCraft +"'"+' and '+ keyField + "IS" + value +' and cd_stepcode' + "IS'"+ valueStep +"'";
  98. }
  99. }
  100. if(caller =='saleSnRule'){
  101. formCondition = keyField + "IS" + "'"+value+"' and sd_prodcode IS '"+record.data['sd_prodcode']+"'";
  102. }
  103. var gridCondition = pfField + "IS" + value;
  104. var newmaster = record.data['CURRENTMASTER'];
  105. if(!Ext.isEmpty(pfField) && pfField.indexOf('+') > -1) {//多条件传入维护界面//vd_vsid@vd_id+vd_class@vd_class
  106. var arr = pfField.split('+'),ff = [],k = [];
  107. Ext.Array.each(arr, function(r){
  108. ff = r.split('@');
  109. k.push(ff[0] + 'IS\'' + record.get(ff[1]) + '\'');
  110. });
  111. gridCondition = k.join(' AND ');
  112. }
  113. var panelId = caller + keyField + "_" + value + gridCondition;
  114. var panel = Ext.getCmp(panelId);
  115. var main = parent.Ext.getCmp("content-panel");
  116. if(!main){
  117. main = parent.parent.Ext.getCmp("content-panel");
  118. }
  119. if(!panel){
  120. var title = "";
  121. if (value.toString().length>4) {
  122. title = value.toString().substring(value.toString().length-4);
  123. } else {
  124. title = value;
  125. }
  126. var myurl = '';
  127. if(me.BaseUtil.contains(url, '?', true)){
  128. myurl = url + '&formCondition='+formCondition+'&gridCondition='+gridCondition;
  129. } else {
  130. myurl = url + '?formCondition='+formCondition+'&gridCondition='+gridCondition;
  131. }
  132. myurl += "&datalistId=" + main.getActiveTab().id;
  133. if( newmaster ){
  134. // myurl += "&newMaster=" + newmaster;
  135. var currentMaster = parent.window.sob;
  136. if ( currentMaster && currentMaster != newmaster) {// 与当前账套不一致
  137. me.openModalWin(newmaster, currentMaster, myurl);return;
  138. }
  139. }
  140. main.getActiveTab().currentStore = me.getCurrentStore(value);//用于单据翻页
  141. main.getActiveTab().currentRecord=record;
  142. if(main._mobile) {
  143. main.addPanel(me.BaseUtil.getActiveTab().title+'('+title+')', myurl, panelId);
  144. } else {
  145. panel = {
  146. title : me.BaseUtil.getActiveTab().title+'('+title+')',
  147. tag : 'iframe',
  148. tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'('+keyField + "=" + value+')'},
  149. border : false,
  150. layout : 'fit',
  151. iconCls : 'x-tree-icon-tab-tab1',
  152. html : '<iframe id="iframe_maindetail_'+caller+"_"+value+'" src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  153. closable : true,
  154. listeners : {
  155. close : function(){
  156. if(!main){
  157. main = parent.parent.Ext.getCmp("content-panel");
  158. }
  159. main.setActiveTab(main.getActiveTab().id);
  160. }
  161. }
  162. };
  163. this.openTab(panel, panelId);
  164. }
  165. }else{
  166. main.setActiveTab(panel);
  167. }
  168. },
  169. openQueryUrl: function(record) {
  170. var me = this, arr = keyField.split('+'),ff = [],k = [];//vd_vsid@vd_id+vd_class@vd_class
  171. Ext.Array.each(arr, function(r){
  172. ff = r.split('@');
  173. var val = record.get(ff[1]);
  174. if(val instanceof Date)
  175. val = Ext.Date.format(val, 'Y-m-d');
  176. k.push(ff[0] + '=' + val);
  177. });
  178. var myurl = k.join('&');
  179. var panelId = caller + "_" + myurl;
  180. var panel = Ext.getCmp(panelId);
  181. var main = parent.Ext.getCmp("content-panel");
  182. if(!main){
  183. main = parent.parent.Ext.getCmp("content-panel");
  184. }
  185. if(!panel){
  186. var title = me.BaseUtil.getActiveTab().title + '-查询';
  187. if(contains(url, '?', true)){
  188. myurl = url + '&' + myurl;
  189. } else {
  190. myurl = url + '?' + myurl;
  191. }
  192. if (main._mobile) {
  193. main.addPanel(title, myurl, panelId);
  194. } else {
  195. panel = {
  196. title : title,
  197. tag : 'iframe',
  198. tabConfig: {tooltip: title},
  199. border : false,
  200. layout : 'fit',
  201. iconCls : 'x-tree-icon-tab-tab1',
  202. html : '<iframe src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  203. closable : true,
  204. listeners : {
  205. close : function(){
  206. if(!main){
  207. main = parent.parent.Ext.getCmp("content-panel");
  208. }
  209. main.setActiveTab(main.getActiveTab().id);
  210. }
  211. }
  212. };
  213. this.openTab(panel, panelId);
  214. }
  215. } else {
  216. main.setActiveTab(panel);
  217. }
  218. },
  219. openTab : function (panel,id){
  220. var o = (typeof panel == "string" ? panel : id || panel.id);
  221. var main = parent.Ext.getCmp("content-panel");
  222. /*var tab = main.getComponent(o); */
  223. if(!main) {
  224. main =parent.parent.Ext.getCmp("content-panel");
  225. }
  226. var tab = main.getComponent(o);
  227. if (tab) {
  228. main.setActiveTab(tab);
  229. } else if(typeof panel!="string"){
  230. panel.id = o;
  231. var p = main.add(panel);
  232. main.setActiveTab(p);
  233. }
  234. },
  235. openModalWin: function(master, current, url) {
  236. if (parent.Ext) {
  237. Ext.Ajax.request({
  238. url: basePath + 'common/changeMaster.action',
  239. params: {
  240. to: master
  241. },
  242. callback: function(opt, s, r) {
  243. if (s) {
  244. var win = parent.Ext.create('Ext.Window', {
  245. width: '100%',
  246. height: '100%',
  247. draggable: false,
  248. closable: false,
  249. modal: true,
  250. id:'modalwindow',
  251. historyMaster:current,
  252. title: '创建到账套' + master + '的临时会话',
  253. html : '<iframe src="' + url + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  254. buttonAlign: 'center',
  255. buttons: [{
  256. text: $I18N.common.button.erpCloseButton,
  257. cls: 'x-btn-blue',
  258. id: 'close',
  259. handler: function(b) {
  260. Ext.Ajax.request({
  261. url: basePath + 'common/changeMaster.action',
  262. params: {
  263. to: current
  264. },
  265. callback: function(opt, s, r) {
  266. if (s) {
  267. b.up('window').close();
  268. } else {
  269. alert('切换到原账套失败!');
  270. }
  271. }
  272. });
  273. }
  274. }]
  275. });
  276. win.show();
  277. } else {
  278. alert('无法创建到账套' + master + '的临时会话!');
  279. }
  280. }
  281. });
  282. }
  283. },
  284. getCurrentStore: function(value){
  285. var grid = Ext.getCmp('grid');
  286. var items = grid.store.data.items;
  287. var array = new Array();
  288. var o = null;
  289. Ext.each(items, function(item, index){
  290. o = new Object();
  291. o.selected = false;
  292. if(index == 0){
  293. o.prev = null;
  294. } else {
  295. o.prev = items[index-1].data[keyField];
  296. }
  297. if(index == items.length - 1){
  298. o.next = null;
  299. } else {
  300. o.next = items[index+1].data[keyField];
  301. }
  302. var v = item.data[keyField];
  303. o.value = v;
  304. if(v == value)
  305. o.selected = true;
  306. array.push(o);
  307. });
  308. return array;
  309. },
  310. showSearchListWin: function(){
  311. var me = this, win = this.searchWin;
  312. if (!win){
  313. win = this.searchWin = Ext.create('Ext.window.Window', {
  314. title: '高级查询',
  315. height: screen.height*0.7*0.8,
  316. width: screen.width*0.7*0.6,
  317. maximizable : true,
  318. closable: false,
  319. buttonAlign : 'center',
  320. layout : 'border',
  321. bodyStyle: 'background:#f1f1f1;',
  322. tools: [{
  323. type: 'close',
  324. handler: function(e, el, header, tool){
  325. tool.ownerCt.ownerCt.down('grid').setEffectData();//保留已选择的条件
  326. tool.ownerCt.ownerCt.hide();
  327. }
  328. }],
  329. items: [{
  330. xtype: 'form',
  331. region: 'north',
  332. layout: 'column',
  333. bodyStyle: 'background:#f1f1f1;',
  334. maxHeight: 100,
  335. buttonAlign: 'center',
  336. buttons: [{
  337. name: 'query',
  338. id: 'query',
  339. text: $I18N.common.button.erpQueryButton,
  340. iconCls: 'x-button-icon-query',
  341. cls: 'x-btn-gray',
  342. handler: function(btn){
  343. Ext.getCmp('grid').getCount(caller);
  344. btn.ownerCt.ownerCt.ownerCt.hide();
  345. }
  346. },{
  347. cls: 'x-btn-gray',
  348. text: '清空',
  349. handler: function(btn){
  350. btn.ownerCt.ownerCt.ownerCt.down('grid').store.loadData([{},{},{},{},{},{},{},{},{},{}]);
  351. Ext.getCmp('grid').getCount(caller);
  352. }
  353. },{
  354. cls: 'x-btn-gray',
  355. text: '关闭',
  356. handler: function(btn){
  357. btn.ownerCt.ownerCt.ownerCt.down('grid').setEffectData();
  358. btn.ownerCt.ownerCt.ownerCt.hide();
  359. }
  360. },{
  361. xtype: 'radio',
  362. name: 'separator',
  363. boxLabel: '与',
  364. checked: true,
  365. inputValue: 'AND',
  366. getCheckValue: function(){
  367. return this.checked ? 'AND' : 'OR';
  368. }
  369. },{
  370. xtype: 'radio',
  371. name: 'separator',
  372. boxLabel: '或',
  373. inputValue: 'OR'
  374. }]
  375. }, me.getSearchListGrid(), me.getTemplateForm() ]
  376. });
  377. Ext.getCmp('grid').searchGrid = win.down('grid');
  378. Ext.getCmp('grid').tempalteForm = win.down('form[name=template]');
  379. this.getTemplates(caller);
  380. }
  381. win.show();
  382. win.down('grid').loadData();
  383. },
  384. showCustomizeWin:function(){
  385. var me = this, win = this.CustomizeWin, grid = Ext.getCmp('grid');
  386. if(!win){
  387. var ablecolumns=new Array(),unselectcolumns=grid.basecolumns;
  388. Ext.Array.each(grid.columns,function(item){
  389. if(item.text && item.text.indexOf('&#160')<0){
  390. ablecolumns.push(item);
  391. }
  392. });
  393. unselectcolumns.splice(0,ablecolumns.length);
  394. this.CustomizeWin=win = Ext.create('Ext.window.Window', {
  395. title: '<div align="center">个性设置</div>',
  396. height: screen.height*0.7,
  397. width: screen.width*0.7*0.9,
  398. layout:'border',
  399. closeAction:'hide',
  400. items:[{
  401. region:'center',
  402. layout:{
  403. type: 'hbox',
  404. align: 'stretch',
  405. padding: 5
  406. },
  407. defaults : { flex : 1 },
  408. items:[{
  409. xtype:'grid',
  410. multiSelect: true,
  411. id: 'fromgrid',
  412. title:'可选项',
  413. flex:0.7,
  414. cls: 'custom-grid',
  415. store:Ext.create('Ext.data.Store', {
  416. fields: [{name:'dataIndex',type:'string'},{name:'text',type:'string'},{name:'width',type:'number'}],
  417. data: unselectcolumns,
  418. filterOnLoad: false
  419. }),
  420. plugins: [Ext.create('erp.view.core.grid.HeaderFilter')],
  421. viewConfig: {
  422. plugins: {
  423. ptype: 'gridviewdragdrop',
  424. dragGroup: 'togrid',
  425. dropGroup: 'togrid'
  426. }
  427. },
  428. stripeRows: false,
  429. columnLines:true,
  430. columns:[{
  431. dataIndex:'dataIndex',
  432. cls :"x-grid-header-1",
  433. text:'字段名称',
  434. width:120,
  435. filter: {
  436. xtype : 'textfield'
  437. }
  438. },{
  439. dataIndex:'text',
  440. text:'描述',
  441. cls :"x-grid-header-1",
  442. flex:1,
  443. filter: {
  444. xtype : 'textfield'
  445. }
  446. },{
  447. dataIndex:'width',
  448. text:'宽度',
  449. width:60,
  450. cls :"x-grid-header-1",
  451. align:'right',
  452. editor: {
  453. xtype: 'numberfield',
  454. format:0
  455. },
  456. filter: {
  457. xtype : 'textfield'
  458. }
  459. }]
  460. },{
  461. xtype:'grid',
  462. multiSelect: true,
  463. id: 'togrid',
  464. stripeRows: true,
  465. columnLines:true,
  466. title:'显示项',
  467. store:Ext.create('Ext.data.Store', {
  468. fields: [{name:'dataIndex',type:'string'},{name:'text',type:'string'},{name:'width',type:'number'},
  469. {name:'orderby',type:'string'},{name:'priority',type:'string'}],
  470. data:ablecolumns,
  471. filterOnLoad: false
  472. }),
  473. necessaryField:'dataIndex',
  474. plugins: [Ext.create('erp.view.core.grid.HeaderFilter'),
  475. Ext.create('Ext.grid.plugin.CellEditing', {
  476. clicksToEdit: 1
  477. })],
  478. viewConfig: {
  479. plugins: {
  480. ptype: 'gridviewdragdrop',
  481. dragGroup: 'togrid',
  482. dropGroup: 'togrid'
  483. }
  484. },
  485. columns:[{
  486. dataIndex:'dataIndex',
  487. text:'字段名称',
  488. cls :"x-grid-header-1",
  489. width:120,
  490. filter: {
  491. xtype : 'textfield'
  492. }
  493. },{
  494. dataIndex:'text',
  495. text:'描述',
  496. cls :"x-grid-header-1",
  497. flex:1,
  498. filter: {
  499. xtype : 'textfield'
  500. }
  501. },{
  502. dataIndex:'width',
  503. text:'宽度',
  504. width:60,
  505. xtype:'numbercolumn',
  506. align:'right',
  507. cls :"x-grid-header-1",
  508. filter: {
  509. xtype : 'textfield'
  510. },
  511. editable:true,
  512. format: '0',
  513. editor: {
  514. xtype: 'numberfield',
  515. hideTrigger: true
  516. },
  517. },
  518. {
  519. dataIndex:'orderby',
  520. text:'排序',
  521. width:60,
  522. xtype:'combocolumn',
  523. cls :"x-grid-header-1",
  524. filter: {
  525. xtype : 'textfield'
  526. },
  527. renderer:function(val){
  528. if(val=='ASC'){
  529. return '<img src="' + basePath + 'resource/images/16/up.png">' +
  530. '<span style="color:red;padding-left:2px">升序</span>';
  531. } else if(val=='DESC') {
  532. return '<img src="' + basePath + 'resource/images/16/down.png">' +
  533. '<span style="color:red;padding-left:2px">降序</span>';
  534. }
  535. },
  536. editor:{
  537. xtype:'combo',
  538. queryMode: 'local',
  539. displayField: 'display',
  540. valueField: 'value',
  541. store:Ext.create('Ext.data.Store', {
  542. fields: ['value', 'display'],
  543. data : [{value:"ASC", display:"升序"},
  544. {value:"DESC", display:"降序"}]
  545. })
  546. }
  547. },{
  548. dataIndex:'priority',
  549. text:'优先级',
  550. width:60,
  551. align:'right',
  552. cls :"x-grid-header-1",
  553. filter: {
  554. xtype : 'textfield'
  555. },
  556. editor:{
  557. xtype:'combo',
  558. queryMode: 'local',
  559. displayField: 'display',
  560. valueField: 'value',
  561. store:Ext.create('Ext.data.Store', {
  562. fields: ['value', 'display'],
  563. data : [{value:"1", display:"1"},
  564. {value:"2", display:"2"},
  565. {value:"3", display:"3"},
  566. {value:"4", display:"4"},
  567. {value:"5", display:"5"},
  568. {value:"6", display:"6"},
  569. {value:"7", display:"7"},
  570. {value:"8", display:"8"},
  571. {value:"9", display:"9"},]
  572. })
  573. }
  574. }]
  575. }]
  576. }],
  577. buttonAlign:'center',
  578. buttons:['->',{
  579. text:'重置',
  580. scope:this,
  581. handler:function(btn){
  582. warnMsg('重置列表将还原配置,确认重置吗?', function(btn){
  583. if(btn == 'yes'){
  584. Ext.Ajax.request({
  585. url : basePath + 'common/resetEmpsDataListDetails.action?_noc=1',
  586. params: {
  587. caller:caller
  588. },
  589. method : 'post',
  590. callback : function(options,success,response){
  591. var localJson = new Ext.decode(response.responseText);
  592. if(localJson.success){
  593. showMessage('提示','重置成功!',1000);
  594. window.location.reload();
  595. } else {
  596. if(localJson.exceptionInfo){
  597. var str = localJson.exceptionInfo;
  598. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  599. str = str.replace('AFTERSUCCESS', '');
  600. showError(str);
  601. } else {
  602. showError(str);return;
  603. }
  604. }
  605. }
  606. }
  607. });
  608. }
  609. });
  610. }
  611. },{
  612. style:'margin-left:5px;',
  613. text:'保存',
  614. scope:this,
  615. handler:function(btn){
  616. var grid=Ext.getCmp('togrid'),fromgrid=Ext.getCmp('fromgrid');
  617. var jsonGridData = new Array(),datas=new Array();
  618. var form = Ext.getCmp('form');
  619. grid.getStore().each(function(item){//将grid里面各行的数据获取并拼成jsonGridData
  620. var data = {
  621. dde_field:item.data.dataIndex,
  622. dde_width:item.data.width,
  623. dde_orderby:item.data.orderby,
  624. dde_priority:item.data.priority
  625. };
  626. item.dirty=false;
  627. jsonGridData.push(Ext.JSON.encode(data));
  628. datas.push(item.data);
  629. });
  630. Ext.Ajax.request({
  631. url : basePath + 'common/saveEmpsDataListDetails.action?_noc=1',
  632. params : {
  633. caller:caller,
  634. data:unescape(jsonGridData.toString())
  635. },
  636. method : 'post',
  637. callback : function(options,success,response){
  638. var localJson = new Ext.decode(response.responseText);
  639. if(localJson.success){
  640. showMessage('提示','保存成功!',1000);
  641. window.location.reload();
  642. }
  643. }
  644. });
  645. }
  646. },{
  647. style:'margin-left:5px;',
  648. text:'关闭',
  649. handler:function(btn){
  650. btn.ownerCt.ownerCt.hide();
  651. }
  652. },'->']
  653. });
  654. }
  655. win.show();
  656. },
  657. getFilterCondition: function(){
  658. var fields = Ext.getCmp('grid').plugins[0].fields;
  659. var items = new Array();
  660. Ext.each(Ext.Object.getKeys(fields), function(key){
  661. var item = fields[key];
  662. if(item.value != null && item.value.toString().trim() != ''){
  663. items.push({
  664. xtype: item.xtype,
  665. id: item.itemId,
  666. fieldLabel: item.fieldLabel,
  667. fieldStyle: item.fieldStyle,
  668. value: item.value,
  669. columnWidth: 0.5,
  670. cls: 'form-field-border',
  671. listeners: {
  672. change: function(f){
  673. Ext.getCmp(item.id).setValue(f.value);
  674. }
  675. }
  676. });
  677. }
  678. });
  679. return items;
  680. },
  681. getGridColumns : function() {
  682. var grid = Ext.getCmp('grid'), columns = grid.headerCt.getGridColumns(), data = [];
  683. Ext.each(columns, function(){
  684. if(this.dataIndex && this.getWidth() > 0) {
  685. data.push({
  686. display : this.text,
  687. value : this.text,
  688. column : this
  689. });
  690. }
  691. });
  692. return data;
  693. },
  694. getSearchListGrid: function(){
  695. var data = this.getGridColumns();
  696. var grid = Ext.create('Ext.grid.Panel', {
  697. maxHeight: 350,
  698. region: 'center',
  699. store: Ext.create('Ext.data.Store', {
  700. fields:[{
  701. name: 'sl_label',
  702. type: 'string'
  703. },{
  704. name: 'sl_field',
  705. type: 'string'
  706. },{
  707. name: 'sl_type',
  708. type: 'string'
  709. },{
  710. name: 'sl_dbfind',
  711. type: 'string'
  712. },{
  713. name: 'union',
  714. type: 'string'
  715. },{
  716. name: 'value'
  717. }],
  718. data: []
  719. }),
  720. columns: [{
  721. text: '条件',
  722. flex: 2,
  723. dataIndex: 'sl_label',
  724. editor: {
  725. xtype: 'combo',
  726. store : Ext.create('Ext.data.Store', {
  727. fields : [ 'display', 'value', 'column' ],
  728. data : data
  729. }),
  730. editable: false,
  731. displayField : 'display',
  732. valueField : 'value',
  733. queryMode : 'local'
  734. },
  735. renderer : function(val, meta, record, x, y, store, view) {
  736. if (val) {
  737. var column = view.ownerCt.headerCt.getHeaderAtIndex(y);
  738. if(column && typeof column.getEditor != 'undefined') {
  739. var editor = column.getEditor(record);
  740. if (editor && editor.lastSelection.length > 0) {
  741. var cm = editor.lastSelection[0].get('column'),
  742. field = cm.dataIndex;
  743. if (record.get('sl_field') != field)
  744. record.set('sl_field', field);
  745. var t = 'S';
  746. if(cm.xtype == 'datecolumn' || cm.xtype == 'datetimecolumn') {
  747. t = 'D';
  748. } else if(cm.xtype == 'numbercolumn') {
  749. t = 'N';
  750. }
  751. if (record.get('sl_type') != t)
  752. record.set('sl_type', t);
  753. }
  754. }
  755. } else {
  756. if (record.get('sl_field')) {
  757. record.set('sl_field', null);
  758. }
  759. }
  760. return val;
  761. },
  762. processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
  763. if (type == 'click' || type == 'dbclick') {
  764. return true;
  765. }
  766. return false;
  767. }
  768. },{
  769. text: '',
  770. hidden: true,
  771. dataIndex: 'sl_field',
  772. processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
  773. return false;
  774. }
  775. },{
  776. text: '',
  777. hidden: true,
  778. dataIndex: 'sl_type',
  779. processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
  780. return false;
  781. }
  782. },{
  783. text: '关系',
  784. flex: 1,
  785. dataIndex: 'union',
  786. xtype:'combocolumn',
  787. editor: {
  788. xtype: 'combo',
  789. store: Ext.create('Ext.data.Store', {
  790. fields: ['display', 'value'],
  791. data : [{"display": '等于', "value": '='},
  792. {"display": '大于', "value": '>'},
  793. {"display": '大于等于', "value": '>='},
  794. {"display": '小于', "value": '<'},
  795. {"display": '小于等于', "value": '<='},
  796. {"display": '不等于', "value": '<>'},
  797. {"display": '介于', "value": 'Between And'},
  798. {"display": '包含', "value": 'like'},
  799. {"display": '不包含', "value": 'not like'},
  800. {"display": '开头是', "value": 'begin like'},
  801. {"display": '开头不是', "value": 'begin not like'},
  802. {"display": '结尾是', "value": 'end like'},
  803. {"display": '结尾不是', "value": 'end not like'}]
  804. }),
  805. displayField: 'display',
  806. valueField: 'value',
  807. queryMode: 'local',
  808. editable: false,
  809. value: 'like'
  810. },
  811. /* renderer : function(v) {
  812. var r = v;
  813. switch(v) {
  814. case 'like':
  815. r = 'Like';break;
  816. case '=':
  817. r = '等于';break;
  818. case '>':
  819. r = '大于';break;
  820. case '>=':
  821. r = '大于等于';break;
  822. case '<':
  823. r = '小于';break;
  824. case '<=':
  825. r = '小于等于';break;
  826. case '<>':
  827. r = '不等于';break;
  828. case 'Between And':
  829. r = '介于';break;
  830. }
  831. return r;
  832. },*/
  833. processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
  834. if (type == 'click' || type == 'dbclick') {
  835. return true;
  836. }
  837. return false;
  838. }
  839. },{
  840. text: '值',
  841. flex: 3,
  842. dataIndex: 'value',
  843. renderer: function(val){
  844. if(Ext.isDate(val)){
  845. return Ext.Date.format(val, 'Y-m-d');
  846. }
  847. return val;
  848. },
  849. processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
  850. if (type == 'click' || type == 'dbclick') {
  851. var s = view.ownerCt.selModel, m = s.getSelection(), n = [];
  852. Ext.Array.each(m, function(){
  853. n.push(this);
  854. });
  855. n.push(view.ownerCt.store.getAt(recordIndex));
  856. s.select(n);
  857. return true;
  858. }
  859. return false;
  860. }
  861. }],
  862. columnLines: true,
  863. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  864. clicksToEdit: 1,
  865. listeners: {
  866. beforeedit: function(e){
  867. if(e.field == 'value'){
  868. var record = e.record;
  869. var column = e.column;
  870. if(record.data['union'] == null || record.data['union'] == ''){
  871. record.set('union', 'like');
  872. }
  873. var f = record.data['sl_field'];
  874. switch(record.data['sl_type']){
  875. case 'D':
  876. switch(record.data['union']){
  877. case 'Between And':
  878. column.setEditor(new erp.view.core.form.FtDateField({
  879. id: f,
  880. name: f
  881. }));break;
  882. default:
  883. column.setEditor(new Ext.form.field.Date({
  884. id: f,
  885. name: f
  886. }));break;
  887. }
  888. break;
  889. case 'S':
  890. switch(record.data['union']){
  891. case 'Between And':
  892. column.setEditor(new erp.view.core.form.FtField({
  893. id: f,
  894. name: f,
  895. value: e.value
  896. }));break;
  897. default:
  898. column.setEditor(new Ext.form.field.Text({
  899. id: f,
  900. name: f
  901. }));break;
  902. }
  903. break;
  904. case 'N':
  905. switch(record.data['union']){
  906. case 'Between And':
  907. column.setEditor(new erp.view.core.form.FtNumberField({
  908. id: f,
  909. name: f
  910. }));break;
  911. default:
  912. column.setEditor(new Ext.form.field.Number({
  913. id: f,
  914. name: f
  915. }));break;
  916. }
  917. break;
  918. case 'T':
  919. column.dbfind = record.get('sl_dbfind');
  920. switch(record.data['union']){
  921. case 'Between And':
  922. column.setEditor(new erp.view.core.form.FtFindField({
  923. id: f,
  924. name: f
  925. }));break;
  926. default:
  927. column.setEditor(new erp.view.core.trigger.DbfindTrigger({
  928. id: f,
  929. name: f
  930. }));break;
  931. }
  932. break;
  933. default:
  934. column.setEditor(null);
  935. }
  936. }
  937. }
  938. }
  939. }),
  940. selModel: Ext.create('Ext.selection.CheckboxModel',{
  941. }),
  942. setEffectData: function(){
  943. var me = this;
  944. var datas = new Array();
  945. Ext.each(me.selModel.getSelection(), function(item){
  946. var data = item.data;
  947. if(!Ext.isEmpty(data.sl_label) && !Ext.isEmpty(data.union) && !Ext.isEmpty(data.value)){
  948. datas.push(data);
  949. }
  950. });
  951. me.effectdata = datas;
  952. },
  953. getEffectData: function(){
  954. return this.effectdata || new Array();
  955. },
  956. loadData: function(){
  957. if(!this.effectdata) {
  958. this.store.add([{},{},{},{},{},{},{},{},{},{}]);
  959. }
  960. },
  961. /**
  962. * 将数据拼成Sql条件语句
  963. */
  964. getCondition: function(){
  965. this.setEffectData();
  966. var condition = '';
  967. var separator = this.up('window').down('form').down('radio').getCheckValue();
  968. Ext.each(this.effectdata, function(data){
  969. if(data.union == 'Between And'){
  970. var v1 = data.value.split('~')[0];
  971. var v2 = data.value.split('~')[1];
  972. if(data.sl_type == 'D'){
  973. if(condition == ''){
  974. condition = '(' + data.sl_field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
  975. + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
  976. } else {
  977. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
  978. + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
  979. }
  980. } else if(data.sl_type == 'N'){
  981. if(condition == ''){
  982. condition = '(' + data.sl_field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
  983. } else {
  984. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
  985. }
  986. } else{
  987. if(condition == ''){
  988. condition = '(' + data.sl_field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
  989. } else {
  990. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
  991. }
  992. }
  993. } else {
  994. if(data.sl_type == 'D'){
  995. var v = data.value, field = data.sl_field;
  996. if(Ext.isDate(v)) {
  997. v = Ext.Date.format(v, 'Y-m-d');
  998. }
  999. if(data.union == '<' || data.union == '<=' || data.union == '>' || data.union == '>='){
  1000. v = "to_date('" + v + "','yyyy-MM-dd')";
  1001. }else {
  1002. v = Ext.Date.format(data.value, 'Ymd');
  1003. field = "to_char(" + field + ",'yyyymmdd')";
  1004. }
  1005. if(condition == ''){
  1006. condition = '(' + field + data.union + v + ') ';
  1007. } else {
  1008. condition += ' ' + separator +' (' + field + data.union + v + ') ';
  1009. }
  1010. } else {
  1011. var v = data.value;
  1012. if(data.union == 'like' || data.union=='not like'){
  1013. v = " '%" + data.value + "%'";
  1014. }else if(data.union =='begin like' || data.union =='begin not like'){
  1015. v = " '" + data.value + "%'";
  1016. data.union=data.union.substring(5);
  1017. }else if(data.union =='end like' || data.union=='end not like'){
  1018. v = " '%" + data.value + "'";
  1019. data.union=data.union.substring(3);
  1020. }else {
  1021. v = " '" + data.value + "'";
  1022. }
  1023. if(condition == ''){
  1024. condition = '(' + data.sl_field + " " + data.union + v + ") ";
  1025. } else {
  1026. condition += ' ' + separator +' (' + data.sl_field + " " + data.union + v + ") ";
  1027. }
  1028. }
  1029. }
  1030. });
  1031. return condition;
  1032. }
  1033. });
  1034. return grid;
  1035. },
  1036. getTemplateForm : function() {
  1037. var me = this;
  1038. return Ext.create('Ext.form.Panel', {
  1039. minHeight : 150,
  1040. region : 'south',
  1041. layout : 'column',
  1042. name : 'template',
  1043. bodyStyle : 'background:#f1f2f5;',
  1044. items : [{
  1045. xtype : 'fieldcontainer',
  1046. columnWidth : .75,
  1047. defaults : {
  1048. xtype : 'radio',
  1049. flex : 1,
  1050. margin : '5 0 5 15',
  1051. labelAlign : 'right'
  1052. },
  1053. items : [{
  1054. name : 'export-type',
  1055. boxLabel : '全部列',
  1056. checked : true
  1057. }]
  1058. }, {
  1059. xtype : 'fieldcontainer',
  1060. columnWidth : .25,
  1061. items : [{
  1062. xtype : 'button',
  1063. cls : 'x-btn-gray',
  1064. iconCls : 'x-button-icon-excel',
  1065. flex : 1,
  1066. margin : '15 0 5 0',
  1067. width : 80,
  1068. text : '导&nbsp;&nbsp;&nbsp;出',
  1069. handler : function(b) {
  1070. var grid = Ext.getCmp('grid'),
  1071. tb = grid.down('erpDatalistToolbar'),
  1072. r = b.ownerCt.ownerCt.down('radio[checked=true]');
  1073. if (r.fields)
  1074. tb.exportData(grid, b, r.boxLabel, r.fields);
  1075. else
  1076. tb.exportData(grid, b);
  1077. }
  1078. }
  1079. //已存在个性化设置列功能
  1080. /*,{
  1081. xtype : 'button',
  1082. cls : 'x-btn-gray',
  1083. flex : 1,
  1084. margin : '5 0 10 0',
  1085. width : 80,
  1086. text : '新建模板',
  1087. handler : function(b, e) {
  1088. var grid = Ext.getCmp('grid');
  1089. me.addTemplate(grid);
  1090. }
  1091. }*/
  1092. ]
  1093. }]
  1094. });
  1095. },
  1096. /* addTemplate : function(grid) {
  1097. var me = this, panel = grid.templatePanel;
  1098. if (!panel) {
  1099. var columns = grid.headerCt.getGridColumns(), data = [];
  1100. Ext.each(columns, function(){
  1101. if(this.dataIndex && this.getWidth() > 0) {
  1102. data.push({
  1103. boxLabel : this.text,
  1104. inputValue : this.dataIndex,
  1105. checked : true
  1106. });
  1107. }
  1108. });
  1109. data.push({
  1110. columnWidth : .8,
  1111. labelWidth : 60,
  1112. fieldLabel : '描述',
  1113. name : 'desc',
  1114. xtype : 'textfield',
  1115. allowBlank : false,
  1116. value : this.BaseUtil.getActiveTab().title + '(模板)-' + em_name
  1117. + '-' + Ext.Date.format(new Date(),'Ymd')
  1118. });
  1119. panel = grid.templatePanel = Ext.create('Ext.panel.Panel', {
  1120. floating : true,
  1121. shadow : 'frame',
  1122. layout : 'column',
  1123. width : 700,
  1124. bodyStyle : 'background:#f1f2f5;z-index:9999;',
  1125. defaults : {
  1126. xtype : 'checkbox',
  1127. margin : '5 5 15 15',
  1128. columnWidth : .25
  1129. },
  1130. items : data,
  1131. buttonAlign : 'center',
  1132. buttons : [{
  1133. text : '确认',
  1134. handler : function(b) {
  1135. var items = panel.query('checkbox[checked=true]'), fs = [];
  1136. Ext.each(items, function(){
  1137. fs.push(this.inputValue);
  1138. });
  1139. me.onTemplateAdd(panel, caller, fs.join(','), panel.down('textfield[name=desc]').value);
  1140. }
  1141. },{
  1142. text : '取消',
  1143. handler : function() {
  1144. panel.hide();
  1145. }
  1146. }]
  1147. });
  1148. }
  1149. panel.show();
  1150. panel.center();
  1151. },*/
  1152. onTemplateAdd : function(panel, caller, fields, desc) {
  1153. warnMsg('确定添加新模板:' + desc + '?', function(b){
  1154. if (b == 'ok' || b == 'yes') {
  1155. Ext.Ajax.request({
  1156. url : basePath + 'common/template/save.action',
  1157. params : {
  1158. _noc : 1,
  1159. caller : caller,
  1160. fields : fields,
  1161. desc : desc
  1162. },
  1163. callback : function(opt, s, res) {
  1164. var r = Ext.decode(res.responseText);
  1165. if (r.success) {
  1166. alert('添加成功!');
  1167. panel.hide();
  1168. var form = Ext.getCmp('grid').tempalteForm;
  1169. form.down('radio[value=true]').setValue(false);
  1170. form.items.first().add({
  1171. name : 'export-type',
  1172. boxLabel : desc,
  1173. fields : fields,
  1174. checked : true
  1175. });
  1176. }
  1177. }
  1178. });
  1179. }
  1180. });
  1181. },
  1182. getTemplates : function(caller) {
  1183. Ext.Ajax.request({
  1184. url : basePath + 'common/getFieldsDatas.action',
  1185. async: false,
  1186. params: {
  1187. caller: 'DataTemplate',
  1188. fields: 'dt_desc,dt_fields',
  1189. condition: 'dt_caller=\'' + caller + '\''
  1190. },
  1191. method : 'post',
  1192. callback : function(opt, s, res){
  1193. var r = new Ext.decode(res.responseText);
  1194. if(r.exceptionInfo){
  1195. showError(r.exceptionInfo);return;
  1196. }
  1197. if (r.success && r.data) {
  1198. var f = [], dd = Ext.decode(r.data);
  1199. if(dd.length > 0) {
  1200. Ext.each(dd, function(){
  1201. f.push({
  1202. name : 'export-type',
  1203. boxLabel : this.DT_DESC,
  1204. fields : this.DT_FIELDS
  1205. });
  1206. });
  1207. var form = Ext.getCmp('grid').tempalteForm;
  1208. form.items.first().add(f);
  1209. }
  1210. }
  1211. }
  1212. });
  1213. },
  1214. indexOf: function(array, item, from) {
  1215. if (supportsIndexOf) {
  1216. return array.indexOf(item, from);
  1217. }
  1218. var i, length = array.length;
  1219. for (i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++) {
  1220. if (array[i] === item) {
  1221. return i;
  1222. }
  1223. }
  1224. return -1;
  1225. },
  1226. });