JprocessDeployList.js 16 KB

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