<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 +
|
'¤t=B'
|
})
|
} else {
|
|
uni.navigateTo({
|
url: 'Add?id=' + ress.data.tbBillList[0].id + '&lotNo=' + ress.data
|
.tbBillList[0].lotNo + '&releaseNo=' + ress.data.tbBillList[0]
|
.releaseNo +
|
'¤t=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>
|