InputBarcode.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class="container-no-container">
  3. <van-dialog v-model:show="barcodeTrueFalseBy"
  4. :beforeClose="beforeClose"
  5. :title="title"
  6. show-cancel-button>
  7. <van-field class="code-input"
  8. v-model="barcode"
  9. ref="barcodeRef"
  10. @keydown.enter="onKeydown"
  11. clearable
  12. autocomplete="off"
  13. :placeholder="title" />
  14. <span class="tips">{{tag}}</span>
  15. </van-dialog>
  16. </div>
  17. </template>
  18. <script setup lang="ts">
  19. import { computed, ref } from 'vue'
  20. import { showToast } from 'vant'
  21. const store = useStore()
  22. const warehouse = store.warehouse
  23. import { useStore } from '@/store/modules/user'
  24. import { goBack } from '@/utils/android'
  25. const barcodeTrueFalseBy=ref(false)
  26. const barcodeRef=ref(null)
  27. const barcode=ref('');
  28. const title=ref('请扫描条码')
  29. const props=defineProps(['back'])
  30. const tag=ref('')
  31. const show = async (code,desc,tips) => {
  32. if(desc!==undefined){
  33. title.value=desc
  34. }
  35. if(tips!==undefined){
  36. tag.value=tips
  37. }
  38. barcodeTrueFalseBy.value = true
  39. barcode.value=code
  40. setTimeout(()=>{
  41. barcodeRef.value?.focus()
  42. },200)
  43. }
  44. //输入拣货容器号
  45. const emit = defineEmits(['setBarcode'])
  46. const beforeClose= (action) =>
  47. new Promise(async (resolve) => {
  48. if (action === 'confirm') {
  49. if (barcode.value === '' || barcode.value==undefined) {
  50. showToast(title.value)
  51. return resolve(false)
  52. }
  53. resolve(true)
  54. emit('setBarcode', barcode.value)
  55. }else {
  56. resolve(true)
  57. if(props.back){
  58. goBack()
  59. return
  60. }
  61. }
  62. });
  63. const onKeydown=()=>{
  64. setTimeout(()=>{
  65. barcodeRef.value?.blur()
  66. },300)
  67. }
  68. defineExpose({show})
  69. </script>
  70. <style scoped lang="sass">
  71. .container-no-container
  72. .code-input
  73. font-size: 22px
  74. font-weight: bold
  75. border-bottom: 2px solid #0077ff
  76. margin-top: 10px
  77. .completion
  78. text-align: right
  79. font-size: 12px
  80. padding: 5px 20px
  81. cursor: pointer
  82. text-decoration: underline
  83. .container-list
  84. max-height: 100px
  85. font-size: 13px
  86. font-weight: bold
  87. display: flex
  88. padding: 5px 20px
  89. justify-content: space-between
  90. flex-wrap: wrap
  91. overflow: auto
  92. .container-item
  93. width: 50%
  94. display: flex
  95. justify-items: center
  96. align-items: center
  97. padding: 2px 0
  98. cursor: pointer
  99. text-decoration: underline
  100. .container-item-line
  101. width: 5px
  102. height: 5px
  103. background: #0077ff
  104. border-radius: 50%
  105. margin-right: 5px
  106. .container-item-no
  107. flex: 1
  108. text-align: left
  109. .tips
  110. font-size: 14px
  111. color: #ff4141
  112. line-height: 20px
  113. </style>