myCars.vue 5.2 KB

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