碧桂园
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

170 行
3.6 KiB

  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. let userInfo = getApp().globalData.userInfo
  5. let token = getApp().globalData.token
  6. console.log(userInfo)
  7. Page({
  8. data: {
  9. avatarModal: false,
  10. phoneModal: false,
  11. phoneModal1: false,
  12. showBg: false,
  13. step: 0,// 头像授权1, 手机授权2
  14. nickNamebind: false,
  15. phonebind: false,
  16. userInfo: null,
  17. userid:'',
  18. token: ''
  19. },
  20. onLoad() {
  21. if (userInfo) {
  22. this.setData({
  23. token: token,
  24. userid: userInfo.id,
  25. userInfo: userInfo
  26. })
  27. if(!!userInfo.userWxName&&!!userInfo.phone){
  28. this.leave()
  29. return;
  30. }
  31. if(!userInfo.userWxName||!userInfo.phone){
  32. this.setData({
  33. showBg: true
  34. })
  35. }else{
  36. this.setData({
  37. showBg: false
  38. })
  39. }
  40. this.setData({
  41. avatarModal: !!userInfo.userWxName?false:true,
  42. phoneModal1: !!userInfo.phone?false:true,
  43. step: 1
  44. })
  45. if(!this.data.avatarModal){
  46. this.setData({
  47. step: 2,
  48. phoneModal: this.data.phoneModal1
  49. })
  50. }
  51. }
  52. },
  53. backhome(){
  54. wx.navigateTo({
  55. url: '/pages/index/index'
  56. })
  57. },
  58. shouquan(){
  59. if(userInfo.phone){
  60. wx.showToast({
  61. icon: 'none',
  62. title: '您已完成授权',
  63. })
  64. }
  65. if(this.data.step==1){
  66. this.setData({
  67. avatarModal: true,
  68. showBg: true
  69. })
  70. }
  71. if(this.data.step==2){
  72. this.setData({
  73. phoneModal: true,
  74. showBg: true
  75. })
  76. }
  77. },
  78. closeModal(){
  79. this.setData({
  80. showBg: false
  81. })
  82. },
  83. leave(){
  84. wx.navigateTo({
  85. url: '/pages/out/index?index=1&userid='+ this.data.userid+'&gameid=1'+'&type=2',
  86. })
  87. },
  88. // 绑定用户头像信息
  89. bindNickname(obj) {
  90. let that = this
  91. let params = {
  92. id: that.data.userid,
  93. userWxHeadImgUrl: obj.avatarUrl,
  94. userWxName: obj.nickName,
  95. userVxGender: obj.gender
  96. }
  97. wx.request({
  98. url: 'https://cktest.2weisou.com/meta/ar/user/bindNickname',
  99. method: "POST",
  100. data: params,
  101. header: {
  102. Authorization: 'bearer '+ that.data.token
  103. },
  104. success(res) {
  105. if (res.statusCode == 200) {
  106. that.setData({
  107. avatarModal: false,
  108. step: 2
  109. })
  110. if(that.data.phoneModal1){
  111. that.setData({
  112. phoneModal: true
  113. })
  114. }
  115. }
  116. }
  117. })
  118. },
  119. getUserInfo(){
  120. let that = this
  121. wx.getUserProfile({
  122. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  123. success: (res) => {
  124. // console.log(res)
  125. that.bindNickname(res.userInfo)
  126. }
  127. })
  128. },
  129. // 授权手机号
  130. getPhoneNumber(e) {
  131. console.log(e);
  132. let that = this
  133. if (e.detail.errMsg == "getPhoneNumber:ok") {
  134. const {
  135. iv,
  136. encryptedData
  137. } = e.detail;
  138. wx.request({
  139. url: 'https://cktest.2weisou.com/meta/ar/user/bindMini',
  140. method: "POST",
  141. data: {
  142. encrypted: encryptedData,
  143. iv
  144. },
  145. header: {
  146. Authorization: 'bearer '+ that.data.token
  147. },
  148. success(res) {
  149. console.log(res)
  150. if (res.data.code == 0) {
  151. // console.log(res)
  152. that.setData({
  153. phoneModal: false,
  154. showBg: false,
  155. step: 0
  156. })
  157. that.leave()
  158. }
  159. }
  160. })
  161. } else {
  162. wx.showToast({
  163. icon: "none",
  164. title: "请授权手机号"
  165. })
  166. }
  167. }
  168. })