123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- 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: {},
- unreadCount: 0
- },
- 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) {
- debugger
- wx.hideLoading();
- let apiReturnData=res.data;
- apiReturnData.data.swNotificationAnnouncementDos.forEach(data=>{
- data.publishtime=data.publishtime.slice(0,10);
- })
- // 所有的通知公告
- app.globalData.notices= apiReturnData.data.swNotificationAnnouncementDos;
- // 该用户所有的消息通知
- 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, // 总计应缴
- waterUsage: apiReturnData.data.waterConsumption ?? 0, // 用水量
- balance: apiReturnData.data.accountbalance ?? 0 // 账户余额
- },
- 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();
- }
-
- // 从任何页面返回时都获取最新的未读消息数
- this.getUnreadNoticeCount();
-
- // 检查是否从户号管理页面返回
- const backFromHuHao = wx.getStorageSync('backFromHuHao');
- if (backFromHuHao) {
- wx.removeStorageSync('backFromHuHao');
- // 从户号管理页面返回时重新加载全部数据
- this.loadHomepageData();
- }
- },
- 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;
- // 该用户所有的消息通知
- app.globalData.userNoticesList = apiReturnData.data.sysNotifyAnnounceUserDos;
- // 更新页面数据
- _this.setData({
- billInfo: {
- totalAmount: apiReturnData.data.duFees ?? 0, // 总计应缴
- waterUsage: apiReturnData.data.waterConsumption ?? 0, // 用水量
- balance: apiReturnData.data.accountbalance ?? 0 // 账户余额
- },
- 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) {
- // 获取当前账单信息
- 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;
- const duration = (title.length + content.length) * 0.5;
- this.setData({
- scrollDuration: duration,
- isScrolling: true,
- });
- },
- onScrollComplete: function() {
- this.setData({
- isScrolling: false
- });
- // 等待2秒后切换到下一条
- setTimeout(() => {
- const nextIndex = (this.data.currentIndex + 1) % this.data.noticeList.length;
- this.setData({
- currentIndex: nextIndex
- }, () => {
- this.startNoticeScroll();
- });
- }, 1000);
- },
- // 加载账户和账单信息
- loadAccountInfo: function() {
- const accountInfo = app.globalData.currentAccountInfo || {};
- // 检查是否是首次加载
- 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 || {}
- });
- }
- });
- },
- onPullDownRefresh: function() {
- // 刷新数据
- this.refreshData();
- },
- // 修改刷新数据的函数
- refreshData: function() {
- console.log('正在刷新数据...');
- this.loadPageData();
- // 刷新完成后停止下拉刷新动画
- wx.stopPullDownRefresh({
- success: (res) => {
- wx.showToast({
- title: '刷新成功',
- icon: 'success',
- duration: 1000
- });
- }
- });
- },
- // 获取未读消息数量的方法
- getUnreadNoticeCount: function() {
- 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
- });
- }
- },
- // 新增方法:加载主页全部数据(包括消息通知)
- loadHomepageData: function() {
- const _this = this;
- wx.showLoading({
- title: '加载中...',
- });
-
- 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();
- if (res.data && res.data.data) {
- let apiReturnData = res.data;
-
- // 更新消息通知数据
- apiReturnData.data.swNotificationAnnouncementDos.forEach(data => {
- data.publishtime = data.publishtime.slice(0,10);
- });
-
- // 更新全局数据
- app.globalData.notices = apiReturnData.data.swNotificationAnnouncementDos;
- app.globalData.userNoticesList = apiReturnData.data.sysNotifyAnnounceUserDos;
-
- // 需要轮播的公告
- let data = apiReturnData.data.swNotificationAnnouncementDos.filter(data => {
- return data.homepageslider == '1';
- });
-
- // 更新未读消息数
- _this.getUnreadNoticeCount();
-
- // 更新页面数据
- _this.setData({
- billInfo: {
- totalAmount: apiReturnData.data.duFees ?? 0,
- waterUsage: apiReturnData.data.waterConsumption ?? 0,
- balance: apiReturnData.data.accountbalance ?? 0
- },
- userInfo: {
- name: apiReturnData.data.username,
- accountNumber: apiReturnData.data.usernumber,
- address: apiReturnData.data.address
- },
- noticeList: data,
- isScrolling: true
- });
-
- // 如果有轮播公告,重新开始轮播
- if(data && data.length > 0) {
- _this.startNoticeScroll();
- }
- }
- },
- fail(error) {
- wx.hideLoading();
- wx.showToast({
- title: '数据加载失败',
- icon: 'none',
- duration: 2000
- });
- }
- });
- }
- })
|