user.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. var data = {
  114. nickName: res.userInfo.nickName,
  115. avatarUrl: res.userInfo.avatarUrl,
  116. usercode: this.data.usercode
  117. }
  118. wx.showLoading({
  119. title: '正在登陆',
  120. })
  121. wx.login({
  122. success(res) {
  123. //获取code
  124. $api.getOpenid({ code: res.code})
  125. .then(res => {
  126. //获取openid
  127. if (res.data.code != 0) {
  128. wx.showToast({
  129. icon: 'none',
  130. title: res.data.message,
  131. })
  132. wx.hideLoading();
  133. return;
  134. }
  135. data.openid = res.data.data.openid;
  136. logindata=data
  137. $api.login(data)
  138. .then(res=>{
  139. //登录成功
  140. wx.setStorage({
  141. key: 'userInfo',
  142. data: res.data.data,
  143. })
  144. //老用户直接进入系统
  145. if(res.data.data.role != 0){
  146. wx.switchTab({
  147. url: '../index/index',
  148. })
  149. return;
  150. }
  151. //新用户选择报名
  152. _this.setData({
  153. status:3,
  154. player_type:0
  155. })
  156. wx.hideLoading();
  157. wx.setNavigationBarTitle({
  158. title: '',
  159. })
  160. if (res.data.code != 0) {
  161. wx.showToast({
  162. icon: 'none',
  163. title: res.data.message,
  164. })
  165. return;
  166. }
  167. })
  168. .catch(err=>{
  169. wx.hideLoading();
  170. })
  171. })
  172. .catch(err => {
  173. //请求失败
  174. wx.hideLoading();
  175. })
  176. }
  177. })
  178. }
  179. })
  180. },
  181. login1(){
  182. logindata.phone=this.data.phone
  183. logindata.phcode=this.data.phcode
  184. if (logindata.phone.length<11){
  185. wx.showToast({
  186. icon: 'none',
  187. title: '请输入正确的手机号',
  188. })
  189. return
  190. }
  191. if (!logindata.phcode) {
  192. wx.showToast({
  193. icon: 'none',
  194. title: '请输入验证码',
  195. })
  196. return
  197. }
  198. $api.login(logindata).then(res=>{
  199. if(res.data.code == 0){
  200. this.setData({
  201. status:3
  202. })
  203. }
  204. })
  205. },
  206. login2(){
  207. if (this.data.phone.length<11) {
  208. wx.showToast({
  209. icon: 'none',
  210. title: '请输入正确的手机号',
  211. })
  212. return
  213. }
  214. if (!this.data.phcode) {
  215. wx.showToast({
  216. icon: 'none',
  217. title: '请输入验证码',
  218. })
  219. return
  220. }
  221. $api.bindphone({phone:this.data.phone,phcode:this.data.phcode}).then(res=>{
  222. if(res.data.code == 0){
  223. this.setData({
  224. status:3
  225. })
  226. }
  227. })
  228. },
  229. onCustomerService(){
  230. wx.openCustomerServiceChat({
  231. extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcc1bd2a8bddad1dfb'},
  232. corpId: 'wwc4de479c81db4706',
  233. success(res) {}
  234. })
  235. },
  236. /**
  237. * 生命周期函数--监听页面初次渲染完成
  238. */
  239. onReady: function () {
  240. },
  241. /**
  242. * 生命周期函数--监听页面显示
  243. */
  244. onShow: function () {
  245. },
  246. /**
  247. * 生命周期函数--监听页面隐藏
  248. */
  249. onHide: function () {
  250. },
  251. /**
  252. * 生命周期函数--监听页面卸载
  253. */
  254. onUnload: function () {
  255. },
  256. /**
  257. * 页面相关事件处理函数--监听用户下拉动作
  258. */
  259. onPullDownRefresh: function () {
  260. },
  261. /**
  262. * 页面上拉触底事件的处理函数
  263. */
  264. onReachBottom: function () {
  265. },
  266. /**
  267. * 用户点击右上角分享
  268. */
  269. onShareAppMessage: function () {
  270. }
  271. })