index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // pages/tabber/my/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. btnInfo: null,
  9. menuList: [
  10. {
  11. icon: '/image/my/youhuiquan.png',
  12. text: '优惠券',
  13. url: '/pages/my/coupon/coupon'
  14. },
  15. // {
  16. // icon: '/image/my/fenxianghaoyou.png',
  17. // text: '分享好友'
  18. // },
  19. {
  20. icon: '/image/my/dizhiguanli.png',
  21. text: '地址管理',
  22. url: '/pages/my/address/address'
  23. },
  24. // {
  25. // icon: '/image/my/fuwuliucheng.png',
  26. // text: '服务流程'
  27. // }, {
  28. // icon: '/image/my/yonghuxieyi.png',
  29. // text: '用户协议'
  30. // },
  31. // {
  32. // icon: '/image/my/lipeixize.png',
  33. // text: '理赔细则'
  34. // },
  35. {
  36. icon: '/image/my/kefurexian.png',
  37. text: '客服热线',
  38. url:""
  39. }
  40. ],
  41. active: true,
  42. userInfo: "",
  43. hasUserInfo: false,
  44. code: "",
  45. yue:0
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad: function (options) {
  51. this.getUser();
  52. if (this.data.active == true) {
  53. this.data.menuList.shift()
  54. this.setData({
  55. code: wx.getStorageSync('phone'),
  56. menuList: this.data.menuList
  57. })
  58. }
  59. this.getwallet();
  60. },
  61. onShow(){
  62. this.getBtnInfo()
  63. },
  64. getBtnInfo() {
  65. this.setData({
  66. btnInfo: app.globalData.btnInfo
  67. })
  68. },
  69. toUrl(e) {
  70. let url = e.currentTarget.dataset.url
  71. wx.navigateTo({
  72. url,
  73. })
  74. },
  75. getUserProfile(e) {
  76. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
  77. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  78. wx.getUserProfile({
  79. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  80. success: (res) => {
  81. // this.setData({
  82. // userInfo: res.userInfo,
  83. // hasUserInfo: true
  84. // })
  85. this.updateUser(res.userInfo);
  86. }
  87. })
  88. },
  89. getPhoneNumber(e) {
  90. console.log(e)
  91. this.setData({
  92. code: e.detail.code,
  93. })
  94. },
  95. getwallet() {
  96. var that = this;
  97. app.api.useApi(app.globalData.baseAppUrl + "api/wallet", {
  98. }, "get").then(function (res) {
  99. if (res.code != 200) {
  100. wx.showLoading({
  101. title: res.message.msg,
  102. })
  103. setTimeout(function () {
  104. wx.hideLoading({
  105. success: (res) => { },
  106. })
  107. }, 2000);
  108. } else {
  109. console.log(res.message.data);
  110. that.setData({
  111. yue: res.message.data.balance,
  112. })
  113. }
  114. }).catch(function (err) {
  115. console.log(222);
  116. })
  117. },
  118. updateUser(userinfo){
  119. wx.showLoading({
  120. title: '更新用户信息中',
  121. })
  122. var that=this;
  123. var userinfo=userinfo;
  124. app.api.useApi(app.globalData.baseAppUrl+"api/user",userinfo,"post").then((res)=>{
  125. if(res.code==200){
  126. wx.hideLoading();
  127. that.getUser()
  128. }else{
  129. that.updateUser(userinfo)
  130. }
  131. }).catch((err)=>{
  132. that.updateUser(userinfo)
  133. })
  134. },
  135. /**
  136. * 获取用户信息
  137. */
  138. getUser(){
  139. var that=this;
  140. app.api.useApi(app.globalData.baseAppUrl+"api/user/getUser","","get").then((res)=>{
  141. if(res.code==200){
  142. wx.hideLoading();
  143. that.setData({
  144. userInfo:res.message.data,
  145. hasUserInfo:res.message.data.avatar!=""?true:false
  146. })
  147. }else{
  148. that.getUser()
  149. }
  150. }).catch((err)=>{
  151. that.getUser()
  152. })
  153. }
  154. })