Browse Source

小程序页面优化

QAQ 陈 4 tháng trước cách đây
mục cha
commit
aa473895fe
1 tập tin đã thay đổi với 68 bổ sung4 xóa
  1. 68 4
      pages/homepage/homepage.js

+ 68 - 4
pages/homepage/homepage.js

@@ -241,7 +241,6 @@ Page({
   // 添加或修改立即缴费按钮点击事件
   goToPayment: function(e) {
     // 获取当前账单信息
-    debugger
     const billInfo = {
       amount: this.data.billInfo.totalAmount, // 应缴金额
       amountDue:this.data.billInfo.totalAmount,  // 总计应缴
@@ -314,9 +313,74 @@ Page({
   // 加载账户和账单信息
   loadAccountInfo: function() {
     const accountInfo = app.globalData.currentAccountInfo || {};
-
-    this.setData({
-      currentAccountInfo: accountInfo
+    // 检查是否是首次加载
+    const isFirstLoad = wx.getStorageSync('isFirstLoad') !== 'false';
+    
+    if (isFirstLoad) {
+      // 首次加载,查找并设置默认账户
+      this.loadDefaultAccount();
+      // 设置标记,表示已不是首次加载
+      wx.setStorageSync('isFirstLoad', 'false');
+    } else {
+      this.setData({
+        currentAccountInfo: accountInfo
+      });
+    }
+  },
+  
+  // 加载默认账户
+  loadDefaultAccount: function() {
+    if (!app.globalData.userWxInfo.token) {
+      return;
+    }
+    
+    const _this = this;
+    wx.showLoading({
+      title: '加载中...',
+    });
+    wx.request({
+      url: app.globalData.interfaceUrls.accountList,
+      method: 'GET',
+      header: {
+        'content-type': 'application/json',
+        'token': app.globalData.userWxInfo.token,
+        'source': "wc"
+      },
+      success(res) {
+        wx.hideLoading();
+        if (res.data && res.data.data) {
+          // 查找 defaultAccount 为 0 的账户
+          const defaultAccount = res.data.data.find(account => account.defaultAccount === "0");
+        
+          if (defaultAccount) {
+            // 设置为当前账户
+            app.globalData.currentAccountInfo = defaultAccount;
+            _this.setData({
+              currentAccountInfo: defaultAccount
+            });
+            
+            // 加载该默认账户的详细信息
+            _this.loadPageData();
+          } else {
+            // 没有找到默认账户,使用当前账户
+            _this.setData({
+              currentAccountInfo: app.globalData.currentAccountInfo || {}
+            });
+          }
+        }
+      },
+      fail(error) {
+        wx.hideLoading();
+        wx.showToast({
+          title: '加载默认账户失败',
+          icon: 'none',
+          duration: 2000
+        });
+        // 使用当前账户作为备选
+        _this.setData({
+          currentAccountInfo: app.globalData.currentAccountInfo || {}
+        });
+      }
     });
   }
 })