homepage.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. const needRefresh = wx.getStorageSync('needRefreshHomepage');
  120. if (needRefresh) {
  121. // 清除刷新标记
  122. wx.removeStorageSync('needRefreshHomepage');
  123. this.loadPageData();
  124. }
  125. },
  126. loadPageData: function() {
  127. const _this = this;
  128. wx.showLoading({
  129. title: '加载中...',
  130. });
  131. // 检查token是否存在
  132. if(!app.globalData.userWxInfo.token){
  133. wx.hideLoading();
  134. return;
  135. }
  136. wx.request({
  137. url: app.globalData.interfaceUrls.homePageInfo + app.globalData.currentAccountInfo.usernumber,
  138. method: 'GET',
  139. header: {
  140. 'content-type': 'application/json',
  141. 'token': app.globalData.userWxInfo.token,
  142. 'source': "wc",
  143. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  144. },
  145. success(res) {
  146. wx.hideLoading();
  147. let apiReturnData = res.data;
  148. // 更新页面数据
  149. _this.setData({
  150. billInfo: {
  151. totalAmount: apiReturnData.data.duFees, // 总计应缴
  152. waterUsage: apiReturnData.data.waterConsumption, // 用水量
  153. balance: apiReturnData.data.accountbalance // 账户余额
  154. },
  155. userInfo: {
  156. name: apiReturnData.data.username,
  157. accountNumber: apiReturnData.data.usernumber,
  158. address: apiReturnData.data.address
  159. },
  160. });
  161. },
  162. fail(error) {
  163. wx.hideLoading();
  164. wx.showToast({
  165. title: '数据加载失败,请稍后再试',
  166. icon: 'none',
  167. duration: 2000
  168. });
  169. }
  170. });
  171. },
  172. // 切换户号
  173. handleSwitchMeter() {
  174. wx.navigateTo({
  175. url: '/pages/huhaoguanli/huhaoguanli'
  176. })
  177. },
  178. // 充值缴费
  179. handlePayment() {
  180. wx.navigateTo({
  181. // url: '/pages/payment/payment'
  182. })
  183. },
  184. // 功能按钮点击事件
  185. handleFunctionClick(e) {
  186. const index = e.currentTarget.dataset.index
  187. const item = this.data.functionList[index]
  188. if (item && item.url) {
  189. wx.navigateTo({
  190. url: item.url,
  191. fail: function(err) {
  192. console.error('页面跳转失败:', err)
  193. wx.showToast({
  194. title: '功能开发中',
  195. icon: 'none',
  196. duration: 2000
  197. })
  198. }
  199. })
  200. } else {
  201. wx.showToast({
  202. title: '功能开发中',
  203. icon: 'none',
  204. duration: 2000
  205. })
  206. }
  207. },
  208. // 查看账单列表
  209. handleViewBill() {
  210. wx.navigateTo({
  211. // url: '/pages/billList/billList'
  212. })
  213. },
  214. // 查看更多活动
  215. handleMoreActivity() {
  216. wx.navigateTo({
  217. // url: '/pages/activityList/activityList'
  218. })
  219. },
  220. // 跳转到立即缴费页面
  221. goToPayment: function() {
  222. wx.navigateTo({
  223. url: '/pages/lijijiaofei/lijijiaofei',
  224. })
  225. },
  226. // 跳转到通知公告列表页面
  227. goToNoticeList: function() {
  228. wx.navigateTo({
  229. url: '/pages/tongzhiList/tongzhiList'
  230. })
  231. },
  232. // 跳转到通知详情页面
  233. goToNoticeDetail: function() {
  234. const currentNotice = this.data.noticeList[this.data.currentIndex];
  235. // 将整个通知对象序列化并编码
  236. const noticeData = encodeURIComponent(JSON.stringify({
  237. id: currentNotice.id,
  238. title: currentNotice.title,
  239. content: currentNotice.content,
  240. date: currentNotice.date,
  241. type: currentNotice.type,
  242. source: currentNotice.source
  243. }));
  244. wx.navigateTo({
  245. url: `/pages/tzxq/tzxq?noticeData=${noticeData}`
  246. });
  247. },
  248. onReady: function() {
  249. this.startNoticeScroll();
  250. },
  251. startNoticeScroll: function() {
  252. if(this.data.noticeList.length==0){
  253. return;
  254. }
  255. let data= (this.data.noticeList||[]).filter(data=>{
  256. return data.homepageslider=='1';
  257. });
  258. const content = data[this.data.currentIndex].scrollingcontent;
  259. const title = data[this.data.currentIndex].noticetitle;
  260. const duration = (title.length + content.length) * 0.3;
  261. this.setData({
  262. scrollDuration: duration,
  263. isScrolling: true,
  264. });
  265. },
  266. onScrollComplete: function() {
  267. debugger;
  268. this.setData({
  269. isScrolling: false
  270. });
  271. // 等待1秒后切换到下一条
  272. setTimeout(() => {
  273. const nextIndex = (this.data.currentIndex + 1) % this.data.noticeList.length;
  274. this.setData({
  275. currentIndex: nextIndex
  276. }, () => {
  277. this.startNoticeScroll();
  278. });
  279. }, 500);
  280. }
  281. })