homepage.js 23 KB

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