|
@@ -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) {
|
|
|
+ // 空函数,仅用于阻止事件冒泡
|
|
|
+ },
|
|
|
})
|