123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- import request from '../../../util/http'
- import apiUrl from '../../../util/apiUrl'
- import util from '../../../util/util'
- import moment from 'moment'
- var app = getApp();
- Page({
- onLoad(query) {
- // 页面加载
- console.log('onLoad');
- console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
- // my.setStorageSync({
- // key: 'userInfo',
- // data: {'id':'3'}
- // });
-
- let storageRes = my.getStorageSync({ key: 'userInfo' });
- console.log(storageRes);
- // my.alert({
- // content: JSON.stringify(storageRes),
- // });
- // this.authInit();
- if(storageRes.data==null){
- // 没有用户信息获取授权
- this.authInit();
- }else{
- let id= storageRes.data.id;
- // 有用户信息更新用户信息
- let params={'userId':id};
- this.getUserInfo(params);
- }
-
- },
- onReady() {
- // 页面加载完成
- },
- onShow() {
- // 页面显示
- },
- onHide() {
- // 页面隐藏
- },
- onUnload() {
- // 页面被关闭
- },
- onTitleClick() {
- // 标题被点击
- },
- onPullDownRefresh() {
- // 页面被下拉
- },
- onReachBottom() {
- // 页面被拉到底部
- },
- onShareAppMessage() {
- // 返回自定义分享信息
- return {
- title: 'My App',
- desc: 'My App description',
- path: 'pages/index/index',
- };
- },
- // 授权登录
- authInit(){
- my.authorize({
- scopes: 'scope.userInfo',
- success: (res) => {
- my.getAuthUserInfo({
- success: (userInfo) => {
- console.log(userInfo);
- // try{
- // let data=await request.httpServicePost(apiUrl.registerUserPath);
- // console.log(data);
- // }catch(e){
- // console.log(e);
- // }
- request.httpServicePost(apiUrl.registerUserPath).then(data=>{
- console.log(data);
- let userInfo=data;
- // 授权注册成功后将用户信息存到本地存储和globalData
- my.setStorageSync({
- key: 'userInfo',
- data: userInfo
- });
- app.globalData.userInfo = userInfo;
- // userType 为空没有身份 1为雇主 2为保姆
- if(userInfo.userType==''){
- //没有身份
- my.redirectTo({
- url: '../userGuide/userGuide'
- });
- }else{
- // 判断缓存中是否上一次选过某个保姆或雇主,没有的话进入列表
- let emReNoStorage = my.getStorageSync({ key: 'employRelationNo' });
- console.log(emReNoStorage);
- if(emReNoStorage.data==null){
- if(userInfo.userType=='1'){
- my.redirectTo({
- url: '../../customer/myServantList/myServantList'
- });
- }else if(userInfo.userType=='2'){
- my.redirectTo({
- url: '../../servant/myCustomerList/myCustomerList'
- });
- }
- }else{
- // 进入工作站
- let emReNo=emReNoStorage.data;
-
- if(userInfo.userType=='1'){
-
- my.redirectTo({
- url: '../../customer/customerCenter/customerCenter?emReNo='+emReNo
- });
- }else if(userInfo.userType=='2'){
-
- my.redirectTo({
- url: '../../servant/servantCenter/servantCenter?emReNo='+emReNo
- });
- }
- }
- // if(userInfo.userType=='1'){
- // my.redirectTo({
- // url: '../../customer/myServantList/myServantList'
- // });
- // }else if(userInfo.userType=='2'){
- // my.redirectTo({
- // url: '../../servant/myCustomerList/myCustomerList'
- // });
- // }
- }
- }).catch(e=>{
- console.log(e);
-
- })
-
- }
- });
- },
- });
- },
- // 获取用户信息
- getUserInfo(params){
- request.httpServiceGet(apiUrl.getUserInfoPath,params).then(data=>{
- console.log(data);
- // 授权用户信息后将用户信息存到本地存储和globalData
- let userInfo=data
- app.globalData.userInfo=data;
- my.setStorageSync({
- key:"userInfo",
- data:data
- });
- // userType 为空没有身份 1为雇主 2为保姆
- if(userInfo.userType==''){
- //没有身份
- my.redirectTo({
- url: '../userGuide/userGuide'
- });
- }else{
- // 判断缓存中是否上一次选过某个保姆或雇主,没有的话进入列表
- let emReNoStorage = my.getStorageSync({ key: 'employRelationNo' });
- console.log(emReNoStorage);
- if(emReNoStorage.data==null){
- if(userInfo.userType=='1'){
- my.redirectTo({
- url: '../../customer/myServantList/myServantList'
- });
- }else if(userInfo.userType=='2'){
- my.redirectTo({
- url: '../../servant/myCustomerList/myCustomerList'
- });
- }
- }else{
- // 进入工作站
- let emReNo=emReNoStorage.data;
-
- if(userInfo.userType=='1'){
-
- my.redirectTo({
- url: '../../customer/customerCenter/customerCenter?emReNo='+emReNo
- });
- }else if(userInfo.userType=='2'){
-
- my.redirectTo({
- url: '../../servant/servantCenter/servantCenter?emReNo='+emReNo
- });
- }
- }
- // if(userInfo.userType=='1'){
- // my.redirectTo({
- // url: '../../customer/myServantList/myServantList'
- // });
- // }else if(userInfo.userType=='2'){
- // my.redirectTo({
- // url: '../../servant/myCustomerList/myCustomerList'
- // });
- // }
- }
-
-
- }).catch(e=>{
- console.log(e);
-
- })
- // let res=await request.httpServiceGet(apiUrl.getUserInfoPath,params);
- // console.log(res);
- }
- });
|