carAdd.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view>
  3. <u-navbar title="车辆管理">
  4. <view class="slot-wrap">
  5. <span class="navBtn" @click="showDelete">删除车辆</span>
  6. </view>
  7. </u-navbar>
  8. <view>
  9. <u-modal v-model="show" @confirm="confirmDelete" confirm-color="#fa3534" :show-cancel-button="true" ref="uModal" :asyncClose="true" :title="title" :content="content"></u-modal>
  10. </view>
  11. <view class="carDet">
  12. <u-form :model="form" ref="uForm">
  13. <ucarkeyboard ref="uKeyboard" mode="car" :showTips="true" :confirmBtn="false" :mask-close-able="false" :tooltip="false" v-show="keyShow" @change="valChange" @backspace="backspace"></ucarkeyboard>
  14. <u-form-item label="车牌号码" label-width="150rpx">
  15. <view style="margin-left: auto;" :style="form.carNum ? 'color:black;': 'color: #c0c4cc;'" v-text="form.carNum ? form.carNum : '请输入内容'" @click="keyClick"></view>
  16. </u-form-item>
  17. <u-form-item label="车辆类型" label-width="150rpx"><u-input input-align="right" placeholder="新能源车" placeholder-style="color:black" disabled /></u-form-item>
  18. <u-form-item label="设为默认车辆" label-width="180rpx"><u-switch slot="right" v-model="form.defaultFlag"></u-switch></u-form-item>
  19. </u-form>
  20. </view>
  21. <u-button class="login-btn" type="success" shape="circle" @click="keepCar">保存</u-button>
  22. </view>
  23. </template>
  24. <script>
  25. import * as userApi from '@/apis/user.js'
  26. import ucarkeyboard from '@/components/Ucarkeyboard.vue'
  27. export default {
  28. components: {
  29. ucarkeyboard
  30. },
  31. data() {
  32. return {
  33. keyShow: false,
  34. show: false,
  35. title: '删除车辆',
  36. content: '是否删除此车牌号?',
  37. form: {
  38. id: '',
  39. carNum: '',
  40. defaultFlag: true,
  41. },
  42. carList: [],
  43. }
  44. },
  45. onLoad(op) {
  46. if(op.id){
  47. this.form.id = op.id;
  48. this.getCarList();
  49. }
  50. },
  51. onReady() {
  52. this.$refs.uKeyboard.changeCarInputMode();
  53. },
  54. methods: {
  55. keyClick() {
  56. this.keyShow = true;
  57. },
  58. // 按键被点击(点击退格键不会触发此事件)
  59. valChange(val) {
  60. // 将每次按键的值拼接到form.carNum变量中,注意+=写法
  61. this.form.carNum += val;
  62. console.log(this.form.carNum);
  63. if(this.form.carNum.length == 1) {
  64. this.$refs.uKeyboard.changeCarInputMode();
  65. }
  66. },
  67. // 退格键被点击
  68. backspace() {
  69. // 删除form.carNum的最后一个字符
  70. if(this.form.carNum.length) this.form.carNum = this.form.carNum.substr(0, this.form.carNum.length - 1);
  71. console.log(this.form.carNum);
  72. var aaa = this.$refs.uKeyboard.changeCarInputValue();
  73. if(this.form.carNum.length == 0 && aaa) {
  74. this.$refs.uKeyboard.changeCarInputMode();
  75. }
  76. },
  77. getCarList() {
  78. uni.showLoading({
  79. title: "加载中",
  80. mask: true,
  81. })
  82. userApi.regUserCarList().then((res) => {
  83. uni.hideLoading();
  84. this.carList = res.data;
  85. for(var i=0;i<this.carList.length;i++) {
  86. var carId = this.carList[i].id
  87. if(this.form.id == carId) {
  88. this.form.carNum = this.carList[i].carNum;
  89. this.form.defaultFlag = this.carList[i].defaultFlag;
  90. }
  91. }
  92. }).catch(error => {
  93. uni.showToast({
  94. title: error,
  95. icon: "none"
  96. })
  97. })
  98. },
  99. showDelete() {
  100. this.show = true;
  101. this.keyShow = false;
  102. },
  103. confirmDelete() {
  104. uni.showLoading({
  105. title: "加载中",
  106. mask: true,
  107. })
  108. userApi.deleteRegUserCar({
  109. id: this.form.id
  110. }).then((res) => {
  111. uni.hideLoading();
  112. this.show = false;
  113. uni.navigateBack({
  114. url: '/pages/user/car/index'
  115. })
  116. }).catch(error => {
  117. uni.showToast({
  118. title: error,
  119. icon: "none"
  120. })
  121. })
  122. },
  123. keepCar() {
  124. this.keyShow = false;
  125. uni.showLoading({
  126. title: "加载中",
  127. mask: true,
  128. })
  129. userApi.addRegUserCar(this.form).then((res) => {
  130. uni.hideLoading();
  131. if(this.code == 'A') {
  132. uni.navigateBack({
  133. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  134. })
  135. } else {
  136. uni.navigateBack({
  137. url: '/pages/user/car/index'
  138. })
  139. }
  140. }).catch(error => {
  141. uni.showToast({
  142. title: error,
  143. icon: "none"
  144. })
  145. })
  146. }
  147. }
  148. }
  149. </script>
  150. <style>
  151. page{
  152. background: #fff;
  153. }
  154. </style>
  155. <style lang="scss" scoped>
  156. .slot-wrap{
  157. flex: 1;
  158. }
  159. .navBtn{
  160. float: right;
  161. margin-right: 15px;
  162. color:#FF6666;
  163. }
  164. .carDet{
  165. padding: 0 16px;
  166. }
  167. .login-btn {
  168. margin: 28px ;
  169. background-color:#00B962!important;
  170. border-color: #00B962!important;
  171. color:#fff!important;
  172. }
  173. </style>