mine.js 4.6 KB

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