user.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. // pages/user/user.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. const $api = require('../../utils/api.js').API;
  5. var logindata={}
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. usercode: '',
  12. phone:'',
  13. phcode:'',
  14. openid: '',
  15. info: {},
  16. userinfo:{},
  17. todayinfo:{},
  18. todayMoney:'',
  19. status:0,
  20. text:'获取验证码',
  21. player_type:0,
  22. signinfo:{}
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. if(options.type){
  29. this.setData({
  30. status:options.type,
  31. player_type:options.player_type
  32. })
  33. }
  34. $api.getsignup().then(res=>{
  35. this.setData({
  36. signinfo:res.data.data
  37. })
  38. })
  39. },
  40. onShow: function () {
  41. wx.hideHomeButton();
  42. },
  43. zx(){
  44. wx.navigateTo({
  45. url: '../message/message',
  46. })
  47. },
  48. getcode(){
  49. if(this.data.phone.length>=11){
  50. $api.sendcode({phone:this.data.phone}).then(res=>{
  51. this.countdown()
  52. })
  53. }else{
  54. wx.showToast({
  55. icon: 'none',
  56. title: '请输入正确的手机号',
  57. })
  58. }
  59. },
  60. countdown(){
  61. var count=60,_this=this;
  62. var timer=setInterval(c,1000)
  63. function c(){
  64. if(count>0){
  65. count--;
  66. _this.setData({
  67. text:count+"s重新发送"
  68. })
  69. }else{
  70. _this.setData({
  71. text:'获取验证码'
  72. })
  73. clearInterval(timer)
  74. }
  75. }
  76. },
  77. inputchange(e) {
  78. this.setData({
  79. phone: e.detail.value
  80. })
  81. },
  82. codechange(e) {
  83. this.setData({
  84. phcode: e.detail.value
  85. })
  86. },
  87. logout() {
  88. wx.removeStorage({
  89. key: 'userInfo'
  90. })
  91. wx.setNavigationBarTitle({
  92. title: '登录',
  93. })
  94. this.setData({
  95. userinfo: {},
  96. usercode: ''
  97. })
  98. },
  99. /**登陆 */
  100. login: function () {
  101. var _this=this;
  102. // if (!this.data.usercode) {
  103. // wx.showToast({
  104. // icon: 'none',
  105. // title: '请输入用户代码',
  106. // })
  107. // return;
  108. // }
  109. wx.getUserProfile({
  110. desc: '用于完善会员资料',
  111. success: res=> {
  112. //获取基本信息
  113. console.log(res.userInfo)
  114. var data = {
  115. nickName: res.userInfo.nickName,
  116. avatarUrl: res.userInfo.avatarUrl,
  117. usercode: this.data.usercode
  118. }
  119. wx.showLoading({
  120. title: '正在登陆',
  121. })
  122. wx.login({
  123. success(res) {
  124. //获取code
  125. $api.getOpenid({ code: res.code})
  126. .then(res => {
  127. //获取openid
  128. if (res.data.code != 0) {
  129. wx.showToast({
  130. icon: 'none',
  131. title: res.data.message,
  132. })
  133. wx.hideLoading();
  134. return;
  135. }
  136. data.openid = res.data.data.openid;
  137. logindata=data
  138. $api.login(data)
  139. .then(res=>{
  140. //登录成功
  141. wx.setStorage({
  142. key: 'userInfo',
  143. data: res.data.data,
  144. })
  145. //老用户直接进入系统
  146. if(res.data.data.role != 0){
  147. wx.switchTab({
  148. url: '../index/index',
  149. })
  150. return;
  151. }
  152. //新用户选择报名
  153. _this.setData({
  154. status:3,
  155. player_type:0
  156. })
  157. wx.hideLoading();
  158. wx.setNavigationBarTitle({
  159. title: '',
  160. })
  161. if (res.data.code != 0) {
  162. wx.showToast({
  163. icon: 'none',
  164. title: res.data.message,
  165. })
  166. return;
  167. }
  168. })
  169. .catch(err=>{
  170. wx.hideLoading();
  171. })
  172. })
  173. .catch(err => {
  174. //请求失败
  175. wx.hideLoading();
  176. })
  177. }
  178. })
  179. }
  180. })
  181. },
  182. login1(){
  183. logindata.phone=this.data.phone
  184. logindata.phcode=this.data.phcode
  185. if (logindata.phone.length<11){
  186. wx.showToast({
  187. icon: 'none',
  188. title: '请输入正确的手机号',
  189. })
  190. return
  191. }
  192. if (!logindata.phcode) {
  193. wx.showToast({
  194. icon: 'none',
  195. title: '请输入验证码',
  196. })
  197. return
  198. }
  199. $api.login(logindata).then(res=>{
  200. if(res.data.code == 0){
  201. this.setData({
  202. status:3
  203. })
  204. }
  205. })
  206. },
  207. login2(){
  208. if (this.data.phone.length<11) {
  209. wx.showToast({
  210. icon: 'none',
  211. title: '请输入正确的手机号',
  212. })
  213. return
  214. }
  215. if (!this.data.phcode) {
  216. wx.showToast({
  217. icon: 'none',
  218. title: '请输入验证码',
  219. })
  220. return
  221. }
  222. $api.bindphone({phone:this.data.phone,phcode:this.data.phcode}).then(res=>{
  223. if(res.data.code == 0){
  224. this.setData({
  225. status:3
  226. })
  227. }
  228. })
  229. },
  230. onCustomerService(){
  231. wx.openCustomerServiceChat({
  232. extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcc1bd2a8bddad1dfb'},
  233. corpId: 'wwc4de479c81db4706',
  234. success(res) {}
  235. })
  236. },
  237. /**
  238. * 生命周期函数--监听页面初次渲染完成
  239. */
  240. onReady: function () {
  241. },
  242. /**
  243. * 生命周期函数--监听页面显示
  244. */
  245. onShow: function () {
  246. },
  247. /**
  248. * 生命周期函数--监听页面隐藏
  249. */
  250. onHide: function () {
  251. },
  252. /**
  253. * 生命周期函数--监听页面卸载
  254. */
  255. onUnload: function () {
  256. },
  257. /**
  258. * 页面相关事件处理函数--监听用户下拉动作
  259. */
  260. onPullDownRefresh: function () {
  261. },
  262. /**
  263. * 页面上拉触底事件的处理函数
  264. */
  265. onReachBottom: function () {
  266. },
  267. /**
  268. * 用户点击右上角分享
  269. */
  270. onShareAppMessage: function () {
  271. }
  272. })