<el-input
ref=“inputDom”
v-model=“card_id”
@input=“changeEnrollId”
@clear=“clear”
clearable
style=“width: 250px; height: 36px”
>
let time
let timeDown // 停止输入
let length = ref(0)
const lock = ref(true) // 避免在转码这个过程中再次触发card_id.value.length > length.value
const changeEnrollId = () => {
if (card_id.value.length == 0) {
// 手动删除完毕时重置状态,此处判断为==1也可,为一表示在输入框为空时刷卡
length.value = 0
lock.value = true
}
clearTimeout(time)
time = setTimeout(() => {
length.value++
}, 100)
clearTimeout(timeDown)
timeDown = setTimeout(() => {
if (!lock.value) return
if (card_id.value.length > length.value) {
let aa = eval(Number(card_id.value) + ‘n’).toString(16)
let cardHex = aa.toUpperCase()
while (cardHex.length < 8) {
cardHex = ‘0’ + cardHex
}
let card_NO =
cardHex.substring(6, 8) +
cardHex.substring(4, 6) +
cardHex.substring(2, 4) +
cardHex.substring(0, 2)
length.value = 0
lock.value = false
card_id.value = card_NO
queryFund()
}
}, 180)
}
// 清空
const clear = () => {
console.log(‘触发clear’)
lock.value = true
length.value = 0
enroll_id.value = ‘’
cardData.user_name = ‘’
cardData.class_name = ‘’
cardData.money = ‘’
console.log(card_id.value, ‘clear’)
}