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