carDet.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. -->
  7. <view class="key-input">
  8. <umessageInput :focus="true"
  9. @selectIndex="getSelectIndex"
  10. :value="form.carNum" :maxlength="maxlength" :disabled-keyboard="true"></umessageInput>
  11. </view>
  12. <ucarkeyboard ref="uKeyboard" mode="car" :showTips="true" :confirmBtn="false" :mask-close-able="false" :tooltip="false" v-model="keyShow" @change="valChange" @backspace="backspace"></ucarkeyboard>
  13. <view class="default">
  14. <!-- <u-checkbox-group>
  15. <u-checkbox class="tips" v-model="form.defaultFlag" shape="circle" @change="checkboxChange()">设为默认车辆</u-checkbox>
  16. </u-checkbox-group> -->
  17. </view>
  18. <u-button class="login-btn" type="success" shape="circle" @click="keepCar">保存</u-button>
  19. </view>
  20. </template>
  21. <script>
  22. import * as userApi from '@/apis/user.js'
  23. import ucarkeyboard from '@/components/Ucarkeyboard.vue'
  24. import umessageInput from '@/components/UmessageInput.vue'
  25. export default {
  26. components: {
  27. ucarkeyboard,umessageInput
  28. },
  29. data() {
  30. return {
  31. isLogin:false,
  32. maxlength:8,
  33. keyShow: true,
  34. code:"",
  35. codeId:"",
  36. form: {
  37. carNum: '鄂',
  38. defaultFlag: true,
  39. },
  40. selectIndex:-1
  41. }
  42. },
  43. onLoad(op) {
  44. if (op.jpcode) {
  45. var str1 = op.jpcode.slice(0, 19);
  46. var str2 = op.jpcode.slice(20, 21);
  47. var str3 = op.jpcode.slice(22);
  48. if (str1 == 'jp_team51_charge_id') {
  49. if (str2 == 'A') {
  50. this.code = str2;
  51. this.codeId = str3;
  52. }
  53. }
  54. }
  55. if(op.login){
  56. this.isLogin=true;
  57. }
  58. },
  59. onReady() {
  60. this.$refs.uKeyboard.changeCarInputMode();
  61. },
  62. methods: {
  63. gotoLink(){
  64. if (this.code == 'A') {
  65. uni.redirectTo({
  66. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  67. })
  68. } else if (this.isLogin){
  69. uni.redirectTo({
  70. url: '/pages/index/index'
  71. })
  72. }else {
  73. uni.navigateBack({
  74. url: '/pages/user/car/index'
  75. })
  76. }
  77. },
  78. checkboxChange() {
  79. this.form.defaultFlag = !this.form.defaultFlag;
  80. },
  81. getSelectIndex(i){
  82. this.selectIndex=i;
  83. if(i==0){
  84. var aaa = this.$refs.uKeyboard.changeCarInputValue();
  85. if( aaa) {
  86. this.$refs.uKeyboard.changeCarInputMode();
  87. }
  88. }
  89. },
  90. // 按键被点击(点击退格键不会触发此事件)
  91. valChange(val) {
  92. if(this.form.carNum.length>=this.maxlength&&this.selectIndex==-1){
  93. return
  94. }
  95. if(this.selectIndex==-1){
  96. this.form.carNum += val;
  97. }else{
  98. const replaceStr = (str, index, char) => {
  99. const strAry = str.split('');
  100. if(index<strAry.length){
  101. strAry[index] = char;
  102. }
  103. return strAry.join('');
  104. }
  105. this.form.carNum=replaceStr(this.form.carNum,this.selectIndex,val) ;
  106. this.selectIndex=-1;
  107. }
  108. // 将每次按键的值拼接到form.carNum变量中,注意+=写法
  109. //(this.form.carNum);
  110. var aaa = this.$refs.uKeyboard.changeCarInputValue();
  111. if((this.form.carNum.length == 0) && aaa) {
  112. this.$refs.uKeyboard.changeCarInputMode();
  113. }else if(!aaa){
  114. this.$refs.uKeyboard.changeCarInputMode();
  115. }
  116. },
  117. // 退格键被点击
  118. backspace() {
  119. // 删除form.carNum的最后一个字符
  120. if(this.form.carNum.length){
  121. if(this.selectIndex==-1){
  122. this.form.carNum = this.form.carNum.substr(0, this.form.carNum.length - 1);
  123. }else{
  124. const replaceStr = (str, index, char) => {
  125. const strAry = str.split('');
  126. if(index<strAry.length){
  127. strAry[index] = char;
  128. }
  129. return strAry.join('');
  130. }
  131. this.form.carNum=replaceStr(this.form.carNum,this.selectIndex,'') ;
  132. //this.selectIndex=-1;
  133. }
  134. }
  135. //(this.form.carNum);
  136. var aaa = this.$refs.uKeyboard.changeCarInputValue();
  137. if(this.form.carNum.length == 0 && aaa) {
  138. this.$refs.uKeyboard.changeCarInputMode();
  139. }
  140. },
  141. keepCar() {
  142. //(this.form)
  143. if(this.form.carNum.length != 8) {
  144. uni.showToast({
  145. title:"请填写新能源车牌"
  146. })
  147. return
  148. }
  149. uni.showLoading({
  150. title: "加载中",
  151. mask: true,
  152. })
  153. userApi.addRegUserCar(this.form).then((res) => {
  154. uni.hideLoading();
  155. this.gotoLink()
  156. }).catch(error => {
  157. uni.showToast({
  158. title: error,
  159. icon: "none"
  160. })
  161. })
  162. }
  163. }
  164. }
  165. </script>
  166. <style>
  167. page {
  168. background-color: #fff;
  169. }
  170. </style>
  171. <style lang="scss" scoped>
  172. .u-char-item{
  173. width: 29px !important;
  174. }
  175. .u-drawer{
  176. z-index: -1 !important;
  177. }
  178. /deep/.u-char-item {
  179. width: 30px !important;
  180. height: 40px !important;
  181. font-size: 18px !important;
  182. }
  183. .key-input {
  184. padding-top: 24px;
  185. }
  186. .default {
  187. margin: 16px 28px;
  188. }
  189. .login-btn {
  190. margin: 28px;
  191. background-color: #00B962 !important;
  192. border-color: #00B962 !important;
  193. color: #fff !important;
  194. }
  195. </style>