Web端输入表单配合扫码枪

聚焦输入框,扫码枪输入,自动换行,若重复扫码,删除

</template>
    <div>
        <!-- *** -->

        <!-- 扫码枪交接对话框 -->
        <el-dialog v-dialogDrag title="报告交接" :visible.sync="isScannerHandoverDialogOpen" width="400px" append-to-body :close-on-click-modal="false" destroy-on-close>
          <el-row v-for="(param, index) in handoverParamList" :key="index">
            <el-col class="inputCol" :span="18">
              <input style="width:100%;" class="input" ref="handoverInputRef" @keydown.enter="handleEnterEvent(index)" v-model="param.reportNo" placeholder="请输入报告编号">
            </el-col>
            <el-col :span="6">
              <el-button style="margin-left: 5px;" @click="addHandoverParam" type="primary" icon="el-icon-plus" plain circle></el-button>
              <el-button style="margin-left: 5px;" @click="deleteHandoverParam(index)" type="danger" icon="el-icon-delete" plain circle></el-button>
            </el-col>
          </el-row>
          <div slot="footer" class="dialog-footer">
            <el-button :loading="buttonLoading" type="primary" @click="handleScannerHandover">确 定</el-button>
            <el-button @click="isScannerHandoverDialogOpen = false">取 消</el-button>
          </div>
        </el-dialog>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                handoverParamList: [{ reportNo: "" }],
            }
        },
        methods: {
            // 添加交接列表项
            addHandoverParam() {
              this.handoverParamList.push({ reportNo: "" });
            },
            // 删除交接列表项
            deleteHandoverParam(index) {
              if (this.handoverParamList.length == 1) {
                return;
              }
              this.handoverParamList.splice(index, 1);
            },
            // 监听回车事件
            handleEnterEvent(index) {
              console.log("回车");
                // 首先取到列表,去除最后一项(需要判断是否重复的,即当前项)
                let list = this.handoverParamList.map((item, index) => {
                  if (this.handoverParamList.length - 1 == index) return "";
                  return item.reportNo;
                });
                // 转为字符串后判断是否包含当前项
                if (list.join().includes(this.$refs.handoverInputRef[index].value)) {
                  // 有重复项时清空
                  this.$refs.handoverInputRef[index].value = "";
                  this.$message({
                    message: "扫描重复!",
                    type: "warning",
                  });
                  return;
                } else {
                  // 没有重复项时新增一行,并自动聚焦
                  this.addHandoverParam();
                  this.$nextTick(() => {
                    // console.log(this.$refs.inputRef[index + 1]);
                    this.$refs.handoverInputRef[index + 1].focus();
                  });
                }
            },
        }
    }
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值