tg_small_v010.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. *2018-08-17
  3. *小件盒包装纸100x150
  4. */
  5. var LODOP; //声明为全局变量
  6. function prn1_print(html,qrcode,l_flow) {
  7. CreateOneFormPage(html,qrcode,l_flow);
  8. // console.log(html);
  9. LODOP.PRINT();
  10. };
  11. function prn1_preview(html,qrcode,l_flow) {
  12. CreateOneFormPage(html,qrcode,l_flow);
  13. LODOP.PREVIEW();
  14. };
  15. function CreateOneFormPage(html,qrcode,l_flow){
  16. LODOP.SET_LICENSES("","152A06E8F6CBD6AC1F213ABFCB0D8604","C94CEE276DB2187AE6B65D56B3FC2848","");
  17. LODOP=getLodop();
  18. LODOP.PRINT_INIT("河南中烟大件二维码打码");
  19. LODOP.SET_PRINT_STYLE("FontSize",16);
  20. LODOP.SET_PRINT_STYLE("Bold",1);
  21. LODOP.SET_PRINT_PAGESIZE(1, 1000, 1500, "CreateCustomPage");
  22. // LODOP.ADD_PRINT_TEXT(30,40,350,45,"浙江美浓世纪集团有限公司");
  23. // LODOP.SET_PRINT_MODE("PRINT_SETUP_PROGRAM",true);//设置打印维护窗口关闭后是否返回程序代码
  24. // LODOP.SET_PREVIEW_WINDOW(1,1,1,800,800,"预览.直接打印");
  25. LODOP.ADD_PRINT_HTM(15,20,350,500,html);
  26. LODOP.SET_PRINT_STYLEA(0,"QRCodeErrorLevel","M");
  27. LODOP.ADD_PRINT_BARCODE(330,70,'70mm','70mm',"QRCode",qrcode);
  28. LODOP.ADD_PRINT_TEXT(400,300,70,80,"大件号"+l_flow);
  29. LODOP.SET_PRINT_STYLEA(0,"FontName","宋体");
  30. LODOP.SET_PRINT_STYLEA(0,"FontSize",14);
  31. LODOP.SET_PRINT_STYLEA(0,"FontColor","#000000");
  32. LODOP.SET_PRINT_STYLEA(0,"Bold",1);
  33. LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
  34. };
  35. function dateFamite(date) {
  36. return '20'+date.substr(0, 2)+'-'+date.substr(2, 2)+'-'+date.substr(4, 2);
  37. }
  38. function changetime(time) {
  39. var gtime=20000000;
  40. var times=parseInt(time)+parseInt(gtime);
  41. return times;
  42. }
  43. function getBathINo(code_cp1,bath_id) {
  44. var bath_no;
  45. if(bath_id.length<6){
  46. bath_no=code_cp1.substr(0, 6);
  47. for(i=0;i<(6-bath_id.length);i++){
  48. bath_no=bath_no+'0';
  49. }
  50. }
  51. bath_no= bath_no+bath_id;
  52. return bath_no;
  53. }
  54. //小件云打印数据处理
  55. function small_v010_print(result,type,idList,reptQty,sign_type) {
  56. data=result;
  57. var p=0;
  58. var flag = 0;
  59. for(j in data['largrlabel']) {
  60. for(k in data['largrlabel'][j]){
  61. if (data['largrlabel'][j][k]['code'].substr(76,10)=='0000000000'){
  62. var pici = data['largrlabel'][j][k]['code'].substr(66,10).replace(/\b(0+)/gi,"");
  63. }else{
  64. var pici = data['largrlabel'][j][k]['code'].substr(66,10).replace(/\b(0+)/gi,"")+'、'+data['largrlabel'][j][k]['code'].substr(76,20).replace(/\b(0+)/gi,"");
  65. }
  66. if(data['largrlabel'][j][k]['is_proportion']){
  67. var proportion = data['largrlabel'][j][k]['l_weight']/100;
  68. }else{
  69. if (data['largrlabel'][j][k]['proportion']){
  70. var proportion = data['largrlabel'][j][k]['numn']*data['largrlabel'][j][k]['proportion'];
  71. //proportion = String(proportion).replace(/^(.*\..{2}).*$/,"$1");
  72. proportion = Math.floor(proportion * 100) / 100;
  73. }else{
  74. var proportion = '';
  75. }
  76. }
  77. if (data['largrlabel'][j][k]['sec_unit']){
  78. var sec_unit = data['largrlabel'][j][k]['sec_unit'];
  79. }else{
  80. var sec_unit = '';
  81. }
  82. var html = template(document.getElementById('tpl').innerHTML, {
  83. product_name: data['largrlabel'][j][k]['matter_name'],
  84. manufacture_date:dateFamite(data['largrlabel'][j][k]['manufacture_date']),
  85. total:data['largrlabel'][j][k]['box_num'],
  86. l_flow:data['largrlabel'][j][k]['l_flow'],
  87. bach_no:data['largrlabel'][j][k]['bach_num'] /*getBathINo(data['largrlabel'][j][k]['code_cp1'],data['largrlabel'][j][k]['bath_id'])*/,
  88. spec: data['largrlabel'][j][k]['matter_size'],
  89. ziliangpihao:data['largrlabel'][j][k]['code'],
  90. pici:pici,
  91. supplier_name: data['largrlabel'][j][k]['supplier_name'],
  92. numn: data['largrlabel'][j][k]['numn'],
  93. qcode: './static/qrcode/none.png',//为了表格撑开
  94. main_unit:data['largrlabel'][j][k]['main_unit'],
  95. sec_unit:sec_unit,
  96. proportion:proportion,
  97. });
  98. // sec_unit:data['largrlabel'][j][k]['sec_unit'],
  99. var qrcode=data['largrlabel'][j][k]['code'];
  100. var l_flow=qrcode.substr(53,6).replace(/\b(0+)/gi,"");
  101. /*if (data['num']>1 && status==1){
  102. //打印多份
  103. for(i=0;i<data['num'];i++){
  104. if (!flag){
  105. //第一次,预览、打印
  106. if(window.location.host=="dm-test.7in6.com"){
  107. //为测试服务器,预览
  108. prn1_preview(html,qrcode,l_flow);//预览
  109. }else if(window.location.host=="dm.7in6.com"){
  110. //prn1_preview(html,qrcode);//预览
  111. //为正式服务器,打印
  112. prn1_print(html,qrcode,l_flow);//打印
  113. }else{
  114. prn1_preview(html,qrcode,l_flow);//打印
  115. LODOP.On_Return=function(TaskID,Value){
  116. flag = Value};
  117. }
  118. }else if (flag){
  119. console.log(flag)
  120. //第二次及以后,直接打印
  121. if(window.location.host=="dm-test.7in6.com"){
  122. //为测试服务器,预览
  123. prn1_preview(html,qrcode,l_flow);//预览
  124. }else if(window.location.host=="dm.7in6.com"){
  125. //prn1_preview(html,qrcode);//预览
  126. //为正式服务器,打印
  127. prn1_print(html,qrcode,l_flow);//打印
  128. }else{
  129. prn1_print(html,qrcode,l_flow);//打印
  130. }
  131. }
  132. }
  133. }else if (data['num']=1 && status!=1) {
  134. }else if (data['num']>1 && status!=1) {
  135. }else{
  136. //打印次数为1,未多选
  137. if(window.location.host=="dm-test.7in6.com"){
  138. //为测试服务器,预览
  139. prn1_preview(html,qrcode,l_flow);//预览
  140. }else if(window.location.host=="dm.7in6.com"){
  141. //prn1_preview(html,qrcode);//预览
  142. //为正式服务器,打印
  143. prn1_print(html,qrcode,l_flow);//打印
  144. }else{
  145. prn1_preview(html,qrcode,l_flow);//打印
  146. }
  147. }*/
  148. if (!flag){
  149. prn1_preview(html,qrcode,l_flow);//预览
  150. LODOP.On_Return=function(TaskID,Value){
  151. p = Value;
  152. if (p>=1){
  153. $.ajax({
  154. url: "index.php?s=/Admin/NewQcode/rePrintTg",
  155. type: "POST",
  156. dataType: "json",
  157. data: {
  158. "type": type,
  159. "idList": idList,
  160. "reptQty": reptQty,
  161. "sign_type": sign_type,
  162. "status": 1,
  163. },
  164. error:function (XMLHttpRequest, textStatus, errorThrown){
  165. $.messager.alert('系统提示', '数据加载错误,请刷新重试!', 'error');
  166. return false;
  167. }
  168. })
  169. }
  170. }
  171. flag++;
  172. }
  173. }
  174. }
  175. var cint = setInterval(function (){
  176. if (p==1){
  177. clearInterval(cint);
  178. flag = 0;
  179. for(j in data['largrlabel']) {
  180. for(k in data['largrlabel'][j]){
  181. if (data['largrlabel'][j][k]['code'].substr(76,10)=='0000000000'){
  182. var pici = data['largrlabel'][j][k]['code'].substr(66,10).replace(/\b(0+)/gi,"");
  183. }else{
  184. var pici = data['largrlabel'][j][k]['code'].substr(66,10).replace(/\b(0+)/gi,"")+'、'+data['largrlabel'][j][k]['code'].substr(76,20).replace(/\b(0+)/gi,"");
  185. }
  186. if(data['largrlabel'][j][k]['is_proportion']){
  187. var proportion = data['largrlabel'][j][k]['l_weight']/100;
  188. }else{
  189. if (data['largrlabel'][j][k]['proportion']){
  190. var proportion = data['largrlabel'][j][k]['numn']*data['largrlabel'][j][k]['proportion'];
  191. //proportion = String(proportion).replace(/^(.*\..{2}).*$/,"$1");
  192. proportion = Math.floor(proportion * 100) / 100;
  193. }else{
  194. var proportion = '';
  195. }
  196. }
  197. if (data['largrlabel'][j][k]['sec_unit']){
  198. var sec_unit = data['largrlabel'][j][k]['sec_unit'];
  199. }else{
  200. var sec_unit = '';
  201. }
  202. var html = template(document.getElementById('tpl').innerHTML, {
  203. product_name: data['largrlabel'][j][k]['matter_name'],
  204. manufacture_date:dateFamite(data['largrlabel'][j][k]['manufacture_date']),
  205. total:data['largrlabel'][j][k]['box_num'],
  206. l_flow:data['largrlabel'][j][k]['l_flow'],
  207. bach_no:data['largrlabel'][j][k]['bach_num'] /*getBathINo(data['largrlabel'][j][k]['code_cp1'],data['largrlabel'][j][k]['bath_id'])*/,
  208. spec: data['largrlabel'][j][k]['matter_size'],
  209. ziliangpihao:data['largrlabel'][j][k]['code'],
  210. pici:pici,
  211. supplier_name: data['largrlabel'][j][k]['supplier_name'],
  212. numn: data['largrlabel'][j][k]['numn'],
  213. qcode: './static/qrcode/none.png',//为了表格撑开
  214. main_unit:data['largrlabel'][j][k]['main_unit'],
  215. sec_unit:sec_unit,
  216. proportion:proportion,
  217. });
  218. var qrcode=data['largrlabel'][j][k]['code'];
  219. var l_flow=qrcode.substr(53,6).replace(/\b(0+)/gi,"");
  220. for(i=0;i<data['num'];i++){
  221. if (!flag){
  222. flag++;
  223. }else{
  224. prn1_print(html,qrcode,l_flow);//打印
  225. flag++;
  226. }
  227. // document.getElementById('wp').innerHTML = html;
  228. }
  229. }
  230. }
  231. }
  232. },2000)
  233. };
  234. function ad(html,qrcode,l_flow){
  235. prn1_print(html,qrcode,l_flow);//打印
  236. }
  237. function toSubmit(){
  238. // console.log('ok');
  239. //请求接口
  240. $.ajax({
  241. type:"POST",
  242. url:"2.php",
  243. success: function(result){
  244. //判断返回值,弹出用户提示
  245. small_v010_print(result);
  246. },
  247. error: function(e){
  248. swal("","网络延迟,稍后操作.");
  249. }
  250. })
  251. }