zjh
2025-04-26 18db0dbf100ff81ead99b1d6a3daa6c4c26e5d91
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
    <view class="container">
        <!-- 主内容区 -->
        <!-- <view class="scan-container"> -->
            <text class="main-title">来料扫码检验</text>
            <text class="subtitle">请对准物料条码,保持10-15cm距离</text>
            <!-- 扫描框 -->
            <view class="scan-box" @click="startScan">
                <view class="scan-line" :style="{top: linePosition + '%'}"></view>
            </view>
            <!-- 手动输入 -->
            <!-- <button class="manual-input" @click="showManualInput">手动输入条码</button> -->
        <!-- </view> -->
        <!-- 手动输入弹窗 -->
        <!-- <uni-popup ref="inputPopup" type="dialog">
            <uni-popup-dialog mode="input" title="手动输入" :value="manualCode"
                @confirm="confirmManualInput"></uni-popup-dialog>
        </uni-popup> -->
    </view>
</template>
                                                                                                                                           
<script>
    export default {
        data() {
            return {
                scanHistory: [],
                linePosition: -10,
                scanTimer: null,
                manualCode: ''
            }
        },
        mounted() {
            this.startScanAnimation()
        },
        methods: {
            // 启动扫描线动画
            startScanAnimation() {
                this.scanTimer = setInterval(() => {
                    this.linePosition = this.linePosition > 110 ? -10 : this.linePosition + 2
                }, 50)
            },
 
            // 调用真实扫码API
            async startScan() {
                try {
                    const res = await uni.scanCode({
                        scanType: ['qrCode', 'barCode'],
                        onlyFromCamera: true
                    })
 
                    this.handleScanResult(res.result)
                    uni.vibrateShort() // 震动反馈
                } catch (err) {
                    // this.showScanError('扫码失败:' + err.errMsg)
                }
            },
 
            // 处理扫码结果
            handleScanResult(code) {
                this.$post({
                    url: "/LLJ/getFromInfo",
                    data: {
                        Barcode: code
                    }
                }).then(ress => { 
                    if (ress.data.tbBillList.length > 0) {
 
                        if (ress.data.tbBillList[0].fsubmit === 1) {
 
                            uni.navigateTo({
                                url: 'Add?id=' + ress.data.tbBillList[0].id + '&lotNo=' + ress.data
                                    .tbBillList[0].lotNo + '&releaseNo=' + ress.data.tbBillList[0]
                                    .releaseNo +
                                    '&current=B'
                            })
                        } else {
 
                            uni.navigateTo({
                                url: 'Add?id=' + ress.data.tbBillList[0].id + '&lotNo=' + ress.data
                                    .tbBillList[0].lotNo + '&releaseNo=' + ress.data.tbBillList[0]
                                    .releaseNo +
                                    '&current=A'
                            })
                        }
 
                    } else {
                        uni.showModal({
                            title: '扫码错误',
                            content: '未查询到条码【' + code + '】相关单据内容',
                            showCancel: false
                        })
                        //showScanError('提示:未查询到条码【' + res.result + '】相关单据内容')
                        //this.msg = '提示:未查询到条码【' + res.result + '】相关单据内容'
                    }
                })
            },
 
            // 显示手动输入框
            showManualInput() {
                this.$refs.inputPopup.open()
            },
 
            // 确认手动输入
            confirmManualInput(value) {
                 
                this.handleScanResult(value)
            },
 
            // 校验条码格式(示例)
            validateCode(code) {
                return /^XB\d{6}$/.test(code)
            },
 
            // 获取当前时间
            getCurrentTime() {
                const now = new Date()
                return `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()} 
              ${now.getHours()}:${now.getMinutes()}`
            },
 
            // 异常处理
            showScanError(msg) {
                uni.showModal({
                    title: '扫码错误',
                    content: msg,
                    showCancel: false
                })
            },
 
 
        }
    }
</script>
 
<style lang="scss">
    .container {
        padding: 20rpx;
        background: #ffffff;
 
    }
 
    .status-bar {
        background: #1890FF;
        color: white;
        padding: 20rpx;
        border-radius: 16rpx 16rpx 0 0;
        font-size: 28rpx;
    }
 
    .scan-container {
        background: white;
        padding: 110rpx;
        border-radius: 0 0 16rpx 16rpx;
        box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
    }
 
    .main-title {
        color: #1890FF;
        font-size: 40rpx;
        font-weight: bold;
        text-align: center;
        display: block;
        margin: 20rpx 0;
    }
 
    .subtitle {
        color: #666;
        font-size: 28rpx;
        text-align: center;
        display: block;
        margin-bottom: 60rpx;
    }
 
    .scan-box {
        width: 500rpx;
        height: 500rpx;
        margin: 0 auto;
        border: 4rpx solid #1890FF;
        position: relative;
        overflow: hidden;
    }
 
    .scan-line {
        width: 100%;
        height: 4rpx;
        background: #1890FF;
        position: absolute;
        transition: top 0.1s linear;
    }
 
    .manual-input {
        margin-top: 60rpx;
        border: 2rpx solid #1890FF;
        color: #1890FF;
        border-radius: 40rpx;
    }
 
    .history {
        margin-top: 40rpx;
        padding-top: 20rpx;
        border-top: 2rpx solid #eee;
 
        .record {
            font-size: 28rpx;
            padding: 10rpx 0;
        }
    }
 
    .action-buttons {
        margin-top: 40rpx;
        display: flex;
        justify-content: space-around;
 
        button {
            padding: 20rpx 40rpx;
            border-radius: 40rpx;
 
            &:first-child {
                background: #FF4D4F;
                color: white;
            }
 
            &:last-child {
                background: #ddd;
            }
        }
    }
</style>