PrintByCondition.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * 按条件打印按钮
  3. */
  4. Ext.define('erp.view.core.button.PrintByCondition',{
  5. id:'printbycondition',
  6. extend: 'Ext.Button',
  7. alias: 'widget.erpPrintByConditionButton',
  8. iconCls: 'x-button-icon-print',
  9. cls: 'x-btn-gray',
  10. text: $I18N.common.button.erpPrintByConditionButton,
  11. style: {
  12. marginLeft: '10px'
  13. },
  14. width: 120,
  15. beforePrint: function(f,callback) {
  16. var me = this;
  17. Ext.Ajax.request({
  18. url: basePath + 'common/report/getFields.action',
  19. method: 'post',
  20. params:{
  21. caller:f
  22. },
  23. callback: function(opt, s, r) {
  24. var rs = Ext.decode(r.responseText);
  25. callback.call(null,rs);
  26. }
  27. });
  28. },
  29. handler: function(){
  30. var me = this;
  31. me.beforePrint(caller,function(data){
  32. if(data.datas.length>1){
  33. Ext.create('Ext.window.Window', {
  34. autoShow: true,
  35. title: '选择打印类型',
  36. width: 400,
  37. height: 300,
  38. layout: 'anchor',
  39. items: [{
  40. anchor:'100% 100%',
  41. xtype:'form',
  42. id :'printbycondition',
  43. buttonAlign : 'center',
  44. items:[{
  45. xtype: 'combo',
  46. id: 'template',
  47. fieldLabel: '选择打印类型',
  48. store: Ext.create('Ext.data.Store', {
  49. autoLoad: true,
  50. fields: ['TITLE','ID','CONDITION','FILE_NAME'],
  51. data:data.datas
  52. }),
  53. queryMode: 'local',
  54. displayField: 'TITLE',
  55. valueField: 'ID',
  56. width:300,
  57. allowBlank:false,
  58. selectOnFocus:true,//用户不能自己输入,只能选择列表中有的记录
  59. style:'margin-left:15px;margin-top:15px;',
  60. listeners : {
  61. afterRender : function(combo) {
  62. combo.setValue(data.datas[0].ID);
  63. }
  64. }
  65. }]
  66. }],
  67. buttonAlign: 'center',
  68. buttons: [{
  69. text: '确定',
  70. handler: function(b) {
  71. var temp = Ext.getCmp('template');
  72. if(temp && temp.value!= null){
  73. var selData = temp.valueModels[0].data;
  74. me.Print(caller,selData.FILE_NAME,selData.CONDITION);
  75. }else{
  76. alert("请选择打印模板");
  77. }
  78. }
  79. }, {
  80. text: '取消',
  81. handler: function(b) {
  82. b.ownerCt.ownerCt.close();
  83. }
  84. }]
  85. });
  86. }else{
  87. me.Print(caller,data.datas[0].FILE_NAME,data.datas[0].CONDITION);
  88. }
  89. });
  90. },
  91. Print:function(caller,reportName,condition){
  92. var me = this, form = me.ownerCt.ownerCt;
  93. var id = Ext.getCmp(form.fo_keyField).value;
  94. condition = condition.replace(/\[(.+?)\]/g,function(r){
  95. var field=r.substring(1,r.length-1);
  96. var da = Ext.getCmp(field);
  97. if(da){
  98. if(da.xtype=='textfield'){
  99. return "'"+da.value+"'";
  100. }else{
  101. return da.value;
  102. }
  103. }else{
  104. return '';
  105. }
  106. });
  107. if (form.printUrl) {
  108. this.execPrintLogic(form.printUrl, id, caller, reportName, condition, this.getPrintConfig);
  109. } else {
  110. this.getPrintConfig(id, caller, reportName, condition);
  111. }
  112. },
  113. execPrintLogic: function(logicUrl, id, caller, reportName, condition, callback) {
  114. var me = this, params={
  115. id:id,
  116. reportName:reportName,
  117. condition:condition
  118. };
  119. if(logicUrl.indexOf('caller=' == -1)){
  120. } else {
  121. params.caller = caller;
  122. }
  123. Ext.Ajax.request({
  124. url : basePath + logicUrl,
  125. params: params,
  126. timeout: 120000,
  127. method:'post',
  128. callback : function(options, success, response){
  129. var res = new Ext.decode(response.responseText);
  130. if(res.success){
  131. callback.call(me, id, caller, reportName, condition);
  132. } else{
  133. showError(res.exceptionInfo);
  134. }
  135. }
  136. });
  137. },
  138. getPrintConfig: function(id, caller, reportName, condition) {
  139. Ext.Ajax.request({
  140. url : basePath + 'common/report/print.action',
  141. params:{
  142. id:id,
  143. caller:caller,
  144. reportName:reportName,
  145. condition:condition
  146. },
  147. timeout: 120000,
  148. method:'post',
  149. callback : function(options, success, response){
  150. var res = new Ext.decode(response.responseText);
  151. if(res.success){
  152. if(res.info.isbz=='pdf'){
  153. window.location.href=res.info.printUrl+'/print?reportname='+res.info.reportname+'&condition='+res.info.condition+'&whichsystem='+res.info.whichsystem+"&"+'defaultCondition='+res.info.defaultCondition;
  154. }else{
  155. var url = res.info.printUrl + '?reportfile=' + res.info.reportname + '&&rcondition='+res.info.condition+'&&company=&&sysdate=373FAE331D06E956870163DCB2A96EC7&&key=3D7595A98BFF809D5EEEA9668B47F4A5&&whichsystem='+res.info.whichsystem+'';
  156. window.open(url,'_blank');
  157. }
  158. //window.location.href=res.info.printUrl+'/print?reportname='+res.info.reportname+'&condition='+res.info.condition+'&whichsystem='+res.info.whichsystem+"&"+'defaultCondition='+res.info.defaultCondition;
  159. }else{
  160. showError(res.exceptionInfo);
  161. }
  162. }
  163. });
  164. },
  165. initComponent : function(){
  166. this.callParent(arguments);
  167. }
  168. });