const app = getApp(); Page({ data: { images: { logo:'/static_file/logo.png', background:'/static_file/background.png', card:'/static_file/card.png', tzd:'/static_file/backgrountzdd.png', phone:'/static_file/phone.png', yl:'/static_file/background.yl', jcsfcjtzd:'/static_file/jcsfcjtzd.png', kapiantubiao:'/static_file/kapiantubiao.png' }, // 用户信息 userInfo: { name: "", accountNumber: "", address: "" }, // 账单信息 billInfo: { totalAmount: "", // 总计应缴 waterUsage: "", // 用水量 balance: "" // 账户余额 }, // 功能按钮配置 functionList: [ { icon: '/static_file/zdlb.png', text: '账单列表', url: '/pages/zhangdanlist/zhangdanlist' }, { icon: '/static_file/jfjl.png', text: '缴费记录', url: '/pages/jiaofeiList/jiaofeiList' }, { icon: '/static_file/yhbx.png', text: '用户报修', url: '/pages/baoxiudj/baoxiudj' }, { icon: '/static_file/tzgg.png', text: '通知公告', url: '/pages/tongzhiList/tongzhiList' }, { icon: '/static_file/ckys.png', text: '户号绑定', url: '/pages/huhaoguanli/huhaoguanli' }, { icon: '/static_file/yjfk.png', text: '投诉建议', url: '/pages/tousujianyi/tousujianyi' } ], currentIndex:0, noticeList:[], // 活动信息 activity: { title: '净水器活动', subtitle: '预留入口', imageUrl: '/static_file/background.png' }, currentAccountInfo: {} }, onLoad() { let refresh= app.globalData.refresh; if(refresh==1){ wx.showLoading({ title: '加载中...', }); if(!app.globalData.userWxInfo.token){ wx.hideLoading(); return; } const _this = this; 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; apiReturnData.data.swNotificationAnnouncementDos.forEach(data=>{ data.publishtime=data.publishtime.slice(0,10); }) // 所有的通知公告 app.globalData.notices= apiReturnData.data.swNotificationAnnouncementDos; // 需要轮播的公告 let data= apiReturnData.data.swNotificationAnnouncementDos.filter(data=>{ return data.homepageslider=='1'; }); _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 }, noticeList :data, isScrolling: true, }) }, fail(error) { wx.hideLoading() utils.simleInfo('登录失败,请稍后再试') } }) } // 加载账户和账单信息 this.loadAccountInfo(); }, 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' }) }, // 充值缴费 handlePayment() { wx.navigateTo({ // url: '/pages/payment/payment' }) }, // 功能按钮点击事件 handleFunctionClick(e) { const index = e.currentTarget.dataset.index const item = this.data.functionList[index] if (item && item.url) { wx.navigateTo({ url: item.url, fail: function(err) { console.error('页面跳转失败:', err) wx.showToast({ title: '功能开发中', icon: 'none', duration: 2000 }) } }) } else { wx.showToast({ title: '功能开发中', icon: 'none', duration: 2000 }) } }, // 查看账单列表 handleViewBill() { wx.navigateTo({ // url: '/pages/billList/billList' }) }, // 查看更多活动 handleMoreActivity() { wx.navigateTo({ // url: '/pages/activityList/activityList' }) }, // 添加或修改立即缴费按钮点击事件 goToPayment: function(e) { // 获取当前账单信息 debugger const billInfo = { amount: this.data.billInfo.totalAmount, // 应缴金额 amountDue:this.data.billInfo.totalAmount, // 总计应缴 balance: this.data.billInfo.balance // 账户余额 }; // 编码账单信息并传递到缴费页面 const billInfoStr = encodeURIComponent(JSON.stringify(billInfo)); wx.navigateTo({ url: `/pages/lijijiaofei/lijijiaofei?billInfo=${billInfoStr}` }); }, // 跳转到通知公告列表页面 goToNoticeList: function() { wx.navigateTo({ url: '/pages/tongzhiList/tongzhiList' }) }, // 跳转到通知详情页面 goToNoticeDetail: function() { const currentNotice = this.data.noticeList[this.data.currentIndex]; wx.navigateTo({ url: `/pages/tzxq/tzxq?id=${currentNotice.id}` }); }, onReady: function() { this.startNoticeScroll(); }, startNoticeScroll: function() { if(this.data.noticeList.length==0){ return; } 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; // 将系数从0.3减小到0.1以加快滚动速度 const duration = (title.length + content.length) * 0.2; this.setData({ scrollDuration: duration, isScrolling: true, }); }, onScrollComplete: function() { this.setData({ isScrolling: false }); // 等待1秒后切换到下一条 setTimeout(() => { const nextIndex = (this.data.currentIndex + 1) % this.data.noticeList.length; this.setData({ currentIndex: nextIndex }, () => { this.startNoticeScroll(); }); }, 500); }, // 加载账户和账单信息 loadAccountInfo: function() { const accountInfo = app.globalData.currentAccountInfo || {}; this.setData({ currentAccountInfo: accountInfo }); } })