QueryDetail.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.QueryDetail', {
  3. extend : 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views : [ 'common.queryDetail.Viewport', 'common.datalist.GridPanel', 'common.query.Form', 'core.trigger.DbfindTrigger',
  6. 'core.form.FtField', 'core.form.ConDateField', 'core.form.YnField', 'core.form.FtDateField','common.datalist.Toolbar',
  7. 'core.form.MonthDateField','core.form.FtFindField', 'core.grid.YnColumn', 'core.grid.TfColumn',
  8. 'core.form.ConMonthDateField' ],
  9. init : function() {
  10. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  11. this.control({
  12. 'erpQueryFormPanel button[id=query]' : {
  13. click : function(btn) {
  14. var grid = Ext.getCmp('grid');
  15. var form = btn.ownerCt.ownerCt;
  16. var urlcondition = grid.defaultCondition || '';
  17. condition = form.spellCondition(urlcondition);
  18. grid.formCondition = condition;
  19. grid.getCount(null, condition);
  20. }
  21. },
  22. 'erpQueryFormPanel': {
  23. afterrender: function(f) {
  24. f.down('button[name=query]').handler = Ext.emptyFn;
  25. f.down('button[name=export]').handler = function(btn){
  26. var grid = Ext.getCmp('grid');
  27. var condition = grid.getCondition() || '';
  28. condition = f.spellCondition(condition);
  29. if(Ext.isEmpty(condition)) {
  30. condition = '1=1';
  31. }
  32. grid.BaseUtil.createExcel(caller, 'datalist', condition);
  33. };
  34. }
  35. },
  36. 'erpDatalistGridPanel' : {
  37. itemclick : this.onGridItemClick,
  38. afterrender:function(grid){
  39. if(Ext.isIE){
  40. document.body.attachEvent('onkeydown', function(){
  41. if(window.event.ctrlKey && window.event.keyCode == 67){//Ctrl + C
  42. var e = window.event;
  43. if(e.srcElement) {
  44. window.clipboardData.setData('text', e.srcElement.innerHTML);
  45. }
  46. }
  47. });
  48. } else {
  49. grid.getEl().dom.addEventListener("mouseover", function(e){
  50. if(e.ctrlKey){
  51. var Contextvalue=e.target.textContent==""?e.target.value:e.target.textContent;
  52. textarea_text = parent.document.getElementById("textarea_text");
  53. textarea_text.value=Contextvalue;
  54. textarea_text.focus();
  55. textarea_text.select();
  56. }
  57. });
  58. }
  59. }
  60. },
  61. 'monthdatefield': {
  62. afterrender: function(f) {
  63. var type = '';
  64. if(f.name == 'cd_yearmonth') {
  65. type = 'MONTH-T';
  66. }
  67. if(type != '') {
  68. this.getCurrentMonth(f, type);
  69. }
  70. }
  71. }
  72. });
  73. },
  74. onGridItemClick: function(selModel, record){//grid行选择
  75. if(keyField != null && keyField != ''){//有些datalist不需要打开明细表,这些表在datalist表里面不用配dl_keyField
  76. if(keyField.indexOf('+') > 0) {//多条件传入查询界面//vd_vsid@vd_id+vd_class@vd_class
  77. this.openQueryUrl(record);
  78. } else {
  79. this.openUrl(record);
  80. }
  81. }
  82. },
  83. openUrl: function(record) {
  84. var me = this, value = record.data[keyField];
  85. var formCondition = keyField + "IS" + value ;
  86. var gridCondition = pfField + "IS" + value;
  87. if(!Ext.isEmpty(pfField) && pfField.indexOf('+') > -1) {//多条件传入维护界面//vd_vsid@vd_id+vd_class@vd_class
  88. var arr = pfField.split('+'),ff = [],k = [];
  89. Ext.Array.each(arr, function(r){
  90. ff = r.split('@');
  91. k.push(ff[0] + 'IS\'' + record.get(ff[1]) + '\'');
  92. });
  93. gridCondition = k.join(' AND ');
  94. }
  95. var panelId = caller + keyField + "_" + value + gridCondition;
  96. var panel = Ext.getCmp(panelId);
  97. var main = parent.Ext.getCmp("content-panel");
  98. if(!main){
  99. main = parent.parent.Ext.getCmp("content-panel");
  100. }
  101. if(!panel){
  102. var title = "";
  103. if (value.toString().length>4) {
  104. title = value.toString().substring(value.toString().length-4);
  105. } else {
  106. title = value;
  107. }
  108. var myurl = '';
  109. if(me.BaseUtil.contains(url, '?', true)){
  110. myurl = url + '&formCondition='+formCondition+'&gridCondition='+gridCondition;
  111. } else {
  112. myurl = url + '?formCondition='+formCondition+'&gridCondition='+gridCondition;
  113. }
  114. myurl += "&datalistId=" + main.getActiveTab().id;
  115. main.getActiveTab().currentStore = me.getCurrentStore(value);//用于单据翻页
  116. if(main._mobile) {
  117. main.addPanel(me.BaseUtil.getActiveTab().title+'('+title+')', myurl, panelId);
  118. } else {
  119. panel = {
  120. title : me.BaseUtil.getActiveTab().title+'('+title+')',
  121. tag : 'iframe',
  122. tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'('+keyField + "=" + value+')'},
  123. frame : true,
  124. border : false,
  125. layout : 'fit',
  126. iconCls : 'x-tree-icon-tab-tab1',
  127. html : '<iframe id="iframe_maindetail_'+caller+"_"+value+'" src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  128. closable : true,
  129. listeners : {
  130. close : function(){
  131. if(!main){
  132. main = parent.parent.Ext.getCmp("content-panel");
  133. }
  134. main.setActiveTab(main.getActiveTab().id);
  135. }
  136. }
  137. };
  138. this.openTab(panel, panelId);
  139. }
  140. }else{
  141. main.setActiveTab(panel);
  142. }
  143. },
  144. openQueryUrl: function(record) {
  145. var me = this, arr = keyField.split('+'),ff = [],k = [];//vd_vsid@vd_id+vd_class@vd_class
  146. Ext.Array.each(arr, function(r){
  147. ff = r.split('@');
  148. k.push(ff[0] + '=' + record.get(ff[1]));
  149. });
  150. var myurl = k.join('&');
  151. var panelId = caller + "_" + myurl;
  152. var panel = Ext.getCmp(panelId);
  153. var main = parent.Ext.getCmp("content-panel");
  154. if(!main){
  155. main = parent.parent.Ext.getCmp("content-panel");
  156. }
  157. if(!panel){
  158. var title = me.BaseUtil.getActiveTab().title + '-查询';
  159. if(contains(url, '?', true)){
  160. myurl = url + '&' + myurl;
  161. } else {
  162. myurl = url + '?' + myurl;
  163. }
  164. if (main._mobile) {
  165. main.addPanel(title, myurl, panelId);
  166. } else {
  167. panel = {
  168. title : title,
  169. tag : 'iframe',
  170. tabConfig: {tooltip: title},
  171. frame : true,
  172. border : false,
  173. layout : 'fit',
  174. iconCls : 'x-tree-icon-tab-tab1',
  175. html : '<iframe src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  176. closable : true,
  177. listeners : {
  178. close : function(){
  179. if(!main){
  180. main = parent.parent.Ext.getCmp("content-panel");
  181. }
  182. main.setActiveTab(main.getActiveTab().id);
  183. }
  184. }
  185. };
  186. this.openTab(panel, panelId);
  187. }
  188. } else {
  189. main.setActiveTab(panel);
  190. }
  191. },
  192. openTab : function (panel,id){
  193. var o = (typeof panel == "string" ? panel : id || panel.id);
  194. var main = parent.Ext.getCmp("content-panel");
  195. /*var tab = main.getComponent(o); */
  196. if(!main) {
  197. main =parent.parent.Ext.getCmp("content-panel");
  198. }
  199. var tab = main.getComponent(o);
  200. if (tab) {
  201. main.setActiveTab(tab);
  202. } else if(typeof panel!="string"){
  203. panel.id = o;
  204. var p = main.add(panel);
  205. main.setActiveTab(p);
  206. }
  207. },
  208. getCurrentStore: function(value){
  209. var grid = Ext.getCmp('grid');
  210. var items = grid.store.data.items;
  211. var array = new Array();
  212. var o = null;
  213. Ext.each(items, function(item, index){
  214. o = new Object();
  215. o.selected = false;
  216. if(index == 0){
  217. o.prev = null;
  218. } else {
  219. o.prev = items[index-1].data[keyField];
  220. }
  221. if(index == items.length - 1){
  222. o.next = null;
  223. } else {
  224. o.next = items[index+1].data[keyField];
  225. }
  226. var v = item.data[keyField];
  227. o.value = v;
  228. if(v == value)
  229. o.selected = true;
  230. array.push(o);
  231. });
  232. return array;
  233. },
  234. getFilterCondition: function(){
  235. var fields = Ext.getCmp('grid').plugins[0].fields;
  236. var items = new Array();
  237. Ext.each(Ext.Object.getKeys(fields), function(key){
  238. var item = fields[key];
  239. if(item.value != null && item.value.toString().trim() != ''){
  240. items.push({
  241. xtype: item.xtype,
  242. id: item.itemId,
  243. fieldLabel: item.fieldLabel,
  244. fieldStyle: item.fieldStyle,
  245. value: item.value,
  246. columnWidth: 0.5,
  247. cls: 'form-field-border',
  248. listeners: {
  249. change: function(f){
  250. Ext.getCmp(item.id).setValue(f.value);
  251. }
  252. }
  253. });
  254. }
  255. });
  256. return items;
  257. },
  258. getCurrentMonth: function(f, type) {
  259. Ext.Ajax.request({
  260. url: basePath + 'fa/getMonth.action',
  261. params: {
  262. type: type
  263. },
  264. callback: function(opt, s, r) {
  265. var rs = Ext.decode(r.responseText);
  266. if(rs.data) {
  267. f.setValue(rs.data.PD_DETNO);
  268. }
  269. }
  270. });
  271. }
  272. });