liuying
2024-12-11 3b8b9cba9ebe15ff4ae1a7d8cb483d1f0ffcfa85
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
// 多张连续打印
import BluePrint from '@/pages/print/bluePrint.js'
import {addPrintRecord} from '@/api/print.js'
 
    export default {
        methods:{
            printComp(reprintPram){
                let reprint = ''
                let ptintContext =[];
                // 是否重复打印
                if(reprintPram){
                    reprint = 'REPRINT'
                }
                uni.showLoading({
                    mask: true,
                    title: "正在连接..."
                })
                // 针对接口返回不同的字段名称进行判断
                if(this.materlist.wareMaterialCode == undefined){
                    this.materlist.wareMaterialCode = this.materlist.code || this.materlist.warematerialCode ||''
                }
                if(this.materlist.wareMaterialName == undefined){
                    this.materlist.wareMaterialName  = this.materlist.warematerialName ||  this.materlist.name || ''
                }
                if(this.materlist.barNo==undefined){
                    this.materlist.barNo =     this.materlist.batchNo || this.materlist.itemBatchNo || '' 
                }
                //物料名称是否换行 
                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
                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.wareMaterialCode}`,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:'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:560,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:560,y2:210,width:2},
 
                    {type:'text',x:10,y:225,text:`PO:${this.materlist.purchaseNo || ''}/${this.materlist.ebelp || ''}`,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.ermNum} ${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.barNo}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
                    // {type:'text',x:155,y:323,text:``,size:3,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:`Time:${this.getCurrentDate().date} ${this.getCurrentDate().time}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
                    // {type:'text',x:155,y:378,text:`${this.getCurrentDate().time}`,size:3,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.ermNum}`,width:4,level:1},
                    {type:'text',x:405,y:390,text:`${reprint}`,size:2,rotate:0,bold:1,underline:false,reverse:false}
                ]
                console.log(ptintContext)
                // addPrintRecord(this.addForm).then(res => {
                BluePrint.print(this.$store,ptintContext).then(()=>{
                    let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
                    let curRoute = routes[routes.length - 1].route //获取当前页面路由
                    if (curRoute == 'pages/print/bluetoothConnection') {// 连接蓝牙失败 跳页面
                        return
                    }
                    this.contLabel--
                    if (this.contLabel <= 0) {
                        uni.hideLoading();
                        uni.showToast({
                            title: `打印完成`,
                            duration: 2000
                        })
                        this.contLabel = 1
                        return
                    }
 
                    uni.showLoading({
                        mask: true,
                        title: `打印中,剩余:${this.contLabel}`
                    })
 
                    this.timer = setTimeout(() => { //间隔5秒 减少打印丢失
                        clearTimeout(this.timer)
                        this.timer = null
                        this.printComp(reprintPram)
                        // 添加打印记录
                        this.addForm.code = this.materlist.wareMaterialCode;
                        this.addForm.name = this.materlist.name;
                        this.addForm.batchNo = this.materlist.barNo ;
                        this.addForm.specificationModel = this.materlist.specificationModel;
                        //这里不再记录打印记录,因为有了斑马打印 【Editby shaocx,2023-05-22】
                        /*
                        addPrintRecord(this.addForm).then(res => {
                            console.log(res);
                        })
                        //*/
 
                    }, 10000)
 
                }).catch((err)=>{
                    uni.showToast({
                        title:'打印失败',
                        duration: 2000
                    })
                })
            }
        }
    }