myCars.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. this.mycarsTotal = Number(res?.data?.total ?? 0);
  130. if (this.page.num >= this.page.total) this.status = 'nomore';
  131. else this.status = 'loading';
  132. }
  133. });
  134. },
  135. // 添加车辆
  136. handleAddCar() {
  137. if (!this.$u.test.carNo(this.newPlateNumber)) {
  138. this.$refs.uToast.show({
  139. title: '请正确填写车牌号',
  140. type: 'error'
  141. });
  142. return;
  143. }
  144. let param = {
  145. vehicleNo: this.newPlateNumber,
  146. vehicleColor: this.vehicleColor
  147. };
  148. this.$u.api
  149. .addCar(param)
  150. .then((res) => {
  151. if (res.code === 200) {
  152. this.$refs.uToast.show({
  153. title: res.msg,
  154. type: 'success'
  155. });
  156. this.handlegetMycars();
  157. } else {
  158. this.$refs.uToast.show({
  159. title: res.msg,
  160. type: 'error'
  161. });
  162. }
  163. })
  164. .catch((err) => {
  165. this.$refs.uToast.show({
  166. title: '操作失败!',
  167. type: 'error'
  168. });
  169. });
  170. },
  171. // 删除车辆
  172. handleDelCar(id, content) {
  173. this.delCarContent = `是否删除${content}`;
  174. this.delCarId = id;
  175. this.delCarshow = true;
  176. },
  177. // 确认删除
  178. confirmDelCar() {
  179. this.$u.api
  180. .delCar(this.delCarId)
  181. .then((res) => {
  182. if (res.code === 200) {
  183. this.$refs.uToast.show({
  184. title: res.msg,
  185. type: 'success'
  186. });
  187. this.handlegetMycars();
  188. } else {
  189. this.$refs.uToast.show({
  190. title: res.msg,
  191. type: 'error'
  192. });
  193. }
  194. })
  195. .catch((err) => {
  196. this.$refs.uToast.show({
  197. title: '操作失败!',
  198. type: 'error'
  199. });
  200. });
  201. },
  202. // 点击输入框
  203. messageInputClick() {
  204. this.keyboardshow = true;
  205. },
  206. // 按键被点击(点击退格键不会触发此事件)
  207. keyboardChange(val) {
  208. // 将每次按键的值拼接到value变量中,注意+=写法
  209. this.newPlateNumber += val;
  210. },
  211. // 退格键被点击
  212. backspace() {
  213. // 删除value的最后一个字符
  214. if (this.newPlateNumber.length) this.newPlateNumber = this.newPlateNumber.substr(0, this.newPlateNumber.length - 1);
  215. },
  216. // 键盘输入完成后确认
  217. keyboardConfirm() {
  218. this.colorShow = true;
  219. },
  220. // 确认颜色
  221. confirmColor(e) {
  222. this.vehicleColor = this.colorList[e].colorCode;
  223. },
  224. // 设置默认车辆操作
  225. handlesetDefault(id) {
  226. this.$u.api
  227. .setDefaultCar({ id: id })
  228. .then((res) => {
  229. if (res.code === 200) {
  230. this.$refs.uToast.show({
  231. title: res.msg,
  232. type: 'success'
  233. });
  234. this.handlegetMycars();
  235. } else {
  236. this.$refs.uToast.show({
  237. title: res.msg,
  238. type: 'error'
  239. });
  240. }
  241. })
  242. .catch((err) => {
  243. this.$refs.uToast.show({
  244. title: '操作失败!',
  245. type: 'error'
  246. });
  247. });
  248. }
  249. }
  250. };
  251. </script>
  252. <style lang="scss" scoped>
  253. @import url('./myCars.scss');
  254. </style>