const app = getApp(); const commonUtil = require("../../utils/commonUtil.js"); Page({ /** * 页面的初始数据 */ data: { wxCode: '', hasUserInfo: '', balance: 0, auth: 0, user: {}, pmdUserInfo: {imgSrc:''}, showMoney:true, openId: '', isLogin: false, cardNum: 0, }, getPmdUserInfo: function() {//客户经理信息 var that = this; wx.request({ url: app.globalData.ip + "/agency/getPmdUserInfo", data: {}, header: app.globalData.headers, method: "GET", success: function(res) { console.log(res) if(res.data.status == 200) { console.log(res); that.setData({ pmdUserInfo: res.data.data }); } } }) }, showphone:function(){ if(app.globalData.isLogin) { this.setData({ iosDialog1: true }); } else { wx.navigateTo({ url: '/pages/login/index', }) } }, openEyes:function(){ this.setData({ showMoney:false }) }, closeEyes:function(){ this.setData({ showMoney:true }) }, close:function(){ this.setData({ iosDialog1: false }); }, toCollect:function(){ wx.navigateTo({ url: '../collect/index', }) }, makePhoneCall() { var that = this; wx.makePhoneCall({ phoneNumber: '13253506869', // that.data.pmdUserInfo.tel }); }, goMyinfo:function(){ wx.navigateTo({ url: '../user/myInfo/index', }) }, goMoney:function(){ wx.navigateTo({ url: '/pages/withdraw/index', }) }, goAgent:function(){ wx.navigateTo({ // url: '/pages/creatAgent/index?fromMiniApp=1', url: '/pages/creatAgent/index?fromMiniApp=1&pmdUserId=' + app.globalData.userId,//path }) }, toMakeInfo:function(){ wx.navigateTo({ url: '/pages/myInfo/index', // url: '/pages/makeInfo/index', }) }, toUrl: function(e) { wx.navigateTo({ url: e.currentTarget.dataset.url }) }, emptyMethod() { }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; //登录=================================start if (app.globalData.isLogin) { this.setData({ isLogin: app.globalData.isLogin, hasUserInfo: app.globalData.hasUserInfo, agencyStatus: app.globalData.agencyStatus, user: app.globalData.user, }); console.log(that.data.user); this.getPmdUserInfo(); } else { // 由于 userLogin 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userLoginCallback = res => { this.setData({ isLogin: app.globalData.isLogin, hasUserInfo: app.globalData.hasUserInfo, agencyStatus: app.globalData.agencyStatus, user: app.globalData.user, }); this.getPmdUserInfo(); } } let agencyUserId = options.agencyUserId; if(agencyUserId) { wx.setStorageSync('storageSyncAgencyUserId', agencyUserId); console.log('agencyUserId', agencyUserId) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, login:function(){ wx.navigateTo({ url: '/pages/login/index', }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { var that = this; this.wxLogin(); console.log('获取微信登录code=====>') if (!app.globalData.isLogin) { } else { this.getWalletInfo(); this.data.cardNum = 0; if (app.globalData.user.idauth == 1) { this.data.cardNum += 1; } if (app.globalData.user.healthAuth == 1) { this.data.cardNum += 1; } this.setData({ user: app.globalData.user, cardNum: this.data.cardNum, }); } this.setData({ isLogin: app.globalData.isLogin, hasUserInfo: app.globalData.hasUserInfo, }); //登录=================================start // if (app.globalData.isLogin) { // that.setData({ // isLogin: app.globalData.isLogin, // hasUserInfo: app.globalData.hasUserInfo, // }); // } else { // // 由于 userLogin 是网络请求,可能会在 Page.onLoad 之后才返回 // // 所以此处加入 callback 以防止这种情况 // app.userLoginCallback = res => { // that.wxLogin(); // that.setData({ // isLogin: app.globalData.isLogin, // hasUserInfo: app.globalData.hasUserInfo, // }); // } // } }, sys(){ wx.scanCode({ success (res) { console.log(res) } }) }, takePhoto() { const ctx = wx.createCameraContext() ctx.takePhoto({ quality: 'high', success: (res) => { this.setData({ src: res.tempImagePath }) } }) }, error(e) { console.log(e.detail) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, getWalletInfo: function() { var that = this; wx.request({ url: app.globalData.ip + "/wallet/info", data: { }, header: app.globalData.headers, method: "GET", success: function(res) { console.log(res) if(res.data.status == 200) { console.log(res); //绑定成功 that.setData({ balance: new Number(res.data.data.balance / 100).toFixed(2), auth: res.data.data.auth, }); } else { wx.showToast({ icon: "none", title: res.data.msg, }) } }, fail: function(res) { console.log("操作失败"); } }) }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { var path = commonUtil.getCurrentPageUrlWithArgs(); if(app.globalData.isLogin && app.globalData.agencyStatus - 0 != 0) {//当前用户是代理人 path += (path.indexOf('?') >= 0 ? '&' : '?') + 'agencyUserId=' + app.globalData.loginUserInfo.id; } console.log(path) return { "title":'稻田代理', 'path': path, } }, wxLogin() { var that = this; wx.login({ success(res) { if (res.code) { that.setData({ wxCode: res.code }); } else { console.log('获取code失败!' + res.errMsg) } } }) }, // makePhoneCall() { // console.log(1); // var that = this; // wx.makePhoneCall({ // // number: that.data.jobDetail.assistantUserTel + "" // phoneNumber:'18039237825' // }); // var that = this; // let res = wx.getStorageSync({ // key: "assistantUserTel" // }); // console.log(res); // console.log("缓存获取电话号:" + res.data); // if (app.isNotEmptyCheck(res.data)) { // wx.makePhoneCall({ // number: res.data // }); // } else { // wx.request({ // url: app.globalData.ip + "/store/job/getOneAssistantUser", // method: "POST", // header: app.globalData.headers, // data: {}, // success: function (res) { // console.log(res.data.data.tel); // wx.setStorageSync({ // key: "assistantUserTel", // data: res.data.data.tel // }); // wx.makePhoneCall({ // number: res.data.data.tel + "" // }); // } // }); // } // }, getPhoneNumber(e) { var that = this; console.log(e) console.log(e.detail.errMsg) if ("getPhoneNumber:ok" == e.detail.errMsg) {//同意 var iv = e.detail.iv; var encryptedData = e.detail.encryptedData; wx.checkSession({ success () { //session_key 未过期,并且在本生命周期一直有效 wx.request({ url: app.globalData.ip + '/getWechatTel', data: { code: that.data.wxCode, iv: iv, encryptedData: encryptedData, type: 'dtdl' }, success: function (res) { console.log(res); app.globalData.openId = res.data.data.openId; let promise = app.setLoginUserTokenInfo(res.data.data.phoneNumber, null); promise.then(res => { that.setData({ isLogin: app.globalData.isLogin, hasUserInfo: app.globalData.hasUserInfo, agencyStatus: app.globalData.agencyStatus, user: app.globalData.user, }); }) }, fail: function (res) { console.log("获取用户手机号错误"); } }) }, fail () { // session_key 已经失效,需要重新执行登录流程 wx.login({ success(res) { if (res.code) { console.log(res.code); //发起网络请求 wx.request({ url: app.globalData.ip + '/getWechatTel', data: { code: res.code, iv: iv, encryptedData: encryptedData, type: 'dtdl' }, success: function (res) { console.log(res); let promise = app.setLoginUserTokenInfo(res.data.data.phoneNumber, null); promise.then(res => { that.setData({ isLogin: app.globalData.isLogin, hasUserInfo: app.globalData.hasUserInfo, agencyStatus: app.globalData.agencyStatus, user: app.globalData.user, }); }) }, fail: function (res) { console.log("获取用户手机号错误"); } }) } else { console.log('获取手机号失败!' + res.errMsg) } } }) } }) } else {//拒绝 try { wx.setStorageSync('comeFromPage', 'me'); } catch (e) { console.log("0-页面跳转,设置参数错误:", e); } wx.navigateTo({ url: '/pages/login/index', }) } return false; }, getUserInfoBtn: function(e) { console.log(e) let that = this; wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) //发起网络请求 wx.request({ url: app.globalData.ip + '/updateUserWechatInfo', data: { nickName: res.userInfo.nickName, avatarUrl: res.userInfo.avatarUrl, gender: res.userInfo.gender, country: res.userInfo.country, province: res.userInfo.province, city: res.userInfo.city, }, method: "POST", header: app.globalData.headers, success: function(res) { console.log(res); app.globalData.hasUserInfo = 1; that.setData({ hasUserInfo: 1 }) // that.goMyinfo(); }, fail: function(res) { } }) }, fail: (res) => { console.log(res) } }) }, onShareTimeline(){}, info(){ wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res); this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) } })