tg_small_v010.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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,545,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,310,65,80,"大件号"+l_flow);
  29. LODOP.SET_PRINT_STYLEA(0,"FontName","宋体");
  30. LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
  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]['l_num']===null){
  67. //走转换关系
  68. if (data['largrlabel'][j][k]['proportion']){
  69. var proportion = data['largrlabel'][j][k]['numn']*data['largrlabel'][j][k]['proportion'];
  70. proportion = Math.floor(proportion * 100) / 100;
  71. }else{
  72. var proportion = '';
  73. }
  74. }else if(data['largrlabel'][j][k]['l_num']==0){
  75. //判断是否是公斤
  76. if(data['largrlabel'][j][k]['main_unit']=='公斤'){
  77. //公斤使用l_weight
  78. var proportion = data['largrlabel'][j][k]['l_weight'];
  79. }else{
  80. //不是公斤走转换关系
  81. if (data['largrlabel'][j][k]['proportion']){
  82. var proportion = data['largrlabel'][j][k]['numn']*data['largrlabel'][j][k]['proportion'];
  83. proportion = Math.floor(proportion * 100) / 100;
  84. }else{
  85. var proportion = '';
  86. }
  87. }
  88. }else{
  89. //箱, 使用l_num
  90. var proportion = data['largrlabel'][j][k]['l_num'];
  91. }
  92. if (data['largrlabel'][j][k]['sec_unit']){
  93. var sec_unit = data['largrlabel'][j][k]['sec_unit'];
  94. }else{
  95. var sec_unit = '';
  96. }
  97. var html = template(document.getElementById('tpl').innerHTML, {
  98. product_name: data['largrlabel'][j][k]['matter_name'],
  99. manufacture_date:dateFamite(data['largrlabel'][j][k]['manufacture_date']),
  100. total:data['largrlabel'][j][k]['box_num'],
  101. l_flow:data['largrlabel'][j][k]['l_flow'],
  102. bach_no:data['largrlabel'][j][k]['bach_num'] /*getBathINo(data['largrlabel'][j][k]['code_cp1'],data['largrlabel'][j][k]['bath_id'])*/,
  103. spec: data['largrlabel'][j][k]['matter_size'],
  104. ziliangpihao:data['largrlabel'][j][k]['code'],
  105. pici:pici,
  106. supplier_name: data['largrlabel'][j][k]['supplier_name'],
  107. numn: data['largrlabel'][j][k]['numn'],
  108. qcode: './static/qrcode/none.png',//为了表格撑开
  109. main_unit:data['largrlabel'][j][k]['main_unit'],
  110. sec_unit:sec_unit,
  111. proportion:proportion,
  112. pCode:data['largrlabel'][j][k]['pCode'],
  113. });
  114. // sec_unit:data['largrlabel'][j][k]['sec_unit'],
  115. var qrcode=data['largrlabel'][j][k]['code'];
  116. var l_flow=qrcode.substr(53,6).replace(/\b(0+)/gi,"");
  117. /*if (data['num']>1 && status==1){
  118. //打印多份
  119. for(i=0;i<data['num'];i++){
  120. if (!flag){
  121. //第一次,预览、打印
  122. if(window.location.host=="dm-test.7in6.com"){
  123. //为测试服务器,预览
  124. prn1_preview(html,qrcode,l_flow);//预览
  125. }else if(window.location.host=="dm.7in6.com"){
  126. //prn1_preview(html,qrcode);//预览
  127. //为正式服务器,打印
  128. prn1_print(html,qrcode,l_flow);//打印
  129. }else{
  130. prn1_preview(html,qrcode,l_flow);//打印
  131. LODOP.On_Return=function(TaskID,Value){
  132. flag = Value};
  133. }
  134. }else if (flag){
  135. console.log(flag)
  136. //第二次及以后,直接打印
  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_print(html,qrcode,l_flow);//打印
  146. }
  147. }
  148. }
  149. }else if (data['num']=1 && status!=1) {
  150. }else if (data['num']>1 && status!=1) {
  151. }else{
  152. //打印次数为1,未多选
  153. if(window.location.host=="dm-test.7in6.com"){
  154. //为测试服务器,预览
  155. prn1_preview(html,qrcode,l_flow);//预览
  156. }else if(window.location.host=="dm.7in6.com"){
  157. //prn1_preview(html,qrcode);//预览
  158. //为正式服务器,打印
  159. prn1_print(html,qrcode,l_flow);//打印
  160. }else{
  161. prn1_preview(html,qrcode,l_flow);//打印
  162. }
  163. }*/
  164. if (!flag){
  165. prn1_preview(html,qrcode,l_flow);//预览
  166. LODOP.On_Return=function(TaskID,Value){
  167. p = Value;
  168. if (p>=1){
  169. $.ajax({
  170. url: "index.php?s=/Admin/NewQcode/rePrintTg",
  171. type: "POST",
  172. dataType: "json",
  173. data: {
  174. "type": type,
  175. "idList": idList,
  176. "reptQty": reptQty,
  177. "sign_type": sign_type,
  178. "status": 1,
  179. },
  180. error:function (XMLHttpRequest, textStatus, errorThrown){
  181. $.messager.alert('系统提示', '数据加载错误,请刷新重试!', 'error');
  182. return false;
  183. }
  184. })
  185. }
  186. }
  187. flag++;
  188. }
  189. }
  190. }
  191. var cint = setInterval(function (){
  192. if (p==1){
  193. clearInterval(cint);
  194. flag = 0;
  195. for(j in data['largrlabel']) {
  196. for(k in data['largrlabel'][j]){
  197. if (data['largrlabel'][j][k]['code'].substr(76,10)=='0000000000'){
  198. var pici = data['largrlabel'][j][k]['code'].substr(66,10).replace(/\b(0+)/gi,"");
  199. }else{
  200. 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,"");
  201. }
  202. // if(data['largrlabel'][j][k]['is_proportion']){
  203. // var proportion = data['largrlabel'][j][k]['l_weight']/100;
  204. // }else{
  205. // if (data['largrlabel'][j][k]['proportion']){
  206. // var proportion = data['largrlabel'][j][k]['numn']*data['largrlabel'][j][k]['proportion'];
  207. // //proportion = String(proportion).replace(/^(.*\..{2}).*$/,"$1");
  208. // proportion = Math.floor(proportion * 100) / 100;
  209. // }else{
  210. // var proportion = '';
  211. // }
  212. // }
  213. if(data['largrlabel'][j][k]['l_num']===null){
  214. //走转换关系
  215. if (data['largrlabel'][j][k]['proportion']){
  216. var proportion = data['largrlabel'][j][k]['numn']*data['largrlabel'][j][k]['proportion'];
  217. proportion = Math.floor(proportion * 100) / 100;
  218. }else{
  219. var proportion = '';
  220. }
  221. }else if(data['largrlabel'][j][k]['l_num']==0){
  222. //判断是否是公斤
  223. if(data['largrlabel'][j][k]['main_unit']=='公斤'){
  224. //公斤使用l_weight
  225. var proportion = data['largrlabel'][j][k]['l_weight'];
  226. }else{
  227. //不是公斤走转换关系
  228. if (data['largrlabel'][j][k]['proportion']){
  229. var proportion = data['largrlabel'][j][k]['numn']*data['largrlabel'][j][k]['proportion'];
  230. proportion = Math.floor(proportion * 100) / 100;
  231. }else{
  232. var proportion = '';
  233. }
  234. }
  235. }else{
  236. //箱, 使用l_num
  237. var proportion = data['largrlabel'][j][k]['l_num'];
  238. }
  239. if (data['largrlabel'][j][k]['sec_unit']){
  240. var sec_unit = data['largrlabel'][j][k]['sec_unit'];
  241. }else{
  242. var sec_unit = '';
  243. }
  244. var html = template(document.getElementById('tpl').innerHTML, {
  245. product_name: data['largrlabel'][j][k]['matter_name'],
  246. manufacture_date:dateFamite(data['largrlabel'][j][k]['manufacture_date']),
  247. total:data['largrlabel'][j][k]['box_num'],
  248. l_flow:data['largrlabel'][j][k]['l_flow'],
  249. bach_no:data['largrlabel'][j][k]['bach_num'] /*getBathINo(data['largrlabel'][j][k]['code_cp1'],data['largrlabel'][j][k]['bath_id'])*/,
  250. spec: data['largrlabel'][j][k]['matter_size'],
  251. ziliangpihao:data['largrlabel'][j][k]['code'],
  252. pici:pici,
  253. supplier_name: data['largrlabel'][j][k]['supplier_name'],
  254. numn: data['largrlabel'][j][k]['numn'],
  255. qcode: './static/qrcode/none.png',//为了表格撑开
  256. main_unit:data['largrlabel'][j][k]['main_unit'],
  257. sec_unit:sec_unit,
  258. proportion:proportion,
  259. pCode:data['largrlabel'][j][k]['pCode'],
  260. });
  261. var qrcode=data['largrlabel'][j][k]['code'];
  262. var l_flow=qrcode.substr(53,6).replace(/\b(0+)/gi,"");
  263. for(i=0;i<data['num'];i++){
  264. if (!flag){
  265. flag++;
  266. }else{
  267. prn1_print(html,qrcode,l_flow);//打印
  268. flag++;
  269. }
  270. // document.getElementById('wp').innerHTML = html;
  271. }
  272. }
  273. }
  274. }
  275. },2000)
  276. };
  277. function ad(html,qrcode,l_flow){
  278. prn1_print(html,qrcode,l_flow);//打印
  279. }
  280. function toSubmit(){
  281. // console.log('ok');
  282. //请求接口
  283. $.ajax({
  284. type:"POST",
  285. url:"2.php",
  286. success: function(result){
  287. //判断返回值,弹出用户提示
  288. small_v010_print(result);
  289. },
  290. error: function(e){
  291. swal("","网络延迟,稍后操作.");
  292. }
  293. })
  294. }