myCars.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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, index) in mycars" :key="index">
  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. // 获取车辆列表
  81. handlegetMycars(){
  82. this.$u.api.getMycars()
  83. .then(res=>{
  84. if (res.code === 200) {
  85. this.mycars = res.data.rows;
  86. this.mycarsTotal = res.data.total;
  87. } else {
  88. this.$refs.uToast.show({
  89. title: res.msg,
  90. type: 'error'
  91. })
  92. }
  93. })
  94. .catch(err=>{
  95. this.$refs.uToast.show({
  96. title: '操作失败!',
  97. type: 'error'
  98. })
  99. });
  100. },
  101. // 添加车辆
  102. handleAddCar(){
  103. if(!this.$u.test.carNo(this.newPlateNumber)){
  104. this.$refs.uToast.show({
  105. title: '请正确填写车牌号',
  106. type: 'error',
  107. });
  108. return
  109. }
  110. let param = {
  111. vehicleNo: this.newPlateNumber,
  112. vehicleColor: this.vehicleColor
  113. };
  114. this.$u.api.addCar(param)
  115. .then(res=>{
  116. if (res.code === 200) {
  117. this.$refs.uToast.show({
  118. title: res.msg,
  119. type: 'success',
  120. });
  121. this.handlegetMycars();
  122. } else {
  123. this.$refs.uToast.show({
  124. title: res.msg,
  125. type: 'error',
  126. });
  127. }
  128. })
  129. .catch(err=>{
  130. this.$refs.uToast.show({
  131. title: '操作失败!',
  132. type: 'error',
  133. });
  134. });
  135. },
  136. // 删除车辆
  137. handleDelCar(id, content){
  138. this.delCarContent = `是否删除${content}`;
  139. this.delCarId = id;
  140. this.delCarshow = true;
  141. },
  142. // 确认删除
  143. confirmDelCar(){
  144. this.$u.api.delCar(this.delCarId)
  145. .then(res=>{
  146. if (res.code === 200) {
  147. this.$refs.uToast.show({
  148. title: res.msg,
  149. type: 'success',
  150. });
  151. this.handlegetMycars();
  152. } else {
  153. this.$refs.uToast.show({
  154. title: res.msg,
  155. type: 'error',
  156. });
  157. }
  158. })
  159. .catch(err=>{
  160. this.$refs.uToast.show({
  161. title: '操作失败!',
  162. type: 'error',
  163. });
  164. });
  165. },
  166. // 点击输入框
  167. messageInputClick(){
  168. this.keyboardshow = true;
  169. },
  170. // 按键被点击(点击退格键不会触发此事件)
  171. keyboardChange(val) {
  172. // 将每次按键的值拼接到value变量中,注意+=写法
  173. this.newPlateNumber += val;
  174. },
  175. // 退格键被点击
  176. backspace() {
  177. // 删除value的最后一个字符
  178. if(this.newPlateNumber.length) this.newPlateNumber = this.newPlateNumber.substr(0, this.newPlateNumber.length - 1);
  179. },
  180. // 键盘输入完成后确认
  181. keyboardConfirm(){
  182. this.colorShow = true;
  183. },
  184. // 确认颜色
  185. confirmColor(e){
  186. this.vehicleColor = this.colorList[e].colorCode;
  187. },
  188. // 设置默认车辆操作
  189. handlesetDefault(id){
  190. this.$u.api.setDefaultCar({id:id})
  191. .then(res=>{
  192. if (res.code === 200) {
  193. this.$refs.uToast.show({
  194. title: res.msg,
  195. type: 'success',
  196. });
  197. this.handlegetMycars();
  198. } else {
  199. this.$refs.uToast.show({
  200. title: res.msg,
  201. type: 'error',
  202. });
  203. }
  204. }).catch(err=>{
  205. this.$refs.uToast.show({
  206. title: '操作失败!',
  207. type: 'error',
  208. });
  209. });
  210. }
  211. },
  212. }
  213. </script>
  214. <style lang="scss" scoped>
  215. @import url("./myCars.scss");
  216. </style>