homepage.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. app.globalData.notices= apiReturnData.data.swNotificationAnnouncementDos;
  92. let data= apiReturnData.data.swNotificationAnnouncementDos.filter(data=>{
  93. return data.homepageslider=='1';
  94. });
  95. _this.setData({
  96. billInfo:{
  97. totalAmount:apiReturnData.data.duFees, // 总计应缴
  98. waterUsage:apiReturnData.data.waterConsumption, // 用水量
  99. balance: apiReturnData.data.accountbalance // 账户余额
  100. },
  101. userInfo:{
  102. name: apiReturnData.data.username,
  103. accountNumber: apiReturnData.data.usernumber,
  104. address: apiReturnData.data.address
  105. },
  106. noticeList :data,
  107. isScrolling: true,
  108. })
  109. },
  110. fail(error) {
  111. wx.hideLoading()
  112. utils.simleInfo('登录失败,请稍后再试')
  113. }
  114. })
  115. }
  116. },
  117. onShow() {
  118. },
  119. // 切换水表
  120. handleSwitchMeter() {
  121. wx.navigateTo({
  122. url: '/pages/huhaoguanli/huhaoguanli'
  123. })
  124. },
  125. // 充值缴费
  126. handlePayment() {
  127. wx.navigateTo({
  128. // url: '/pages/payment/payment'
  129. })
  130. },
  131. // 功能按钮点击事件
  132. handleFunctionClick(e) {
  133. const index = e.currentTarget.dataset.index
  134. const item = this.data.functionList[index]
  135. if (item && item.url) {
  136. wx.navigateTo({
  137. url: item.url,
  138. fail: function(err) {
  139. console.error('页面跳转失败:', err)
  140. wx.showToast({
  141. title: '功能开发中',
  142. icon: 'none',
  143. duration: 2000
  144. })
  145. }
  146. })
  147. } else {
  148. wx.showToast({
  149. title: '功能开发中',
  150. icon: 'none',
  151. duration: 2000
  152. })
  153. }
  154. },
  155. // 查看账单列表
  156. handleViewBill() {
  157. wx.navigateTo({
  158. // url: '/pages/billList/billList'
  159. })
  160. },
  161. // 查看更多活动
  162. handleMoreActivity() {
  163. wx.navigateTo({
  164. // url: '/pages/activityList/activityList'
  165. })
  166. },
  167. // 跳转到立即缴费页面
  168. goToPayment: function() {
  169. wx.navigateTo({
  170. url: '/pages/lijijiaofei/lijijiaofei',
  171. })
  172. },
  173. // 跳转到通知公告列表页面
  174. goToNoticeList: function() {
  175. wx.navigateTo({
  176. url: '/pages/tongzhiList/tongzhiList'
  177. })
  178. },
  179. // 跳转到通知详情页面
  180. goToNoticeDetail: function() {
  181. const currentNotice = this.data.noticeList[this.data.currentIndex];
  182. // 将整个通知对象序列化并编码
  183. const noticeData = encodeURIComponent(JSON.stringify({
  184. id: currentNotice.id,
  185. title: currentNotice.title,
  186. content: currentNotice.content,
  187. date: currentNotice.date,
  188. type: currentNotice.type,
  189. source: currentNotice.source
  190. }));
  191. wx.navigateTo({
  192. url: `/pages/tzxq/tzxq?noticeData=${noticeData}`
  193. });
  194. },
  195. onReady: function() {
  196. this.startNoticeScroll();
  197. },
  198. startNoticeScroll: function() {
  199. if(this.data.noticeList.length==0){
  200. return;
  201. }
  202. let data= (this.data.noticeList||[]).filter(data=>{
  203. return data.homepageslider=='1';
  204. });
  205. const content = data[this.data.currentIndex].scrollingcontent;
  206. const title = data[this.data.currentIndex].noticetitle;
  207. const duration = (title.length + content.length) * 0.3;
  208. this.setData({
  209. scrollDuration: duration,
  210. isScrolling: true,
  211. });
  212. },
  213. onScrollComplete: function() {
  214. debugger;
  215. this.setData({
  216. isScrolling: false
  217. });
  218. // 等待1秒后切换到下一条
  219. setTimeout(() => {
  220. const nextIndex = (this.data.currentIndex + 1) % this.data.noticeList.length;
  221. this.setData({
  222. currentIndex: nextIndex
  223. }, () => {
  224. this.startNoticeScroll();
  225. });
  226. }, 500);
  227. }
  228. })