homepage.js 7.2 KB

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