MyTask.js 17 KB

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