// index.js // 获取应用实例 const app = getApp() const util = require('../../utils/jmsUtil.js'); const user = require('../../utils/user.js'); const jms = require('../../api/jms.js'); Page({ data: { isChecked:false, userInfo: {}, mobile: '', captcha: '', //验证码 code: '', //小程序登录code jmsMobile: '', jmsCaptcha: '', loginType: '2' //1一键登录 2:验证登录 }, onShareAppMessage: function () { var path = '/pages/index/index'; return { title: "鲸致生活-服务者小程序", path: path, imageUrl: '/static/images/logo.png' } }, onLoad(options) { // this.getLoginCode(); }, onLoginChange(e) { console.log(e); this.setData({ loginType:e.detail }); }, goShelter() { wx.navigateTo({ url: '/pages/shelter/index', }) }, onShow() { let that = this; //验证是否登陆过 user.checkLogin().then(res => { app.globalData.hasLogin = true; let userInfo = wx.getStorageSync('userInfo'); // 兼职人员 wx.redirectTo({ url: '/pages/temp/serviceOrder/serviceOrder', }) }).catch(res => { // that.getLoginCode(); }) }, getLoginCode() { let that = this; user.login().then(res => { console.info(res) that.setData({ code: res.code }) }) }, getPhoneNumber: function (e) { if(!this.data.isChecked){ wx.showToast({ title: '请点击下方用户协议', icon: 'none', duration: 3000 }); return; } console.log(e); var that = this; //------执行Login--------- util.request(jms.AuthRegister, { code: e.detail.code, loginType: 1 }, 'POST').then(function (res) { console.info(res) if (res.errno === 0) { //存储用户信息 console.info("登录成功1") app.globalData.hasLogin = true; wx.setStorageSync('userInfo', res.data.fraUser); wx.setStorageSync('token', res.data.token); wx.showToast({ title: '授权登录成功', icon: 'success', duration: 2000, complete: function () { wx.redirectTo({ url: '/pages/temp/serviceOrder/serviceOrder', }) } }) } else { console.info(res); // that.getLoginCode(); wx.showToast({ title: res.errmsg, duration: 3000, icon: 'none' }); } }); //-----------------是否授权,授权通过进入主页面,授权拒绝则停留在登陆界面 if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { //用户点击拒绝 wx.showModal({ title: '警告', content: '您点击了拒绝授权,功能无法使用!!!', showCancel: false, confirmText: '确定', success: function (res) { // 用户没有授权成功,不需要改变 isHide 的值 if (res.confirm) { wx.redirectTo({ url: '/pages/temp/serviceOrder/serviceOrder', }); }; } }) } }, bindMobileInput(e) { this.setData({ mobile: e.detail.value }); }, bindcaptchaInput(e) { this.setData({ captcha: e.detail.value }); }, goInvite() { wx.navigateTo({ url: '/pages/upgrade/invite/invite', }) }, goTemp() { wx.navigateTo({ url: '/pages/temp/login/login', }); }, bindJmsMobileInput(e) { this.setData({ jmsMobile: e.detail.value }); }, bindJmsCaptchaInput(e) { this.setData({ jmsCaptcha: e.detail.value }); }, getJmsCaptcha() { if (this.data.jmsMobile.length != 11 || this.data.jmsMobile.startsWith("1") == false) { wx.showToast({ title: '请输入正确手机号', icon: 'none', duration: 3000 }); return; } util.request(jms.AuthCaptcha, { tel: this.data.jmsMobile }, "GET").then(res => { if (res.errno == 0) wx.showToast({ title: '验证码发送成功', duration: 3000 }); else wx.showToast({ title: res.errmsg, duration: 3000, icon: 'none' }); }).catch(res => { console.info('getCaptcha error') wx.showToast({ title: res.errmsg, icon: 'none', duration: 3000 }); }) }, loginTemp() { if(!this.data.isChecked){ wx.showToast({ title: '请点击下方用户协议', icon: 'none', duration: 3000 }); return; } if (this.data.jmsMobile.length != 11 || this.data.jmsMobile.startsWith("1") == false) { wx.showToast({ title: '请输入正确手机号', icon: 'none', duration: 3000 }); return; } else if (this.data.jmsCaptcha == '') { wx.showToast({ title: '请输入验证码', icon: 'none', duration: 3000 }); return; } else { //登录 util.request(jms.AuthRegister, { tel: this.data.jmsMobile, verifyCode: this.data.jmsCaptcha, loginType:2 }, 'POST').then(res => { //存储用户信息 console.info("登录成功") if (res.errno == 0) { app.globalData.hasLogin = true; let user = res.data.fraUser; wx.setStorageSync('userInfo', user); wx.setStorageSync('token', res.data.token); app.globalData.userInfo=user; wx.redirectTo({ url: '/pages/temp/serviceOrder/serviceOrder', }); } else if (res.errno === 301) { wx.showModal({ title: '提示', content: '您还未注册,是否现在去注册?', // showCancel:false, complete: (res) => { if (res.cancel) { } if (res.confirm) { wx.navigateTo({ url: '/pages/temp/register/register', }) } } }) } else { // util.showErrorToast(res.errmsg); wx.showToast({ title: res.errmsg, icon: 'none', duration: 3000 }); } }).catch(err => { }) } }, bindJmsMobileInput(e) { this.setData({ jmsMobile: e.detail.value }); }, bindJmsCaptchaInput(e) { this.setData({ jmsCaptcha: e.detail.value }); }, goRegister() { wx.navigateTo({ url: '/pages/temp/register/register', }) }, checkProBtn() { wx.navigateTo({ url: '/pages/temp/jzxhAppletsUserPro/jzxhAppletsUserPro' }) }, checkChange(e){ this.setData({ isChecked: e.detail, }); }, })