QAQ 陈 4 hónapja
szülő
commit
21b90bfe87

+ 56 - 1
pages/homepage/homepage.js

@@ -112,10 +112,65 @@ Page({
     }
   },
   onShow() {
+    // 检查是否需要刷新
+    const needRefresh = wx.getStorageSync('needRefreshHomepage');
+    if (needRefresh) {
+      // 清除刷新标记
+      wx.removeStorageSync('needRefreshHomepage');
+      this.loadPageData();
+    }
+  },
 
+  loadPageData: function() {
+    const _this = this;
+    wx.showLoading({
+      title: '加载中...',
+    });
+    
+    // 检查token是否存在
+    if(!app.globalData.userWxInfo.token){
+      wx.hideLoading();
+      return;
+    }
+    wx.request({
+      url: app.globalData.interfaceUrls.homePageInfo + app.globalData.currentAccountInfo.usernumber,
+      method: 'GET',
+      header: {
+        'content-type': 'application/json',
+        'token': app.globalData.userWxInfo.token,
+        'source': "wc",
+        '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
+      },
+      success(res) {
+        wx.hideLoading();
+        let apiReturnData = res.data;
+        
+        // 更新页面数据
+        _this.setData({
+          billInfo: {
+            totalAmount: apiReturnData.data.duFees,  // 总计应缴
+            waterUsage: apiReturnData.data.waterConsumption,  // 用水量
+            balance: apiReturnData.data.accountbalance   // 账户余额
+          },
+          userInfo: {
+            name: apiReturnData.data.username,
+            accountNumber: apiReturnData.data.usernumber,
+            address: apiReturnData.data.address
+          },
+        });
+      },
+      fail(error) {
+        wx.hideLoading();
+        wx.showToast({
+          title: '数据加载失败,请稍后再试',
+          icon: 'none',
+          duration: 2000
+        });
+      }
+    });
   },
 
-  // 切换水表
+  // 切换户号
   handleSwitchMeter() {
     wx.navigateTo({
        url: '/pages/huhaoguanli/huhaoguanli'

+ 63 - 8
pages/huhaoguanli/huhaoguanli.js

@@ -10,6 +10,10 @@ Page({
   },
 
   onLoad: function (options) {
+    console.log('页面加载时的全局数据:', {
+      currentAccountInfo: app.globalData.currentAccountInfo,
+      userWxInfo: app.globalData.userWxInfo
+    });
     this.getAccountList();
   },
 
@@ -24,7 +28,7 @@ Page({
       url: app.globalData.interfaceUrls.accountList,
       method: 'GET',
       header: {
-        'content-type': 'application/json', // 默认值
+        'content-type': 'application/json',
         'token': app.globalData.userWxInfo.token,
         'source': "wc",
         '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
@@ -32,14 +36,35 @@ Page({
       success(res) {
         wx.hideLoading();
         let apiReturnData = res.data;
-        debugger;
+        
+        // 从全局获取当前账户的信息currentAccountInfo
+        const currentUsernumber = app.globalData.currentAccountInfo.usernumber;
+        
+        console.log('当前用户信息:', {
+          currentUsernumber: currentUsernumber,
+          currentAccountInfo: app.globalData.currentAccountInfo
+        });
+        
         _this.setData({
-          huHaoList: apiReturnData.data,
-        })
+          huHaoList: apiReturnData.data.map(item => {
+            const isCurrent = item.usernumber === currentUsernumber;
+            console.log('比较户号:', {
+              itemNumber: item.usernumber,
+              currentNumber: currentUsernumber,
+              isCurrent: isCurrent,
+              username: item.username
+            });
+            
+            return {
+              ...item,
+              isCurrentUser: isCurrent
+            };
+          })
+        });
       },
       fail(error) {
-        wx.hideLoading()
-        utils.simleInfo('获取数据失败,请稍后再试')
+        wx.hideLoading();
+        utils.simleInfo('获取数据失败,请稍后再试');
       }
     });
   },
@@ -88,13 +113,11 @@ Page({
         account: unbindInfo.usernumber,
         deKey: unbindInfo.dsKey,
         refresh: false,
-        //为true 时otherDsKeys最好必填节约后端请求时间
         otherDsKeys: []
       },
       header: {
         'content-type': 'application/json', // 默认值
         'token': app.globalData.userWxInfo.token,
-        // '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
       },
       success(res) {
         wx.hideLoading();
@@ -148,4 +171,36 @@ Page({
   goBack: function () {
     wx.navigateBack();
   },
+
+  switchHuHao(e) {
+    const huHaoInfo = e.currentTarget.dataset.item;
+    // 更新全局数据
+    app.globalData.userWxInfo = {
+      ...app.globalData.userWxInfo,
+      username: huHaoInfo.username,
+      usernumber: huHaoInfo.usernumber,
+      address: huHaoInfo.address,
+      groupName: huHaoInfo.groupName,
+      currentDsKey: huHaoInfo.dsKey  // 更新 currentDsKey
+    };
+    
+    // 更新当前账户信息
+    app.globalData.currentAccountInfo = huHaoInfo;
+    // 将新选择的户号信息保存到本地存储
+    wx.setStorageSync('currentHuHao', huHaoInfo);
+    wx.showToast({
+      title: '户号切换成功',
+      icon: 'success',
+      duration: 1500
+    });
+    // 设置一个标记表示需要刷新首页
+    wx.setStorageSync('needRefreshHomepage', true);
+    
+    // 延迟跳转到首页
+    setTimeout(() => {
+      wx.switchTab({
+        url: '/pages/homepage/homepage'
+      });
+    }, 1500);
+  },
 }) 

+ 1 - 1
pages/huhaoguanli/huhaoguanli.wxml

@@ -12,7 +12,7 @@
   
   <scroll-view scroll-y="true" class="scroll-area">
     <view class="card-list">
-      <view class="card" wx:for="{{huHaoList}}" wx:key="id">
+      <view class="card {{item.isCurrentUser ? 'current-user-card' : ''}}" wx:for="{{huHaoList}}" wx:key="id" bindtap="switchHuHao" data-item="{{item}}">
         <view class="card-inner">
           <image class="card-background" src="/static_file/card.png" mode="aspectFill" />
           <view class="card-header">

+ 20 - 3
pages/huhaoguanli/huhaoguanli.wxss

@@ -67,17 +67,16 @@
 .card-list {
   width: 100%;
   padding-bottom: 40rpx;
-  padding-top: 20rpx;
+  padding-top: 50rpx;
 }
 
 .card {
   width: 96%;
   margin: 0 auto 20rpx;
-  border-radius: 20rpx;
-  overflow: hidden;
   border-radius: 16rpx;
   box-shadow: 0rpx 6rpx 12rpx rgba(0, 0, 0, 0.16);
   position: relative;
+  overflow: hidden;
 }
 
 .card-inner {
@@ -299,3 +298,21 @@
   opacity: 1;
   border: 2rpx solid rgba(232, 232, 232, 1);
 }
+
+.current-user-card {
+  position: relative;
+}
+
+.current-user-card::before {
+  content: "";
+  position: absolute;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+  border: 8rpx solid #3580f1;
+  border-radius: 16rpx;
+  pointer-events: none;
+  z-index: 10;
+  box-sizing: border-box;
+}