PlatNum.vue 9.88 KB
<template>
  <div class="enter-wrap">
    <div class="plateInput" id="plateInput">
      <div class="item" :class="{ active: plateInput.input.type === 'p1' }" @click.stop="clickInput('p1')">
        <span id="p1">{{ plateInput.input.value.p1 }}</span>
      </div>
      <div class="item" :class="{ active: plateInput.input.type === 'p2' }" @click.stop="clickInput('p2')">
        <span id="p2">{{ plateInput.input.value.p2 }}</span>
      </div>
      <div class="icon-black"></div>
      <div class="item" :class="{ active: plateInput.input.type === 'p3' }" @click.stop="clickInput('p3')">
        <span id="p3">{{ plateInput.input.value.p3 }}</span>
      </div>
      <div class="item" :class="{ active: plateInput.input.type === 'p4' }" @click.stop="clickInput('p4')">
        <span id="p4">{{ plateInput.input.value.p4 }}</span>
      </div>
      <div class="item" :class="{ active: plateInput.input.type === 'p5' }" @click.stop="clickInput('p5')">
        <span id="p5">{{ plateInput.input.value.p5 }}</span>
      </div>
      <div class="item" :class="{ active: plateInput.input.type === 'p6' }" @click.stop="clickInput('p6')">
        <span id="p6">{{ plateInput.input.value.p6 }}</span>
      </div>
      <div class="item" :class="{ active: plateInput.input.type === 'p7' }" @click.stop="clickInput('p7')">
        <span id="p7">{{ plateInput.input.value.p7 }}</span>
      </div>
      <div class="item" :class="{ active: plateInput.input.type === 'p8', new: !plateInput.input.value.p8 }" @click.stop="clickInput('p8')">
        <span id="p8">{{ plateInput.input.value.p8 }}</span>
      </div>
    </div>
    <div class="bords" v-if="plateInput.input.dialogVisible">
      <div class="bor">
        <div class="btns">
          <button type="primary" size="small" plain @click="hiddenKeybord">取消</button>
          <button type="primary" class="success" size="small" plain @click="enterWord">完成</button>
        </div>
        <ul class="keyboard province" id="province" v-if="plateInput.input.dialogVisible && plateInput.input.type === 'p1'">
          <li v-for="i in Keyboard.province" @click.stop="clickKeyboard(i)" :key="i">{{ i }}</li>
          <li class="delete" @click.stop="clickDelete">
            <div class="sprite-icon icon-delete"></div>
            <!-- 删 -->
          </li>
        </ul>
        <ul class="keyboard province" id="number" v-if="plateInput.input.dialogVisible && plateInput.input.type !== 'p1'">
          <li
            :key="i"
            v-for="i in Keyboard.number"
            :class="{
              num:
                (plateInput.input.type === 'p2' && parseInt(i) >= 0 && parseInt(i) <= 9) ||
                (['学', '港', '澳', '挂'].includes(i) && ['p1', 'p2', 'p3', 'p4', 'p5', 'p6'].includes(plateInput.input.type)),
              lastBtn: lastBtn
            }"
            @click.stop="clickKeyboard(i)"
          >
            {{ i }}
          </li>
          <li class="delete deletes" @click.stop="clickDelete">
            <div class="sprite-icon icon-delete"></div>
            <!-- 删 -->
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'PlatNum',
  data() {
    return {
      currentPlate: undefined,
      plateInput: {
        input: {
          value: {
            p1: '',
            p2: '',
            p3: '',
            p4: '',
            p5: '',
            p6: '',
            p7: '',
            p8: ''
          },
          type: 'p1',
          dialogVisible: false
        }
      },
      Keyboard: {
        province: [
          '京',
          '粤',
          '津',
          '晋',
          '冀',
          '蒙',
          '辽',
          '吉',
          '黑',
          '渝',
          '苏',
          '浙',
          '皖',
          '闽',
          '赣',
          '鲁',
          '鄂',
          '沪',
          '宁',
          '桂',
          '琼',
          '川',
          '贵',
          '云',
          '藏',
          '陕',
          '新',
          '豫',
          '湘',
          '青',
          '甘'
        ],
        number: [
          '0',
          '1',
          '2',
          '3',
          '4',
          '5',
          '6',
          '7',
          '8',
          '9',
          'A',
          'B',
          'C',
          'D',
          'E',
          'F',
          'G',
          'H',
          'J',
          'K',
          'L',
          'M',
          'N',
          'P',
          'Q',
          'R',
          'S',
          'T',
          'U',
          'V',
          'W',
          'X',
          'Y',
          'Z',
          '学',
          '港',
          '澳',
          '挂'
        ]
      },
      lastBtn: false
    }
  },
  props: ['name', 'plateNumber', 'noRightPart'],
  computed: {
    plateNumber1: {
      get() {
        return this.plateNumber || ''
      },
      set(val) {
        this.$emit('update:plateNumber', val)
      }
    }
  },
  methods: {
    clickInput(type) {
      this.plateInput.input.type = type
      let val = this.plateInput.input.value['p' + (Number(type.split('')[1]) - 1)]
      if (['学', '港', '澳', '挂'].includes(val) && this.plateInput.input.type == 'p8') {
        this.lastBtn = true
      } else {
        this.lastBtn = false
      }
      this.plateInput.input.dialogVisible = true
    },
    hiddenKeybord() {
      this.plateInput.input.dialogVisible = false
    },
    enterWord() {
      this.$emit('updateChange', this.plateInput.input.value)
    },
    clickKeyboard(val) {
      if (this.plateInput.input.type === 'p2' && parseInt(val) >= 0 && parseInt(val) <= 9) {
        return
      }
      if (['学', '港', '澳', '挂'].includes(val) && ['p1', 'p2', 'p3', 'p4', 'p5', 'p6'].includes(this.plateInput.input.type)) {
        return
      }
      if (['学', '港', '澳', '挂'].includes(val) && this.plateInput.input.type == 'p7') {
        this.lastBtn = true
      }
      if (this.lastBtn && this.plateInput.input.type == 'p8') {
        return
      }
      this.plateInput.input.value[this.plateInput.input.type] = val
      let type = this.plateInput.input.type.split('p')[1]
      if (type !== '8') {
        this.plateInput.input.type = 'p' + (parseInt(type) + 1)
      }
    },
    clickDelete() {
      this.plateInput.input.value[this.plateInput.input.type] = undefined
      let nu = this.plateInput.input.type.split('p')[1] - 1
      if (nu >= 0) {
        this.plateInput.input.value['p' + nu] = undefined
      }
      let type = this.plateInput.input.type.split('p')[1]
      if (type !== '1') {
        this.plateInput.input.type = 'p' + (parseInt(type) - 1)
      }
    },
    setPlateNumber() {
      if (this.plateInput.input.plateNumber) {
        this.plateNumber1 = this.plateInput.input.plateNumber
      } else {
        this.plateNumber1 = undefined
      }
    },
    setDirectIssuedPlateNumber() {
      if (this.plateInput.input.plateNumber) {
        this.plateNumber1 = this.plateInput.input.plateNumber
      } else {
        this.plateNumber1 = undefined
      }
    }
  }
}
</script>

 <style scoped lang='scss'>
