myCars.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view>
  3. <u-navbar
  4. title-color="#fff"
  5. :custom-back="customBack"
  6. :border-bottom="false"
  7. back-icon-color="#CCE8FF"
  8. :background="{background: '#008CFF' }" title="车辆管理"></u-navbar>
  9. <view class="header">
  10. <view class="header-title">我的车辆</view>
  11. </view>
  12. <view class="wrap">
  13. <view class="statistics">
  14. <view class="statistics-title">车辆</view>
  15. <view class="statistics-center"></view>
  16. <view class="statistics-number-wrap"><span class="number">{{mycarsTotal}}</span>辆</view>
  17. </view>
  18. <view class="new-plate-number">
  19. <view class="message-input-wrap" @click="messageInputClick">
  20. <u-message-input :maxlength="8" width="70" font-size="50" :disabled-keyboard="true" v-model="newPlateNumber"></u-message-input>
  21. </view>
  22. <u-keyboard ref="uKeyboard" mode="car" @change="keyboardChange" @confirm="keyboardConfirm" @backspace="backspace" v-model="keyboardshow"></u-keyboard>
  23. </view>
  24. <view class="add-car-btn" @click="handleAddCar">添加车辆</view>
  25. <view class="mycars">
  26. <view class="mycars-item" v-for="item in mycars">
  27. <view class="mycars-item-name">{{item.vehicleNo}}</view>
  28. <view class="mycars-item-type">{{item.energyTpye | energyTpye}}</view>
  29. <view class="mycars-item-tool">
  30. <span class="default" :class="{'isDefault':item.isDefault == 1}" @click="handlesetDefault(item.id)">默认</span>
  31. <span @click="handleDelCar(item.id,item.vehicleNo)">删除</span>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <u-toast ref="uToast" />
  37. <u-modal v-model="delCarshow" :show-cancel-button="true" @confirm="confirmDelCar" :content="delCarContent"></u-modal>
  38. <u-action-sheet :list="colorList" @click="confirmColor" v-model="colorShow"></u-action-sheet>
  39. </view>
  40. </template>
  41. <script>
  42. export default{
  43. data(){
  44. return{
  45. keyboardshow:false,
  46. delCarshow:false,
  47. delCarId:null,
  48. delCarContent:'',
  49. newPlateNumber:'',
  50. vehicleColor:0,
  51. mycars:[],
  52. mycarsTotal:0,
  53. colorShow:false,
  54. colorList:[
  55. {text:'蓝色',colorCode:0}
  56. ,{text:'黄色',colorCode:1}
  57. ,{text:'黑色',colorCode:2}
  58. ,{text:'白色',colorCode:3}
  59. ,{text:'绿色',colorCode:4}
  60. ,{text:'其他',colorCode:99}
  61. ],
  62. }
  63. },
  64. onLoad(){
  65. this.handlegetMycars();
  66. },
  67. methods:{
  68. customBack(){
  69. this.$u.route({
  70. type:'switchTab',
  71. url: 'pages/index/index'
  72. });
  73. },
  74. handlegetMycars(){
  75. this.$u.api.getMycars()
  76. .then(res=>{
  77. this.mycars = res.data.rows;
  78. this.mycarsTotal = res.data.total;
  79. console.log('this.mycars',this.mycars)
  80. }).catch(err=>{
  81. console.log('getMycars ',err)
  82. });
  83. },
  84. handleAddCar(){
  85. if(!this.$u.test.carNo(this.newPlateNumber)){
  86. this.$refs.uToast.show({
  87. title: '请正确填写车牌号',
  88. type: 'error',
  89. });
  90. return
  91. }
  92. let param ={
  93. vehicleNo: this.newPlateNumber,
  94. vehicleColor: this.vehicleColor
  95. };
  96. this.$u.api.addCar(param)
  97. .then(res=>{
  98. this.$refs.uToast.show({
  99. title: res.msg,
  100. type: 'success',
  101. });
  102. this.handlegetMycars();
  103. console.log('getMycars',res)
  104. }).catch(err=>{
  105. this.$refs.uToast.show({
  106. title: err.msg,
  107. type: 'error',
  108. });
  109. console.log('getMycars ',err)
  110. });
  111. },
  112. handleDelCar(id,content){
  113. this.delCarContent = `是否删除${content}`;
  114. this.delCarId = id;
  115. this.delCarshow = true;
  116. },
  117. confirmDelCar(){
  118. console.log(this.delCarId);
  119. this.$u.api.delCar(this.delCarId)
  120. .then(res=>{
  121. this.$refs.uToast.show({
  122. title: res.msg,
  123. type: 'success',
  124. });
  125. this.handlegetMycars();
  126. console.log('getMycars',res)
  127. }).catch(err=>{
  128. this.$refs.uToast.show({
  129. title: err.msg,
  130. type: 'error',
  131. });
  132. console.log('getMycars ',err)
  133. });
  134. },
  135. messageInputClick(){
  136. this.keyboardshow = true;
  137. },
  138. // 按键被点击(点击退格键不会触发此事件)
  139. keyboardChange(val) {
  140. // 将每次按键的值拼接到value变量中,注意+=写法
  141. this.newPlateNumber += val;
  142. console.log(this.newPlateNumber);
  143. },
  144. // 退格键被点击
  145. backspace() {
  146. // 删除value的最后一个字符
  147. if(this.newPlateNumber.length) this.newPlateNumber = this.newPlateNumber.substr(0, this.newPlateNumber.length - 1);
  148. console.log(this.newPlateNumber);
  149. },
  150. keyboardConfirm(){
  151. this.colorShow = true;
  152. },
  153. confirmColor(e){
  154. this.vehicleColor = this.colorList[e].colorCode;
  155. },
  156. // 设置默认车辆
  157. handlesetDefault(id){
  158. this.$u.api.setDefaultCar({id:id})
  159. .then(res=>{
  160. this.$refs.uToast.show({
  161. title: res.msg,
  162. type: 'success',
  163. });
  164. this.handlegetMycars();
  165. console.log('handlesetDefault',res)
  166. }).catch(err=>{
  167. this.$refs.uToast.show({
  168. title: err.msg,
  169. type: 'error',
  170. });
  171. console.log('handlesetDefault err',err)
  172. });
  173. }
  174. },
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. @import url("./myCars.scss");
  179. </style>