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||storageRes.data==''){ // 没有用户信息获取授权 this.authInit(); }else{ this.getUserInfo(); // let id= storageRes.data.id; // if(id!=undefined&&id!=''){ // // 有用户信息更新用户信息 // let params={'userId':id}; // this.getUserInfo(params); // }else{ // this.authInit(); // } } }, 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||emReNoStorage.data==''){ 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; app.globalData.employRelationNo=emReNo; my.setStorageSync({ key: 'employRelationNo', data: emReNo }); 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||emReNoStorage.data==''){ 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; app.globalData.employRelationNo=emReNo; my.setStorageSync({ key: 'employRelationNo', data: emReNo }); 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); // 获取用户信息失败,重新授权 this.authInit(); }) // let res=await request.httpServiceGet(apiUrl.getUserInfoPath,params); // console.log(res); } });