myCars.vue 5.1 KB

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