myCars.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. onShow() {
  70. this.handlegetMycars();
  71. },
  72. methods:{
  73. customBack(){
  74. this.$u.route({
  75. type:'switchTab',
  76. url: 'pages/index/index'
  77. });
  78. },
  79. handlegetMycars(){
  80. this.$u.api.getMycars()
  81. .then(res=>{
  82. this.mycars = res.data.rows;
  83. this.mycarsTotal = res.data.total;
  84. console.log('this.mycars',this.mycars)
  85. }).catch(err=>{
  86. console.log('getMycars ',err)
  87. });
  88. },
  89. handleAddCar(){
  90. if(!this.$u.test.carNo(this.newPlateNumber)){
  91. this.$refs.uToast.show({
  92. title: '请正确填写车牌号',
  93. type: 'error',
  94. });
  95. return
  96. }
  97. let param ={
  98. vehicleNo: this.newPlateNumber,
  99. vehicleColor: this.vehicleColor
  100. };
  101. this.$u.api.addCar(param)
  102. .then(res=>{
  103. this.$refs.uToast.show({
  104. title: res.msg,
  105. type: 'success',
  106. });
  107. this.handlegetMycars();
  108. console.log('getMycars',res)
  109. }).catch(err=>{
  110. this.$refs.uToast.show({
  111. title: err.msg,
  112. type: 'error',
  113. });
  114. console.log('getMycars ',err)
  115. });
  116. },
  117. handleDelCar(id,content){
  118. this.delCarContent = `是否删除${content}`;
  119. this.delCarId = id;
  120. this.delCarshow = true;
  121. },
  122. confirmDelCar(){
  123. console.log(this.delCarId);
  124. this.$u.api.delCar(this.delCarId)
  125. .then(res=>{
  126. this.$refs.uToast.show({
  127. title: res.msg,
  128. type: 'success',
  129. });
  130. this.handlegetMycars();
  131. console.log('getMycars',res)
  132. }).catch(err=>{
  133. this.$refs.uToast.show({
  134. title: err.msg,
  135. type: 'error',
  136. });
  137. console.log('getMycars ',err)
  138. });
  139. },
  140. messageInputClick(){
  141. this.keyboardshow = true;
  142. },
  143. // 按键被点击(点击退格键不会触发此事件)
  144. keyboardChange(val) {
  145. // 将每次按键的值拼接到value变量中,注意+=写法
  146. this.newPlateNumber += val;
  147. console.log(this.newPlateNumber);
  148. },
  149. // 退格键被点击
  150. backspace() {
  151. // 删除value的最后一个字符
  152. if(this.newPlateNumber.length) this.newPlateNumber = this.newPlateNumber.substr(0, this.newPlateNumber.length - 1);
  153. console.log(this.newPlateNumber);
  154. },
  155. keyboardConfirm(){
  156. this.colorShow = true;
  157. },
  158. confirmColor(e){
  159. this.vehicleColor = this.colorList[e].colorCode;
  160. },
  161. // 设置默认车辆
  162. handlesetDefault(id){
  163. this.$u.api.setDefaultCar({id:id})
  164. .then(res=>{
  165. this.$refs.uToast.show({
  166. title: res.msg,
  167. type: 'success',
  168. });
  169. this.handlegetMycars();
  170. console.log('handlesetDefault',res)
  171. }).catch(err=>{
  172. this.$refs.uToast.show({
  173. title: err.msg,
  174. type: 'error',
  175. });
  176. console.log('handlesetDefault err',err)
  177. });
  178. }
  179. },
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. @import url("./myCars.scss");
  184. </style>