Datalist2.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.Datalist2', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil', 'erp.util.FormUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'common.datalist.Viewport','common.datalist.GridPanel2','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'
  10. ],
  11. init:function(){
  12. var me=this;
  13. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  14. this.FormUtil = Ext.create('erp.util.FormUtil');
  15. this.control({
  16. 'erpDatalistGridPanel2': {
  17. //itemclick: this.onGridItemClick,
  18. /*afterrender:function(grid){
  19. if(Ext.isIE){
  20. document.body.attachEvent('onkeydown', function(){
  21. if(window.event.ctrlKey && window.event.keyCode == 67){//Ctrl + C
  22. var e = window.event;
  23. if(e.srcElement) {
  24. window.clipboardData.setData('text', e.srcElement.innerHTML);
  25. }
  26. }
  27. });
  28. } else {
  29. grid.getEl().dom.addEventListener("mouseover", function(e){
  30. if(e.ctrlKey){
  31. var Contextvalue=e.target.textContent==""?e.target.value:e.target.textContent;
  32. textarea_text = parent.document.getElementById("textarea_text");
  33. textarea_text.value=Contextvalue;
  34. textarea_text.focus();
  35. textarea_text.select();
  36. }
  37. });
  38. }
  39. },*/
  40. itemdblclick:function(record){
  41. var grid=record.ownerCt;
  42. var data=grid.getSelectionModel().lastSelected.data;
  43. var s=grid.ur+'?formCondition='+grid.keyF+'IS'+data[grid.keyF];
  44. var html='<iframe width=100% height=100% src="'+s+'"/>';
  45. var win=new Ext.window.Window({
  46. height:400,
  47. width:800,
  48. modal:true,
  49. listeners : {
  50. close : function(){
  51. grid.getColumnsAndStore();
  52. }
  53. },
  54. html:html});
  55. win.show();
  56. }
  57. },
  58. 'erpVastDeleteButton': {
  59. click: function(btn){
  60. var dlwin = new Ext.window.Window({
  61. id : 'dlwin',
  62. title: btn.text,
  63. height: "100%",
  64. width: "80%",
  65. maximizable : true,
  66. buttonAlign : 'center',
  67. layout : 'anchor',
  68. items: [{
  69. tag : 'iframe',
  70. frame : true,
  71. anchor : '100% 100%',
  72. layout : 'fit',
  73. 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>'
  74. }],
  75. buttons : [{
  76. text: btn.text,
  77. iconCls: btn.iconCls,
  78. cls: 'x-btn-gray-1',
  79. handler: function(){
  80. }
  81. },{
  82. text : '关 闭',
  83. iconCls: 'x-button-icon-close',
  84. cls: 'x-btn-gray',
  85. handler : function(){
  86. Ext.getCmp('dlwin').close();
  87. }
  88. }]
  89. });
  90. dlwin.show();
  91. }
  92. },
  93. 'button[id=searchlist]': {
  94. click: function(){
  95. this.showSearchListWin();
  96. }
  97. },
  98. 'dbfindtrigger[name=sl_label]': {
  99. afterrender: function(t){
  100. t.dbBaseCondition = 'sl_caller=\'' + caller + '\'';
  101. }
  102. }
  103. });
  104. },
  105. onGridItemClick: function(selModel, record){//grid行选择
  106. var me = this;
  107. if(keyField != null && keyField != ''){//有些datalist不需要打开明细表,这些表在datalist表里面不用配dl_keyField
  108. var value = record.data[keyField];
  109. var formCondition = keyField + "IS" + value ;
  110. var gridCondition = pfField + "IS" + value;
  111. //var panel = Ext.getCmp(caller + keyField + "=" + value);
  112. /*var main = parent.Ext.getCmp("content-panel");
  113. if(!main){
  114. main = parent.parent.Ext.getCmp("content-panel");
  115. }*/
  116. var title = "";
  117. if (value.toString().length>4) {
  118. title = value.toString().substring(value.toString().length-4);
  119. } else {
  120. title = value;
  121. }
  122. var myurl = '';
  123. if(me.BaseUtil.contains(url, '?', true)){
  124. myurl = url + '&formCondition='+formCondition+'&gridCondition='+gridCondition;
  125. } else {
  126. myurl = url + '?formCondition='+formCondition+'&gridCondition='+gridCondition;
  127. }
  128. myurl += "&datalistId=" + main.getActiveTab().id;
  129. //main.getActiveTab().currentStore = me.getCurrentStore(value);//用于单据翻页
  130. var win=new Ext.window.Window({
  131. height:400,
  132. width:400,
  133. modal:true,
  134. title : me.BaseUtil.getActiveTab().title+'('+title+')',
  135. tag : 'iframe',
  136. tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'('+keyField + "=" + value+')'},
  137. frame : true,
  138. border : false,
  139. layout : 'fit',
  140. iconCls : 'x-tree-icon-tab-tab1',
  141. html : '<iframe id="iframe_maindetail_'+caller+"_"+value+'" src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  142. closable : true,
  143. listeners : {
  144. close : function(){
  145. if(!main){
  146. main = parent.parent.Ext.getCmp("content-panel");
  147. }
  148. main.setActiveTab(main.getActiveTab().id);
  149. }
  150. } });
  151. win.show();
  152. }
  153. },
  154. openTab : function (panel,id){
  155. var o = (typeof panel == "string" ? panel : id || panel.id);
  156. var main = parent.Ext.getCmp("content-panel");
  157. /*var tab = main.getComponent(o); */
  158. if(!main) {
  159. main =parent.parent.Ext.getCmp("content-panel");
  160. }
  161. var tab = main.getComponent(o);
  162. if (tab) {
  163. main.setActiveTab(tab);
  164. } else if(typeof panel!="string"){
  165. panel.id = o;
  166. var p = main.add(panel);
  167. main.setActiveTab(p);
  168. }
  169. },
  170. getCurrentStore: function(value){
  171. var grid = Ext.getCmp('grid');
  172. var items = grid.store.data.items;
  173. var array = new Array();
  174. var o = null;
  175. Ext.each(items, function(item, index){
  176. o = new Object();
  177. o.selected = false;
  178. if(index == 0){
  179. o.prev = null;
  180. } else {
  181. o.prev = items[index-1].data[keyField];
  182. }
  183. if(index == items.length - 1){
  184. o.next = null;
  185. } else {
  186. o.next = items[index+1].data[keyField];
  187. }
  188. var v = item.data[keyField];
  189. o.value = v;
  190. if(v == value)
  191. o.selected = true;
  192. array.push(o);
  193. });
  194. return array;
  195. },
  196. showSearchListWin: function(){
  197. var me = this;
  198. if(!Ext.getCmp('slwin')){
  199. Ext.create('Ext.window.Window', {
  200. id : 'slwin',
  201. title: '高级查询',
  202. height: screen.height*0.7*0.8,
  203. width: screen.width*0.7*0.6,
  204. maximizable : true,
  205. closable: false,
  206. buttonAlign : 'center',
  207. layout : 'border',
  208. bodyStyle: 'background:#f1f1f1;',
  209. tools: [{
  210. type: 'close',
  211. handler: function(){
  212. Ext.getCmp('slwin').down('grid').setEffectData();//保留已选择的条件
  213. Ext.getCmp('slwin').hide();
  214. }
  215. }],
  216. items: [{
  217. xtype: 'form',
  218. region: 'north',
  219. layout: 'column',
  220. bodyStyle: 'background:#f1f1f1;',
  221. title: '已选择条件',
  222. maxHeight: 100,
  223. items: me.getFilterCondition(),
  224. buttonAlign: 'center',
  225. buttons: [{
  226. name: 'query',
  227. id: 'query',
  228. text: $I18N.common.button.erpQueryButton,
  229. iconCls: 'x-button-icon-query',
  230. cls: 'x-btn-gray',
  231. handler: function(btn){
  232. var con = btn.ownerCt.ownerCt.ownerCt.down('grid').getCondition();//保留已选择的条件
  233. Ext.getCmp('grid').getCount(caller, con);
  234. btn.ownerCt.ownerCt.ownerCt.hide();
  235. }
  236. },{
  237. cls: 'x-btn-gray',
  238. text: $I18N.common.button.erpOffButton,
  239. handler: function(btn){
  240. btn.ownerCt.ownerCt.ownerCt.down('grid').setEffectData();
  241. btn.ownerCt.ownerCt.ownerCt.hide();
  242. }
  243. },{
  244. xtype: 'radio',
  245. name: 'separator',
  246. boxLabel: '与',
  247. checked: true,
  248. inputValue: 'AND',
  249. getCheckValue: function(){
  250. return this.checked ? 'AND' : 'OR';
  251. }
  252. },{
  253. xtype: 'radio',
  254. name: 'separator',
  255. boxLabel: '或',
  256. inputValue: 'OR'
  257. }]
  258. }, me.getSearchListGrid()]
  259. });
  260. }
  261. Ext.getCmp('slwin').show();
  262. Ext.getCmp('slwin').down('grid').loadData();
  263. },
  264. getFilterCondition: function(){
  265. var fields = Ext.getCmp('grid').plugins[0].fields;
  266. var items = new Array();
  267. Ext.each(Ext.Object.getKeys(fields), function(key){
  268. var item = fields[key];
  269. if(item.value != null && item.value.toString().trim() != ''){
  270. items.push({
  271. xtype: item.xtype,
  272. id: item.itemId,
  273. fieldLabel: item.fieldLabel,
  274. fieldStyle: item.fieldStyle,
  275. value: item.value,
  276. columnWidth: 0.5,
  277. cls: 'form-field-border',
  278. listeners: {
  279. change: function(f){
  280. Ext.getCmp(item.id).setValue(f.value);
  281. }
  282. }
  283. });
  284. }
  285. });
  286. return items;
  287. },
  288. getSearchListGrid: function(){
  289. var grid = Ext.create('Ext.grid.Panel', {
  290. minHeight: 300,
  291. region: 'center',
  292. store: Ext.create('Ext.data.Store', {
  293. fields:[{
  294. name: 'sl_label',
  295. type: 'string'
  296. },{
  297. name: 'sl_field',
  298. type: 'string'
  299. },{
  300. name: 'sl_type',
  301. type: 'string'
  302. },{
  303. name: 'union',
  304. type: 'string'
  305. },{
  306. name: 'value'
  307. }],
  308. data: []
  309. }),
  310. columns: [{
  311. text: '条件',
  312. flex: 2,
  313. dataIndex: 'sl_label',
  314. editor: {
  315. xtype: 'dbfindtrigger'
  316. },
  317. dbfind: 'SearchList|sl_label'
  318. },{
  319. text: '',
  320. hidden: true,
  321. dataIndex: 'sl_field'
  322. },{
  323. text: '',
  324. hidden: true,
  325. dataIndex: 'sl_type'
  326. },{
  327. text: '关系',
  328. flex: 1,
  329. dataIndex: 'union',
  330. editor: {
  331. xtype: 'combo',
  332. store: Ext.create('Ext.data.Store', {
  333. fields: ['display', 'value'],
  334. data : [
  335. {"display": 'Like', "value": 'like'},
  336. {"display": '等于', "value": '='},
  337. {"display": '大于', "value": '>'},
  338. {"display": '小于', "value": '<'},
  339. {"display": '不等于', "value": '<>'},
  340. {"display": '介于', "value": 'Between And'}
  341. ]
  342. }),
  343. displayField: 'display',
  344. valueField: 'value',
  345. queryMode: 'local',
  346. editable: false,
  347. value: 'like'
  348. }
  349. },{
  350. text: '值',
  351. flex: 3,
  352. dataIndex: 'value',
  353. renderer: function(val){
  354. if(Ext.isDate(val)){
  355. return Ext.Date.format(val, 'Y-m-d');
  356. }
  357. return val;
  358. }
  359. }],
  360. columnLines: true,
  361. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  362. clicksToEdit: 1,
  363. listeners: {
  364. beforeedit: function(e){
  365. if(e.field == 'value'){
  366. var record = e.record;
  367. var column = e.column;
  368. if(record.data['union'] == null || record.data['union'] == ''){
  369. record.set('union', '=');
  370. }
  371. var f = record.data['sl_field'];
  372. switch(record.data['sl_type']){
  373. case 'D':
  374. switch(record.data['union']){
  375. case 'Between And':
  376. column.setEditor(new erp.view.core.form.FtDateField({
  377. id: f,
  378. name: f
  379. }));break;
  380. default:
  381. column.setEditor(new Ext.form.field.Date({
  382. id: f,
  383. name: f
  384. }));break;
  385. }
  386. break;
  387. case 'S':
  388. switch(record.data['union']){
  389. case 'Between And':
  390. column.setEditor(new erp.view.core.form.FtField({
  391. id: f,
  392. name: f,
  393. value: e.value
  394. }));break;
  395. default:
  396. column.setEditor(new Ext.form.field.Text({
  397. id: f,
  398. name: f
  399. }));break;
  400. }
  401. break;
  402. case 'N':
  403. switch(record.data['union']){
  404. case 'Between And':
  405. column.setEditor(new erp.view.core.form.FtNumberField({
  406. id: f,
  407. name: f
  408. }));break;
  409. default:
  410. column.setEditor(new Ext.form.field.Number({
  411. id: f,
  412. name: f
  413. }));break;
  414. }
  415. break;
  416. case 'T':
  417. column.dbfind = 'a|b';
  418. switch(record.data['union']){
  419. case 'Between And':
  420. column.setEditor(new erp.view.core.form.FtFindField({
  421. id: f,
  422. name: f
  423. }));break;
  424. default:
  425. column.setEditor(new erp.view.core.trigger.DbfindTrigger({
  426. id: f,
  427. name: f
  428. }));break;
  429. }
  430. break;
  431. default:
  432. column.setEditor(null);
  433. }
  434. }
  435. }
  436. }
  437. }),
  438. dbfinds: [{
  439. field: 'sl_label',
  440. dbGridField: 'sl_label'
  441. },{
  442. field: 'sl_field',
  443. dbGridField: 'sl_field'
  444. },{
  445. field: 'sl_type',
  446. dbGridField: 'sl_type'
  447. }],
  448. selModel: Ext.create('Ext.selection.CheckboxModel',{
  449. }),
  450. setEffectData: function(){
  451. var me = this;
  452. var datas = new Array();
  453. Ext.each(me.selModel.getSelection(), function(item){
  454. var data = item.data;
  455. if(!Ext.isEmpty(data.sl_label) && !Ext.isEmpty(data.union) && !Ext.isEmpty(data.value)){
  456. datas.push(data);
  457. }
  458. });
  459. me.effectdata = datas;
  460. },
  461. getEffectData: function(){
  462. return this.effectdata || new Array();
  463. },
  464. loadData: function(){
  465. var data = this.getEffectData();
  466. this.store.loadData(data);
  467. this.selModel.selectAll();
  468. this.store.add([{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]);
  469. },
  470. /**
  471. * 将数据拼成Sql条件语句
  472. */
  473. getCondition: function(){
  474. this.setEffectData();
  475. var condition = '';
  476. var separator = this.up('window').down('form').down('radio').getCheckValue();
  477. Ext.each(this.effectdata, function(data){
  478. if(data.union == 'Between And'){
  479. var v1 = data.value.split('~')[0];
  480. var v2 = data.value.split('~')[1];
  481. if(data.sl_type == 'D'){
  482. if(condition == ''){
  483. condition = '(' + data.sl_field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
  484. + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
  485. } else {
  486. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
  487. + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
  488. }
  489. } else if(data.sl_type == 'N'){
  490. if(condition == ''){
  491. condition = '(' + data.sl_field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
  492. } else {
  493. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
  494. }
  495. } else{
  496. if(condition == ''){
  497. condition = '(' + data.sl_field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
  498. } else {
  499. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
  500. }
  501. }
  502. } else {
  503. if(data.sl_type == 'D'){
  504. var v = data.value;
  505. if(data.union == '<'){
  506. v = "to_date('" + v + " 00:00:00','yyyy-MM-dd HH24:mi:ss')";
  507. } else if(data.union == '>'){
  508. v = "to_date('" + v + " 23:59:59','yyyy-MM-dd HH24:mi:ss')";
  509. } else {
  510. v = "to_date('" + v + "','yyyy-MM-dd')";
  511. }
  512. if(condition == ''){
  513. condition = '(' + data.sl_field + data.union + v + ') ';
  514. } else {
  515. condition += ' ' + separator +' (' + data.sl_field + data.union + v + ') ';
  516. }
  517. } else {
  518. var v = data.value;
  519. if(data.union == 'like'){
  520. v = " '%" + data.value + "%'";
  521. } else {
  522. v = " '" + data.value + "'";
  523. }
  524. if(condition == ''){
  525. condition = '(' + data.sl_field + " " + data.union + v + ") ";
  526. } else {
  527. condition += ' ' + separator +' (' + data.sl_field + " " + data.union + v + ") ";
  528. }
  529. }
  530. }
  531. });
  532. return condition;
  533. }
  534. });
  535. return grid;
  536. }
  537. });