fs-license-plate.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view>
  3. <view class="title text-center gutter-v" style="padding: 20rpx;">请输入车牌号</view>
  4. <view class="fs-plate">
  5. <view
  6. class="fs-plate-item"
  7. :class="{'fs-plate-item-active': curIndex === index, 'fs-plate-new': index === 6 && !item}"
  8. v-for="(item, index) in carNo"
  9. :key="index"
  10. @click="handleInput(index)">
  11. {{item || ''}}
  12. </view>
  13. </view>
  14. <fs-keyboard mode="car" v-model="visible" :index="curIndex" @change="handleChange"></fs-keyboard>
  15. </view>
  16. </template>
  17. <script setup>
  18. import { ref } from 'vue'
  19. const props = defineProps({
  20. modelValue: String
  21. })
  22. const emits = defineEmits(['update:modelValue', 'change'])
  23. const carNo = ref(new Array(7))
  24. if (props.modelValue) {
  25. for (let i = 0; i < props.modelValue.length; i++) {
  26. carNo.value[i] = props.modelValue[i]
  27. }
  28. }
  29. let curIndex = ref(-1)
  30. const handleChange = item => {
  31. const length = carNo.value.filter(item => item).length
  32. if (item === 'del') {
  33. if (length >= 1) {
  34. curIndex.value--
  35. carNo.value[curIndex.value] = ''
  36. }
  37. } else{
  38. if (length <= 6) {
  39. carNo.value[curIndex.value] = item
  40. curIndex.value++
  41. }
  42. }
  43. emits('update:modelValue', carNo.value.join(''))
  44. }
  45. let visible = ref(false)
  46. const handleInput = (index) => {
  47. curIndex.value = index
  48. visible.value = true
  49. }
  50. </script>
  51. <style lang="scss" scoped>
  52. .fs-plate{
  53. display: flex;
  54. justify-content: center;
  55. align-items: center;
  56. &-item{
  57. width: 70rpx;
  58. height: 80rpx;
  59. line-height: 80rpx;
  60. border-radius: 8rpx;
  61. border: 1px solid #CBCBCB;
  62. text-align: center;
  63. & + &{
  64. margin-left: 20rpx;
  65. }
  66. &-active{
  67. border-color: var(--primary);
  68. }
  69. }
  70. &-new{
  71. position: relative;
  72. &::after{
  73. content: "新能源";
  74. color: #999999;
  75. width: 100%;
  76. font-size: 9px;
  77. text-align: center;
  78. position: absolute;
  79. left: 0;
  80. right: 0;
  81. top: 50%;
  82. transform: translateY(-50%);
  83. }
  84. }
  85. }
  86. </style>