carAdd.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. <u-keyboard ref="uKeyboard" mode="car" v-model="keyShow" @change="valChange" @backspace="backspace"></u-keyboard>
  14. <u-form-item label="车牌号码" label-width="150rpx"><u-input input-align="right" v-model="form.carNum" @click="keyShow=true" /></u-form-item>
  15. <u-form-item label="车辆类型" label-width="150rpx"><u-input input-align="right" placeholder="新能源车" placeholder-style="color:black" disabled /></u-form-item>
  16. <u-form-item label="设为默认车辆" label-width="180rpx"><u-switch slot="right" v-model="form.defaultFlag"></u-switch></u-form-item>
  17. </u-form>
  18. </view>
  19. <u-button class="login-btn" type="success" shape="circle" @click="keepCar">保存</u-button>
  20. </view>
  21. </template>
  22. <script>
  23. import * as userApi from '@/apis/user.js'
  24. export default {
  25. data() {
  26. return {
  27. keyShow: false,
  28. show: false,
  29. title: '删除车辆',
  30. content: '是否删除此车牌号?',
  31. form: {
  32. id: '',
  33. carNum: '',
  34. defaultFlag: true,
  35. },
  36. carList: [],
  37. }
  38. },
  39. onLoad(op) {
  40. if(op.id){
  41. var str1 = res.slice(0,19);
  42. var str2 = res.slice(20,21);
  43. var str3 = res.slice(22);
  44. if(str1 == 'jp_team51_charge_id') {
  45. if(str2 == 'A') {
  46. this.code = str2;
  47. this.codeId = str3;
  48. }
  49. } else {
  50. this.form.id = op.id;
  51. this.getCarList();
  52. }
  53. }
  54. },
  55. methods: {
  56. // 按键被点击(点击退格键不会触发此事件)
  57. valChange(val) {
  58. // 将每次按键的值拼接到form.carNum变量中,注意+=写法
  59. this.form.carNum += val;
  60. console.log(this.form.carNum);
  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. },
  68. getCarList() {
  69. uni.showLoading({
  70. title: "加载中",
  71. mask: true,
  72. })
  73. userApi.regUserCarList().then((res) => {
  74. uni.hideLoading();
  75. this.carList = res.data;
  76. for(var i=0;i<this.carList.length;i++) {
  77. var carId = this.carList[i].id
  78. if(this.form.id == carId) {
  79. this.form.carNum = this.carList[i].carNum;
  80. this.form.defaultFlag = this.carList[i].defaultFlag;
  81. }
  82. }
  83. }).catch(error => {
  84. uni.showToast({
  85. title: error,
  86. icon: "none"
  87. })
  88. })
  89. },
  90. showDelete() {
  91. this.show = true;
  92. },
  93. confirmDelete() {
  94. uni.showLoading({
  95. title: "加载中",
  96. mask: true,
  97. })
  98. userApi.deleteRegUserCar({
  99. id: this.form.id
  100. }).then((res) => {
  101. uni.hideLoading();
  102. this.show = false;
  103. uni.redirectTo({
  104. url: '/pages/user/car/index'
  105. })
  106. }).catch(error => {
  107. uni.showToast({
  108. title: error,
  109. icon: "none"
  110. })
  111. })
  112. },
  113. keepCar() {
  114. uni.showLoading({
  115. title: "加载中",
  116. mask: true,
  117. })
  118. userApi.addRegUserCar(this.form).then((res) => {
  119. uni.hideLoading();
  120. if(this.code == 'A') {
  121. uni.redirectTo({
  122. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  123. })
  124. } else {
  125. uni.redirectTo({
  126. url: '/pages/user/car/index'
  127. })
  128. }
  129. }).catch(error => {
  130. uni.showToast({
  131. title: error,
  132. icon: "none"
  133. })
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style>
  140. page{
  141. background: #fff;
  142. }
  143. </style>
  144. <style lang="scss" scoped>
  145. .slot-wrap{
  146. flex: 1;
  147. }
  148. .navBtn{
  149. float: right;
  150. margin-right: 15px;
  151. color:#FF6666;
  152. }
  153. .carDet{
  154. padding: 0 16px;
  155. }
  156. .login-btn {
  157. margin: 28px ;
  158. background-color:#00B962!important;
  159. border-color: #00B962!important;
  160. color:#fff!important;
  161. }
  162. </style>