carDet.vue 3.8 KB

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