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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
| // 带机床号 工序 DO的标贴
| import BluePrint from '@/pages/print/bluePrint.js'
| import {addPrintRecord} from '@/api/print.js'
|
| export default {
| methods:{
| printComp(reprintPram){
| // 数组只有一个对象
| this.materlist = this.arrPt[0]
| console.log( this.materlist )
| uni.showLoading({
| mask: true,
| title: "正在连接..."
| })
| // 针对接口返回不同的字段名称进行判断
| if(this.materlist.wareMaterialCode == undefined){
| this.materlist.wareMaterialCode = this.materlist.code || this.materlist.warematerialCode || this.materlist.materialCode ||''
| }
| if(this.materlist.wareMaterialName == undefined){
| this.materlist.wareMaterialName = this.materlist.warematerialName || this.materlist.name || this.materlist.materialName || ''
| }
| if(this.materlist.barNo==undefined){
| this.materlist.barNo = this.materlist.batchNo || ''
| }
| //物料名称是否换行
| let name = this.materlist.wareMaterialName || ''
| let name_1 = name.length > 38 ? name.substr(0, 38) : name
| let name_2 = name.length > 38 ? name.substr(38) : ''
| //供应商是否换行
| let desc = this.materlist.supplier || ''
| let desc_1 = desc.length > 38 ? desc.substr(0, 38) : desc
| let desc_2 = desc.length > 38 ? desc.substr(38) : ''
| // this.warehouse.PurchaseNo
| 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:570,y2: 3,width:2}, //上边线
| {type:'line',x1:3,y1:3,x2:3,y2: 420,width:2},//左边线
| {type:'line',x1:3,y1:420,x2:570,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.wareMaterialCode}`,size:4,rotate:0,bold:1,underline:false,reverse:false},
| {type:'line',x1:3,y1:80,x2:565,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:'text',x:10,y:115,text:`${name_2}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
| {type:'line',x1:3,y1:150,x2:565,y2:150,width:2},
| {type:'text',x:10,y:170,text:`Vendor:${desc_1}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
| {type:'text',x:10,y:175,text:`${desc_2}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
| {type:'line',x1:3,y1:210,x2:565,y2:210,width:2},
|
| {type:'text',x:10,y:225,text:`DO:${this.materlist.deliveryNo || ''}`,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.completeQuantity} ${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:`process:${this.materlist.process}/${this.materlist.equipment}`,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:`Batch:${this.materlist.batchNo || ''}`,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:380,y:220,text:`PARTS NUMBER: ${this.materlist.wareMaterialCode},SAP: ${this.materlist.sap_Location || ''},LOT NO: ${this.materlist.barNo},QUANTITY: ${this.materlist.quantity}`,width:4,level:1},
| { type: 'qr', x: 380, y: 220, text: `PARTS NUMBER: ${this.materlist.wareMaterialCode},SAP: ${this.materlist.sap_Location || ''},LOT NO: ${this.materlist.batchNo || ''},ORDER NO: ${this.materlist.orderNo || ''},QUANTITY: ${this.materlist.completeQuantity}`, width: 4, level: 1 },
|
| // {type:'text',x:405,y:390,text:`${reprint}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
|
| //发货标签不显示时间 【Editby shaocx,2023-05-11】
| { type: 'text', x: 355, y: 390, text: `${this.getCurrentDate().date} ${this.getCurrentDate().time}`, size: 1, rotate: 0, bold: 1, underline: false, reverse: false }
| // { type: 'text', x: 355, y: 390, text: ``, size: 2, 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.wareMaterialCode}`
| })
| this.timer = setTimeout(() => {// 设置定时器的作用:连接蓝牙失败跳页面,js运行有时有延迟,造成读取当前页面路由错误
| clearTimeout(this.timer)
| this.printComp()
| // 添加打印记录:和打印分开,互不干扰
| this.addForm.code = this.materlist.wareMaterialCode;
| this.addForm.name = this.materlist.wareMaterialName;
| this.addForm.batchNo = this.materlist.batchNo;
| console.log(this.addForm)
| //这里不再记录打印记录,因为有了斑马打印 【Editby shaocx,2023-05-22】
| /*
| addPrintRecord(this.addForm).then(res => {
| if (res.code == 200) {
| } else {
| uni.hideLoading();
| // uni.showToast({
| // icon: 'none',
| // title: '打印记录存储失败',
| // duration: 2000
| // })
| }
| })
| //*/
| }, 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}`
| }
| },
| }
| }
|
|