schangxiang@126.com
2025-09-17 ff43ddf18764629ff875478e4e47a7281cbd230a
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<template>
    <div class="print-delivering-label-page">
        <cu-custom bgColor="bg-white" :isBack="true">
            <block slot="backText">
            </block>
            <block slot="content">发货标签</block>
        </cu-custom>
        <scroll-view scroll-y="true" style="height: 100vh;">
            <view class="page-content">
                <u-form :model="materialForm" ref="materialRef" label-position="top">
                    <u-row style="padding: 0 0 0 15rpx;">
                        <u-col span="12">
                            <u-form-item label="物料编号:" prop="materialCode" required >
                                <u-input v-model="materialForm.materialCode"  placeholder="请扫描物料编号" @blur="materialBlur"></u-input>
                            </u-form-item>
                        </u-col>
                        <u-col span="12">
                            <u-form-item label="出库数量:" prop="number" required>
                                <u-input v-model="materialForm.number"  placeholder="请输入出库数量"></u-input>
                            </u-form-item>
                        </u-col>
                        <u-col span="12">
                            <u-form-item label="出库单号:" prop="outOrder" required>
                                <u-input v-model="materialForm.outOrder"  placeholder="请输入或扫描出库单号"></u-input>
                            </u-form-item>
                        </u-col>
                    </u-row>
                </u-form>
                <view class="btns-view">
                    <button type="primary" @tap="onPrint">打 印</button>
                </view>
            </view>
        </scroll-view>
    </div>
</template>
 
<script>
import BluePrint from './bluePrint.js'
import {getAttrValue} from '@/utils/tool.js'
import {getMaterialInfo} from '../../api/print.js'
export default {
    name:'printDeliveringLabelPage',
    data(){
        return {
            materialForm: {
                materialCode: '', //物料编号
                number: '', //发货数量
                outOrder: '', //出库单号
                lotNo: '', //批次
                // materialName: '' ,//物料名称
                // qrCode: '', //二维码内容
            },
            materialRules: {
                materialCode: [{required: true,message: '物料编号不能为空',trigger: 'blur'}],
                number: [{required: true,message: '物料编号不能为空',trigger: 'blur'}],
                outOrder: [{required: true,message: '出库单号不能为空',trigger: 'blur'}]
            }
        }
    },
    onReady() {
        this.$refs.materialRef.setRules(this.materialRules)
    },
    methods:{
        //物料编号失焦事件
        materialBlur() {
            //判断是否是录入的
            // if(this.materialForm.materialCode.length < 50) {
            //     uni.showToast({
            //         title:'扫码错误'
            //     })
            //     return
            // }
            //物料名称
            // this.materialForm.materialName = getAttrValue(this.materialForm.materialCode,'MATERIALNAME')
            //物料批次
            this.materialForm.lotNo = getAttrValue(this.materialForm.materialCode,'LOTNO')
            //物料编号
            this.materialForm.materialCode = getAttrValue(this.materialForm.materialCode,'PARTSNUMBER')
            //二维码内容
            // this.materialForm.qrCode = this.materialForm.materialCode
        },
        onPrint(){
            this.$refs.materialRef.validate(vali => {
                if(vali) {
                    //获取数据\
                    getMaterialInfo({materialCode: this.materialForm.materialCode}).then(res => {
                        if(Array.isArray(res.data.rows) && res.data.rows.length == 1) {
                            const result = res.data.rows[0];
                            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:565,y2: 3,width:2},
                                {type:'line',x1:3,y1:3,x2:3,y2: 345,width:2},
                                {type:'line',x1:3,y1:345,x2:565,y2: 345,width:2},
                                {type:'line',x1:565,y1:345,x2:565,y2:3,width:2},
                                {type:'text',x:80,y:15,text:'牧野汽车装备(武汉)有限公司',size:3,rotate:0,bold:1,underline:false,reverse:false},
                                {type:'line',x1:3,y1:60,x2:565,y2:60,width:2},
                                {type:'text',x:10,y:75,text:`物料编号: ${result.code}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
                                {type:'line',x1:3,y1:110,x2:380,y2:110,width:2},
                                {type:'text',x:10,y:125,text:`物料名称: ${result.materialTypeId}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
                                {type:'line',x1:3,y1:160,x2:380,y2:160,width:2},
                                {type:'text',x:10,y:175,text:`批次: ${this.materialForm.lotNo}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
                                {type:'line',x1:3,y1:210,x2:565,y2:210,width:2},
                                {type:'line',x1:380,y1:60,x2:380,y2:210,width:2},
                                {type:'qr',x:410,y:70,text: result.code,width:6,level:1},
                                {type:'text',x:10,y:225,text:`发货数量(QTY): ${this.materialForm.number}`,size:2,rotate:0,bold:1,underline:false,reverse:false},
                                {type:'line',x1:3,y1:260,x2:565,y2:260,width:2},
                                {type:'text',x:120,y:290,text:`DO号: ${this.materialForm.outOrder}`,size:3,rotate:0,bold:1,underline:false,reverse:false},
                                
                            ]
                            
                            BluePrint.print(this.$store,ptintContext).then(()=>{
                                uni.showToast({
                                    title:'打印成功',
                                    duration: 2000
                                })
                                this.materialForm.materialCode = ''; //物料编号
                                this.materialForm.number = ''; //发货数量
                                this.materialForm.lotNo = ''; //批次
                                this.materialForm.outOrder = '';
                            }).catch(()=>{
                                uni.showToast({
                                    title:'打印失败',
                                    duration: 2000
                                })
                            })
                        }else {
                            uni.showToast({
                                title:'物料信息不存在',
                                duration: 2000
                            })
                        }
                    })
                }else {
                    uni.showToast({
                        title:'表单验证失败',
                        type: 'warning'
                    })
                }
            })
        }
    }
}
</script>
 
<style lang="scss" scoped>
.print-delivering-label-page{
    .page-content{
        display: flex;
        flex-direction: column;
        align-items: center;
        $blockWidth:90%;
        .label-show,.btns-view{
            width: $blockWidth;
            box-sizing: border-box;
        }
        .label-show{
            margin-top: 30upx;
            background-color: #fff;
            border-radius: 20upx;
        }
        .btns-view{
            margin-top: 30upx;
        }
    }
}
 
</style>