Forráskód Böngészése

小程序页面优化

QAQ 陈 4 hónapja
szülő
commit
a074576b0f
2 módosított fájl, 67 hozzáadás és 20 törlés
  1. 48 18
      pages/huhaoguanli/huhaoguanli.js
  2. 19 2
      pages/huhaoguanli/huhaoguanli.wxml

+ 48 - 18
pages/huhaoguanli/huhaoguanli.js

@@ -6,14 +6,16 @@ Page({
   data: {
     huHaoList: [],
     showUnbindModal: false,
-    unbindId: null
+    unbindId: null,
+    showDefaultModal: false,
+    defaultId: null
   },
 
   onLoad: function (options) {
     this.getAccountList();
   },
 
-  // 过滤户号列表,只显示deleted=0的数据
+  // 过滤户号列表,只显示deleted=0的数据,并按默认户号排序
   getAccountList: function () {
     const _this = this;
     wx.showLoading({
@@ -34,18 +36,28 @@ Page({
         let apiReturnData = res.data;
         // 从全局获取当前账户的信息currentAccountInfo
         const currentUsernumber = app.globalData.currentAccountInfo.usernumber;
+        
+        // 对返回的数据进行排序,将默认户号(defaultAccount='0')排在前面
+        const sortedData = apiReturnData.data.sort((a, b) => {
+          // 先按defaultAccount排序('0'排在前面)
+          if (a.defaultAccount !== b.defaultAccount) {
+            return a.defaultAccount === '0' ? -1 : 1;
+          }
+          // 如果defaultAccount相同,则按是否是当前户号排序
+          if (a.usernumber === currentUsernumber) return -1;
+          if (b.usernumber === currentUsernumber) return 1;
+          return 0;
+        });
+        
         _this.setData({
-          huHaoList: apiReturnData.data.map(item => {
+          huHaoList: sortedData.map(item => {
             const isCurrent = item.usernumber === currentUsernumber;
             return {
               ...item,
               isCurrentUser: isCurrent
             };
           })
-        }, () => {
         });
-        debugger
-        
       },
       fail(error) {
         wx.hideLoading();
@@ -198,15 +210,26 @@ Page({
   // 设置默认户号
   setDefaultHuHao: function(e) {
     const id = e.currentTarget.dataset.id;
-    wx.showModal({
-      title: '提示',
-      content: '是否将此户号设为默认户号?',
-      success: (res) => {
-        debugger
-        if (res.confirm) {
-          this.setDefaultAccount(id);
-        }
-      }
+    this.setData({
+      showDefaultModal: true,
+      defaultId: id
+    });
+  },
+  
+  // 取消设置默认户号
+  cancelDefault: function() {
+    this.setData({
+      showDefaultModal: false,
+      defaultId: null
+    });
+  },
+  
+  // 确认设置默认户号
+  confirmDefault: function() {
+    const id = this.data.defaultId;
+    this.setDefaultAccount(id);
+    this.setData({
+      showDefaultModal: false
     });
   },
   
@@ -232,13 +255,15 @@ Page({
         'token': app.globalData.userWxInfo.token,
       },
       success: (res) => {
-        debugger
         if (res.data.code === "200") {
           wx.showToast({
-            title: '切换成功',
+            title: '设置成功',
             icon: 'success'
           });
-          this.getAccountList();
+          // 延迟一小段时间后刷新列表,确保后台数据已更新
+          setTimeout(() => {
+            this.getAccountList();
+          }, 300);
         } else {
           wx.showToast({
             title: res.data.msg || '设置失败',
@@ -257,4 +282,9 @@ Page({
       }
     });
   },
+
+  // 阻止事件冒泡
+  stopPropagation: function(e) {
+    // 空函数,仅用于阻止事件冒泡
+  },
 }) 

+ 19 - 2
pages/huhaoguanli/huhaoguanli.wxml

@@ -25,11 +25,11 @@
             <text class="phone">{{item.usernumber}}</text>
             <text class="address">{{item.address}}</text>
           </view>
-          <view class="card-footer">
+          <view class="card-footer" catchtap="stopPropagation">
             <view class="button-group">
               <button class="unbind-btn" catchtap="unbindHuHao" data-id="{{item.id}}">解除绑定</button>
               <button class="default-btn" wx:if="{{item.defaultAccount == '1'}}" catchtap="setDefaultHuHao" data-id="{{item.id}}">设为默认</button>
-              <text class="default-tag" wx:if="{{item.defaultAccount == '0'}}" catchtap="switchHuHao" data-item="{{item}}">默认户号</text>
+              <text class="default-tag" wx:if="{{item.defaultAccount == '0'}}">默认户号</text>
             </view>
           </view>
         </view>
@@ -58,4 +58,21 @@
       </view>
     </view>
   </view>
+  
+  <!-- 设置默认户号确认弹窗 -->
+  <view class="modal-mask" wx:if="{{showDefaultModal}}">
+    <view class="modal-content">
+      <view class="modal-icon-wrapper">
+        <image class="modal-icon" src="/static_file/jbtx.png" mode="aspectFit"></image>
+      </view>
+      <view class="modal-body">
+        <view class="modal-title">确定设为默认户号吗?</view>
+        <view class="modal-desc">设置后将作为默认登录账户</view>
+        <view class="modal-btns">
+          <button class="cancel-btn" bindtap="cancelDefault">取消</button>
+          <button class="confirm-btn" bindtap="confirmDefault">确定</button>
+        </view>
+      </view>
+    </view>
+  </view>
 </view>