|
@@ -123,29 +123,48 @@ Page({
|
|
|
success(res) {
|
|
|
wx.hideLoading();
|
|
|
let apiReturnData = res.data;
|
|
|
- apiReturnData.data.swNotificationAnnouncementDos.forEach(data => {
|
|
|
- data.publishtime = data.publishtime.slice(0, 10);
|
|
|
- })
|
|
|
- // 所有的通知公告
|
|
|
- app.globalData.notices = apiReturnData.data.swNotificationAnnouncementDos;
|
|
|
+
|
|
|
+ // 处理轮播通知数据
|
|
|
+ if (apiReturnData.data && apiReturnData.data.swNotificationAnnouncementDos) {
|
|
|
+ // 处理日期格式
|
|
|
+ apiReturnData.data.swNotificationAnnouncementDos.forEach(data => {
|
|
|
+ if (data.publishtime) {
|
|
|
+ data.publishtime = data.publishtime.slice(0, 10);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 所有的通知公告
|
|
|
+ app.globalData.notices = apiReturnData.data.swNotificationAnnouncementDos;
|
|
|
+
|
|
|
+ // 需要轮播的公告
|
|
|
+ let noticeData = apiReturnData.data.swNotificationAnnouncementDos.filter(data => {
|
|
|
+ return data.homepageslider == '1';
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新轮播通知数据
|
|
|
+ _this.setData({
|
|
|
+ noticeList: noticeData,
|
|
|
+ isScrolling: noticeData && noticeData.length > 0
|
|
|
+ });
|
|
|
+
|
|
|
+ // 如果有轮播数据,立即开始轮播
|
|
|
+ if (noticeData && noticeData.length > 0) {
|
|
|
+ _this.startNoticeScroll();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 该用户所有的消息通知
|
|
|
app.globalData.userNoticesList = apiReturnData.data.sysNotifyAnnounceUserDos;
|
|
|
- // 需要轮播的公告
|
|
|
- let data = apiReturnData.data.swNotificationAnnouncementDos.filter(data => {
|
|
|
- return data.homepageslider == '1';
|
|
|
- });
|
|
|
+
|
|
|
+ // 计算未读消息数
|
|
|
if (app.globalData.userNoticesList) {
|
|
|
- // 假设 userNoticesList 中有一个 isRead 属性表示消息是否已读
|
|
|
const unreadCount = app.globalData.userNoticesList.filter(notice => notice.readstate === '2').length;
|
|
|
_this.setData({
|
|
|
unreadCount: unreadCount
|
|
|
});
|
|
|
- } else {
|
|
|
- _this.setData({
|
|
|
- unreadCount: 0
|
|
|
- });
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ // 更新页面数据
|
|
|
_this.setData({
|
|
|
billInfo: {
|
|
|
totalAmount: apiReturnData.data.duFees ?? 0, // 总计应缴
|
|
@@ -156,10 +175,8 @@ Page({
|
|
|
name: apiReturnData.data.username,
|
|
|
accountNumber: apiReturnData.data.usernumber,
|
|
|
address: apiReturnData.data.address
|
|
|
- },
|
|
|
- noticeList: data,
|
|
|
- isScrolling: true,
|
|
|
- })
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
fail(error) {
|
|
|
wx.hideLoading()
|
|
@@ -256,8 +273,47 @@ Page({
|
|
|
success(res) {
|
|
|
wx.hideLoading();
|
|
|
let apiReturnData = res.data;
|
|
|
+
|
|
|
+ // 处理轮播通知数据
|
|
|
+ if (apiReturnData.data && apiReturnData.data.swNotificationAnnouncementDos) {
|
|
|
+ // 处理日期格式
|
|
|
+ apiReturnData.data.swNotificationAnnouncementDos.forEach(data => {
|
|
|
+ if (data.publishtime) {
|
|
|
+ data.publishtime = data.publishtime.slice(0, 10);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 所有的通知公告
|
|
|
+ app.globalData.notices = apiReturnData.data.swNotificationAnnouncementDos;
|
|
|
+
|
|
|
+ // 需要轮播的公告
|
|
|
+ let noticeData = apiReturnData.data.swNotificationAnnouncementDos.filter(data => {
|
|
|
+ return data.homepageslider == '1';
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新轮播通知数据
|
|
|
+ _this.setData({
|
|
|
+ noticeList: noticeData,
|
|
|
+ isScrolling: noticeData && noticeData.length > 0
|
|
|
+ });
|
|
|
+
|
|
|
+ // 如果有轮播数据,立即开始轮播
|
|
|
+ if (noticeData && noticeData.length > 0) {
|
|
|
+ _this.startNoticeScroll();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 该用户所有的消息通知
|
|
|
app.globalData.userNoticesList = apiReturnData.data.sysNotifyAnnounceUserDos;
|
|
|
+
|
|
|
+ // 计算未读消息数
|
|
|
+ if (app.globalData.userNoticesList) {
|
|
|
+ const unreadCount = app.globalData.userNoticesList.filter(notice => notice.readstate === '2').length;
|
|
|
+ _this.setData({
|
|
|
+ unreadCount: unreadCount
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
// 更新页面数据
|
|
|
_this.setData({
|
|
|
billInfo: {
|
|
@@ -269,7 +325,7 @@ Page({
|
|
|
name: apiReturnData.data.username,
|
|
|
accountNumber: apiReturnData.data.usernumber,
|
|
|
address: apiReturnData.data.address
|
|
|
- },
|
|
|
+ }
|
|
|
});
|
|
|
},
|
|
|
fail(error) {
|
|
@@ -365,18 +421,36 @@ Page({
|
|
|
},
|
|
|
|
|
|
startNoticeScroll: function () {
|
|
|
- if (this.data.noticeList.length == 0) {
|
|
|
+ // 检查是否有通知数据
|
|
|
+ if (!this.data.noticeList || this.data.noticeList.length === 0) {
|
|
|
+ console.log('无轮播通知数据');
|
|
|
return;
|
|
|
}
|
|
|
- let data = (this.data.noticeList || []).filter(data => {
|
|
|
+
|
|
|
+ // 过滤需要轮播的公告
|
|
|
+ let data = this.data.noticeList.filter(data => {
|
|
|
return data.homepageslider == '1';
|
|
|
});
|
|
|
-
|
|
|
- const content = data[this.data.currentIndex].scrollingcontent;
|
|
|
- const title = data[this.data.currentIndex].noticetitle;
|
|
|
- const duration = (title.length + content.length) * 0.5;
|
|
|
-
|
|
|
+
|
|
|
+ // 如果没有需要轮播的公告,直接返回
|
|
|
+ if (!data || data.length === 0) {
|
|
|
+ console.log('没有需要轮播的公告');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保currentIndex在有效范围内
|
|
|
+ const safeIndex = this.data.currentIndex < data.length ? this.data.currentIndex : 0;
|
|
|
+
|
|
|
+ // 获取当前公告内容和标题
|
|
|
+ const content = data[safeIndex].scrollingcontent || '';
|
|
|
+ const title = data[safeIndex].noticetitle || '';
|
|
|
+
|
|
|
+ // 计算滚动时长,基于内容长度
|
|
|
+ const duration = Math.max(3, (title.length + content.length) * 0.5);
|
|
|
+
|
|
|
+ // 更新数据
|
|
|
this.setData({
|
|
|
+ currentIndex: safeIndex,
|
|
|
scrollDuration: duration,
|
|
|
isScrolling: true,
|
|
|
});
|
|
@@ -696,4 +770,4 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-})
|
|
|
+})
|