#
whycq
2024-07-29 3d5efbc419d3ddff189d8d0c36cf743887d28eaa
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
171
172
173
174
<template>
    <view>
        <view class="print-model" :style="style">
            <view class="display" :style="">
                <table>
                    <tr>
                        <td>料号</td>
                        <td>{{mat.matnr}}</td>
                        <td colspan="1" rowspan="2" style="width: 150px;">
                            <!-- 二维码 -->
                            <view class="qr-box">
                                <canvas canvas-id="qrcode" v-show="qrShow" style="width: 300rpx;margin: 0 auto;" />
                            </view>
                        </td>
                    </tr>
                    <tr>
                        <td>商品</td>
                        <td colspan="1">{{mat.maktx}}</td>
                    </tr>
                    <tr>
                        <td>日期</td>
                        <td colspan="2">{{time}}</td>
                    </tr>
                </table>
            </view>
        </view>
        <view>
            <button @click="toPrint">打印</button>
        </view>
    </view>
</template>
 
<script>
    import uQRCode from '@/static/js/uqrcode.js' //引入uqrcode.js
    export default {
        data() {
            return {
                style: {
                    height: '3px'
                },
                mat: {
                    matnr: '1200128-10055',
                    maktx: 'X5S-4-M03/333'
                },
                qrShow: false,
                time: ''
            }
        },
        onShow() {
            let getWindowInfo = uni.getWindowInfo()
            // console.log(getWindowInfo.screenHeight); //屏幕高度
            // console.log(getWindowInfo.screenWidth); //屏幕宽度
            // console.log(getWindowInfo.windowHeight); //可操作页面高度
            // console.log(getWindowInfo.windowWidth); //可操作页面宽度
            // console.log(getWindowInfo);
            // console.log('获取窗口信息');
            let height = (getWindowInfo.screenWidth + 10) * 48 / 74
            // console.log(height);
            this.style.height = height + 'px'
            this.getDate()
 
        },
        onLoad(opt) {
            let that = this
            const eventChannel = this.getOpenerEventChannel();
            eventChannel.on('data', function(data) {
                that.mat = data.data 
                that.qrFun(that.mat.matnr)
            })
            
        },
        methods: {
            // 打印
            toPrint() {
                let that = this
                uni.navigateTo({
                    url: "../print/printUNI",
                    success: function(res) {
                        // 通过eventChannel向被打开页面传送数据   向另外一个页面传递值的
                        res.eventChannel.emit('data1', {
                            data: that.mat,
                            time: that.time
                        })
                    },
                    events: {
                        // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据  另外一个页面传过来的
                        acceptDataFromOpenedPage: function(data) {
                            that.matnr = data.data
                        },
                    },
                
                
                });
            },
            //**生成二维码**//
            qrFun(text) {
                this.qrShow = true
                uQRCode.make({
                    canvasId: 'qrcode',
                    componentInstance: this,
                    text: text,
                    size: 150,
                    margin: 0,
                    backgroundColor: '#ffffff',
                    foregroundColor: '#000000',
                    fileType: 'jpg',
                    errorCorrectLevel: uQRCode.errorCorrectLevel.H,
                    success: res => {}
                })
            },
            // 日历
            getDate() {
                var dt = new Date();
                var year,month,day,hours,minutes,seconds,weeks
                year = dt.getFullYear();
                month = (dt.getMonth()+1) < 10 ? '0'+ (dt.getMonth()+1) : (dt.getMonth()+1);
                day = dt.getDate() < 10 ? '0'+dt.getDate() : dt.getDate();
                hours = dt.getHours() < 10 ? '0' + dt.getHours() : dt.getHours();
                minutes = dt.getMinutes() < 10 ? '0' + dt.getMinutes() : dt.getMinutes();
                seconds = dt.getSeconds() < 10 ? '0' + dt.getSeconds() : dt.getSeconds(); 
                weeks = dt.getDay(); 
                switch (weeks) {
                    case 0: weeks = "星期日"; break;
                    case 1: weeks = "星期一"; break;
                    case 2: weeks = "星期二"; break;
                    case 3: weeks = "星期三"; break;
                    case 4: weeks = "星期四"; break;
                    case 5: weeks = "星期五"; break;
                    default : weeks = "星期六";
                }
                this.time = year + "年" + month + "月" + day + "日 " + hours + ":" + minutes + ":" + seconds + " "
            },
        }
    }
</script>
 
<style>
    .print-model {
        width: 100%;
        /* background-color: #555555; */
        display: flex;
        align-items: center;
        justify-content: center;
    }
 
    .display {
        width: 96%;
        height: 96%;
        border-radius: 5px;
        background-color: #FFF;
        box-shadow: #bdbdbd;
        display: flex;
        align-items: center;
        justify-content: center;
    }
 
    .display-pak {
        margin: 2%;
        height: 92%;
        border: 1px solid #8a8a8a;
    }
 
    table {
        width: 92%;
        height: 92%;
        border: 0;
        border-collapse: collapse;
    }
 
    td {
        border: 1px solid #8a8a8a;
        text-align: center;
    }
</style>