.enter-wrap {
  .plateInput {
    padding: 0 32px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    .item {
      width: 30px;
      height: 40px;
      background: rgba(50, 127, 250, 0.1);
      border: 0.5px solid rgba(50, 127, 250, 0.15);
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 600;
      font-size: 18px;
      color: #282829;
      &:last-child {
        background: #f3ffe7;
        border: 0.5px solid #e0f8c9;
      }
    }
    .icon-black {
      height: 8px;
      width: 8px;
      background: #282829;
      border-radius: 100%;
    }
    .active {
      border: 1.5px solid #327ffa !important;
    }
  }
  .bords {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 999;
    .bor {
      position: relative;
      .btns {
        width: 375px;
        height: 38px;
        background: #ffffff;
        position: absolute;
        display: flex;
        justify-content: space-between;
        align-items: center;
        top: -35px;
        left: 0;
        padding: 0 15px;
        box-sizing: border-box;
        button {
          background: #f2f2f2;
          border-radius: 4px;
          padding: 5px 12px;
          box-sizing: border-box;
          font-weight: 600;
          font-size: 14px;
          color: #3b3b3d;
          text-align: center;
          border: 0;
        }
        .success {
          background: #07c160;
          border-radius: 4px;
          color: #ffffff;
        }
      }
    }
    // 键盘
    .keyboard {
      position: fixed;
      bottom: 0;
      left: 0;
      background: #f7f7f7;
      width: 100%;
      height: 180px;
      margin: 0;
      padding: 0;
      font-size: 18px;
      z-index: 1;
    }
    .keyboard li {
      list-style: none;
      border-radius: 4px;
    }
    .keyboard li {
      float: left;
      background: #ffffff;
      border-radius: 4px;
      margin-left: 7px;
      margin-top: 8px;
      font-size: 16px;
      color: #333333;
    }
    .num {
      background: #ffffff;
      border-radius: 4px;
      font-size: 16px;
      color: #cacacc !important;
    }
    .lastBtn {
      background: #ffffff !important;
      border-radius: 4px;
      font-size: 16px;
      color: #cacacc !important;
    }
    .province {
      position: relative;
    }
    .provinces {
      position: relative;
    }
    .province li {
      width: calc((100% - 8px * 11) / 10);
      height: calc((100% - 8px * 5) / 4);
      display: flex;
      display: -webkit-flex;
      align-items: center;
      -webkit-align-items: center;
      justify-content: center;
      -webkit-justify-content: center;
    }
    .province li.delete {
      width: calc((100% - 8px * 11) / 10 * 2);
    }
    .province li.deletes {
      width: calc((100% - 8px * 11) / 10 * 2 + 10px);
    }
    .disabled {
      color: rgba(0, 0, 0, 0.15);
    }
  }
}
</style>