123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- // index.js
- // 获取应用实例
- const app = getApp()
- const util = require('../../utils/util.js');
- const user = require('../../utils/user.js');
- const api = require('../../api/api.js');
- const map = require('../../utils/map.js');
- Page({
- data: {
- userInfo: {},
- mobile: '',
- captcha: '', //验证码
- code: '' //小程序登录code
- },
- onLoad() {
- let userInfo = wx.getStorageSync('userInfo');
- if (userInfo && userInfo.type == 1) return; //小哥登录 不验证地理位置
- this.getLoginCode();
- // map.getCity().then(res => {}).catch(res => {
- // if (res == 3) {
- // wx.showModal({
- // title: '提醒',
- // showCancel: false,
- // content: '当前区域,无服务门店'
- // })
- // } else {
- // wx.showModal({
- // title: '提醒',
- // showCancel: false,
- // content: '您未授权,部分功能将受限'
- // })
- // }
- // })
- },
- goShelter() {
- wx.navigateTo({
- url: '/pages/shelter/index',
- })
- },
- onShow() {
- let that = this;
- //验证是否登陆过
- user.checkLogin().then(res => {
- app.globalData.hasLogin = true;
- wx.switchTab({
- url: '/pages/upgrade/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) {
- var ivObj = e.detail.iv
- var telObj = e.detail.encryptedData
- var that = this;
- //------执行Login---------
- util.request(api.AuthRegister, {
- code: that.data.code,
- encryptedData: telObj,
- iv: ivObj,
- loginType: 1
- },'POST').then(function (res) {
- console.info(res)
- if (res.errno === 0) {
- //存储用户信息
- console.info("登录成功")
- app.globalData.hasLogin = true;
- wx.setStorageSync('userInfo', res.data.userInfo);
- wx.setStorageSync('token', res.data.token);
- that.setData({
- mobile: res.data.mobile
- })
- wx.showToast({
- title: '授权注册成功',
- icon: 'success',
- duration: 2000,
- complete: function () {
- // if(res.data.userInfo.type==1)
- // wx.navigateTo({
- // url: '/pages/pre/index',
- // })
- // else
- // wx.navigateTo({
- // url: '/pages/servant/servant',
- // })
- wx.switchTab({
- url: '/pages/upgrade/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.switchTab({
- url: '/pages/index/index',
- })
- };
- }
- })
- }
- },
- getUserProfile(e) {
- let that = this
- // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
- wx.getUserProfile({
- desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (res) => {
- console.log(res)
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- //登录
- util.request(api.AuthLoginByCaptcha, {
- mobile: that.data.mobile,
- captcha: that.data.captcha,
- userInfo: res.userInfo,
- code: that.data.code
- }, "POST").then(res => {
- if (res.errno == 0) {
- //存储用户信息
- console.info("登录成功")
- app.globalData.hasLogin = true;
- wx.setStorageSync('userInfo', res.data.userInfo);
- wx.setStorageSync('token', res.data.token);
- that.setData({
- mobile: res.data.mobile
- })
- wx.showToast({
- title: '授权注册成功',
- icon: 'success',
- duration: 2000,
- complete: function () {
- wx.switchTab({
- url: '/pages/upgrade/serviceOrder/serviceOrder',
- })
- }
- })
- } else {
- wx.showToast({
- title: res.errmsg,
- duration: 3000
- });
- }
- }).catch(res => {
- })
- }
- })
- },
- getCaptcha() {
- console.info(this.data.mobile)
- if (this.data.mobile.length != 11 || this.data.mobile.startsWith("1") == false) {
- wx.showToast({
- title: '请输入正确手机号',
- icon:'none',
- duration: 3000
- });
- return;
- }
- util.request(api.AuthCaptcha, {
- mobile: this.data.mobile
- }, "POST").then(res => {
- if (res.errno == 0)
- wx.showToast({
- title: '验证码发送成功',
- duration: 3000
- });
- else
- wx.showToast({
- title: res.errmsg,
- duration: 3000
- });
- }).catch(res => {
- wx.showToast({
- title: res.errMsg,
- icon: 'error',
- duration: 3000
- });
- })
- },
- bindMobileInput(e) {
- console.info(e)
- this.setData({
- mobile: e.detail.value
- });
- },
- bindcaptchaInput(e) {
- this.setData({
- captcha: e.detail.value
- });
- },
- goInvite(){
- wx.navigateTo({
- url: '/pages/upgrade/invite/invite',
- })
- }
- })
|