Datalist.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.product.Datalist', {
  3. extend: 'Ext.app.Controller',
  4. BaseUtil: Ext.create('erp.util.BaseUtil'),
  5. FormUtil: Ext.create('erp.util.FormUtil'),
  6. //RenderUtil:Ext.create('erp.util.RenderUtil'),
  7. views:[
  8. 'scm.product.datalist.Viewport','scm.product.datalist.GridPanel','scm.product.datalist.Toolbar','core.button.VastAudit','core.button.VastDelete',
  9. 'core.button.VastPrint','core.button.VastReply','core.button.VastSubmit','core.button.ResAudit','core.button.Add','core.grid.YnColumn'
  10. ],
  11. init:function(){
  12. this.control({
  13. 'erpDatalistGridPanel': {
  14. itemclick: this.onGridItemClick
  15. },
  16. 'erpAddButton':{
  17. click: function(btn){
  18. var title = this.BaseUtil.getActiveTab().title;
  19. this.FormUtil.onAdd(caller + '_scan', title, url);
  20. }
  21. },
  22. 'erpVastDeleteButton': {
  23. click: function(btn){
  24. var dlwin = new Ext.window.Window({
  25. id : 'dlwin',
  26. title: btn.text,
  27. height: "100%",
  28. width: "80%",
  29. maximizable : true,
  30. buttonAlign : 'center',
  31. layout : 'anchor',
  32. items: [{
  33. tag : 'iframe',
  34. frame : true,
  35. anchor : '100% 100%',
  36. layout : 'fit',
  37. 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>'
  38. }],
  39. buttons : [{
  40. text: btn.text,
  41. iconCls: btn.iconCls,
  42. cls: 'x-btn-gray-1',
  43. handler: function(){
  44. }
  45. },{
  46. text : '关 闭',
  47. iconCls: 'x-button-icon-close',
  48. cls: 'x-btn-gray',
  49. handler : function(){
  50. Ext.getCmp('dlwin').close();
  51. }
  52. }]
  53. });
  54. dlwin.show();
  55. }
  56. }
  57. });
  58. },
  59. onGridItemClick: function(selModel, record){//grid行选择
  60. var me = this;
  61. if(keyField != null && keyField != ''){//有些datalist不需要打开明细表,这些表在datalist表里面不用配dl_keyField
  62. var value = record.data[keyField];
  63. var formCondition = keyField + "IS" + value ;
  64. var gridCondition = pfField + "IS" + value;
  65. var panel = Ext.getCmp(caller + keyField + "=" + value);
  66. var main = parent.Ext.getCmp("content-panel");
  67. if(!panel){
  68. var title = "";
  69. if (value.toString().length>4) {
  70. title = value.toString().substring(value.toString().length-4);
  71. } else {
  72. title = value;
  73. }
  74. var myurl = '';
  75. if(me.BaseUtil.contains(url, '?', true)){
  76. myurl = url + '&formCondition='+formCondition+'&gridCondition='+gridCondition;
  77. } else {
  78. myurl = url + '?formCondition='+formCondition+'&gridCondition='+gridCondition;
  79. }
  80. myurl += "&datalistId=" + main.getActiveTab().id;
  81. main.getActiveTab().currentStore = me.getCurrentStore(value);//用于单据翻页
  82. panel = {
  83. title : me.BaseUtil.getActiveTab().title+'('+title+')',
  84. tag : 'iframe',
  85. tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'('+keyField + "=" + value+')'},
  86. frame : true,
  87. border : false,
  88. layout : 'fit',
  89. iconCls : 'x-tree-icon-tab-tab1',
  90. html : '<iframe id="iframe_maindetail_'+caller+"_"+value+'" src="' + myurl + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>',
  91. closable : true,
  92. listeners : {
  93. close : function(){
  94. main.setActiveTab(main.getActiveTab().id);
  95. }
  96. }
  97. };
  98. this.openTab(panel, caller + keyField + "=" + record.data[keyField]);
  99. }else{
  100. main.setActiveTab(panel);
  101. }
  102. }
  103. },
  104. openTab : function (panel,id){
  105. var o = (typeof panel == "string" ? panel : id || panel.id);
  106. var main = parent.Ext.getCmp("content-panel");
  107. /*var tab = main.getComponent(o); */
  108. if(!main) {
  109. main =parent.parent.Ext.getCmp("content-panel");
  110. }
  111. var tab = main.getComponent(o);
  112. if (tab) {
  113. main.setActiveTab(tab);
  114. } else if(typeof panel!="string"){
  115. panel.id = o;
  116. var p = main.add(panel);
  117. main.setActiveTab(p);
  118. }
  119. },
  120. getCurrentStore: function(value){
  121. var grid = Ext.getCmp('grid');
  122. var items = grid.store.data.items;
  123. var array = new Array();
  124. var o = null;
  125. Ext.each(items, function(item, index){
  126. o = new Object();
  127. o.selected = false;
  128. if(index == 0){
  129. o.prev = null;
  130. } else {
  131. o.prev = items[index-1].data[keyField];
  132. }
  133. if(index == items.length - 1){
  134. o.next = null;
  135. } else {
  136. o.next = items[index+1].data[keyField];
  137. }
  138. var v = item.data[keyField];
  139. o.value = v;
  140. if(v == value)
  141. o.selected = true;
  142. array.push(o);
  143. });
  144. return array;
  145. }
  146. });