carAdd.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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-form-item label="车牌号码" label-width="150rpx"><u-input input-align="right" v-model="form.carNum" /></u-form-item>
  14. <u-form-item label="车辆类型" label-width="150rpx"><u-input input-align="right" placeholder="新能源车" placeholder-style="color:black" disabled /></u-form-item>
  15. <u-form-item label="设为默认车辆" label-width="180rpx"><u-switch slot="right" v-model="form.defaultFlag"></u-switch></u-form-item>
  16. </u-form>
  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. export default {
  24. data() {
  25. return {
  26. show: false,
  27. title: '删除车辆',
  28. content: '是否删除此车牌号?',
  29. form: {
  30. id: '',
  31. carNum: '',
  32. defaultFlag: true,
  33. },
  34. carList: [],
  35. }
  36. },
  37. onLoad(op) {
  38. if(op.id){
  39. this.form.id = op.id;
  40. this.getCarList();
  41. }
  42. },
  43. methods: {
  44. getCarList() {
  45. uni.showLoading({
  46. title: "加载中",
  47. mask: true,
  48. })
  49. userApi.regUserCarList().then((res) => {
  50. uni.hideLoading();
  51. this.carList = res.data;
  52. for(var i=0;i<this.carList.length;i++) {
  53. var carId = this.carList[i].id
  54. if(this.form.id == carId) {
  55. this.form.carNum = this.carList[i].carNum;
  56. this.form.defaultFlag = this.carList[i].defaultFlag;
  57. }
  58. }
  59. }).catch(error => {
  60. uni.showToast({
  61. title: error,
  62. icon: "none"
  63. })
  64. })
  65. },
  66. showDelete() {
  67. this.show = true;
  68. },
  69. confirmDelete() {
  70. uni.showLoading({
  71. title: "加载中",
  72. mask: true,
  73. })
  74. userApi.deleteRegUserCar({
  75. id: this.form.id
  76. }).then((res) => {
  77. uni.hideLoading();
  78. this.show = false;
  79. uni.redirectTo({
  80. url: '/pages/user/car/index'
  81. })
  82. }).catch(error => {
  83. uni.showToast({
  84. title: error,
  85. icon: "none"
  86. })
  87. })
  88. },
  89. keepCar() {
  90. uni.showLoading({
  91. title: "加载中",
  92. mask: true,
  93. })
  94. userApi.addRegUserCar(this.form).then((res) => {
  95. uni.hideLoading();
  96. uni.redirectTo({
  97. url: '/pages/user/car/index'
  98. })
  99. }).catch(error => {
  100. uni.showToast({
  101. title: error,
  102. icon: "none"
  103. })
  104. })
  105. }
  106. }
  107. }
  108. </script>
  109. <style>
  110. page{
  111. background: #fff;
  112. }
  113. </style>
  114. <style lang="scss" scoped>
  115. .slot-wrap{
  116. flex: 1;
  117. }
  118. .navBtn{
  119. float: right;
  120. margin-right: 15px;
  121. color:#FF6666;
  122. }
  123. .carDet{
  124. padding: 0 16px;
  125. }
  126. .login-btn {
  127. margin: 28px ;
  128. background-color:#00B962!important;
  129. border-color: #00B962!important;
  130. color:#fff!important;
  131. }
  132. </style>