From c098f1e3a3e052aa3d65584aae6dc003a70d75ad Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期二, 16 十二月 2025 00:09:14 +0800
Subject: [PATCH] feat: 停止轮询 uncount
---
app/pages/bind-vehicle.vue | 149 +++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 135 insertions(+), 14 deletions(-)
diff --git a/app/pages/bind-vehicle.vue b/app/pages/bind-vehicle.vue
index 4897419..417e3a4 100644
--- a/app/pages/bind-vehicle.vue
+++ b/app/pages/bind-vehicle.vue
@@ -4,8 +4,8 @@
<text class="title">缁戝畾杞﹁締</text>
</view>
- <!-- 鎵爜缁戝畾 -->
- <view class="scan-section">
+ <!-- 鎵爜缁戝畾 - 宸查殣钘� -->
+ <!-- <view class="scan-section">
<view class="section-title">鎵竴鎵粦瀹�</view>
<view class="scan-content">
<view class="scan-icon" @click="scanQRCode">
@@ -13,7 +13,7 @@
<text class="scan-text">鐐瑰嚮鎵爜缁戝畾杞﹁締</text>
</view>
</view>
- </view>
+ </view> -->
<!-- 涓嬫媺閫夋嫨缁戝畾 -->
<view class="form-section">
@@ -37,15 +37,90 @@
</template>
<script>
+ import { mapState } from 'vuex'
+ import { listAvailableVehicles, bindVehicleToUser, getUserBoundVehicle } from '@/api/vehicle'
+
export default {
data() {
return {
selectedVehiclePlate: '',
- // 妯℃嫙杞﹁締鍒楄〃鏁版嵁
- vehiclePlates: ['绮12345', '绮67890', '绮11111', '绮22222', '绮33333']
+ selectedVehicleId: null,
+ // 杞﹁締鍒楄〃鏁版嵁
+ vehiclePlates: [],
+ vehicleOptions: [],
+ loading: false,
+ // 褰撳墠缁戝畾鐨勮溅杈嗕俊鎭�
+ currentBoundVehicle: null
}
},
+ computed: {
+ ...mapState({
+ currentUser: state => state.user
+ })
+ },
+ onLoad() {
+ // 鍔犺浇杞﹁締鍒楄〃
+ this.loadVehicleList()
+ // 鍔犺浇褰撳墠鐢ㄦ埛缁戝畾鐨勮溅杈�
+ this.loadCurrentBoundVehicle()
+ },
methods: {
+ // 鍔犺浇褰撳墠鐢ㄦ埛缁戝畾鐨勮溅杈�
+ loadCurrentBoundVehicle() {
+ const userId = this.currentUser.userId
+ getUserBoundVehicle(userId).then(response => {
+ if (response.code === 200 && response.data) {
+ this.currentBoundVehicle = response.data
+ console.log('褰撳墠缁戝畾杞﹁締:', this.currentBoundVehicle)
+ } else {
+ this.currentBoundVehicle = null
+ }
+ }).catch(error => {
+ console.error('鑾峰彇缁戝畾杞﹁締澶辫触:', error)
+ this.currentBoundVehicle = null
+ })
+ },
+
+ // 鍔犺浇杞﹁締鍒楄〃锛堝彧鍔犺浇鍚屼竴鍒嗗叕鍙哥殑杞﹁締锛�
+ loadVehicleList() {
+ this.loading = true
+ // 鑾峰彇褰撳墠鐢ㄦ埛鐨勯儴闂↖D
+ const deptId = this.currentUser.deptId
+
+ if (!deptId) {
+ this.loading = false
+ console.error('鏃犳硶鑾峰彇鐢ㄦ埛閮ㄩ棬淇℃伅')
+ this.$modal.showToast('鏃犳硶鑾峰彇鐢ㄦ埛閮ㄩ棬淇℃伅')
+ return
+ }
+
+ // 浣跨敤鐢ㄦ埛鎵�鍦ㄧ殑閮ㄩ棬ID鍔犺浇杞﹁締鍒楄〃
+ listAvailableVehicles(deptId, 'GENERAL').then(response => {
+ this.loading = false
+ const vehicleList = response.data || response.rows || []
+
+ if (vehicleList.length === 0) {
+ console.log('褰撳墠鍒嗗叕鍙告殏鏃犲彲鐢ㄨ溅杈�')
+ this.$modal.showToast('褰撳墠鍒嗗叕鍙告殏鏃犲彲鐢ㄨ溅杈�')
+ }
+
+ this.vehicleOptions = vehicleList.map(vehicle => ({
+ id: vehicle.vehicleId,
+ name: vehicle.vehicleNo,
+ type: vehicle.vehicleType,
+ brand: vehicle.vehicleBrand,
+ model: vehicle.vehicleModel
+ }))
+ this.vehiclePlates = this.vehicleOptions.map(v => v.name)
+
+ console.log(`鍔犺浇浜� ${vehicleList.length} 杈嗚溅杈嗭紙閮ㄩ棬ID: ${deptId}锛塦)
+ }).catch(error => {
+ this.loading = false
+ console.error('鍔犺浇杞﹁締鍒楄〃澶辫触:', error)
+ this.$modal.showToast('鍔犺浇杞﹁締鍒楄〃澶辫触')
+ })
+ },
+
// 鎵爜缁戝畾杞﹁締
scanQRCode() {
// #ifdef H5
@@ -72,23 +147,69 @@
// 杞︾墝鍙烽�夋嫨
onVehiclePlateChange(e) {
- this.selectedVehiclePlate = this.vehiclePlates[e.detail.value]
+ const index = e.detail.value
+ this.selectedVehiclePlate = this.vehiclePlates[index]
+ this.selectedVehicleId = this.vehicleOptions[index]?.id
},
// 缁戝畾杞﹁締
bindVehicle() {
- if (!this.selectedVehiclePlate) {
+ if (!this.selectedVehiclePlate || !this.selectedVehicleId) {
this.$modal.showToast('璇烽�夋嫨杞︾墝鍙�')
return
}
- // 杩欓噷鍙互璋冪敤API杩涜杞﹁締缁戝畾
- this.$modal.confirm('纭缁戝畾杞﹁締 ' + this.selectedVehiclePlate + ' 鍚楋紵').then(() => {
- this.$modal.showToast('杞﹁締缁戝畾鎴愬姛')
- // 杩斿洖涓婁竴椤�
- this.$tab.navigateBack()
- }).catch(() => {
- // 鐢ㄦ埛鍙栨秷鎿嶄綔
+ // 妫�鏌ユ槸鍚﹂�夋嫨鐨勬槸褰撳墠宸茬粦瀹氱殑杞﹁締
+ if (this.currentBoundVehicle && this.currentBoundVehicle.vehicleId === this.selectedVehicleId) {
+ this.$modal.showToast('褰撳墠宸茬粦瀹氭杞﹁締锛屾棤闇�閲嶅缁戝畾')
+ return
+ }
+
+ // 濡傛灉宸茬粡缁戝畾浜嗗叾浠栬溅杈嗭紝鎻愮ず鏄惁寮哄埗缁戝畾
+ if (this.currentBoundVehicle) {
+ const currentVehicleNo = this.currentBoundVehicle.vehicleNumber || '鏈煡杞︾墝'
+ const confirmMsg = `鎮ㄥ綋鍓嶅凡缁戝畾杞﹁締锛�${currentVehicleNo}\n\n纭瑕佽В缁戞棫杞﹁締骞剁粦瀹氭柊杞﹁締锛�${this.selectedVehiclePlate} 鍚楋紵`
+
+ this.$modal.confirm(confirmMsg).then(() => {
+ this.performBind()
+ }).catch(() => {
+ // 鐢ㄦ埛鍙栨秷寮哄埗缁戝畾
+ console.log('鐢ㄦ埛鍙栨秷寮哄埗缁戝畾')
+ })
+ } else {
+ // 娌℃湁缁戝畾杞﹁締锛岀洿鎺ョ粦瀹�
+ this.$modal.confirm('纭缁戝畾杞﹁締 ' + this.selectedVehiclePlate + ' 鍚楋紵').then(() => {
+ this.performBind()
+ }).catch(() => {
+ // 鐢ㄦ埛鍙栨秷鎿嶄綔
+ })
+ }
+ },
+
+ // 鎵ц缁戝畾鎿嶄綔
+ performBind() {
+ this.loading = true
+ const userId = this.currentUser.userId
+
+ bindVehicleToUser(userId, this.selectedVehicleId).then(response => {
+ this.loading = false
+
+ if (response.code === 200) {
+ this.$modal.showToast('杞﹁締缁戝畾鎴愬姛')
+ // 鏇存柊Vuex涓殑鐢ㄦ埛淇℃伅
+ this.$store.dispatch('GetInfo')
+ // 杩斿洖涓婁竴椤�
+ setTimeout(() => {
+ this.$tab.navigateBack()
+ }, 1500)
+ } else {
+ this.$modal.showToast(response.msg || '缁戝畾澶辫触')
+ }
+ }).catch(error => {
+ this.loading = false
+ console.error('缁戝畾杞﹁締澶辫触:', error)
+ const errorMsg = error.msg || error.message || '缁戝畾杞﹁締澶辫触锛岃閲嶈瘯'
+ this.$modal.showToast(errorMsg)
})
},
--
Gitblit v1.9.1