liuying
2024-12-10 fd067b408ae97f16c13b0e25b9c870d23f4d0ba3
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
// 打印单张 分拣 全检移库 移库 手工出入库  出库 越库-非生产订单   单号长度 1271007265
import BluePrint from '@/pages/print/bluePrint.js'
import {addPrintRecord} from '@/api/print.js'
 
    export default {
        methods:{
            // 参数1 是否重复打印 参数2 打印DO标贴还是PO标贴
            printComp(reprintPram,typeOrder){
                let reprint = '';
                let ptintContext =[];
                let str_order = ''
                // 是否重复打印
                if(reprintPram){
                    reprint = 'REPRINT'
                }
 
                // 针对接口返回不同的字段名称进行判断
                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 || ''
                }
                if(this.materlist.sap_Location==undefined){
                    this.materlist.sap_Location =     this.materlist.saP_StorageLocation || ''
                }
                if(this.materlist.quantityLable== undefined){
                    this.materlist.quantityLable = this.materlist.uncollectedQuantity || this.materlist.quantity ||''
                }
                //PO单 二维码带物料 DO:单号
                var ewm = "";
                var ewmX = 390;
                var ewmY = 250;
                var ewmWidth = 6;
 
                // 打印PO单 还是DO单 
                if(typeOrder=='DO'){ //分拣单需要加行号
                    str_order = `NO:${this.materlist.deliveryNo || ''}/${this.materlist.lineNumber || ''}`
                    ewm = `${this.materlist.deliveryNo || ''}`;
                }
                if(typeOrder=='PO'){
                    ewmX = 380;
                    ewmY = 220;
                    ewmWidth = 4;
                    str_order = `PO:${this.materlist.purchaseNo || ''}/${this.materlist.ebelp || this.materlist.lineNumber || ''}`
                    ewm = `PARTS NUMBER: ${this.materlist.wareMaterialCode},SAP: ${this.materlist.sap_Location || ''},LOT NO: ${this.materlist.barNo || ''},QUANTITY: ${this.materlist.quantityLable}`;
                }
                uni.showLoading({
                    mask: true,
                    title: "正在连接..."
                })
                //物料名称是否换行 
                let name = this.materlist.wareMaterialName || ''
                let name_1 = name.length > 38 ? name.substr(0, 38) : name
                //供应商是否换行
                var s1 =  ""
                if(this.materlist.supplierName){
                    s1 =  this.materlist.supplierNo + this.materlist.supplierName
                }
                let desc = this.materlist.supplier || s1  || ''
                let desc_1 = desc.length > 38 ? desc.substr(0, 38) : desc
                let desc_2 = desc.length > 38 ? desc.substr(38) : ''
                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:'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:`${str_order}`,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.quantityLable}`,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:'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:'line',x1:350,y1:210,x2:350,y2:420,width:2},
                    {type:'qr',x:ewmX,y:ewmY,text:`${ewm}`,width:ewmWidth,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 //获取当前页面路由
                        console.log(curRoute)
                        if (curRoute == 'pages/print/bluetoothConnection') {// 连接蓝牙失败 跳页面
                            return
                        }
                        uni.showToast({
                            title:'打印成功',
                            duration:2000
                        })
                        this.addForm.code = this.materlist.wareMaterialCode;
                        this.addForm.name = this.materlist.wareMaterialName;
                        this.addForm.batchNo = this.materlist.batchNo;
                        this.addForm.specificationModel = this.materlist.specificationModel;
                    }).catch((err)=>{
                        // uni.showToast({
                        //     title:'打印失败',
                        //     duration: 2000
                        // })
                    })
            }
        }
    }