addLicensePlates.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <ax-body title="车牌管理">
  3. <view class="body">
  4. <!-- 车牌列表 -->
  5. <view class="plate-list">
  6. <view class="plate-card" v-for="(item, index) in vehicleList" :key="index">
  7. <image class="plate-bg"
  8. src="https://national-motion.oss-cn-beijing.aliyuncs.com/20260318/f0babdfe99ca49c69cf26454f9084107.png"
  9. mode="aspectFill"></image>
  10. <view class="plate-content">
  11. <view class="plate-number">{{ item.licensePlate }}</view>
  12. <view class="plate-actions">
  13. <view class="default-tag" v-if="item.isDefault">默认</view>
  14. <view class="set-default" v-else @click="setDefault(item)">设为默认</view>
  15. <view class="delete-btn" @click="deleteVehicle(item)">
  16. <text class="delete-icon">🗑</text>
  17. <text>删除</text>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 空状态 -->
  24. <view class="empty-state" v-if="vehicleList.length === 0">
  25. <text>暂无绑定车辆</text>
  26. </view>
  27. <view class="rules-tips">
  28. <view class="tips-title">
  29. 规则说明
  30. </view>
  31. <view class="tips-texts">
  32. <view class="">1.绑定车牌后,将按订单充电时长+30分钟离场时间进行减免停车费;(例如:充电时长60分钟,系统自动延长30分钟离场时间,即离场时减免90分钟停车费)</view>
  33. <view class="">2.绑定多个车牌时,请在充电开始前,确认充电车辆已设为当前默认充电车辆后,再开始充电,否则无法进行减免停车费。</view>
  34. <view class="">3.车牌绑定错误或默认车牌未对应现场充电车辆导致无法减免停车费,因此产生的一切损失与本平台无关。</view>
  35. </view>
  36. <view style="height: 30rpx;"></view>
  37. </view>
  38. </view>
  39. <!-- 底部添加按钮 -->
  40. <view class="bottom-btn-wrap">
  41. <view class="add-btn" @click="openAddPopup">添加车辆</view>
  42. </view>
  43. <!-- 添加车辆弹窗 -->
  44. <ax-popup ref="addPopup" position="bottom" maskType="black" maskClose @closed="onPopupClosed">
  45. <view class="popup-content">
  46. <view class="popup-header">
  47. <view class="popup-title">添加车辆</view>
  48. <view class="popup-close" @click="closeAddPopup">×</view>
  49. </view>
  50. <view class="popup-body">
  51. <view class="form-tip">请点击下方输入框输入车牌号</view>
  52. <best-plate-keyboard v-model="newPlateNumber" placeholder="点击输入车牌号" @complete="onPlateComplete" />
  53. </view>
  54. </view>
  55. </ax-popup>
  56. </ax-body>
  57. </template>
  58. <script>
  59. import BestPlateKeyboard from '../components/best-plate-keyboard/index.vue'
  60. export default {
  61. components: {
  62. BestPlateKeyboard
  63. },
  64. data() {
  65. return {
  66. vehicleList: [],
  67. newPlateNumber: ''
  68. }
  69. },
  70. onShow() {
  71. this.getVehicleList();
  72. },
  73. methods: {
  74. // 获取车辆列表
  75. getVehicleList() {
  76. this.$api.base('get', '/applet/v1/vehicle/list', {}, {
  77. error: false
  78. }).then(res => {
  79. if (res && res.data) {
  80. this.vehicleList = Array.isArray(res.data) ? res.data : [];
  81. }
  82. }).catch(() => {
  83. this.vehicleList = [];
  84. });
  85. },
  86. // 设为默认
  87. setDefault(item) {
  88. this.$app.popup.confirm('是否确认操作?','提示').then(confirm=>{
  89. if(confirm){
  90. this.$api.base('put', `/applet/v1/vehicle/default/${item.id}`, {}).then(res => {
  91. if (res.code === '00000') {
  92. setTimeout(()=>{
  93. uni.showToast({
  94. title: '设置成功',
  95. icon: 'success'
  96. });
  97. },500)
  98. this.getVehicleList();
  99. }
  100. });
  101. }
  102. })
  103. },
  104. // 删除车辆
  105. deleteVehicle(item) {
  106. this.$app.popup.confirm('确认删除该车辆?', '提示').then(confirm => {
  107. if (confirm) {
  108. this.$api.base('delete', `/applet/v1/vehicle/${item.id}`, {}).then(res => {
  109. if (res.code === '00000') {
  110. setTimeout(()=>{
  111. uni.showToast({
  112. title: '删除成功',
  113. icon: 'success'
  114. });
  115. },500)
  116. this.getVehicleList();
  117. }
  118. });
  119. }
  120. });
  121. },
  122. // 打开添加弹窗
  123. openAddPopup() {
  124. this.newPlateNumber = ''
  125. this.$refs.addPopup.open()
  126. },
  127. // 关闭添加弹窗
  128. closeAddPopup() {
  129. this.$refs.addPopup.close()
  130. },
  131. // 弹窗关闭后
  132. onPopupClosed() {
  133. this.newPlateNumber = ''
  134. },
  135. // 车牌输入完成
  136. onPlateComplete(plateNumber) {
  137. if (!plateNumber) {
  138. return
  139. }
  140. const userInfo = this.$app.storage.get('USER_INFO') || {}
  141. // 如果没有车辆,新添加的默认设为默认车辆
  142. const isDefault = this.vehicleList.length === 0 ? 1 : 0
  143. this.$api.base('post', '/applet/v1/vehicle', {
  144. userId: userInfo.appletUserId || '',
  145. licensePlate: plateNumber,
  146. isDefault: isDefault // 是否默认车辆(0-否 1-是)
  147. }).then(res => {
  148. if (res.code === '00000') {
  149. setTimeout(()=>{
  150. uni.showToast({ title: '添加成功', icon: 'success' })
  151. },100)
  152. this.closeAddPopup()
  153. this.getVehicleList()
  154. setTimeout(()=>{
  155. uni.navigateBack()
  156. },500)
  157. }
  158. })
  159. },
  160. }
  161. }
  162. </script>
  163. <style scoped>
  164. page {
  165. background-color: #F5F7FB;
  166. }
  167. .body {
  168. padding: 20rpx;
  169. padding-bottom: 140rpx;
  170. }
  171. /* 车牌列表 */
  172. .plate-list {
  173. display: flex;
  174. flex-direction: column;
  175. gap: 20rpx;
  176. }
  177. .plate-card {
  178. position: relative;
  179. width: 100%;
  180. height: 180rpx;
  181. border-radius: 16rpx;
  182. overflow: hidden;
  183. }
  184. .plate-bg {
  185. position: absolute;
  186. top: 0;
  187. left: 0;
  188. width: 100%;
  189. height: 100%;
  190. }
  191. .plate-content {
  192. position: relative;
  193. z-index: 1;
  194. display: flex;
  195. align-items: center;
  196. justify-content: space-between;
  197. height: 100%;
  198. padding: 0 30rpx;
  199. }
  200. .plate-number {
  201. font-size: 40rpx;
  202. font-weight: bold;
  203. color: #2b303a;
  204. letter-spacing: 4rpx;
  205. }
  206. .plate-actions {
  207. display: flex;
  208. flex-direction: column;
  209. align-items: flex-end;
  210. gap: 16rpx;
  211. }
  212. .default-tag {
  213. position: absolute;
  214. right: 0;
  215. top: 0;
  216. border-radius: 0rpx 16rpx 0rpx 16rpx;
  217. padding: 8rpx 24rpx;
  218. background: linear-gradient(135deg, #47aeff 0%, #3eb6f8 100%);
  219. font-size: 24rpx;
  220. color: #fff;
  221. }
  222. .set-default {
  223. font-size: 26rpx;
  224. color: #666;
  225. }
  226. .delete-btn {
  227. display: flex;
  228. align-items: center;
  229. gap: 8rpx;
  230. font-size: 26rpx;
  231. color: #666;
  232. }
  233. .delete-icon {
  234. font-size: 28rpx;
  235. }
  236. /* 空状态 */
  237. .empty-state {
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. padding: 200rpx 0;
  242. font-size: 28rpx;
  243. color: #999;
  244. border-radius: 16rpx;
  245. background: linear-gradient( 180deg, #C7FFFD 0%, #F2FFFF 100%);
  246. }
  247. .rules-tips{
  248. margin-top: 20rpx;
  249. }
  250. .tips-title{
  251. font-size: 28rpx;
  252. font-weight: bold;
  253. }
  254. .tips-texts{
  255. font-size: 26rpx;
  256. color: #333;
  257. }
  258. /* 弹窗样式 */
  259. .popup-content {
  260. width: 100vw;
  261. background: #fff;
  262. border-radius: 32rpx 32rpx 0 0;
  263. overflow: hidden;
  264. }
  265. .popup-header {
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-between;
  269. padding: 30rpx;
  270. border-bottom: 1rpx solid #f0f0f0;
  271. }
  272. .popup-title {
  273. font-size: 32rpx;
  274. font-weight: 600;
  275. color: #333;
  276. }
  277. .popup-close {
  278. width: 48rpx;
  279. height: 48rpx;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. font-size: 40rpx;
  284. color: #999;
  285. }
  286. .popup-body {
  287. padding: 30rpx;
  288. padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
  289. }
  290. .form-tip {
  291. font-size: 26rpx;
  292. color: #999;
  293. margin-bottom: 20rpx;
  294. }
  295. /* 底部按钮 */
  296. .bottom-btn-wrap {
  297. position: fixed;
  298. left: 0;
  299. right: 0;
  300. bottom: 0;
  301. padding: 20rpx 30rpx;
  302. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  303. background: #fff;
  304. box-shadow: 0 -2rpx 20rpx rgba(0, 0, 0, 0.05);
  305. }
  306. .add-btn {
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. height: 96rpx;
  311. background: linear-gradient(to right, #8ff8fb, #47aeff);
  312. border-radius: 48rpx;
  313. font-size: 32rpx;
  314. color: #2b303a;
  315. font-weight: 500;
  316. }
  317. </style>