MakePlan.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.MakePlan', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil', 'erp.util.FormUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'pm.make.MakePlan','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','common.batchDeal.Form','core.form.MonthDateField','core.form.ConMonthDateField','core.trigger.DbfindTrigger','core.form.ConDateField'
  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=query]':{
  76. beforerender:function(btn){
  77. btn.handler=function(){
  78. var form=btn.ownerCt.ownerCt;
  79. if(form){
  80. var condition=form.getCondition();
  81. if(!Ext.isEmpty(condition)) {
  82. var grid=Ext.getCmp('grid');
  83. grid.getCount(caller,condition);
  84. }
  85. }
  86. };
  87. }
  88. },
  89. 'button[id=searchlist]': {
  90. click: function(){
  91. this.showSearchListWin();
  92. }
  93. },
  94. 'dbfindtrigger[name=sl_label]': {
  95. afterrender: function(t){
  96. t.dbBaseCondition = 'sl_caller=\'' + caller + '\'';
  97. }
  98. }
  99. });
  100. },
  101. onGridItemClick: function(selModel, record){
  102. //打开小窗口 编辑 分拆工单
  103. var ma_code=record.data.ma_code;
  104. Ext.create('Ext.window.Window',{
  105. width:850,
  106. height:'80%',
  107. iconCls:'x-grid-icon-partition',
  108. title:'<h1>工单拆分</h1>',
  109. id:'win',
  110. items:[{
  111. xtype:'form',
  112. layout:'column',
  113. region:'north',
  114. frame:true,
  115. defaults:{
  116. xtype:'textfield',
  117. columnWidth:0.5,
  118. readOnly:true,
  119. fieldStyle:'background:#f0f0f0;border: 0px solid #8B8970;color:blue;'
  120. },
  121. items:[{
  122. fieldLabel:'制造单号',
  123. value:record.data.ma_code,
  124. id:'macode'
  125. },{
  126. fieldLabel:'物料编号' ,
  127. value:record.data.ma_prodcode
  128. },{
  129. fieldLabel:'物料名称',
  130. value:record.data.pr_detail
  131. },{
  132. fieldLabel:'订单编号' ,
  133. value:record.data.ma_salecode
  134. },{
  135. fieldLabel:'订单序号',
  136. value:record.data.ma_saledetno
  137. },{
  138. fieldLabel:'制单数量',
  139. value:record.data.ma_qty,
  140. id:'ma_qty'
  141. },{
  142. fieldLabel:'已完工数',
  143. value:record.data.ma_madeqty,
  144. id:'ma_madeqty'
  145. }]
  146. },{
  147. xtype:'form',
  148. layout:'column',
  149. frame:true,
  150. id:'planform',
  151. defaults:{
  152. xtype:'textfield',
  153. columnWidth:0.26,
  154. readOnly:false,
  155. labelAlign:'right',
  156. fieldStyle:'background:#FFFAFA;color:#515151;'
  157. },
  158. items:[{
  159. fieldLabel:'计划开工日期',
  160. xtype:'datefield',
  161. id:'ma_planbegindate',
  162. name:'ma_planbegindate',
  163. value:record.data.ma_planbegindate
  164. },{
  165. fieldLabel:'计划完工日期',
  166. xtype:'datefield',
  167. id:'ma_planenddate',
  168. name:'ma_planenddate',
  169. value:record.data.ma_planenddate
  170. },{
  171. fieldLabel:'线别',
  172. id:'ma_teamcode',
  173. name:'ma_teamcode',
  174. labelWidth:50,
  175. columnWidth:0.2,
  176. xtype:'dbfindtrigger',
  177. value:record.data.ma_teamcode
  178. },{
  179. id:'ma_id',
  180. xtype:'hidden',
  181. name:'ma_id',
  182. value:record.data.ma_id
  183. },{
  184. xtype:'button',
  185. columnWidth:0.12,
  186. text:'保存',
  187. width:60,
  188. iconCls: 'x-button-icon-save',
  189. margin:'0 0 0 30',
  190. handler:function(btn){
  191. var store=Ext.getCmp('smallgrid').getStore();
  192. var count=0;
  193. var jsonData=new Array();
  194. var dd,version;
  195. Ext.Array.each(store.data.items,function(item){
  196. if(item.data.ma_planbegindate!=null&&item.data.ma_planenddate!=null&&item.data.ma_qty>0){
  197. version=item.data.ma_version;
  198. if(!version){
  199. dd=new Object();
  200. //说明是新增批次
  201. dd['ma_planbegindate']=Ext.Date.format(item.data.ma_planbegindate, 'Y-m-d');
  202. dd['ma_planenddate']=Ext.Date.format(item.data.ma_planenddate, 'Y-m-d');
  203. dd['ma_qty']=item.data.ma_qty;
  204. dd['ma_teamcode']=item.data.ma_teamcode;
  205. jsonData.push(Ext.JSON.encode(dd));
  206. count+=Number(item.data.ma_qty);
  207. }
  208. }
  209. });
  210. var r=Ext.getCmp('planform').getValues();
  211. var params=new Object();
  212. params.formdata = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  213. params.data = unescape(jsonData.toString().replace(/\\/g,"%"));
  214. var assqty=Number(record.data.ma_qty)-Number(record.data.ma_madeqty);
  215. if(count>assqty){
  216. showError('分拆数量不能大于未完工数!') ;
  217. return;
  218. }else{
  219. Ext.Ajax.request({
  220. url : basePath +'pm/make/splitMake.action',
  221. params : params,
  222. method : 'post',
  223. callback : function(options,success,response){
  224. var localJson = new Ext.decode(response.responseText);
  225. if(localJson.success){
  226. saveSuccess(function(){
  227. //add成功后刷新页面进入可编辑的页面
  228. Ext.create('erp.util.GridUtil').loadNewStore(Ext.getCmp('smallgrid'),{
  229. caller:'MakeSplit',
  230. condition:"ma_version='"+ma_code+"' order by ma_id desc"
  231. });
  232. });
  233. } else if(localJson.exceptionInfo){
  234. var str = localJson.exceptionInfo;
  235. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  236. str = str.replace('AFTERSUCCESS', '');
  237. saveSuccess(function(){
  238. //add成功后刷新页面进入可编辑的页面
  239. Ext.create('erp.util.GridUtil').loadNewStore(Ext.getCmp('smallgrid'),{
  240. caller:'MakeSplit',
  241. condition:"ma_version='"+ma_code+"' order by ma_id desc"
  242. });
  243. });
  244. showError(str);
  245. } else {
  246. showError(str);
  247. return;
  248. }
  249. } else{
  250. saveFailure();
  251. }
  252. }
  253. });
  254. }
  255. }
  256. },{
  257. xtype:'button',
  258. columnWidth:0.1,
  259. text:'关闭',
  260. width:60,
  261. iconCls: 'x-button-icon-close',
  262. margin:'0 0 0 10',
  263. handler:function(btn){
  264. Ext.getCmp('win').close();
  265. }
  266. }]
  267. },{
  268. xtype:'gridpanel',
  269. region:'south',
  270. id:'smallgrid',
  271. layout:'fit',
  272. height:0.45*(window.height),
  273. autoScroll:true,
  274. columnLines:true,
  275. store:Ext.create('Ext.data.Store',{
  276. fields:[{name:'ma_planbegindate',type:'date'},{name:'ma_planenddate',type:'date'},{name:'ma_teamcode',type:'string'},{name:'ma_qty',type:'int'},{name:'ma_code',type:'string'},{name:'ma_version',type:'string'}],
  277. data:[]
  278. }),
  279. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  280. clicksToEdit: 1,
  281. listeners:{
  282. 'edit':function(editor,e,Opts){
  283. var record=e.record;
  284. var version=record.data.ma_version;
  285. if(version){
  286. e.record.reject();
  287. Ext.Msg.alert('提示','不能修改已拆分工单!');
  288. }
  289. }
  290. }
  291. })],
  292. tbar: [{
  293. tooltip: '添加批次',
  294. iconCls: 'x-button-icon-add',
  295. width:25,
  296. handler : function() {
  297. var store = Ext.getCmp('smallgrid').getStore();
  298. var r = new Object();
  299. r.ma_planbegindate=null;
  300. r.ma_planenddate=null;
  301. r.ma_qty=null;
  302. r.ma_code=null;
  303. store.insert(store.getCount(), r);
  304. }
  305. }, {
  306. tooltip: '删除批次',
  307. width:25,
  308. itemId: 'delete',
  309. iconCls: 'x-button-icon-delete',
  310. handler: function(btn) {
  311. var sm = Ext.getCmp('smallgrid').getSelectionModel();
  312. //ma_version 存在则不让删除
  313. var store=Ext.getCmp('smallgrid').getStore();
  314. store.remove(sm.getSelection());
  315. if (store.getCount() > 0) {
  316. sm.select(0);
  317. }
  318. },
  319. disabled: true
  320. }],
  321. listeners:{
  322. itemmousedown:function(selmodel, record){
  323. selmodel.ownerCt.down('#delete').setDisabled(false);
  324. }
  325. },
  326. dbfinds:[{
  327. dbGridField: "dlc_display",
  328. field: "ma_teamcode",
  329. trigger:'ma_teamcode'
  330. }],
  331. columns:[{
  332. dataIndex:'ma_planbegindate',
  333. header:'计划开工日期',
  334. xtype:'datecolumn',
  335. width:120,
  336. editable:true,
  337. renderer:function(val,meta,record){
  338. if(record.data.ma_version){
  339. meta.tdCls = "x-grid-cell-renderer-cl";
  340. }
  341. if(val)
  342. return Ext.Date.format(val, 'Y-m-d');
  343. else return null;
  344. },
  345. editor:{
  346. xtype: 'datefield',
  347. format:'Y-m-d'
  348. },
  349. },{
  350. dataIndex:'ma_planenddate',
  351. header:'计划完工日期',
  352. xtype:'datecolumn',
  353. width:120,
  354. editable:true,
  355. renderer:function(val,meta,record){
  356. if(record.data.ma_version){
  357. meta.tdCls = "x-grid-cell-renderer-cl";
  358. }
  359. if(val)
  360. return Ext.Date.format(val, 'Y-m-d');
  361. else return null;
  362. },
  363. format:'Y-m-d',
  364. editor:{
  365. xtype: 'datefield',
  366. format:'Y-m-d'
  367. }
  368. },{
  369. dataIndex:'ma_qty',
  370. header:'数量',
  371. width:120,
  372. xtype:'numbercolumn',
  373. editable:true,
  374. renderer:function(val,meta,record){
  375. if(record.data.ma_version){
  376. meta.tdCls = "x-grid-cell-renderer-cl";
  377. }
  378. return val;
  379. },
  380. editor:{
  381. xtype:'numberfield',
  382. format:'0',
  383. hideTrigger: true
  384. }
  385. },{
  386. dataIndex:'ma_teamcode',
  387. header:'线别',
  388. width:120,
  389. editable:true,
  390. renderer:function(val,meta,record){
  391. if(record.data.ma_version){
  392. meta.tdCls = "x-grid-cell-renderer-cl";
  393. }
  394. return val;
  395. },
  396. dbfind:'MakeTeam|dlc_display',
  397. editor:{
  398. xtype:'dbfindtrigger',
  399. hideTrigger: false,
  400. name:'ma_teamcode',
  401. which:'grid',
  402. dbfind:'MakeTeam|dlc_display'
  403. }
  404. },{
  405. dataIndex:'ma_code',
  406. header:'制造单号',
  407. width:150,
  408. renderer:function(val,meta,record){
  409. if(record.data.ma_version){
  410. meta.tdCls = "x-grid-cell-renderer-cl";
  411. }
  412. return val;
  413. },
  414. },{
  415. dataIndex:'ma_version',
  416. header:'原始工单',
  417. width:150,
  418. editable:false
  419. }]
  420. }]
  421. }).show();
  422. //给grid 赋值
  423. Ext.create('erp.util.GridUtil').loadNewStore(Ext.getCmp('smallgrid'),{
  424. caller:'MakeSplit',
  425. condition:"ma_version='"+ma_code+"' order by ma_id desc"
  426. });
  427. },
  428. openUrl: function(record) {
  429. var me = this, value = record.data[keyField];
  430. var formCondition = keyField + "IS" + value ;
  431. var gridCondition = pfField + "IS" + value;
  432. if(!Ext.isEmpty(pfField) && pfField.indexOf('+') > -1) {//多条件传入维护界面//vd_vsid@vd_id+vd_class@vd_class
  433. var arr = pfField.split('+'),ff = [],k = [];
  434. Ext.Array.each(arr, function(r){
  435. ff = r.split('@');
  436. k.push(ff[0] + 'IS\'' + record.get(ff[1]) + '\'');
  437. });
  438. gridCondition = k.join(' AND ');
  439. }
  440. var panelId = caller + keyField + "_" + value + gridCondition;
  441. var panel = Ext.getCmp(panelId);
  442. var main = parent.Ext.getCmp("content-panel");
  443. if(!main){
  444. main = parent.parent.Ext.getCmp("content-panel");
  445. }
  446. if(!panel){
  447. var title = "";
  448. if (value.toString().length>4) {
  449. title = value.toString().substring(value.toString().length-4);
  450. } else {
  451. title = value;
  452. }
  453. var myurl = '';
  454. if(me.BaseUtil.contains(url, '?', true)){
  455. myurl = url + '&formCondition='+formCondition+'&gridCondition='+gridCondition;
  456. } else {
  457. myurl = url + '?formCondition='+formCondition+'&gridCondition='+gridCondition;
  458. }
  459. myurl += "&datalistId=" + main.getActiveTab().id;
  460. main.getActiveTab().currentStore = me.getCurrentStore(value);//用于单据翻页
  461. if(main._mobile) {
  462. main.addPanel(me.BaseUtil.getActiveTab().title+'('+title+')', myurl, panelId);
  463. } else {
  464. panel = {
  465. title : me.BaseUtil.getActiveTab().title+'('+title+')',
  466. tag : 'iframe',
  467. tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'('+keyField + "=" + value+')'},
  468. frame : true,
  469. border : false,
  470. layout : 'fit',
  471. iconCls : 'x-tree-icon-tab-tab1',
  472. html : '<iframe id="iframe_maindetail_'+caller+"_"+value+'" src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  473. closable : true,
  474. listeners : {
  475. close : function(){
  476. if(!main){
  477. main = parent.parent.Ext.getCmp("content-panel");
  478. }
  479. main.setActiveTab(main.getActiveTab().id);
  480. }
  481. }
  482. };
  483. this.openTab(panel, panelId);
  484. }
  485. }else{
  486. main.setActiveTab(panel);
  487. }
  488. },
  489. openQueryUrl: function(record) {
  490. var me = this, arr = keyField.split('+'),ff = [],k = [];//vd_vsid@vd_id+vd_class@vd_class
  491. Ext.Array.each(arr, function(r){
  492. ff = r.split('@');
  493. k.push(ff[0] + '=' + record.get(ff[1]));
  494. });
  495. var myurl = k.join('&');
  496. var panelId = caller + "_" + myurl;
  497. var panel = Ext.getCmp(panelId);
  498. var main = parent.Ext.getCmp("content-panel");
  499. if(!main){
  500. main = parent.parent.Ext.getCmp("content-panel");
  501. }
  502. if(!panel){
  503. var title = me.BaseUtil.getActiveTab().title + '-查询';
  504. if(contains(url, '?', true)){
  505. myurl = url + '&' + myurl;
  506. } else {
  507. myurl = url + '?' + myurl;
  508. }
  509. if (main._mobile) {
  510. main.addPanel(title, myurl, panelId);
  511. } else {
  512. panel = {
  513. title : title,
  514. tag : 'iframe',
  515. tabConfig: {tooltip: title},
  516. frame : true,
  517. border : false,
  518. layout : 'fit',
  519. iconCls : 'x-tree-icon-tab-tab1',
  520. html : '<iframe src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  521. closable : true,
  522. listeners : {
  523. close : function(){
  524. if(!main){
  525. main = parent.parent.Ext.getCmp("content-panel");
  526. }
  527. main.setActiveTab(main.getActiveTab().id);
  528. }
  529. }
  530. };
  531. this.openTab(panel, panelId);
  532. }
  533. } else {
  534. main.setActiveTab(panel);
  535. }
  536. },
  537. openTab : function (panel,id){
  538. var o = (typeof panel == "string" ? panel : id || panel.id);
  539. var main = parent.Ext.getCmp("content-panel");
  540. /*var tab = main.getComponent(o); */
  541. if(!main) {
  542. main =parent.parent.Ext.getCmp("content-panel");
  543. }
  544. var tab = main.getComponent(o);
  545. if (tab) {
  546. main.setActiveTab(tab);
  547. } else if(typeof panel!="string"){
  548. panel.id = o;
  549. var p = main.add(panel);
  550. main.setActiveTab(p);
  551. }
  552. },
  553. getCurrentStore: function(value){
  554. var grid = Ext.getCmp('grid');
  555. var items = grid.store.data.items;
  556. var array = new Array();
  557. var o = null;
  558. Ext.each(items, function(item, index){
  559. o = new Object();
  560. o.selected = false;
  561. if(index == 0){
  562. o.prev = null;
  563. } else {
  564. o.prev = items[index-1].data[keyField];
  565. }
  566. if(index == items.length - 1){
  567. o.next = null;
  568. } else {
  569. o.next = items[index+1].data[keyField];
  570. }
  571. var v = item.data[keyField];
  572. o.value = v;
  573. if(v == value)
  574. o.selected = true;
  575. array.push(o);
  576. });
  577. return array;
  578. },
  579. showSearchListWin: function(){
  580. var me = this;
  581. if(!Ext.getCmp('slwin')){
  582. Ext.create('Ext.window.Window', {
  583. id : 'slwin',
  584. title: '高级查询',
  585. height: screen.height*0.7*0.8,
  586. width: screen.width*0.7*0.6,
  587. maximizable : true,
  588. closable: false,
  589. buttonAlign : 'center',
  590. layout : 'border',
  591. bodyStyle: 'background:#f1f1f1;',
  592. tools: [{
  593. type: 'close',
  594. handler: function(){
  595. Ext.getCmp('slwin').down('grid').setEffectData();//保留已选择的条件
  596. Ext.getCmp('slwin').hide();
  597. }
  598. }],
  599. items: [{
  600. xtype: 'form',
  601. region: 'north',
  602. layout: 'column',
  603. bodyStyle: 'background:#f1f1f1;',
  604. title: '已选择条件',
  605. maxHeight: 100,
  606. items: me.getFilterCondition(),
  607. buttonAlign: 'center',
  608. buttons: [{
  609. name: 'query',
  610. id: 'query',
  611. text: $I18N.common.button.erpQueryButton,
  612. iconCls: 'x-button-icon-query',
  613. cls: 'x-btn-gray',
  614. handler: function(btn){
  615. var con = btn.ownerCt.ownerCt.ownerCt.down('grid').getCondition();//保留已选择的条件
  616. Ext.getCmp('grid').getCount(caller, con);
  617. btn.ownerCt.ownerCt.ownerCt.hide();
  618. }
  619. },{
  620. cls: 'x-btn-gray',
  621. text: $I18N.common.button.erpOffButton,
  622. handler: function(btn){
  623. btn.ownerCt.ownerCt.ownerCt.down('grid').setEffectData();
  624. btn.ownerCt.ownerCt.ownerCt.hide();
  625. }
  626. },{
  627. xtype: 'radio',
  628. name: 'separator',
  629. boxLabel: '与',
  630. checked: true,
  631. inputValue: 'AND',
  632. getCheckValue: function(){
  633. return this.checked ? 'AND' : 'OR';
  634. }
  635. },{
  636. xtype: 'radio',
  637. name: 'separator',
  638. boxLabel: '或',
  639. inputValue: 'OR'
  640. }]
  641. }, me.getSearchListGrid()]
  642. });
  643. }
  644. Ext.getCmp('slwin').show();
  645. Ext.getCmp('slwin').down('grid').loadData();
  646. },
  647. getFilterCondition: function(){
  648. var fields = Ext.getCmp('grid').plugins[0].fields;
  649. var items = new Array();
  650. Ext.each(Ext.Object.getKeys(fields), function(key){
  651. var item = fields[key];
  652. if(item.value != null && item.value.toString().trim() != ''){
  653. items.push({
  654. xtype: item.xtype,
  655. id: item.itemId,
  656. fieldLabel: item.fieldLabel,
  657. fieldStyle: item.fieldStyle,
  658. value: item.value,
  659. columnWidth: 0.5,
  660. cls: 'form-field-border',
  661. listeners: {
  662. change: function(f){
  663. Ext.getCmp(item.id).setValue(f.value);
  664. }
  665. }
  666. });
  667. }
  668. });
  669. return items;
  670. },
  671. getSearchListGrid: function(){
  672. var grid = Ext.create('Ext.grid.Panel', {
  673. minHeight: 300,
  674. region: 'center',
  675. store: Ext.create('Ext.data.Store', {
  676. fields:[{
  677. name: 'sl_label',
  678. type: 'string'
  679. },{
  680. name: 'sl_field',
  681. type: 'string'
  682. },{
  683. name: 'sl_type',
  684. type: 'string'
  685. },{
  686. name: 'union',
  687. type: 'string'
  688. },{
  689. name: 'value'
  690. }],
  691. data: []
  692. }),
  693. columns: [{
  694. text: '条件',
  695. flex: 2,
  696. dataIndex: 'sl_label',
  697. editor: {
  698. xtype: 'dbfindtrigger'
  699. },
  700. dbfind: 'SearchList|sl_label'
  701. },{
  702. text: '',
  703. hidden: true,
  704. dataIndex: 'sl_field'
  705. },{
  706. text: '',
  707. hidden: true,
  708. dataIndex: 'sl_type'
  709. },{
  710. text: '关系',
  711. flex: 1,
  712. dataIndex: 'union',
  713. editor: {
  714. xtype: 'combo',
  715. store: Ext.create('Ext.data.Store', {
  716. fields: ['display', 'value'],
  717. data : [
  718. {"display": 'Like', "value": 'like'},
  719. {"display": '等于', "value": '='},
  720. {"display": '大于', "value": '>'},
  721. {"display": '小于', "value": '<'},
  722. {"display": '不等于', "value": '<>'},
  723. {"display": '介于', "value": 'Between And'}
  724. ]
  725. }),
  726. displayField: 'display',
  727. valueField: 'value',
  728. queryMode: 'local',
  729. editable: false,
  730. value: 'like'
  731. }
  732. },{
  733. text: '值',
  734. flex: 3,
  735. dataIndex: 'value',
  736. renderer: function(val){
  737. if(Ext.isDate(val)){
  738. return Ext.Date.format(val, 'Y-m-d');
  739. }
  740. return val;
  741. }
  742. }],
  743. columnLines: true,
  744. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  745. clicksToEdit: 1,
  746. listeners: {
  747. beforeedit: function(e){
  748. if(e.field == 'value'){
  749. var record = e.record;
  750. var column = e.column;
  751. if(record.data['union'] == null || record.data['union'] == ''){
  752. record.set('union', '=');
  753. }
  754. var f = record.data['sl_field'];
  755. switch(record.data['sl_type']){
  756. case 'D':
  757. switch(record.data['union']){
  758. case 'Between And':
  759. column.setEditor(new erp.view.core.form.FtDateField({
  760. id: f,
  761. name: f
  762. }));break;
  763. default:
  764. column.setEditor(new Ext.form.field.Date({
  765. id: f,
  766. name: f
  767. }));break;
  768. }
  769. break;
  770. case 'S':
  771. switch(record.data['union']){
  772. case 'Between And':
  773. column.setEditor(new erp.view.core.form.FtField({
  774. id: f,
  775. name: f,
  776. value: e.value
  777. }));break;
  778. default:
  779. column.setEditor(new Ext.form.field.Text({
  780. id: f,
  781. name: f
  782. }));break;
  783. }
  784. break;
  785. case 'N':
  786. switch(record.data['union']){
  787. case 'Between And':
  788. column.setEditor(new erp.view.core.form.FtNumberField({
  789. id: f,
  790. name: f
  791. }));break;
  792. default:
  793. column.setEditor(new Ext.form.field.Number({
  794. id: f,
  795. name: f
  796. }));break;
  797. }
  798. break;
  799. case 'T':
  800. column.dbfind = 'a|b';
  801. switch(record.data['union']){
  802. case 'Between And':
  803. column.setEditor(new erp.view.core.form.FtFindField({
  804. id: f,
  805. name: f
  806. }));break;
  807. default:
  808. column.setEditor(new erp.view.core.trigger.DbfindTrigger({
  809. id: f,
  810. name: f
  811. }));break;
  812. }
  813. break;
  814. default:
  815. column.setEditor(null);
  816. }
  817. }
  818. }
  819. }
  820. }),
  821. dbfinds: [{
  822. field: 'sl_label',
  823. dbGridField: 'sl_label'
  824. },{
  825. field: 'sl_field',
  826. dbGridField: 'sl_field'
  827. },{
  828. field: 'sl_type',
  829. dbGridField: 'sl_type'
  830. }],
  831. selModel: Ext.create('Ext.selection.CheckboxModel',{
  832. }),
  833. setEffectData: function(){
  834. var me = this;
  835. var datas = new Array();
  836. Ext.each(me.selModel.getSelection(), function(item){
  837. var data = item.data;
  838. if(!Ext.isEmpty(data.sl_label) && !Ext.isEmpty(data.union) && !Ext.isEmpty(data.value)){
  839. datas.push(data);
  840. }
  841. });
  842. me.effectdata = datas;
  843. },
  844. getEffectData: function(){
  845. return this.effectdata || new Array();
  846. },
  847. loadData: function(){
  848. var data = this.getEffectData();
  849. this.store.loadData(data);
  850. this.selModel.selectAll();
  851. this.store.add([{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]);
  852. },
  853. /**
  854. * 将数据拼成Sql条件语句
  855. */
  856. getCondition: function(){
  857. this.setEffectData();
  858. var condition = '';
  859. var separator = this.up('window').down('form').down('radio').getCheckValue();
  860. Ext.each(this.effectdata, function(data){
  861. if(data.union == 'Between And'){
  862. var v1 = data.value.split('~')[0];
  863. var v2 = data.value.split('~')[1];
  864. if(data.sl_type == 'D'){
  865. if(condition == ''){
  866. condition = '(' + data.sl_field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
  867. + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
  868. } else {
  869. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
  870. + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
  871. }
  872. } else if(data.sl_type == 'N'){
  873. if(condition == ''){
  874. condition = '(' + data.sl_field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
  875. } else {
  876. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
  877. }
  878. } else{
  879. if(condition == ''){
  880. condition = '(' + data.sl_field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
  881. } else {
  882. condition += ' ' + separator + ' (' + data.sl_field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
  883. }
  884. }
  885. } else {
  886. if(data.sl_type == 'D'){
  887. var v = data.value;
  888. if(data.union == '<'){
  889. v = "to_date('" + v + " 00:00:00','yyyy-MM-dd HH24:mi:ss')";
  890. } else if(data.union == '>'){
  891. v = "to_date('" + v + " 23:59:59','yyyy-MM-dd HH24:mi:ss')";
  892. } else {
  893. v = "to_date('" + v + "','yyyy-MM-dd')";
  894. }
  895. if(condition == ''){
  896. condition = '(' + data.sl_field + data.union + v + ') ';
  897. } else {
  898. condition += ' ' + separator +' (' + data.sl_field + data.union + v + ') ';
  899. }
  900. } else {
  901. var v = data.value;
  902. if(data.union == 'like'){
  903. v = " '%" + data.value + "%'";
  904. } else {
  905. v = " '" + data.value + "'";
  906. }
  907. if(condition == ''){
  908. condition = '(' + data.sl_field + " " + data.union + v + ") ";
  909. } else {
  910. condition += ' ' + separator +' (' + data.sl_field + " " + data.union + v + ") ";
  911. }
  912. }
  913. }
  914. });
  915. return condition;
  916. }
  917. });
  918. return grid;
  919. }
  920. });