carAdd.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view>
  3. <u-navbar title="车辆管理">
  4. <view class="slot-wrap">
  5. <span class="navBtn" :style="form.id ? '': 'color: #E68C91;'" @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">
  15. <view style="margin-left: auto;" :style="form.carNum ? 'color:black;': 'color: #c0c4cc;'" v-text="form.carNum ? form.carNum : '请输入内容'" @click="keyShow = true"></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. export default {
  27. data() {
  28. return {
  29. keyShow: false,
  30. show: false,
  31. title: '删除车辆',
  32. content: '是否删除此车牌号?',
  33. form: {
  34. id: '',
  35. carNum: '',
  36. defaultFlag: true,
  37. },
  38. carList: [],
  39. }
  40. },
  41. onLoad(op) {
  42. if(op.id){
  43. var str1 = op.id.slice(0,19);
  44. var str2 = op.id.slice(20,21);
  45. var str3 = op.id.slice(22);
  46. if(str1 == 'jp_team51_charge_id') {
  47. if(str2 == 'A') {
  48. this.code = str2;
  49. this.codeId = str3;
  50. }
  51. } else {
  52. this.form.id = op.id;
  53. this.getCarList();
  54. }
  55. }
  56. },
  57. methods: {
  58. // 按键被点击(点击退格键不会触发此事件)
  59. valChange(val) {
  60. // 将每次按键的值拼接到form.carNum变量中,注意+=写法
  61. this.form.carNum += val;
  62. console.log(this.form.carNum);
  63. },
  64. // 退格键被点击
  65. backspace() {
  66. // 删除form.carNum的最后一个字符
  67. if(this.form.carNum.length) this.form.carNum = this.form.carNum.substr(0, this.form.carNum.length - 1);
  68. console.log(this.form.carNum);
  69. },
  70. getCarList() {
  71. uni.showLoading({
  72. title: "加载中",
  73. mask: true,
  74. })
  75. userApi.regUserCarList().then((res) => {
  76. uni.hideLoading();
  77. this.carList = res.data;
  78. for(var i=0;i<this.carList.length;i++) {
  79. var carId = this.carList[i].id
  80. if(this.form.id == carId) {
  81. this.form.carNum = this.carList[i].carNum;
  82. this.form.defaultFlag = this.carList[i].defaultFlag;
  83. }
  84. }
  85. }).catch(error => {
  86. uni.showToast({
  87. title: error,
  88. icon: "none"
  89. })
  90. })
  91. },
  92. showDelete() {
  93. if(this.form.id) {
  94. this.show = true;
  95. }
  96. },
  97. confirmDelete() {
  98. uni.showLoading({
  99. title: "加载中",
  100. mask: true,
  101. })
  102. userApi.deleteRegUserCar({
  103. id: this.form.id
  104. }).then((res) => {
  105. uni.hideLoading();
  106. this.show = false;
  107. uni.navigateBack({
  108. url: '/pages/user/car/index'
  109. })
  110. }).catch(error => {
  111. uni.showToast({
  112. title: error,
  113. icon: "none"
  114. })
  115. })
  116. },
  117. keepCar() {
  118. uni.showLoading({
  119. title: "加载中",
  120. mask: true,
  121. })
  122. userApi.addRegUserCar(this.form).then((res) => {
  123. uni.hideLoading();
  124. if(this.code == 'A') {
  125. uni.navigateBack({
  126. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  127. })
  128. } else {
  129. uni.navigateBack({
  130. url: '/pages/user/car/index'
  131. })
  132. }
  133. }).catch(error => {
  134. uni.showToast({
  135. title: error,
  136. icon: "none"
  137. })
  138. })
  139. }
  140. }
  141. }
  142. </script>
  143. <style>
  144. page{
  145. background: #fff;
  146. }
  147. </style>
  148. <style lang="scss" scoped>
  149. .slot-wrap{
  150. flex: 1;
  151. }
  152. .navBtn{
  153. float: right;
  154. margin-right: 15px;
  155. color:#FF6666;
  156. }
  157. .carDet{
  158. padding: 0 16px;
  159. }
  160. .login-btn {
  161. margin: 28px ;
  162. background-color:#00B962!important;
  163. border-color: #00B962!important;
  164. color:#fff!important;
  165. }
  166. </style>