fs-license-plate.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. >
  12. {{ item || '' }}
  13. </view>
  14. </view>
  15. <fs-keyboard mode="car" v-model="visible" :index="curIndex" @change="handleChange"></fs-keyboard>
  16. </view>
  17. </template>
  18. <script>
  19. /**
  20. * 车牌组件
  21. * @description 车牌组件
  22. * @event {Function} change chagne事件
  23. */
  24. export default {
  25. name: 'fs-license-plate'
  26. }
  27. </script>
  28. <script setup>
  29. import { ref } from 'vue'
  30. const props = defineProps({
  31. modelValue: String
  32. })
  33. const emits = defineEmits(['update:modelValue', 'change'])
  34. const carNo = ref(new Array(7))
  35. if (props.modelValue) {
  36. for (let i = 0; i < props.modelValue.length; i++) {
  37. carNo.value[i] = props.modelValue[i]
  38. }
  39. }
  40. let curIndex = ref(-1)
  41. const handleChange = item => {
  42. const length = carNo.value.filter(item => item).length
  43. if (item === 'del') {
  44. if (length >= 1) {
  45. curIndex.value--
  46. carNo.value[curIndex.value] = ''
  47. }
  48. } else {
  49. if (length <= 6) {
  50. carNo.value[curIndex.value] = item
  51. curIndex.value++
  52. }
  53. }
  54. emits('update:modelValue', carNo.value.join(''))
  55. emits('change', carNo.value.join(''))
  56. }
  57. let visible = ref(false)
  58. const handleInput = index => {
  59. curIndex.value = index
  60. visible.value = true
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .fs-plate {
  65. display: flex;
  66. justify-content: center;
  67. align-items: center;
  68. &-item {
  69. width: 80rpx;
  70. height: 90rpx;
  71. line-height: 90rpx;
  72. border-radius: 8rpx;
  73. border: 1px solid #cbcbcb;
  74. text-align: center;
  75. & + & {
  76. margin-left: 20rpx;
  77. }
  78. &-active {
  79. border-color: var(--primary);
  80. }
  81. }
  82. &-new {
  83. position: relative;
  84. &::after {
  85. content: '新能源';
  86. color: #999999;
  87. width: 100%;
  88. font-size: 10px;
  89. text-align: center;
  90. position: absolute;
  91. left: 0;
  92. right: 0;
  93. top: 50%;
  94. transform: translateY(-50%);
  95. }
  96. }
  97. }
  98. </style>