myCars.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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' }"
  9. title="车辆管理"
  10. ></u-navbar>
  11. <view class="header">
  12. <view class="header-title">我的车辆</view>
  13. </view>
  14. <view class="wrap">
  15. <view class="statistics">
  16. <view class="statistics-title">车辆</view>
  17. <view class="statistics-center"></view>
  18. <view class="statistics-number-wrap"
  19. ><span class="number">{{ mycarsTotal }}</span
  20. >辆</view
  21. >
  22. </view>
  23. <view class="new-plate-number">
  24. <view class="message-input-wrap" @click="messageInputClick">
  25. <u-message-input :maxlength="8" width="70" font-size="50" :disabled-keyboard="true" v-model="newPlateNumber"></u-message-input>
  26. </view>
  27. <u-keyboard
  28. ref="uKeyboard"
  29. mode="car"
  30. @change="keyboardChange"
  31. @confirm="keyboardConfirm"
  32. @backspace="backspace"
  33. v-model="keyboardshow"
  34. ></u-keyboard>
  35. </view>
  36. <view class="add-car-btn" @click="handleAddCar">添加车辆</view>
  37. <view class="mycars">
  38. <template v-if="mycars.length">
  39. <view class="mycars-item" v-for="(item, index) in mycars" :key="index">
  40. <view class="mycars-item-name">{{ item.vehicleNo }}</view>
  41. <view class="mycars-item-type">{{ item.energyTpye | energyTpye }}</view>
  42. <view class="mycars-item-sign" v-if="item.contractStatus == 1">已签约</view>
  43. <view class="mycars-item-sign1" v-if="item.contractStatus == 0">未签约</view>
  44. <view class="mycars-item-tool">
  45. <span class="default" v-if="item.isDefault == 1" :class="{ isDefault: item.isDefault == 1 }" @click="handlesetDefault(item.id)"
  46. >默认</span
  47. >
  48. <span class="default" v-else @click="handlesetDefault(item.id)">设为默认</span>
  49. <span @click="handleDelCar(item.id, item.vehicleNo)">删除</span>
  50. </view>
  51. </view>
  52. <u-loadmore :status="status" />
  53. </template>
  54. <template v-else>
  55. <u-empty text="无车辆数据" mode="list"></u-empty>
  56. </template>
  57. </view>
  58. </view>
  59. <u-toast ref="uToast" />
  60. <u-modal v-model="delCarshow" :show-cancel-button="true" @confirm="confirmDelCar" :content="delCarContent"></u-modal>
  61. <u-action-sheet :list="colorList" @click="confirmColor" v-model="colorShow"></u-action-sheet>
  62. </view>
  63. </template>
  64. <script>
  65. export default {
  66. data() {
  67. return {
  68. keyboardshow: false,
  69. delCarshow: false,
  70. delCarId: null,
  71. delCarContent: '',
  72. newPlateNumber: '',
  73. vehicleColor: 0,
  74. mycars: [],
  75. status: 'loadmore',
  76. page: {
  77. num: 1,
  78. size: 10,
  79. total: 0
  80. },
  81. mycarsTotal: 0,
  82. colorShow: false,
  83. colorList: [
  84. { text: '蓝色', colorCode: 0 },
  85. { text: '黄色', colorCode: 1 },
  86. { text: '黑色', colorCode: 2 },
  87. { text: '白色', colorCode: 3 },
  88. { text: '绿色', colorCode: 4 },
  89. { text: '其他', colorCode: 99 }
  90. ]
  91. };
  92. },
  93. onLoad() {
  94. this.handlegetMycars();
  95. },
  96. onReachBottom() {
  97. if (this.page.num >= this.page.total) return;
  98. this.status = 'loading';
  99. this.page.num = ++this.page.num;
  100. setTimeout(() => {
  101. this.handlegetMycars();
  102. }, 1500);
  103. },
  104. methods: {
  105. customBack() {
  106. uni.getStorage({
  107. key: 'messageBack',
  108. success: (res) => {
  109. this.$u.route({
  110. type: 'switchTab',
  111. url: res.data
  112. });
  113. },
  114. fail: () => {
  115. this.$u.route({
  116. type: 'switchTab',
  117. url: 'pages/index/index'
  118. });
  119. }
  120. });
  121. },
  122. // 获取车辆列表
  123. handlegetMycars() {
  124. const { num, size } = this.page;
  125. this.$u.api.getMycars({ pageNum: num, pageSize: size }).then((res) => {
  126. if (res.code === 200) {
  127. this.mycars = this.mycars.concat(res?.data?.rows ?? []);
  128. this.page.total = Number(res?.data?.pages ?? 0);
  129. if (this.page.num >= this.page.total) this.status = 'nomore';
  130. else this.status = 'loading';
  131. }
  132. });
  133. },
  134. // 添加车辆
  135. handleAddCar() {
  136. if (!this.$u.test.carNo(this.newPlateNumber)) {
  137. this.$refs.uToast.show({
  138. title: '请正确填写车牌号',
  139. type: 'error'
  140. });
  141. return;
  142. }
  143. let param = {
  144. vehicleNo: this.newPlateNumber,
  145. vehicleColor: this.vehicleColor
  146. };
  147. this.$u.api
  148. .addCar(param)
  149. .then((res) => {
  150. if (res.code === 200) {
  151. this.$refs.uToast.show({
  152. title: res.msg,
  153. type: 'success'
  154. });
  155. this.handlegetMycars();
  156. } else {
  157. this.$refs.uToast.show({
  158. title: res.msg,
  159. type: 'error'
  160. });
  161. }
  162. })
  163. .catch((err) => {
  164. this.$refs.uToast.show({
  165. title: '操作失败!',
  166. type: 'error'
  167. });
  168. });
  169. },
  170. // 删除车辆
  171. handleDelCar(id, content) {
  172. this.delCarContent = `是否删除${content}`;
  173. this.delCarId = id;
  174. this.delCarshow = true;
  175. },
  176. // 确认删除
  177. confirmDelCar() {
  178. this.$u.api
  179. .delCar(this.delCarId)
  180. .then((res) => {
  181. if (res.code === 200) {
  182. this.$refs.uToast.show({
  183. title: res.msg,
  184. type: 'success'
  185. });
  186. this.handlegetMycars();
  187. } else {
  188. this.$refs.uToast.show({
  189. title: res.msg,
  190. type: 'error'
  191. });
  192. }
  193. })
  194. .catch((err) => {
  195. this.$refs.uToast.show({
  196. title: '操作失败!',
  197. type: 'error'
  198. });
  199. });
  200. },
  201. // 点击输入框
  202. messageInputClick() {
  203. this.keyboardshow = true;
  204. },
  205. // 按键被点击(点击退格键不会触发此事件)
  206. keyboardChange(val) {
  207. // 将每次按键的值拼接到value变量中,注意+=写法
  208. this.newPlateNumber += val;
  209. },
  210. // 退格键被点击
  211. backspace() {
  212. // 删除value的最后一个字符
  213. if (this.newPlateNumber.length) this.newPlateNumber = this.newPlateNumber.substr(0, this.newPlateNumber.length - 1);
  214. },
  215. // 键盘输入完成后确认
  216. keyboardConfirm() {
  217. this.colorShow = true;
  218. },
  219. // 确认颜色
  220. confirmColor(e) {
  221. this.vehicleColor = this.colorList[e].colorCode;
  222. },
  223. // 设置默认车辆操作
  224. handlesetDefault(id) {
  225. this.$u.api
  226. .setDefaultCar({ id: id })
  227. .then((res) => {
  228. if (res.code === 200) {
  229. this.$refs.uToast.show({
  230. title: res.msg,
  231. type: 'success'
  232. });
  233. this.handlegetMycars();
  234. } else {
  235. this.$refs.uToast.show({
  236. title: res.msg,
  237. type: 'error'
  238. });
  239. }
  240. })
  241. .catch((err) => {
  242. this.$refs.uToast.show({
  243. title: '操作失败!',
  244. type: 'error'
  245. });
  246. });
  247. }
  248. }
  249. };
  250. </script>
  251. <style lang="scss" scoped>
  252. @import url('./myCars.scss');
  253. </style>