carDet.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="wrap">
  3. <u-navbar title="添加车牌"></u-navbar>
  4. <view class="key-input">
  5. <u-message-input :focus="true" :value="form.carNum" :maxlength="maxlength" :disabled-keyboard="true"></u-message-input>
  6. </view>
  7. <ucarkeyboard ref="uKeyboard" mode="car" :showTips="true" :confirmBtn="false" :mask-close-able="false" :tooltip="false" v-model="keyShow" @change="valChange" @backspace="backspace"></ucarkeyboard>
  8. <view class="default">
  9. <u-checkbox-group>
  10. <u-checkbox class="tips" v-model="form.defaultFlag" shape="circle" @change="checkboxChange()">设为默认车辆</u-checkbox>
  11. </u-checkbox-group>
  12. </view>
  13. <u-button class="login-btn" type="success" shape="circle" @click="keepCar">保存</u-button>
  14. </view>
  15. </template>
  16. <script>
  17. import * as userApi from '@/apis/user.js'
  18. import ucarkeyboard from '@/components/Ucarkeyboard.vue'
  19. export default {
  20. components: {
  21. ucarkeyboard
  22. },
  23. data() {
  24. return {
  25. maxlength:8,
  26. keyShow: true,
  27. form: {
  28. carNum: '鄂',
  29. defaultFlag: true,
  30. },
  31. }
  32. },
  33. onLoad(op) {
  34. if (op.id) {
  35. var str1 = op.id.slice(0, 19);
  36. var str2 = op.id.slice(20, 21);
  37. var str3 = op.id.slice(22);
  38. if (str1 == 'jp_team51_charge_id') {
  39. if (str2 == 'A') {
  40. this.code = str2;
  41. this.codeId = str3;
  42. }
  43. }
  44. }
  45. },
  46. onReady() {
  47. this.$refs.uKeyboard.changeCarInputMode();
  48. },
  49. methods: {
  50. checkboxChange() {
  51. this.form.defaultFlag = !this.form.defaultFlag;
  52. },
  53. // 按键被点击(点击退格键不会触发此事件)
  54. valChange(val) {
  55. // 将每次按键的值拼接到form.carNum变量中,注意+=写法
  56. this.form.carNum += val;
  57. console.log(this.form.carNum);
  58. if(this.form.carNum.length == 1) {
  59. this.$refs.uKeyboard.changeCarInputMode();
  60. }
  61. },
  62. // 退格键被点击
  63. backspace() {
  64. // 删除form.carNum的最后一个字符
  65. if (this.form.carNum.length) this.form.carNum = this.form.carNum.substr(0, this.form.carNum.length - 1);
  66. console.log(this.form.carNum);
  67. var aaa = this.$refs.uKeyboard.changeCarInputValue();
  68. if(this.form.carNum.length == 0 && aaa) {
  69. this.$refs.uKeyboard.changeCarInputMode();
  70. }
  71. },
  72. keepCar() {
  73. console.log(this.form)
  74. uni.showLoading({
  75. title: "加载中",
  76. mask: true,
  77. })
  78. userApi.addRegUserCar(this.form).then((res) => {
  79. uni.hideLoading();
  80. if (this.code == 'A') {
  81. uni.navigateBack({
  82. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  83. })
  84. } else {
  85. uni.navigateBack({
  86. url: '/pages/user/car/index'
  87. })
  88. }
  89. }).catch(error => {
  90. uni.showToast({
  91. title: error,
  92. icon: "none"
  93. })
  94. })
  95. }
  96. }
  97. }
  98. </script>
  99. <style>
  100. page {
  101. background-color: #fff;
  102. }
  103. </style>
  104. <style lang="scss" scoped>
  105. .u-drawer{
  106. z-index: -1 !important;
  107. }
  108. /deep/.u-char-item {
  109. width: 30px !important;
  110. height: 40px !important;
  111. font-size: 18px !important;
  112. }
  113. .key-input {
  114. padding-top: 24px;
  115. }
  116. .default {
  117. margin: 16px 28px;
  118. }
  119. .login-btn {
  120. margin: 28px;
  121. background-color: #00B962 !important;
  122. border-color: #00B962 !important;
  123. color: #fff !important;
  124. }
  125. </style>