homepage.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. const app = getApp();
  2. Page({
  3. data: {
  4. images: {
  5. logo: '/static_file/logo.png',
  6. background: '/static_file/background.png',
  7. card: '/static_file/card.png',
  8. tzd: '/static_file/backgrountzdd.png',
  9. phone: '/static_file/phone.png',
  10. yl: '/static_file/background.yl',
  11. jcsfcjtzd: '/static_file/jcsfcjtzd.png',
  12. kapiantubiao: '/static_file/kapiantubiao.png'
  13. },
  14. // 用户信息
  15. userInfo: {
  16. name: "",
  17. accountNumber: "",
  18. address: ""
  19. },
  20. //企业地址信息
  21. enterPriseAddress:"",
  22. // 账单信息
  23. billInfo: {
  24. totalAmount: "", // 总计应缴
  25. waterUsage: "", // 用水量
  26. balance: "" // 账户余额
  27. },
  28. // 功能按钮配置
  29. functionList: [{
  30. icon: '/static_file/zdlb.png',
  31. text: '账单列表',
  32. url: '/pages/zhangdanlist/zhangdanlist'
  33. },
  34. {
  35. icon: '/static_file/jfjl.png',
  36. text: '缴费记录',
  37. url: '/pages/jiaofeiList/jiaofeiList'
  38. },
  39. // {
  40. // icon: '/static_file/yhbx.png',
  41. // text: '用户报修',
  42. // url: '/pages/baoxiudj/baoxiudj'
  43. // },
  44. {
  45. icon: '/static_file/tzgg.png',
  46. text: '消息通知',
  47. url: '/pages/tongzhiList/tongzhiList'
  48. },
  49. {
  50. icon: '/static_file/ckys.png',
  51. text: '户号绑定',
  52. url: '/pages/huhaoguanli/huhaoguanli'
  53. },
  54. // {
  55. // icon: '/static_file/yjfk.png',
  56. // text: '投诉建议',
  57. // url: '/pages/tousujianyi/tousujianyi'
  58. // },
  59. {
  60. icon: '/static_file/yjfk.png',
  61. text: '用户须知',
  62. url: '/pages/usernotice/usernotice'
  63. }
  64. ],
  65. currentIndex: 0,
  66. noticeList: [],
  67. // 活动信息
  68. activity: {
  69. title: '净水器活动',
  70. subtitle: '预留入口',
  71. imageUrl: '/static_file/background.png'
  72. },
  73. currentAccountInfo: {},
  74. unreadCount: 0
  75. },
  76. onLoad() {
  77. // 检查是否刚刚绑定了新户号
  78. const justBoundNewAccount = wx.getStorageSync('justBoundNewAccount');
  79. if (justBoundNewAccount) {
  80. // 清除标记
  81. wx.removeStorageSync('justBoundNewAccount');
  82. // 直接加载页面数据
  83. this.loadPageData();
  84. return;
  85. }
  86. // 检查是否所有户号已解绑
  87. const allAccountsUnbound = wx.getStorageSync('allAccountsUnbound');
  88. if (allAccountsUnbound) {
  89. // 清除标记
  90. wx.removeStorageSync('allAccountsUnbound');
  91. // 跳转到首次绑定页面
  92. wx.redirectTo({
  93. url: '/pages/FirstBangDing/FirstBangDing',
  94. });
  95. return;
  96. }
  97. // 检查全局用户信息是否存在
  98. if (!app.globalData.currentAccountInfo ||
  99. !app.globalData.currentAccountInfo.usernumber ||
  100. app.globalData.userWxInfo.currentDsKey === "") {
  101. wx.redirectTo({
  102. url: '/pages/FirstBangDing/FirstBangDing',
  103. });
  104. return;
  105. }
  106. let refresh = app.globalData.refresh;
  107. if (refresh == 1) {
  108. wx.showLoading({
  109. title: '加载中...',
  110. });
  111. if (!app.globalData.userWxInfo.token) {
  112. wx.hideLoading();
  113. return;
  114. }
  115. const _this = this;
  116. wx.request({
  117. url: app.globalData.interfaceUrls.homePageInfo + app.globalData.currentAccountInfo.usernumber,
  118. method: 'GET',
  119. header: {
  120. 'content-type': 'application/json', // 默认值
  121. 'token': app.globalData.userWxInfo.token,
  122. 'source': "wc",
  123. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  124. },
  125. success(res) {
  126. wx.hideLoading();
  127. let apiReturnData = res.data;
  128. // 处理轮播通知数据
  129. if (apiReturnData.data && apiReturnData.data.swNotificationAnnouncementDos) {
  130. // 处理日期格式
  131. apiReturnData.data.swNotificationAnnouncementDos.forEach(data => {
  132. if (data.publishtime) {
  133. data.publishtime = data.publishtime.slice(0, 10);
  134. }
  135. });
  136. // 所有的通知公告
  137. app.globalData.notices = apiReturnData.data.swNotificationAnnouncementDos;
  138. // 需要轮播的公告
  139. let noticeData = apiReturnData.data.swNotificationAnnouncementDos.filter(data => {
  140. return data.homepageslider == '1';
  141. });
  142. // 更新轮播通知数据
  143. _this.setData({
  144. noticeList: noticeData,
  145. isScrolling: noticeData && noticeData.length > 0
  146. });
  147. // 如果有轮播数据,立即开始轮播
  148. if (noticeData && noticeData.length > 0) {
  149. _this.startNoticeScroll();
  150. }
  151. }
  152. // 该用户所有的消息通知
  153. app.globalData.userNoticesList = apiReturnData.data.sysNotifyAnnounceUserDos;
  154. // 计算未读消息数
  155. if (app.globalData.userNoticesList) {
  156. const unreadCount = app.globalData.userNoticesList.filter(notice => notice.readstate === '2').length;
  157. _this.setData({
  158. unreadCount: unreadCount
  159. });
  160. }
  161. // 更新页面数据
  162. _this.setData({
  163. billInfo: {
  164. totalAmount: apiReturnData.data.duFees ?? 0, // 总计应缴
  165. waterUsage: apiReturnData.data.waterConsumption ?? 0, // 用水量
  166. balance: apiReturnData.data.accountbalance ?? 0 // 账户余额
  167. },
  168. userInfo: {
  169. name: apiReturnData.data.username,
  170. accountNumber: apiReturnData.data.usernumber,
  171. address: apiReturnData.data.address
  172. },
  173. enterPriseAddress:apiReturnData.data.enterPriseAddress,
  174. userNotices:apiReturnData.data.userNotice
  175. });
  176. },
  177. fail(error) {
  178. wx.hideLoading()
  179. utils.simleInfo('登录失败,请稍后再试')
  180. }
  181. })
  182. }
  183. // 加载账户和账单信息
  184. this.loadAccountInfo();
  185. },
  186. onShow() {
  187. // 检查是否刚刚绑定了新户号
  188. const justBoundNewAccount = wx.getStorageSync('justBoundNewAccount');
  189. if (justBoundNewAccount) {
  190. // 清除标记
  191. wx.removeStorageSync('justBoundNewAccount');
  192. // 直接加载页面数据
  193. this.loadPageData();
  194. return;
  195. }
  196. // 首先检查全局用户信息是否存在,如果没有则跳转到首次绑定页面
  197. if (!app.globalData.currentAccountInfo ||
  198. !app.globalData.currentAccountInfo.usernumber ||
  199. app.globalData.userWxInfo.currentDsKey === "") {
  200. wx.redirectTo({
  201. url: '/pages/FirstBangDing/FirstBangDing',
  202. });
  203. return;
  204. }
  205. // 检查是否需要刷新
  206. const needRefresh = wx.getStorageSync('needRefreshHomepage');
  207. if (needRefresh) {
  208. // 清除刷新标记
  209. wx.removeStorageSync('needRefreshHomepage');
  210. this.loadPageData();
  211. }
  212. // 检查是否从户号管理页面返回
  213. const backFromHuHao = wx.getStorageSync('backFromHuHao');
  214. if (backFromHuHao) {
  215. wx.removeStorageSync('backFromHuHao');
  216. // 从户号管理页面返回时重新加载全部数据
  217. this.loadHomepageData();
  218. } else {
  219. // 即使不是从户号管理页面返回,也更新未读消息数
  220. this.getUnreadNoticeCount();
  221. }
  222. },
  223. loadPageData: function () {
  224. const _this = this;
  225. wx.showLoading({
  226. title: '加载中...',
  227. });
  228. // 检查token和账户信息是否存在
  229. if (!app.globalData.userWxInfo.token ||
  230. !app.globalData.currentAccountInfo ||
  231. !app.globalData.currentAccountInfo.usernumber ||
  232. !app.globalData.userWxInfo.currentDsKey) {
  233. wx.hideLoading();
  234. console.error('缺少必要的账户信息');
  235. // 尝试从本地存储恢复账户信息
  236. const storedHuHao = wx.getStorageSync('currentHuHao');
  237. if (storedHuHao && storedHuHao.usernumber) {
  238. app.globalData.currentAccountInfo = storedHuHao;
  239. app.globalData.userWxInfo.currentDsKey = storedHuHao.dsKey;
  240. // 重新尝试加载
  241. setTimeout(() => {
  242. this.loadPageData();
  243. }, 100);
  244. return;
  245. }
  246. // 如果无法恢复,则跳转到首次绑定页面
  247. wx.redirectTo({
  248. url: '/pages/FirstBangDing/FirstBangDing',
  249. });
  250. return;
  251. }
  252. wx.request({
  253. url: app.globalData.interfaceUrls.homePageInfo + app.globalData.currentAccountInfo.usernumber,
  254. method: 'GET',
  255. header: {
  256. 'content-type': 'application/json',
  257. 'token': app.globalData.userWxInfo.token,
  258. 'source': "wc",
  259. '!SAAS_LOGIN_TOKEN_!': app.globalData.userWxInfo.currentDsKey
  260. },
  261. success(res) {
  262. wx.hideLoading();
  263. let apiReturnData = res.data;
  264. // 处理轮播通知数据
  265. if (apiReturnData.data && apiReturnData.data.swNotificationAnnouncementDos) {
  266. // 处理日期格式
  267. apiReturnData.data.swNotificationAnnouncementDos.forEach(data => {
  268. if (data.publishtime) {
  269. data.publishtime = data.publishtime.slice(0, 10);
  270. }
  271. });
  272. // 所有的通知公告
  273. app.globalData.notices = apiReturnData.data.swNotificationAnnouncementDos;
  274. // 需要轮播的公告
  275. let noticeData = apiReturnData.data.swNotificationAnnouncementDos.filter(data => {
  276. return data.homepageslider == '1';
  277. });
  278. // 更新轮播通知数据
  279. _this.setData({
  280. noticeList: noticeData,
  281. isScrolling: noticeData && noticeData.length > 0
  282. });
  283. // 如果有轮播数据,立即开始轮播
  284. if (noticeData && noticeData.length > 0) {
  285. _this.startNoticeScroll();
  286. }
  287. }
  288. // 该用户所有的消息通知
  289. app.globalData.userNoticesList = apiReturnData.data.sysNotifyAnnounceUserDos;
  290. // 计算未读消息数
  291. if (app.globalData.userNoticesList) {
  292. const unreadCount = app.globalData.userNoticesList.filter(notice => notice.readstate === '2').length;
  293. _this.setData({
  294. unreadCount: unreadCount
  295. });
  296. }
  297. // 更新页面数据
  298. _this.setData({
  299. billInfo: {
  300. totalAmount: apiReturnData.data.duFees ?? 0, // 总计应缴
  301. waterUsage: apiReturnData.data.waterConsumption ?? 0, // 用水量
  302. balance: apiReturnData.data.accountbalance ?? 0 // 账户余额
  303. },
  304. userInfo: {
  305. name: apiReturnData.data.username,
  306. accountNumber: apiReturnData.data.usernumber,
  307. address: apiReturnData.data.address
  308. },
  309. enterPriseAddress:apiReturnData.data.enterPriseAddress
  310. });
  311. },
  312. fail(error) {
  313. wx.hideLoading();
  314. wx.showToast({
  315. title: '数据加载失败,请稍后再试',
  316. icon: 'none',
  317. duration: 2000
  318. });
  319. }
  320. });
  321. },
  322. // 切换户号
  323. handleSwitchMeter() {
  324. wx.navigateTo({
  325. url: '/pages/huhaoguanli/huhaoguanli'
  326. })
  327. },
  328. // 充值缴费
  329. handlePayment() {
  330. wx.navigateTo({
  331. // url: '/pages/payment/payment'
  332. })
  333. },
  334. // 功能按钮点击事件
  335. handleFunctionClick(e) {
  336. const index = e.currentTarget.dataset.index
  337. const item = this.data.functionList[index]
  338. if (item && item.url) {
  339. if (item.url === '/pages/usernotice/usernotice') {
  340. // 如果是跳转到用户须知页面,将用户须知信息存储到全局数据中
  341. app.globalData.currentAccountInfo = {
  342. ...app.globalData.currentAccountInfo,
  343. userNotices: this.data.userNotices
  344. };
  345. }
  346. wx.navigateTo({
  347. url: item.url,
  348. fail: function (err) {
  349. console.error('页面跳转失败:', err)
  350. wx.showToast({
  351. title: '功能开发中',
  352. icon: 'none',
  353. duration: 2000
  354. })
  355. }
  356. })
  357. } else {
  358. wx.showToast({
  359. title: '功能开发中',
  360. icon: 'none',
  361. duration: 2000
  362. })
  363. }
  364. },
  365. // 查看账单列表
  366. handleViewBill() {
  367. wx.navigateTo({
  368. // url: '/pages/billList/billList'
  369. })
  370. },
  371. // 查看更多活动
  372. handleMoreActivity() {
  373. wx.navigateTo({
  374. // url: '/pages/activityList/activityList'
  375. })
  376. },
  377. // 添加或修改立即缴费按钮点击事件
  378. goToPayment: function (e) {
  379. wx.navigateTo({
  380. url: `/pages/lijijiaofei/lijijiaofei`
  381. });
  382. },
  383. // 跳转到通知公告列表页面
  384. goToNoticeList: function () {
  385. wx.navigateTo({
  386. url: '/pages/tongzhiList/tongzhiList'
  387. })
  388. },
  389. // 跳转到通知详情页面
  390. goToNoticeDetail: function () {
  391. const currentNotice = this.data.noticeList[this.data.currentIndex];
  392. wx.navigateTo({
  393. url: `/pages/tzxq/tzxq?id=${currentNotice.id}`
  394. });
  395. },
  396. onReady: function () {
  397. this.startNoticeScroll();
  398. },
  399. startNoticeScroll: function () {
  400. // 检查是否有通知数据
  401. if (!this.data.noticeList || this.data.noticeList.length === 0) {
  402. console.log('无轮播通知数据');
  403. return;
  404. }
  405. // 过滤需要轮播的公告
  406. let data = this.data.noticeList.filter(data => {
  407. return data.homepageslider == '1';
  408. });
  409. // 如果没有需要轮播的公告,直接返回
  410. if (!data || data.length === 0) {
  411. console.log('没有需要轮播的公告');
  412. return;
  413. }
  414. // 确保currentIndex在有效范围内
  415. const safeIndex = this.data.currentIndex < data.length ? this.data.currentIndex : 0;
  416. // 获取当前公告内容和标题
  417. const content = data[safeIndex].scrollingcontent || '';
  418. const title = data[safeIndex].noticetitle || '';
  419. // 计算滚动时长,基于内容长度
  420. const duration = Math.max(3, (title.length + content.length) * 0.5);
  421. // 更新数据
  422. this.setData({
  423. currentIndex: safeIndex,
  424. scrollDuration: duration,
  425. isScrolling: true,
  426. });
  427. },
  428. onScrollComplete: function () {
  429. this.setData({
  430. isScrolling: false
  431. });
  432. // 等待2秒后切换到下一条
  433. setTimeout(() => {
  434. const nextIndex = (this.data.currentIndex + 1) % this.data.noticeList.length;
  435. this.setData({
  436. currentIndex: nextIndex
  437. }, () => {
  438. this.startNoticeScroll();
  439. });
  440. }, 1000);
  441. },
  442. // 加载账户和账单信息
  443. loadAccountInfo: function () {
  444. const accountInfo = app.globalData.currentAccountInfo || {};
  445. // 检查账户信息是否为空(解绑后返回的情况)
  446. if (!accountInfo || !accountInfo.usernumber) {
  447. // 检查是否已全部解绑
  448. const allAccountsUnbound = wx.getStorageSync('allAccountsUnbound');
  449. if (allAccountsUnbound) {
  450. // 清除标记
  451. wx.removeStorageSync('allAccountsUnbound');
  452. // 跳转到首次绑定页面
  453. wx.redirectTo({
  454. url: '/pages/FirstBangDing/FirstBangDing',
  455. });
  456. return;
  457. }
  458. // 尝试请求账户列表,查看是否有其他账户
  459. this.checkAndFetchAccounts();
  460. return;
  461. }
  462. // 检查是否是首次加载
  463. const isFirstLoad = wx.getStorageSync('isFirstLoad') !== 'false';
  464. // 检查是否在户号管理页面切换过账户
  465. const hasUserSwitchedAccount = wx.getStorageSync('hasUserSwitchedAccount') === true;
  466. if (isFirstLoad && !hasUserSwitchedAccount) {
  467. // 首次加载且未切换过账户,查找并设置默认账户
  468. this.loadDefaultAccount();
  469. // 设置标记,表示已不是首次加载
  470. wx.setStorageSync('isFirstLoad', 'false');
  471. } else {
  472. if (!isFirstLoad && hasUserSwitchedAccount) {
  473. // 未切换过账户,查找并设置默认账户
  474. this.loadDefaultAccount();
  475. } else {
  476. // 非首次加载或已在户号管理中切换过账户,直接使用当前账户
  477. this.setData({
  478. currentAccountInfo: accountInfo
  479. });
  480. // 如果是从户号管理页面切换了账户,需要清除该标记
  481. if (hasUserSwitchedAccount) {
  482. wx.removeStorageSync('hasUserSwitchedAccount');
  483. }
  484. }
  485. }
  486. },
  487. // 检查并获取账户列表
  488. checkAndFetchAccounts: function() {
  489. if (!app.globalData.userWxInfo.token) {
  490. // 没有token,直接跳转到首次绑定页面
  491. wx.redirectTo({
  492. url: '/pages/FirstBangDing/FirstBangDing',
  493. });
  494. return;
  495. }
  496. const _this = this;
  497. wx.showLoading({
  498. title: '加载中...',
  499. });
  500. wx.request({
  501. url: app.globalData.interfaceUrls.accountList,
  502. method: 'GET',
  503. header: {
  504. 'content-type': 'application/json',
  505. 'token': app.globalData.userWxInfo.token,
  506. 'source': "wc"
  507. },
  508. success(res) {
  509. wx.hideLoading();
  510. if (res.data && res.data.data && res.data.data.length > 0) {
  511. // 找到了账户,设置默认账户
  512. const defaultAccount = res.data.data.find(account => account.defaultAccount === "0") || res.data.data[0];
  513. // 更新全局账户信息
  514. app.globalData.currentAccountInfo = defaultAccount;
  515. app.globalData.userWxInfo.currentDsKey = defaultAccount.dsKey;
  516. app.globalData.userWxInfo.username = defaultAccount.username;
  517. app.globalData.userWxInfo.usernumber = defaultAccount.usernumber;
  518. app.globalData.userWxInfo.address = defaultAccount.address;
  519. app.globalData.userWxInfo.groupName = defaultAccount.groupName;
  520. // 保存到本地存储
  521. wx.setStorageSync('currentHuHao', defaultAccount);
  522. // 更新页面数据并加载详细信息
  523. _this.setData({
  524. currentAccountInfo: defaultAccount
  525. });
  526. _this.loadPageData();
  527. } else {
  528. // 没有找到任何账户,跳转到首次绑定页面
  529. wx.redirectTo({
  530. url: '/pages/FirstBangDing/FirstBangDing',
  531. });
  532. }
  533. },
  534. fail(error) {
  535. wx.hideLoading();
  536. // 请求失败,跳转到首次绑定页面
  537. wx.redirectTo({
  538. url: '/pages/FirstBangDing/FirstBangDing',
  539. });
  540. }
  541. });
  542. },
  543. // 加载默认账户
  544. loadDefaultAccount: function () {
  545. if (!app.globalData.userWxInfo.token) {
  546. return;
  547. }
  548. const _this = this;
  549. wx.showLoading({
  550. title: '加载中...',
  551. });
  552. wx.request({
  553. url: app.globalData.interfaceUrls.accountList,
  554. method: 'GET',
  555. header: {
  556. 'content-type': 'application/json',
  557. 'token': app.globalData.userWxInfo.token,
  558. 'source': "wc"
  559. },
  560. success(res) {
  561. wx.hideLoading();
  562. if (res.data && res.data.data) {
  563. // 查找 defaultAccount 为 0 的账户
  564. const defaultAccount = res.data.data.find(account => account.defaultAccount === "0");
  565. debugger
  566. if (defaultAccount) {
  567. // 设置为当前账户
  568. app.globalData.currentAccountInfo = defaultAccount;
  569. _this.setData({
  570. currentAccountInfo: defaultAccount
  571. });
  572. // 加载该默认账户的详细信息
  573. _this.loadPageData();
  574. } else {
  575. // 没有找到默认账户,使用当前账户
  576. _this.setData({
  577. currentAccountInfo: app.globalData.currentAccountInfo || {}
  578. });
  579. }
  580. }
  581. },
  582. fail(error) {
  583. wx.hideLoading();
  584. wx.showToast({
  585. title: '加载默认账户失败',
  586. icon: 'none',
  587. duration: 2000
  588. });
  589. // 使用当前账户作为备选
  590. _this.setData({
  591. currentAccountInfo: app.globalData.currentAccountInfo || {}
  592. });
  593. }
  594. });
  595. },
  596. onPullDownRefresh: function () {
  597. // 刷新数据
  598. this.refreshData();
  599. },
  600. // 修改刷新数据的函数
  601. refreshData: function () {
  602. console.log('正在刷新数据...');
  603. this.loadPageData();
  604. // 刷新完成后停止下拉刷新动画
  605. wx.stopPullDownRefresh({
  606. success: (res) => {
  607. wx.showToast({
  608. title: '刷新成功',
  609. icon: 'success',
  610. duration: 1000
  611. });
  612. }
  613. });
  614. },
  615. // 获取未读消息数量的方法
  616. getUnreadNoticeCount: function () {
  617. const _this = this;
  618. // 从服务器获取最新的消息通知数据
  619. if (app.globalData.userWxInfo.token && app.globalData.currentAccountInfo) {
  620. wx.request({
  621. url: app.globalData.interfaceUrls.homePageInfo + app.globalData.currentAccountInfo.usernumber,
  622. method: 'GET',
  623. header: {
  624. 'content-type': 'application/json',
  625. 'token': app.globalData.userWxInfo.token,
  626. 'source': "wc",
  627. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  628. },
  629. success(res) {
  630. if (res.data && res.data.data) {
  631. // 更新全局的用户通知列表
  632. app.globalData.userNoticesList = res.data.data.sysNotifyAnnounceUserDos;
  633. // 计算未读消息数量
  634. const unreadCount = app.globalData.userNoticesList.filter(notice => notice.readstate === '2').length;
  635. _this.setData({
  636. unreadCount: unreadCount,
  637. enterPriseAddress:apiReturnData.data.enterPriseAddress
  638. });
  639. }
  640. }
  641. });
  642. } else {
  643. this.setData({
  644. unreadCount: 0
  645. });
  646. }
  647. },
  648. // 新增方法:加载主页全部数据(包括消息通知)
  649. loadHomepageData: function () {
  650. const _this = this;
  651. wx.showLoading({
  652. title: '加载中...',
  653. });
  654. if (!app.globalData.userWxInfo.token) {
  655. wx.hideLoading();
  656. return;
  657. }
  658. wx.request({
  659. url: app.globalData.interfaceUrls.homePageInfo + app.globalData.currentAccountInfo.usernumber,
  660. method: 'GET',
  661. header: {
  662. 'content-type': 'application/json',
  663. 'token': app.globalData.userWxInfo.token,
  664. 'source': "wc",
  665. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  666. },
  667. success(res) {
  668. wx.hideLoading();
  669. if (res.data && res.data.data) {
  670. let apiReturnData = res.data;
  671. // 更新消息通知数据
  672. apiReturnData.data.swNotificationAnnouncementDos.forEach(data => {
  673. data.publishtime = data.publishtime.slice(0, 10);
  674. });
  675. // 更新全局数据
  676. app.globalData.notices = apiReturnData.data.swNotificationAnnouncementDos;
  677. app.globalData.userNoticesList = apiReturnData.data.sysNotifyAnnounceUserDos;
  678. // 需要轮播的公告
  679. let data = apiReturnData.data.swNotificationAnnouncementDos.filter(data => {
  680. return data.homepageslider == '1';
  681. });
  682. // 更新未读消息数
  683. _this.getUnreadNoticeCount();
  684. // 更新页面数据
  685. _this.setData({
  686. billInfo: {
  687. totalAmount: apiReturnData.data.duFees ?? 0,
  688. waterUsage: apiReturnData.data.waterConsumption ?? 0,
  689. balance: apiReturnData.data.accountbalance ?? 0
  690. },
  691. userInfo: {
  692. name: apiReturnData.data.username,
  693. accountNumber: apiReturnData.data.usernumber,
  694. address: apiReturnData.data.address
  695. },
  696. enterPriseAddress:apiReturnData.data.enterPriseAddress,
  697. noticeList: data,
  698. isScrolling: true
  699. });
  700. // 如果有轮播公告,重新开始轮播
  701. if (data && data.length > 0) {
  702. _this.startNoticeScroll();
  703. }
  704. }
  705. },
  706. fail(error) {
  707. wx.hideLoading();
  708. wx.showToast({
  709. title: '数据加载失败',
  710. icon: 'none',
  711. duration: 2000
  712. });
  713. }
  714. });
  715. },
  716. // 显示地址弹窗并提供复制功能
  717. showAddressPopup(e) {
  718. const address = e.currentTarget.dataset.address;
  719. if (!address) return;
  720. wx.showModal({
  721. title: '地址信息',
  722. content: address,
  723. showCancel: false,
  724. confirmText: '确定'
  725. });
  726. }
  727. })