mine.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // pages/mine/mine.js
  2. var app = getApp()
  3. Page({
  4. data: {
  5. userInfo: '',//用户信息
  6. deposit: '',//是否缴纳押金 未缴纳0 已缴纳1
  7. arr: [],
  8. show: false,
  9. setting: '',//设置
  10. src: '',//用户头像地址
  11. },
  12. onLoad: function (options) {
  13. // 页面加载完成
  14. my.getAuthCode({
  15. scopes: 'auth_user',
  16. success: (res) => {
  17. my.getAuthUserInfo({
  18. success: (userInfo) => {
  19. //my.alert({content: userInfo.avatar});
  20. this.setData({ src: userInfo.avatar });
  21. console.log(userInfo, 'userInfo')
  22. if (userInfo) {
  23. let sex = 0
  24. if (userInfo.gender == "m") {
  25. let sex = 1
  26. }
  27. else if (userInfo.gender == "f") {
  28. let sex = 2
  29. }
  30. else {
  31. let sex = 0
  32. }
  33. var data = {
  34. 'area_id': userInfo.area_id,
  35. 'avatar': userInfo.avatar,
  36. 'city': userInfo.city,
  37. 'gender': 0,
  38. 'nickName': userInfo.nickName,
  39. 'province': userInfo.province,
  40. 'language': '中国'
  41. }
  42. this.userInfo(data)
  43. }
  44. }
  45. });
  46. },
  47. });
  48. },
  49. //同步用户信息
  50. userInfo: function (data) {
  51. let that = this
  52. app.request("/auth/weapp-userinfo-sync", data, "POST").then(res => {
  53. console.log(res, 'shouquan yonghuxinxi')
  54. if (res.status == 200) {
  55. // my.showToast({
  56. // content: '授权成功',
  57. // icon: 'none'
  58. // })
  59. my.setStorageSync({ 'key': 'userInfo', data: res.data.user })
  60. // wx.navigateBack()
  61. that.setData({ userInfo: res.data })
  62. } else {
  63. // my.showToast({
  64. // content: '登陆失败请重试',
  65. // icon: 'none'
  66. // })
  67. }
  68. })
  69. },
  70. getUser() {
  71. let token = my.getStorageSync({ 'key': 'token' }).data
  72. if (token != '') {
  73. app.request("/me", '', "GET").then(res => {
  74. console.log(res)
  75. 200 == res.status && my.setStorageSync({ 'key': "userInfo", data: res.data })
  76. this.setData({
  77. userInfo: res.data,
  78. deposit: my.getStorageSync({ 'key': 'userState' }).data,
  79. setting: my.getStorageSync({ 'key': 'setting' }).data
  80. })
  81. }).catch(err => {
  82. console.log(err)
  83. })
  84. }
  85. },
  86. onReady: function () {
  87. },
  88. onShow: function () {
  89. let that = this
  90. this.getUser();
  91. var area_id = ''
  92. if (my.getStorageSync({ 'key': 'home' }).data= undefined) {
  93. area_id = my.getStorageSync({ 'key': 'home' }).data.id
  94. }
  95. var data = {
  96. 'area_id': area_id
  97. }
  98. app.request("/card_riding/user_card", data, "GET").then(res => {
  99. console.log(res)
  100. that.setData({ arr: res.data.user_card, show: res.data.is_card_begin })
  101. })
  102. },
  103. onHide: function () {
  104. },
  105. onUnload: function () {
  106. },
  107. onPullDownRefresh: function () {
  108. },
  109. onReachBottom: function () {
  110. },
  111. onShareAppMessage: function () {
  112. },
  113. adDetail: function () {
  114. my.navigateTo({
  115. url: '/pages/ride_zige/ride_zige',
  116. })
  117. },
  118. balance: function () {
  119. my.navigateTo({
  120. url: '/pages/balance/balance',
  121. })
  122. },
  123. coupon: function () {
  124. my.navigateTo({
  125. url: '/pages/coupon/coupon',
  126. })
  127. },
  128. myCard: function () {
  129. my.navigateTo({
  130. url: '/pages/mine_card/mine_card',
  131. })
  132. },
  133. rideZige: function () {
  134. console.log(my.getStorageSync({ 'key': 'home' }).data)
  135. if (!my.getStorageSync({ 'key': 'home' }).data) {
  136. my.alert({
  137. title: '提示',
  138. content: '您附近暂无运营区',
  139. })
  140. } else {
  141. my.navigateTo({
  142. url: '/pages/ride_zige/ride_zige',
  143. })
  144. }
  145. },
  146. setUp: function () {
  147. my.navigateTo({
  148. url: '/pages/set_up/set_up',
  149. })
  150. },
  151. mineData: function () {
  152. my.navigateTo({
  153. url: '/pages/mine_data/mine_data',
  154. })
  155. },
  156. trip: function () {
  157. my.navigateTo({
  158. url: '/pages/trip/trip',
  159. })
  160. },
  161. accountDetails: function () {
  162. my.navigateTo({
  163. url: '/pages/account_details/account_details',
  164. })
  165. },
  166. weizhang: function () {
  167. my.navigateTo({
  168. url: '/pages/weizhang/weizhang',
  169. })
  170. },
  171. buyCard: function () {
  172. my.navigateTo({
  173. // url: '/pages/ride_zige/ride_zige',
  174. url: '/pages/buy-card/buy-card'
  175. })
  176. },
  177. //退还押金
  178. backDeposit: function () {
  179. my.navigateTo({
  180. url: '/pages/ride_zige/ride_zige',
  181. })
  182. },
  183. })