myCars.vue 5.9 KB

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