user.js 5.9 KB

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