123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- // pages/user/user.js
- const app = getApp()
- var host = app.globalData.host;
- const $api = require('../../utils/api.js').API;
- var logindata={}
- const defaultAvatarUrl = '../../images/userdefault.png'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- usercode: '',
- phone:'',
- phcode:'',
- openid: '',
- info: {},
- userinfo:{},
- todayinfo:{},
- todayMoney:'',
- status:0,
- text:'获取验证码',
- player_type:0,
- signinfo:{},
- avatarUrl: defaultAvatarUrl,
- nickName:'',
- openid:'',
- unionid:'',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if(options.type){
- this.setData({
- status:options.type,
- player_type:options.player_type
- })
- }
- // $api.getsignup().then(res=>{
- // this.setData({
- // signinfo:res.data.data
- // })
- // })
- },
- onShow: function () {
- wx.hideHomeButton();
- },
- zx(){
- wx.navigateTo({
- url: '../message/message',
- })
- },
- getcode(){
- if(this.data.phone.length>=11){
- $api.sendcode({phone:this.data.phone}).then(res=>{
- this.countdown()
- })
- }else{
- wx.showToast({
- icon: 'none',
- title: '请输入正确的手机号',
- })
- }
-
- },
- countdown(){
- var count=60,_this=this;
- var timer=setInterval(c,1000)
- function c(){
- if(count>0){
- count--;
- _this.setData({
- text:count+"s重新发送"
- })
- }else{
- _this.setData({
- text:'获取验证码'
- })
- clearInterval(timer)
- }
- }
-
-
-
- },
- onChooseAvatar(e) {
- const { avatarUrl } = e.detail
- this.setData({
- avatarUrl,
- })
- this.uploadImg(this.data.avatarUrl)
- },
-
- nameChange(e){
- this.setData({
- nickName: e.detail.value
- })
- },
- inputchange(e) {
- this.setData({
- phone: e.detail.value
- })
- },
- codechange(e) {
- this.setData({
- phcode: e.detail.value
- })
- },
- logout() {
- wx.removeStorage({
- key: 'userInfo'
- })
- wx.setNavigationBarTitle({
- title: '登录',
- })
- this.setData({
- userinfo: {},
- usercode: ''
- })
- },
- /**登陆 */
- login: function () {
- this.islogin();
- },
- register(e){
- if(this.data.avatarUrl == defaultAvatarUrl){
- wx.showToast({
- icon: 'none',
- title: '请选择头像',
- })
- return
- }
- if(this.data.nickName == ''){
- wx.showToast({
- icon: 'none',
- title: '请输入昵称',
- })
- return
- }
- this.wxlogin()
- },
-
- islogin(){
- var _this=this;
- wx.showLoading({
- title: '正在登陆',
- })
-
- wx.login({
- success(res) {
- //获取code
- $api.getOpenid({ code: res.code})
- .then(res => {
- //获取openid
- if (res.data.code != 0) {
- wx.showToast({
- icon: 'none',
- title: res.data.message,
- })
- wx.hideLoading();
- return;
- }
- var nopenid = res.data.data.openid
- var nunionid = res.data.data.unionid
- _this.setData({
- openid:nopenid,
- unionid:nunionid,
- })
- // console.log(res.data.data.unionid,222)
- $api.isUserLogin({openid:nopenid,unionid:nunionid})
- .then(res=>{
- wx.hideLoading();
- if (res.data.code != 0) {
- wx.showToast({
- icon: 'none',
- title: res.data.message,
- })
- return;
- }
-
- //有登录
- if(res.data.data.id){
- _this.setData({
- nickName:res.data.data.username,
- avatarUrl:res.data.data.avatar,
- })
- _this.wxlogin()
-
- } else{
- _this.setData({
- status:10,
- })
- }
-
- })
- .catch(err=>{
- wx.hideLoading();
- })
- })
- .catch(err => {
- //请求失败
- wx.hideLoading();
- })
-
- }
- })
- },
- wxlogin(){
- var _this=this;
- wx.showLoading({
- title: '正在登陆',
- })
- var udata = {};
- udata.openid = this.data.openid;
- udata.unionid = this.data.unionid;
- udata.nickName = this.data.nickName;
- udata.avatarUrl = this.data.avatarUrl;
- $api.login(udata)
- .then(res=>{
- //登录成功
- wx.hideLoading();
- if (res.data.code != 0) {
- wx.showToast({
- icon: 'none',
- title: res.data.message,
- })
- return;
- }
- // console.log(res.data.data,'user')
- wx.setStorage({
- key: 'userInfo',
- data: res.data.data,
- })
- wx.setStorage({
- key: 'user',
- data: res.data.data,
- })
-
- //老用户直接进入系统
- if(res.data.data.role != 0){
- app.globalData.follow = 1
- wx.switchTab({
- url: '../index/index',
- })
-
- return;
- }
- //新用户选择报名
- _this.setData({
- status:3,
- player_type:0
- })
-
- wx.setNavigationBarTitle({
- title: '',
- })
-
- })
- .catch(err=>{
- wx.hideLoading();
- })
- },
- login1(){
- logindata.phone=this.data.phone
- logindata.phcode=this.data.phcode
- if (logindata.phone.length<11){
- wx.showToast({
- icon: 'none',
- title: '请输入正确的手机号',
- })
- return
- }
- if (!logindata.phcode) {
- wx.showToast({
- icon: 'none',
- title: '请输入验证码',
- })
- return
- }
- $api.login(logindata).then(res=>{
- if(res.data.code == 0){
- this.setData({
- status:3
- })
- }
- })
- },
- login2(){
- if (this.data.phone.length<11) {
- wx.showToast({
- icon: 'none',
- title: '请输入正确的手机号',
- })
- return
- }
- if (!this.data.phcode) {
- wx.showToast({
- icon: 'none',
- title: '请输入验证码',
- })
- return
- }
- $api.bindphone({phone:this.data.phone,phcode:this.data.phcode}).then(res=>{
- if(res.data.code == 0){
- this.setData({
- status:3
- })
- }
- })
- },
- uploadImg(path){
- $api.uploadAvatar(path,'file').then(res=>{
- if(res.code == 0){
- this.setData({
- avatarUrl: res.data.url
- })
- }
- })
- },
-
- onCustomerService(){
- wx.openCustomerServiceChat({
- extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcc1bd2a8bddad1dfb'},
- corpId: 'wwc4de479c81db4706',
- success(res) {}
- })
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|