homepage.js 23 KB

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