1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
| // 生产库取货标签 越库生产订单打印
| import BluePrint from '@/pages/print/bluePrint.js'
| import {addPrintRecord} from '@/api/print.js'
|
| export default {
| methods:{
| printShengChanComp(reprintPram){
| // 数组只有一个对象
| this.materlist = this.arrPt[0]
|
| uni.showLoading({
| mask: true,
| title: "正在连接..."
| })
|
| if(this.materlist.code==undefined){
| this.materlist.code = this.materlist.wareMaterialCode || ""
| }
| if(this.materlist.name == undefined){
| this.materlist.name = this.materlist.wareMaterialName || ""
| }
| //物料名称是否换行
| let name = this.materlist.name || '';
| let name_1 = name.length > 38 ? name.substr(0, 38) : name;
|
| let ptintContext = [
| {type:'text',x:0,y:0,text:'',size:2,rotate:0,bold:0,underline:false,reverse:false},
| {type:'text',x:0,y:0,text:'',size:2,rotate:0,bold:0,underline:false,reverse:false},
| {type:'text',x:0,y:0,text:'',size:2,rotate:0,bold:0,underline:false,reverse:false},
| /* 以上空数据,为防止丢包时打印不正常 */
| {type:'line',x1:3,y1:3,x2:560,y2: 3,width:2}, //上边线
| {type:'line',x1:3,y1:3,x2:3,y2: 420,width:2},//左边线
| {type:'line',x1:3,y1:420,x2:560,y2: 420,width:2}, //最下边线
| {type:'line',x1:560,y1:3,x2:560,y2:420,width:2}, //右边线
| {type:'text',x:10,y:34,text:`Part:`,size:2,rotate:0,bold:1,underline:false,reverse:false},
| {type:'text',x:80,y:24,text:`${this.materlist.code}`,size:4,rotate:0,bold:1,underline:false,reverse:false},
| {type:'line',x1:3,y1:80,x2:560,y2:80,width:2},
| {type:'text',x:10,y:90,text:`Descript:${name_1}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
| {type:'line',x1:3,y1:150,x2:560,y2:150,width:2},
| {type:'text',x:10,y:170,text:`Collective Order:${this.materlist.subOrderNo || ''}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
| {type:'line',x1:3,y1:210,x2:560,y2:210,width:2},
|
| {type:'text',x:10,y:225,text:`BOM No.:${this.materlist.bomNumber || ''}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
|
| {type:'line',x1:3,y1:260,x2:350,y2:260,width:2},
|
| {type:'text',x:10,y:275,text:`Qty:${this.materlist.quantity} ${this.materlist.unit == null ? '' : this.materlist.unit}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
|
| {type:'line',x1:3,y1:310,x2:350,y2:310,width:2},
|
| {type:'text',x:10,y:325,text:`Batch:${this.materlist.batchNo || ''}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
|
| {type:'line',x1:3,y1:360,x2:350,y2:360,width:2},
|
| {type:'text',x:10,y:380,text:`Stage:${this.materlist.process} Machine:${this.materlist.equipment}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
| {type:'line',x1:350,y1:210,x2:350,y2:420,width:2},
| { type: 'qr', x: 390, y: 240, text: `${this.materlist.subOrderNo || ''}`, width: 6, level: 1 },
| { type: 'text', x: 380, y: 388, text: `${this.getCurrentDate().date} ${this.getCurrentDate().time}`, size: 1, rotate: 0, bold: 1, underline: false, reverse: false }
| ]
| console.log(ptintContext)
| // addPrintRecord(this.addForm).then(res => {
| BluePrint.print(this.$store,ptintContext).then(()=>{
| this.printHandle()
| }).catch((err)=>{
| uni.hideLoading();
| uni.showToast({
| title:'打印失败',
| duration: 2000
| })
| })
| },
| printHandle() {
| let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
| let curRoute = routes[routes.length - 1].route //获取当前页面路由
| if (curRoute == 'pages/print/bluetoothConnection') {// 连接蓝牙失败 跳页面
| return
| }
| this.arrPt.splice(0, 1)
| if (this.arrPt.length == 0) {
| uni.hideLoading();
| uni.showToast({
| title: `打印完成`,
| duration: 2000
| })
| return
| }
| uni.showLoading({
| mask: true,
| title: `打印成功:${this.materlist.code}`
| })
| this.timer = setTimeout(() => {// 设置定时器的作用:连接蓝牙失败跳页面,js运行有时有延迟,造成读取当前页面路由错误
| this.timer = null
| clearTimeout(this.timer)
| uni.hideLoading();
| this.printShengChanComp()
| }, 10000)
| },
|
| //获取print date print time
| getCurrentDate() {
| let date = new Date();
| let year = date.getFullYear(); //年
| let month = date.getMonth() + 1; //月
| month = month >= 10 ? month : '0' + month;
| let day = date.getDate(); //日
| day = day >= 10 ? day : '0' + day;
| let hour = date.getHours() //时
| hour = hour >= 10 ? hour : '0' + hour;
| let min = date.getMinutes(); //分
| min = min >= 10 ? min : '0' + min;
| let second = date.getSeconds(); //秒
| second = second >= 10 ? second : '0' + second;
| return {
| date: `${day}.${month}.${year}`,
| time: `${hour}:${min}:${second}`,
| formate: `${year}/${month}/${day}`
| }
| },
| }
| }
|
|