index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. sonlabel:'近期用水量'
  15. }, {
  16. id: 'waterabnormal',
  17. label: '异常预警',
  18. icon: '/static/img/icon_water_abnormal.png',
  19. sonlabel:'用水异常提醒'
  20. },
  21. {
  22. id: 'wateranalysis',
  23. label: '用水趋势',
  24. icon: '/static/img/icon_water_analysis.png',
  25. sonlabel:'年度用水趋势'
  26. }, {
  27. id: 'customermanage',
  28. label: '户号管理',
  29. icon: '/static/img/icon_customer_manage.png',
  30. sonlabel:'绑定户号'
  31. }],
  32. weixinLogin: false,
  33. },
  34. getPhoneNumber(e) {
  35. let that = this;
  36. if (e.detail.encryptedData) {
  37. const {
  38. iv,
  39. encryptedData
  40. } = e.detail;
  41. const {
  42. param,
  43. item = {}
  44. } = e.currentTarget.dataset;
  45. wx.login({
  46. success: res => {
  47. const {
  48. code
  49. } = res;
  50. app.$http.postForm('/appletUser/bindingMobile', {
  51. code,
  52. encryptedData,
  53. iv
  54. }).then(({
  55. status,
  56. data = {}
  57. }) => {
  58. if (status === 0) {
  59. // 绑定成功
  60. if (this.data.userInfo.deviceId) {
  61. wx.navigateTo({
  62. url: `/pages/${item.id || param}/${item.id || param}${item.url ? item.url : ''}`
  63. })
  64. }
  65. wx.showToast({
  66. title: '授权成功',
  67. icon: 'none',
  68. duration: 2000
  69. })
  70. that.setData({
  71. weixinLogin:true
  72. })
  73. return;
  74. }
  75. // 绑定成功未注册
  76. else {
  77. wx.showToast({
  78. title: '您尚未注册,请到平台端开通账号后重试',
  79. icon: 'none',
  80. duration: 2000
  81. })
  82. return;
  83. }
  84. })
  85. }
  86. })
  87. }
  88. },
  89. gotopage(e) {
  90. const {
  91. param,
  92. item = {}
  93. } = e.currentTarget.dataset;
  94. if (!this.data.weixinLogin) {
  95. wx.showToast({
  96. title: '请您先进行授权',
  97. icon: 'none',
  98. duration: 2000
  99. })
  100. return;
  101. }
  102. console.log("app的值",app)
  103. if (!this.data.userInfo.userNumber && param != 'customermanage' && item.id != 'customermanage') {
  104. wx.showToast({
  105. title: '请先绑定你的户号',
  106. icon: 'none',
  107. duration: 2000
  108. })
  109. return;
  110. }
  111. wx.navigateTo({
  112. url: `/pages/${item.id || param}/${item.id || param}${item.url ? item.url : ''}`
  113. })
  114. },
  115. getAccountInfo() {
  116. this.setData({
  117. onQuery: true
  118. })
  119. app.$util.selfUserInfo(app.globalData, true).then((data) => {
  120. if (data) {
  121. this.setData({
  122. userInfo: data,
  123. waterInfo: data.waterStages
  124. })
  125. } else {
  126. this.setData({
  127. userInfo: {},
  128. waterInfo: {}
  129. })
  130. }
  131. this.setData({
  132. onQuery: false
  133. })
  134. }).catch(() => {
  135. this.setData({
  136. onQuery: false
  137. })
  138. })
  139. },
  140. // 获取用户注册状态 /user/getUser
  141. isRegister(){
  142. let that=this;
  143. app.$http.postForm('/appletUser/getUser').then(({ status, msg, data }) => {
  144. // 已授权但客户不存在
  145. // 未授权
  146. if(status===-602){
  147. that.setData({
  148. weixinLogin:false
  149. })
  150. }else{
  151. that.setData({
  152. weixinLogin:true
  153. })
  154. }
  155. })
  156. },
  157. onShow() {
  158. this.getAccountInfo();
  159. this.isRegister()
  160. },
  161. toLogin(msg) {
  162. this.popup && this.popup.setData({
  163. type: 'error',
  164. title: '提示',
  165. content: msg,
  166. showCancel: false
  167. });
  168. this.popup.show();
  169. },
  170. cancelEvent: function () {
  171. this.popup.close();
  172. },
  173. confirmEvent: function () {
  174. this.getAccountInfo(true);
  175. },
  176. /**
  177. * 生命周期函数--监听页面初次渲染完成
  178. */
  179. onReady: function () {
  180. //获得popup组件
  181. this.popup = this.selectComponent("#popup");
  182. },
  183. })