PrintMT.js 4.4 KB

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