BatchPrint.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**
  2. * 打印按钮
  3. */
  4. Ext.define('erp.view.core.button.BatchPrint',{
  5. id:'print',
  6. extend: 'Ext.Button',
  7. alias: 'widget.erpBatchPrintButton',
  8. iconCls: 'x-button-icon-print',
  9. cls: 'x-btn-gray',
  10. text: $I18N.common.button.erpBatchPrintButton,
  11. style: {
  12. marginLeft: '10px'
  13. },
  14. width: 100,
  15. initComponent : function(){
  16. this.callParent(arguments);
  17. },
  18. beforePrint: function(f,callback) {
  19. var me = this;
  20. Ext.Ajax.request({
  21. url: basePath + 'common/JasperReportPrint/getFields.action',
  22. method: 'post',
  23. params:{
  24. caller:f
  25. },
  26. callback: function(opt, s, r) {
  27. var rs = Ext.decode(r.responseText);
  28. callback.call(null,rs);
  29. }
  30. });
  31. },
  32. handler : function (){
  33. var me = this;
  34. me.idS = '';
  35. var lps_Barcaller='';
  36. if(caller == 'NewBar!BaPrint' || caller == 'Barcode!BaPrint' || caller == 'BarcodeStatus!query'){
  37. lps_Barcaller = 'Barcode!Print';
  38. }
  39. var bool = false;
  40. var grid = Ext.getCmp('batchDealGridPanel');
  41. var items = grid.selModel.getSelection();
  42. var idArray = [];
  43. Ext.each(items, function(item, index){
  44. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  45. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  46. idArray.push(this.data[grid.keyField]);
  47. bool = true;
  48. }
  49. });
  50. if(bool){
  51. var idS = idArray.toString();
  52. //me.print(idS,lps_Barcaller);
  53. me.idS = idS;
  54. me.zplPrint(lps_Barcaller);
  55. }else{
  56. showError("没有勾选需要打印的行,请勾选");
  57. }
  58. },
  59. print : function(idS,lps_Barcaller){
  60. var me = this;
  61. Ext.Ajax.request({
  62. url : basePath + 'common/JasperReportPrint/getPrintType.action',
  63. method : 'get',
  64. async : false,
  65. callback : function(opt, s, res){
  66. var r = new Ext.decode(res.responseText);
  67. if(r.success && r.printtype){
  68. me.printType=r.printtype;
  69. }
  70. }
  71. });
  72. me.beforePrint(lps_Barcaller,function(data){
  73. if(data.datas.length>1){
  74. this.window = Ext.create('Ext.window.Window', {
  75. autoShow: true,
  76. title: '选择打印类型',
  77. width: 400,
  78. height: 300,
  79. layout: 'anchor',
  80. items: [{
  81. anchor:'100% 100%',
  82. xtype:'form',
  83. id :'printbycondition',
  84. buttonAlign : 'center',
  85. items:[{
  86. xtype: 'combo',
  87. id: 'template',
  88. fieldLabel: '选择打印类型',
  89. store: Ext.create('Ext.data.Store', {
  90. autoLoad: true,
  91. fields: ['TITLE','ID','REPORTNAME'],
  92. data:data.datas
  93. }),
  94. queryMode: 'local',
  95. displayField: 'TITLE',
  96. valueField: 'ID',
  97. width:300,
  98. allowBlank:false,
  99. selectOnFocus:true,//用户不能自己输入,只能选择列表中有的记录
  100. style:'margin-left:15px;margin-top:15px;',
  101. listeners : {
  102. afterRender : function(combo) {
  103. combo.setValue(data.datas[0].ID);
  104. }
  105. }
  106. }]
  107. }],
  108. buttonAlign: 'center',
  109. buttons: [{
  110. text: '确定',
  111. handler: function(b) {
  112. var temp = Ext.getCmp('template');
  113. if(temp && temp.value!= null){
  114. var selData = temp.valueModels[0].data;
  115. me.jasperReportPrint(lps_Barcaller,selData.REPORTNAME,idS);
  116. }else{
  117. alert("请选择打印模板");
  118. }
  119. }
  120. }, {
  121. text: '取消',
  122. handler: function(b) {
  123. b.ownerCt.ownerCt.close();
  124. }
  125. }]
  126. });
  127. }else if(data.datas.length == 0){
  128. showError("请先配置对应的打印文件")
  129. }else{
  130. me.jasperReportPrint(lps_Barcaller,data.datas[0].REPORTNAME,idS);
  131. }
  132. });
  133. },
  134. jasperReportPrint : function(caller,reportname,idS){
  135. var me = this;
  136. var params = new Object();
  137. params['idS'] = idS;
  138. Ext.Ajax.request({
  139. url : basePath +'common/JasperReportPrint/print.action',
  140. params: {
  141. params: unescape(escape(Ext.JSON.encode(params))),
  142. caller: caller,
  143. reportname:reportname
  144. },
  145. method : 'post',
  146. timeout: 360000,
  147. callback : function(options,success,response){
  148. var res = new Ext.decode(response.responseText);
  149. if(res.success){
  150. var printcondition = '(barcode.bar_id in ('+idS+'))';
  151. printcondition = res.info.whereCondition=='' ? 'where '+printcondition :'where '+res.info.whereCondition+' and '+printcondition;
  152. var url = res.info.printurl + '?userName='+res.info.userName+'&reportName='+res.info.reportName+'&whereCondition='+printcondition+'&otherParameters=&printType='+res.info.printtype;
  153. window.open(url,'_blank');
  154. }else if(res.exceptionInfo){
  155. var str = res.exceptionInfo;
  156. showError(str);return;
  157. }
  158. }
  159. });
  160. },
  161. zplPrint:function(caller){//zpl打印语句
  162. // 获取选择打印文件,用户选择分辨率,和打印机
  163. var me = this;
  164. if(!me.window){
  165. setup_web_print(function(printers,selected_printer){
  166. me.window = Ext.create('Ext.window.Window', {
  167. autoShow: true,
  168. title: '选择打印模板',
  169. width: 400,
  170. height: 300,
  171. layout: 'anchor',
  172. id :'template-win',
  173. closeAction:'hide',
  174. items: [{
  175. anchor:'100% 100%',
  176. xtype:'form',
  177. buttonAlign : 'center',
  178. items:[{
  179. xtype: 'combo',
  180. id: 'printers',
  181. fieldLabel: '打印机列表',
  182. store: Ext.create('Ext.data.Store', {
  183. autoLoad: true,
  184. fields: ['display', 'value'],
  185. data:printers
  186. }),
  187. queryMode: 'local',
  188. displayField: 'display',
  189. valueField: 'value',
  190. width:361,
  191. allowBlank:false,
  192. value:selected_printer.uid,
  193. selectOnFocus:true,//用户不能自己输入,只能选择列表中有的记录
  194. style:'margin-left:15px;margin-top:15px;'
  195. },{
  196. xtype: 'combo',
  197. id: 'dpi',
  198. fieldLabel: '打印机分辨率',
  199. style:'margin-left:15px;margin-top:15px;',
  200. store: Ext.create('Ext.data.Store', {
  201. fields: ['display', 'value'],
  202. data : [{"display": '203dpi', "value": '203'},
  203. {"display": '300dpi', "value": '300'},
  204. {"display": '600dpi', "value": '600'},
  205. {"display": '1200dpi', "value": '1200'}]
  206. }),
  207. displayField: 'display',
  208. valueField: 'value',
  209. queryMode: 'local',
  210. value:resolutionCookie||'203',
  211. width:361,
  212. allowBlank:false,
  213. selectOnFocus:true//用户不能自己输入,只能选择列表中有的记录
  214. }]
  215. }],
  216. buttonAlign: 'center',
  217. buttons: [{
  218. text: '确定',
  219. handler: function(b) {
  220. var printers = Ext.getCmp('printers');
  221. var dpi = Ext.getCmp('dpi');
  222. if(printers && printers.value!= null){
  223. me.zebraPrint(caller,printers.value,dpi.value);
  224. b.ownerCt.ownerCt.close();
  225. }else{
  226. alert("请选择打印机 ");
  227. }
  228. }
  229. }, {
  230. text: '取消',
  231. handler: function(b) {
  232. b.ownerCt.ownerCt.close();
  233. }
  234. }]
  235. });
  236. });
  237. }else if(me.window.isHidden()){
  238. me.window.show();
  239. }
  240. },
  241. zebraPrint:function(caller,printer,dpi){
  242. var me = this;
  243. var params = new Object();
  244. params['condition'] = 'bar_id in ('+me.idS +")";
  245. sendData(caller,printer,dpi,params);
  246. }
  247. });