index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. userInfo: {},
  7. waterInfo: {},
  8. onQuery: true,
  9. items: [{
  10. id: 'realtimewater',
  11. label: '用水量',
  12. icon: '/static/img/icon-water.png',
  13. url: '?period=7'
  14. }, {
  15. id: 'waterprice',
  16. label: '水价查询',
  17. icon: '/static/img/icon_water_price.png'
  18. }, {
  19. id: 'payment',
  20. label: '缴费',
  21. icon: '/static/img/icon-payment.png'
  22. }, {
  23. id: 'wateranalysis',
  24. label: '用水趋势',
  25. icon: '/static/img/icon_water_analysis.png'
  26. }, {
  27. id: 'waterabnormal',
  28. label: '异常预警',
  29. icon: '/static/img/icon_water_abnormal.png'
  30. }, {
  31. id: 'customermanage',
  32. label: '户号管理',
  33. icon: '/static/img/icon_customer_manage.png'
  34. }
  35. ]
  36. },
  37. getPhoneNumber(e) {
  38. if (e.detail.encryptedData) {
  39. const {
  40. iv,
  41. encryptedData
  42. } = e.detail;
  43. const {
  44. param,
  45. item = {}
  46. } = e.currentTarget.dataset;
  47. wx.login({
  48. success: res => {
  49. const {
  50. code
  51. } = res;
  52. app.$http.postForm('/user/bindingMobile', {
  53. code,
  54. encryptedData,
  55. iv
  56. }).then(({
  57. status,
  58. data = {}
  59. }) => {
  60. if (status === 0) {
  61. if (this.data.userInfo.deviceId) {
  62. wx.navigateTo({
  63. url: `/pages/${item.id || param}/${item.id || param}${item.url ? item.url : ''}`
  64. })
  65. } else {
  66. wx.navigateTo({
  67. url: "/pages/customermanage/customermanage"
  68. })
  69. }
  70. }
  71. })
  72. }
  73. })
  74. }
  75. },
  76. gotopage(e) {
  77. const {
  78. param,
  79. item = {}
  80. } = e.currentTarget.dataset;
  81. if (!this.data.userInfo.userNumber && param != 'customermanage' && item.id != 'customermanage') {
  82. wx.showToast({
  83. title: '请先绑定您的户号',
  84. icon: 'none',
  85. duration: 2000
  86. })
  87. return;
  88. }
  89. wx.navigateTo({
  90. url: `/pages/${item.id || param}/${item.id || param}${item.url ? item.url : ''}`
  91. })
  92. },
  93. getAccountInfo() {
  94. this.setData({
  95. onQuery: true
  96. })
  97. //app.showLoading()
  98. app.$util.selfUserInfo(app.globalData, true).then((data) => {
  99. if (data) {
  100. this.setData({
  101. userInfo: data,
  102. waterInfo: data.waterStages
  103. })
  104. }else {
  105. this.setData({
  106. userInfo: {},
  107. waterInfo: {}
  108. })
  109. }
  110. this.setData({
  111. onQuery: false
  112. })
  113. //app.hideLoading();
  114. }).catch(() => {
  115. //app.hideLoading();
  116. this.setData({
  117. onQuery: false
  118. })
  119. })
  120. },
  121. onShow() {
  122. this.getAccountInfo();
  123. },
  124. toLogin(msg) {
  125. this.popup && this.popup.setData({
  126. type: 'error',
  127. title: '提示',
  128. content: msg,
  129. showCancel: false
  130. });
  131. this.popup.show();
  132. },
  133. cancelEvent: function() {
  134. this.popup.close();
  135. },
  136. confirmEvent: function() {
  137. this.getAccountInfo(true);
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function() {
  143. //获得popup组件
  144. this.popup = this.selectComponent("#popup");
  145. },
  146. })