春风项目四线(合箱线、总装线)
yyt
2024-06-03 5030f3d30ccc1bd16db371c6970a48103aff9191
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
<template>
  <div style="height: 100%;width: 100%">
    <el-card class="box-card">
      <el-form size="large" :inline="true" label-width="68px" @submit.native.prevent>
        <el-form-item label-width="200" label="箱体码" :prop="barcode1"  style="align-content: center">
          <input v-model="barcode1"
                 ref="inputdata1"
                 style="height: 39px; width: 300px"
                 placeholder="请扫描箱体码"
          />
        </el-form-item>
 
        <el-form-item label-width="200" label="宝码" :prop="barcode2"  style="align-content: center">
          <input v-model="barcode2"
                 ref="inputdata2"
                 style="height: 39px; width: 300px"
                 placeholder="请扫描宝码"
          />
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data(){
    return {
      scannerFlag: false,
      barcode1: "",
      barcode2: "",
    };
  },
 
  mounted() {
    this.setFocus()
    this.$refs.inputdata1.addEventListener('keydown',this.handleScannerInput1)
    this.$refs.inputdata2.addEventListener('keydown',this.handleScannerInput2)
  },
  beforeDestroy() {
    this.$refs.inputdata1.removeEventListener('keydown',this.handleScannerInput1)
    this.$refs.inputdata2.removeEventListener('keydown',this.handleScannerInput2)
  },
  methods: {
    refresh() {
      location.reload();
    },
    setFocus(){
      this.$nextTick(()=>{
        this.$refs.inputdata1.focus()
      })
    },
    handleScannerInput1(event){
      if (this.scannerFlag){
        this.barcode1 = ''
        this.$refs.inputdata1.value = ''
        this.scannerFlag = false
      }
      const input = event.target
      const inputValue = input.value
      this.barcode1 = inputValue
      if (event.key === 'Enter'){
        this.scannerFlag = true
        console.log('条码1:',this.barcode1)
        this.$refs.inputdata2.focus();
        //扫描完成
      }
    },
    handleScannerInput2(event){
      if (this.scannerFlag){
        this.barcode2 = ''
        this.$refs.inputdata2.value = ''
        this.scannerFlag = false
      }
      const input = event.target
      const inputValue = input.value
      this.barcode2 = inputValue
      if (event.key === 'Enter'){
        this.scannerFlag = true
        console.log('条码2:',this.barcode2)
        this.$refs.inputdata1.focus();
        //扫描完成
      }
    },
  },
}
</script>
<style scoped lang="scss">
</style>