homepage.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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: 0, // 总计应缴
  23. waterUsage: 0, // 用水量
  24. balance: 0 // 账户余额
  25. },
  26. // 功能按钮配置
  27. functionList: [
  28. {
  29. icon: '/static_file/zdlb.png',
  30. text: '账单列表',
  31. url: '/pages/zhangdanlist/zhangdanlist'
  32. },
  33. {
  34. icon: '/static_file/jfjl.png',
  35. text: '缴费记录',
  36. // url: '/pages/feedback/feedback'
  37. },
  38. {
  39. icon: '/static_file/yhbx.png',
  40. text: '用户报修',
  41. url: '/pages/baoxiudj/baoxiudj'
  42. },
  43. {
  44. icon: '/static_file/tzgg.png',
  45. text: '通知公告',
  46. url: '/pages/tongzhiList/tongzhiList'
  47. },
  48. {
  49. icon: '/static_file/ckys.png',
  50. text: '户号绑定',
  51. url: '/pages/huhaoguanli/huhaoguanli'
  52. },
  53. {
  54. icon: '/static_file/yjfk.png',
  55. text: '投诉建议',
  56. url: '/pages/tousujianyi/tousujianyi'
  57. }
  58. ],
  59. currentIndex:0,
  60. noticeList:[],
  61. // 活动信息
  62. activity: {
  63. title: '净水器活动',
  64. subtitle: '预留入口',
  65. imageUrl: '/static_file/background.png'
  66. }
  67. },
  68. onLoad() {
  69. let refresh= app.globalData.refresh;
  70. if(refresh==1){
  71. wx.showLoading({
  72. title: '加载中...',
  73. });
  74. if(!app.globalData.userWxInfo.token){
  75. wx.hideLoading();
  76. return;
  77. }
  78. const _this = this;
  79. wx.request({
  80. url: app.globalData.interfaceUrls.homePageInfo+app.globalData.currentAccountInfo.usernumber,
  81. method: 'GET',
  82. header: {
  83. 'content-type': 'application/json', // 默认值
  84. 'token':app.globalData.userWxInfo.token,
  85. 'source':"wc",
  86. '!SAAS_LOGIN_TOKEN_!':app.globalData.currentAccountInfo.dsKey
  87. },
  88. success (res) {
  89. wx.hideLoading();
  90. let apiReturnData=res.data;
  91. apiReturnData.data.swNotificationAnnouncementDos.forEach(data=>{
  92. data.publishtime=data.publishtime.slice(0,10);
  93. })
  94. // 所有的通知公告
  95. app.globalData.notices= apiReturnData.data.swNotificationAnnouncementDos;
  96. // 需要轮播的公告
  97. let data= apiReturnData.data.swNotificationAnnouncementDos.filter(data=>{
  98. return data.homepageslider=='1';
  99. });
  100. _this.setData({
  101. billInfo:{
  102. totalAmount:apiReturnData.data.duFees, // 总计应缴
  103. waterUsage:apiReturnData.data.waterConsumption, // 用水量
  104. balance: apiReturnData.data.accountbalance // 账户余额
  105. },
  106. userInfo:{
  107. name: apiReturnData.data.username,
  108. accountNumber: apiReturnData.data.usernumber,
  109. address: apiReturnData.data.address
  110. },
  111. noticeList :data,
  112. isScrolling: true,
  113. })
  114. },
  115. fail(error) {
  116. wx.hideLoading()
  117. utils.simleInfo('登录失败,请稍后再试')
  118. }
  119. })
  120. }
  121. },
  122. onShow() {
  123. // 检查是否需要刷新
  124. const needRefresh = wx.getStorageSync('needRefreshHomepage');
  125. if (needRefresh) {
  126. // 清除刷新标记
  127. wx.removeStorageSync('needRefreshHomepage');
  128. this.loadPageData();
  129. }
  130. },
  131. loadPageData: function() {
  132. const _this = this;
  133. wx.showLoading({
  134. title: '加载中...',
  135. });
  136. // 检查token是否存在
  137. if(!app.globalData.userWxInfo.token){
  138. wx.hideLoading();
  139. return;
  140. }
  141. wx.request({
  142. url: app.globalData.interfaceUrls.homePageInfo + app.globalData.currentAccountInfo.usernumber,
  143. method: 'GET',
  144. header: {
  145. 'content-type': 'application/json',
  146. 'token': app.globalData.userWxInfo.token,
  147. 'source': "wc",
  148. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  149. },
  150. success(res) {
  151. wx.hideLoading();
  152. let apiReturnData = res.data;
  153. // 更新页面数据
  154. _this.setData({
  155. billInfo: {
  156. totalAmount: apiReturnData.data.duFees, // 总计应缴
  157. waterUsage: apiReturnData.data.waterConsumption, // 用水量
  158. balance: apiReturnData.data.accountbalance // 账户余额
  159. },
  160. userInfo: {
  161. name: apiReturnData.data.username,
  162. accountNumber: apiReturnData.data.usernumber,
  163. address: apiReturnData.data.address
  164. },
  165. });
  166. },
  167. fail(error) {
  168. wx.hideLoading();
  169. wx.showToast({
  170. title: '数据加载失败,请稍后再试',
  171. icon: 'none',
  172. duration: 2000
  173. });
  174. }
  175. });
  176. },
  177. // 切换户号
  178. handleSwitchMeter() {
  179. wx.navigateTo({
  180. url: '/pages/huhaoguanli/huhaoguanli'
  181. })
  182. },
  183. // 充值缴费
  184. handlePayment() {
  185. wx.navigateTo({
  186. // url: '/pages/payment/payment'
  187. })
  188. },
  189. // 功能按钮点击事件
  190. handleFunctionClick(e) {
  191. const index = e.currentTarget.dataset.index
  192. const item = this.data.functionList[index]
  193. if (item && item.url) {
  194. wx.navigateTo({
  195. url: item.url,
  196. fail: function(err) {
  197. console.error('页面跳转失败:', err)
  198. wx.showToast({
  199. title: '功能开发中',
  200. icon: 'none',
  201. duration: 2000
  202. })
  203. }
  204. })
  205. } else {
  206. wx.showToast({
  207. title: '功能开发中',
  208. icon: 'none',
  209. duration: 2000
  210. })
  211. }
  212. },
  213. // 查看账单列表
  214. handleViewBill() {
  215. wx.navigateTo({
  216. // url: '/pages/billList/billList'
  217. })
  218. },
  219. // 查看更多活动
  220. handleMoreActivity() {
  221. wx.navigateTo({
  222. // url: '/pages/activityList/activityList'
  223. })
  224. },
  225. // 跳转到立即缴费页面
  226. goToPayment: function() {
  227. wx.navigateTo({
  228. url: '/pages/lijijiaofei/lijijiaofei',
  229. })
  230. },
  231. // 跳转到通知公告列表页面
  232. goToNoticeList: function() {
  233. wx.navigateTo({
  234. url: '/pages/tongzhiList/tongzhiList'
  235. })
  236. },
  237. // 跳转到通知详情页面
  238. goToNoticeDetail: function() {
  239. const currentNotice = this.data.noticeList[this.data.currentIndex];
  240. // 将整个通知对象序列化并编码
  241. const noticeData = encodeURIComponent(JSON.stringify({
  242. id: currentNotice.id,
  243. title: currentNotice.title,
  244. content: currentNotice.content,
  245. date: currentNotice.date,
  246. type: currentNotice.type,
  247. source: currentNotice.source
  248. }));
  249. wx.navigateTo({
  250. url: `/pages/tzxq/tzxq?noticeData=${noticeData}`
  251. });
  252. },
  253. onReady: function() {
  254. this.startNoticeScroll();
  255. },
  256. startNoticeScroll: function() {
  257. if(this.data.noticeList.length==0){
  258. return;
  259. }
  260. let data= (this.data.noticeList||[]).filter(data=>{
  261. return data.homepageslider=='1';
  262. });
  263. const content = data[this.data.currentIndex].scrollingcontent;
  264. const title = data[this.data.currentIndex].noticetitle;
  265. const duration = (title.length + content.length) * 0.3;
  266. this.setData({
  267. scrollDuration: duration,
  268. isScrolling: true,
  269. });
  270. },
  271. onScrollComplete: function() {
  272. debugger;
  273. this.setData({
  274. isScrolling: false
  275. });
  276. // 等待1秒后切换到下一条
  277. setTimeout(() => {
  278. const nextIndex = (this.data.currentIndex + 1) % this.data.noticeList.length;
  279. this.setData({
  280. currentIndex: nextIndex
  281. }, () => {
  282. this.startNoticeScroll();
  283. });
  284. }, 500);
  285. }
  286. })