wlzboy
2025-10-26 5c5cddb1c2ee0d19adddebaf3a3a10a6d93fd2ad
app/pages/mine/index.vue
@@ -80,6 +80,18 @@
            <view>编辑资料</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleUserAgreement">
          <view class="menu-item-box">
            <view class="iconfont icon-text menu-icon"></view>
            <view>用户服务协议</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handlePrivacyPolicy">
          <view class="menu-item-box">
            <view class="iconfont icon-safe menu-icon"></view>
            <view>隐私政策</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleHelp">
          <view class="menu-item-box">
            <view class="iconfont icon-help menu-icon"></view>
@@ -106,13 +118,15 @@
<script>
  import storage from '@/utils/storage'
  import { getUserProfile } from "@/api/system/user"
  import { getUserBoundVehicle, unbindVehicleFromUser } from '@/api/vehicle'
  
  export default {
    data() {
      return {
        name: this.$store.state.user.name,
        name: this.$store.state.user.nickName,
        phonenumber: '',
        boundVehicle: '', // 模拟绑定的车辆信息
        boundVehicle: '', // 绑定的车辆信息
        boundVehicleId: null, // 绑定的车辆ID
        version: getApp().globalData.config.appInfo.version
      }
    },
@@ -130,18 +144,35 @@
    methods: {
      // 获取用户信息
      getUserInfo() {
        const userId = this.$store.state.user.userId
        // 获取用户基本信息
        getUserProfile().then(response => {
          const user = response.data
          this.name = user.userName
          this.phonenumber = user.phonenumber
          // 模拟绑定车辆信息,实际项目中应从用户信息或车辆接口获取
          this.boundVehicle = '粤A12345'
        }).catch(() => {
          // 获取用户信息失败时使用默认值
          this.name = this.$store.state.user.name || '未登录'
          this.name = this.$store.state.user.nickName || '未登录'
          this.phonenumber = '未绑定'
          this.boundVehicle = '未绑定'
        })
        // 获取用户绑定的车辆信息
        if (userId) {
          getUserBoundVehicle(userId).then(response => {
            if (response.code === 200 && response.data) {
              const vehicle = response.data
              this.boundVehicle = vehicle.vehicleNumber || '未知车牌'
              this.boundVehicleId = vehicle.vehicleId
            } else {
              this.boundVehicle = '未绑定'
              this.boundVehicleId = null
            }
          }).catch(() => {
            this.boundVehicle = '未绑定'
            this.boundVehicleId = null
          })
        }
      },
      
      // 跳转到绑定车辆页面
@@ -151,10 +182,30 @@
      
      // 取消绑定车辆
      unbindVehicle() {
        this.$modal.confirm('是否取消绑定车辆?').then(() => {
          // 这里可以调用API取消绑定车辆
          this.boundVehicle = '未绑定'
          this.$modal.showToast('取消绑定成功')
        const userId = this.$store.state.user.userId
        const vehicleId = this.boundVehicleId
        if (!userId || !vehicleId) {
          this.$modal.showToast('无法获取绑定信息')
          return
        }
        this.$modal.confirm(`确认取消绑定车辆 ${this.boundVehicle} 吗?`).then(() => {
          // 调用API取消绑定车辆
          unbindVehicleFromUser(userId, vehicleId).then(response => {
            if (response.code === 200) {
              this.boundVehicle = '未绑定'
              this.boundVehicleId = null
              this.$modal.showToast('取消绑定成功')
              // 更新用户信息
              this.$store.dispatch('GetInfo')
            } else {
              this.$modal.showToast(response.msg || '取消绑定失败')
            }
          }).catch(error => {
            console.error('取消绑定失败:', error)
            this.$modal.showToast('取消绑定失败,请重试')
          })
        }).catch(() => {
          // 用户取消操作
        })
@@ -188,6 +239,12 @@
      handleAbout() {
        this.$tab.navigateTo('/pages/mine/about/index')
      },
      handleUserAgreement() {
        this.$tab.navigateTo('/pages/mine/user-agreement/index')
      },
      handlePrivacyPolicy() {
        this.$tab.navigateTo('/pages/mine/privacy-policy/index')
      },
      handleJiaoLiuQun() {
        this.$modal.showToast('QQ群:①133713780(满)、②146013835(满)、③189091635')
      },