import { postUrl, postUrl3 } from '../../utils/util'; import apiArr from '../../api/water_filter'; Page({ /** * 页面的初始数据 */ data: { isLogin: false, loginType: 'account', // 默认手机登录 password: "", account: "", type:"" }, navigateToAgreement() { wx.navigateTo({ url: '../Agreement/Agreement', }) }, accountIpt(e) { let that = this that.setData({ account: e.detail.value }) }, passwordIpt(e) { let that = this that.setData({ password: e.detail.value }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this let loginType = '' if (wx.getStorageSync('LoginType')) { loginType = 'account' } else { loginType = 'phone' } that.setData({ loginType, type:options.type }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, headerLoginClick() { wx.showLoading({ title: '加载中', }); wx.login({ success: (res) => { postUrl(apiArr.login, { code: res.code }, res => { console.log('eaasdaadd', res) wx.setStorageSync('is_master', res.is_master); if (res.error) return; postUrl(apiArr.loginInfo, {}, ress => { if (ress.error) return; // 保存userId 后续接口使用 wx.setStorageSync('userId', ress.user_id); wx.setStorageSync('userInfo', ress) if(wx.getStorageSync('openId')){ wx.setStorageSync('loginMaster', 1) //是否登录过师傅 2登录师傅 }else{ wx.setStorageSync('loginMaster', 2) //是否登录过师傅 2登录师傅 } this.setData({ isLogin: true, }) }, res.token) wx.setStorageSync('ctoken', res.token); wx.hideLoading(); }) }, }) }, getPhoneNumber(event) { let that = this const { isLogin } = this.data; console.log('获取信息', event); if (event.detail.errMsg === "getPhoneNumber:ok") { wx.showLoading({ title: '加载中', }); postUrl(apiArr.loginGetPhone, { code: event.detail.code }, res => { if (isLogin) { console.log(res); wx.setStorageSync('phone', res.phone); wx.hideLoading(); wx.showToast({ title: '登录成功', icon: 'success', mask: true, duration: 2000, success: () => { this.tohome(); } }); } else { wx.hideLoading(); wx.showToast({ title: '登录失败', icon: 'error', mask: true, duration: 2000, }) } }) } else { wx.removeStorageSync('ctoken'); wx.removeStorageSync('userId'); wx.removeStorageSync('openId'); wx.removeStorageSync('phone'); wx.removeStorageSync('is_deal'); wx.removeStorageSync('is_dev'); wx.removeStorageSync('is_shop'); wx.removeStorageSync('shopId'); wx.removeStorageSync('mshopId'); wx.removeStorageSync('dealer_id'); console.error('用户拒绝授权:', event.detail.errMsg); } }, accountLogin() { let that = this wx.showLoading({ title: '登录中...', }) let version = wx.getStorageSync('version') if(version){ wx.login({ success: (ress) => { postUrl3(apiArr.accountLogin, { phone: that.data.account, pass: that.data.password, version, code:ress.code }, version, res => { wx.hideLoading() wx.hideLoading() if (res.token) { wx.setStorageSync('ctoken', res.token); wx.setStorageSync('is_deal', res.is_deal); wx.setStorageSync('is_dev', res.is_dev); wx.setStorageSync('is_shop', res.is_shop); postUrl(apiArr.loginInfo, {}, ress => { if (ress.error) return; // 保存userId 后续接口使用 wx.setStorageSync('userId', ress.user_id); wx.setStorageSync('openId', ress.open_id); wx.setStorageSync('shopId', ress.wshop_id); wx.setStorageSync('mshopId', ress.mshop_id); wx.setStorageSync('dealer_id', ress.dealer_id); this.setData({ isLogin: true, }) }, res.token) wx.showToast({ title: '登录成功', icon: 'success', mask: true, duration: 2000, success: () => { console.log(wx.getStorageSync('is_dev'),'isdev'); if(wx.getStorageSync('is_dev') == '0' || wx.getStorageSync('is_dev') == '1'){ wx.navigateTo({ url: '/pages/deposit/deposit', }) }else{ setTimeout(() => { this.tohome(); }, 2000) } } }); }else{ } }) }, }) } }, // 返回主页 tohome: function () { let that= this if(that.data.type == 'client'){ wx.redirectTo({ url: '/pages/water_filter/water_filter' }); }else{ if(wx.getStorageSync('is_master')){ wx.redirectTo({ url: '/packages/master/order/index' }); }else{ wx.showToast({ title: '您还不是师傅', icon: "none" }) setTimeout(() => { wx.redirectTo({ url: '/pages/chooseEntrance/chooseEntrance', }) }, 1500); } } }, backHomes(){ wx.redirectTo({ url: '/pages/chooseEntrance/chooseEntrance', }) }, })