FirstBangDing.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/FirstBangDing/FirstBangDing.js
  2. const app = getApp()
  3. const utils = require('../../utils/util.js')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. maxBindCount: 5,
  10. notices: [
  11. '部分小区水费由物业代收,请联系小区物业进行咨询缴费操作。',
  12. '户号绑定: 在绑定页面手动查询,输入地址关键词信息。',
  13. '每个微信用户最多绑定5个户号。'
  14. ],
  15. images: {
  16. logo: '',
  17. background: '',
  18. card: '',
  19. tzd: "",
  20. phone: "",
  21. yl: "",
  22. jcsfcjtzd: ""
  23. }
  24. },
  25. onLoad(options) {
  26. // 页面加载时获取图片路径
  27. this.setData({
  28. images: {
  29. logo: app.globalData.images.logo,
  30. background: app.globalData.images.background,
  31. card: app.globalData.images.card,
  32. tzd: app.globalData.images.tzd,
  33. phone: app.globalData.images.phone,
  34. yl: app.globalData.images.yl,
  35. jcsfcjtzd: app.globalData.images.jcsfcjtzd
  36. }
  37. })
  38. },
  39. /**
  40. * 生命周期函数--监听页面初次渲染完成
  41. */
  42. onReady() {
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow() {
  48. const _this = this;
  49. // 重新获取用户信息
  50. wx.login({
  51. success: res => {
  52. if(res.code){
  53. wx.request({
  54. method: 'POST',
  55. url: app.globalData.interfaceUrls.loginUrl,
  56. data: {
  57. wxCode: res.code,
  58. dsKey: app.globalData.launchPara
  59. },
  60. success(res) {
  61. if (res.data.code == "200" && res.data.data) {
  62. const resData = res.data.data;
  63. // 更新全局用户信息
  64. app.globalData.userWxInfo = {
  65. openid: resData.openid,
  66. session_key: resData.session_key,
  67. token: resData.token,
  68. bindAccountInfo: resData.swUserManagementVos,
  69. currentDsKey: ""
  70. }
  71. // 检查是否有绑定的户号
  72. if(resData.swUserManagementVos && resData.swUserManagementVos.length > 0){
  73. app.globalData.currentAccountInfo = resData.swUserManagementVos[0];
  74. app.globalData.userWxInfo.currentDsKey = resData.swUserManagementVos[0].dsKey;
  75. // 保存到本地存储
  76. wx.setStorageSync('currentHuHao', resData.swUserManagementVos[0]);
  77. // 设置刷新标记
  78. app.globalData.refresh = 1;
  79. // 跳转到首页
  80. wx.switchTab({
  81. url: '/pages/homepage/homepage',
  82. success: function() {
  83. // 确保首页重新加载数据
  84. const pages = getCurrentPages();
  85. const homepage = pages[pages.length - 1];
  86. if (homepage && homepage.onLoad) {
  87. homepage.onLoad();
  88. }
  89. }
  90. });
  91. }
  92. }
  93. }
  94. });
  95. }
  96. }
  97. });
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide() {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload() {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh() {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom() {
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage() {
  123. },
  124. bindAccount() {
  125. wx.navigateTo({
  126. url: '/pages/bind/bind'
  127. })
  128. },
  129. switchTab(e) {
  130. const page = e.currentTarget.dataset.page
  131. if (page === 'profile') {
  132. wx.switchTab({
  133. url: '/pages/profile/profile'
  134. })
  135. }
  136. },
  137. goToBindHuhao() {
  138. // 设置标记表示将要进行户号绑定
  139. wx.setStorageSync('goingToBindNewAccount', true);
  140. // 预先设置refresh标记,这样homepage在加载时就会刷新数据
  141. app.globalData.refresh = 1;
  142. // 提前将justBoundNewAccount标记设为true
  143. // 这样即使从huhaobangding直接跳转到homepage也能正确加载数据
  144. wx.setStorageSync('justBoundNewAccount', true);
  145. // 跳转到户号绑定页面
  146. wx.navigateTo({
  147. url: '/pages/huhaobangding/huhaobangding',
  148. fail: function(err) {
  149. console.error('跳转失败:', err);
  150. // 如果跳转失败,清除标记
  151. wx.removeStorageSync('goingToBindNewAccount');
  152. wx.removeStorageSync('justBoundNewAccount');
  153. utils.simleInfo('跳转失败,请稍后再试');
  154. }
  155. });
  156. }
  157. })