//logs.js const util = require('../../../utils/util.js') var _request = require('../../../utils/request.js') var version = getApp().globalData.version var channel // 渠道二维码信息 var scene // 渠道二维码id var url = '' // 分享或模板落地页 var invite = 0 //邀请id var poster = [] var project = [] Page({ data: { userInfo: {}, balance: 0, integral:0, silver:0, bindTel: false, checkData: {}, merchant: {}, info: {}, show: 0, checkhead:true, wxlogincode:'', bindTelfirst:0, cashbalance:0, kfqr:'',//客服二维码 showqr:false }, onLoad: function () { //// console.log(options) // url = 0 // if (options.scene) { // scene = decodeURIComponent(options.scene) // if (scene.indexOf('invite_wx_') > -1) { // invite = scene.slice(10) // } else if (scene.indexOf('poster') > -1) { // this.getPoster(scene) // } else if (scene.indexOf('project') > -1) { // this.getPosterProject(scene) // } else { // this.getScene(scene) // } // } else if (options.url) { // this.urlHandle(options) // } // if (options.invite) { // invite = options.invite // } // var that = this this.checkLogin(); this.info(); }, onShow: function () { var that = this; // that.checkLogin(); this.info(); that.getBalanceInfo() that.getCashBalanceInfo() this.getqcode() // that.getIntegralInfo() // if (this.data.bindTel) { // this.getBalanceInfo() // this.getIntegralInfo() // if (that.data.checkData.merchant_id > 0) { // that.getmerchant() // } // } else { // // this.check() // // this.info() // } //原登陆检测 }, checkLogin:function(){ var that = this; //2020登陆检测 wx.login({ success: res => { getApp().globalData.try_login = true; console.log('checkLogin',res.code) var url = 'xcx/login'; invite = wx.getStorageSync('invite'); var params = { code: res.code, invite_id: invite//新token模式 } that.setData({ wxlogincode: res.code }) var success = function (res) { console.log('pageLogin',res); wx.setStorageSync('lbt_session_key', res.data.session_key) wx.setStorageSync('lbt_session_time', Date.now()) wx.setStorageSync('lbt_token_key', res.data.token) console.log('nowtoken',res.data.token); if(res.data.wx_user && res.data.wx_user.head != ''){ var userInfo = res.data.wx_user; that.setData({ userInfo: userInfo }) that.info() that.getBalanceInfo() that.getCashBalanceInfo() // that.getIntegralInfo() // if (that.data.checkData.merchant_id > 0) { // that.getmerchant() // } //checkwxhead---start // console.log('that.data.checkhead',that.data.checkhead); if(res.data.wx_user.head == '' ){ that.setData({ checkhead: false }) wx.getSetting({ success: res => { var auth = res.authSetting if (auth['scope.userInfo']) { console.log('wxhead none') // wx.getUserInfo({ // success: function(res3) { // console.log('userinfo',res3) // var url = 'xcx/save_wx_user/info' // var params = { // userinfo: JSON.stringify(res3) // } // var success = function (res4) { // console.log('authorize',res4) // that.onShow() // } // _request.$post(url, params, success) // } // }) //新授权 wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: function(res3) { console.log('userinfo',res3) var url = 'xcx/save_wx_user/info' var params = { userinfo: JSON.stringify(res3.userInfo) } var success = function (res4) { console.log('authorize',res4); that.onLoad() } _request.$post(url, params, success) } }) }else{ that.setData({ userInfo: 'nologin' }) } } }) } //checkwxhead---end }else{ that.setData({ userInfo: 'nologin' }) } } _request.$get(url, params, success) } }) }, getPoster: function (val) { poster = val.split('$') if (poster.length > 0) { invite = poster[2] } }, getPosterProject: function (val) { project = val.split('$') if (project.length > 0) { invite = project[2] } }, urlHandle: function (val) { if (val.url) { url = val.url + '?' for (var i in val) { if (i !== 'url') { url += i + '=' + val[i] + '&' } } } }, getScene: function () { var that = this var url = 'v1/xcx/channel/info/' + scene var params = {} var success = function (res) { channel = res.data } _request.$get(url, params, success) }, getUserInfo: function (val) { var channel_id = 0; invite = wx.getStorageSync('invite'); if (channel && Number(channel.parent_id) > 0) { channel_id = Number(channel.parent_id) } var that = this if (val.detail.errMsg === 'getUserInfo:ok') { wx.showLoading({ title: '加载中' }) console.log('val',val) // _request.sendInfo(val, channel_id, invite, that) that.onLoad(); // wx.showToast({ // title: '请绑定手机号~', // icon: 'none', // duration: 2000 // }) // wx.navigateTo({ // url: '/packageUser/pages/user/bind/bind' // }) } }, getUserProfile:function(){ console.log('tap') var that = this // wx.getUserProfile({ // desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 // success: (res) => { // this.setData({ // userInfo: res.userInfo, // hasUserInfo: true // }) // var channel_id = 0; // invite = wx.getStorageSync('invite'); // if (channel && Number(channel.parent_id) > 0) { // channel_id = Number(channel.parent_id) // } // var that = this // console.log('res',res); // if (res.errMsg === "getUserProfile:ok") { // wx.showLoading({ // title: '加载中' // }) // res['wxlogincode'] = that.data.wxlogincode; // _request.sendInfo(res, channel_id, invite, that) // that.onShow(); // } // } // }) wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: function(res3) { console.log('userinfo',res3) var url = 'xcx/save_wx_user/info' var params = { userinfo: JSON.stringify(res3.userInfo) } var success = function (res4) { console.log('authorize',res4) that.onLoad() } _request.$post(url, params, success) } }) }, getVersion: function (val) { // this.check() }, info(){ console.log('oninfo'); var that = this var url = 'v1/user/info' var params = {} var success = function (res) { console.log(res) that.setData({ info: res.data, show: res.data.wx_user?res.data.wx_user.show_invite_mode:'', bindTel: res.data.user.tel ? true : false }) console.log('untel',res.data.user.tel) console.log('res.data.wx_user',res.data.wx_user) if(res.data.wx_user.head == ''){ console.log('indddddddddddddddddddddddd') that.setData({ userInfo: 'nologin' }) } if(that.data.userInfo != 'nologin' && res.data.user.tel == '' && that.data.bindTelfirst == 0){ that.setData({ bindTelfirst:1 }) wx.navigateTo({ url: '/packageUser/pages/user/bind/bind' }) wx.showToast({ title: '请先绑定手机号~', icon: 'none', duration: 2000 }) } } _request.$get(url, params, success) }, check () { var that = this var url = 'v1/user/check' var params = { cache: false } var success = function (res) { if (res.data.wx_user_id <= 0) { wx.login({ success: res => { _request.login(res) } }) } else { that.setData({ checkData: res.data }) if (that.data.checkData.merchant_id > 0) { that.getmerchant() } if (res.data.user_id > 0 && !that.data.bindTel) { // that.setData({ // bindTel: true // }) that.getBalanceInfo() that.getCashBalanceInfo() // that.getIntegralInfo() that.info() } } } _request.$get(url, params, success) }, buyVoucher(){ if(this.data.info.user.tel == ''){//未绑定手机号 wx.navigateTo({ url: '/packageUser/pages/user/bind/bind' }) wx.showToast({ title: '请先绑定手机号~', icon: 'none', duration: 2000 }) //2020 wx.setStorageSync('bindbackurl', '/packageUser/pages/user/buy/buy'); //存入手机绑定后跳转页面 }else{ wx.navigateTo({ url: '/packageUser/pages/user/buy/buy' }) } }, getmerchant () { var that = this var url = 'v1/merchant/orders/count' var params = { merchant_id: that.data.checkData.merchant_id } var success = function (res) { var result = res.data that.setData({ merchant: result }) console.log(that.data.merchant) } _request.$get(url, params, success) }, getBalanceInfo () { var that = this var url = 'v1/user/balance/info' var params = { } var success = function (res) { var result = res.data.total that.setData({ balance: result, silver: res.data.silver_total }) } _request.$get(url, params, success) }, getCashBalanceInfo () { var that = this var url = 'v1/user/cash/balance/info' var params = { } var success = function (res) { var result = res.data.total that.setData({ cashbalance: result }) } _request.$get(url, params, success) }, getSilverInfo () { var that = this var url = 'v1/user/cent/info' var params = { } var success = function (res) { var result = res.data.total that.setData({ integral: result }) } _request.$get(url, params, success) }, toInviteList () { var that = this; if(that.data.info.user.tel == ''){ wx.navigateTo({ url: '/packageUser/pages/user/bind/bind' }) wx.showToast({ title: '请先绑定手机号~', icon: 'none', duration: 2000 }) }else{ wx.navigateTo({ url: '/packageUser/pages/user/invite/invite' }) } }, // checkbindtel(){ // var that = this; // if(that.data.info.user.tel == ''){ // setTimeout(function(){ // wx.navigateTo({ // url: '/packageUser/pages/user/bind/bind' // }) // wx.showToast({ // title: '请先绑定手机号~', // icon: 'none', // duration: 2000 // }) // },500) // } // }, toCashList () { if(this.data.info.user.tel == ''){//未绑定手机号 wx.navigateTo({ url: '/packageUser/pages/user/bind/bind' }) wx.showToast({ title: '请先绑定手机号~', icon: 'none', duration: 2000 }) //2020 wx.setStorageSync('bindbackurl', '/packageUser/pages/user/fund/fund'); //存入手机绑定后跳转页面 }else{ wx.navigateTo({ url: '/packageUser/pages/user/fund/fund' }) } }, toUserInfo() { wx.navigateTo({ url: '/packageUser/pages/user/userInfo/userInfo' }) }, toBindOldSys () { let that = this; wx.navigateTo({ url: '/packageUser/pages/user/bindoldsys/bindoldsys?id='+that.data.userInfo.id }) }, toPromotion () { wx.navigateTo({ url: '/packageUser/pages/user/promotion/promotion' }) }, toIdentity () { wx.navigateTo({ url: '/packageUser/pages/user/identity/identity' }) }, toBankInfo () { wx.navigateTo({ url: '/packageUser/pages/user/bankinfo/bankinfo' }) }, toAddressList () { wx.navigateTo({ url: '/packageUser/pages/user/address/address' }) }, toRadish () { wx.navigateTo({ url: '/packageUser/pages/user/radish/radish' }) }, toCash () { wx.navigateTo({ url: '/packageUser/pages/user/cash/cash' }) }, toIntegral () { wx.navigateTo({ url: '/packageUser/pages/user/integral/integral' }) }, toSilver () { wx.navigateTo({ url: '/packageUser/pages/user/silver/silver' }) }, toSafe () { wx.navigateTo({ url: '/packageUser/pages/user/safe/safe' }) }, toCustom () { wx.reLaunch({ url: '/pages/customservice/customservice' }) }, toProxy () { wx.navigateTo({ url: '/packageUser/pages/user/proxyList/proxyList' }) }, toApplyLeader () { wx.navigateTo({ url: '/packageUser/pages/user/applyLeader/applyLeader' }) }, toAreaCart () { wx.navigateTo({ url: '/pages/areacart/areacart' }) }, toBindTel () { wx.navigateTo({ url: '/packageUser/pages/user/bind/bind' }) }, toAbout () { var host = getApp().globalData.d5c if (host === 'tm.d5ct.com') { wx.navigateTo({ url: '/pages/parse/parse?id=2' }) } else if (host === 'm.d5ct.com') { wx.navigateTo({ url: '/pages/parse/parse?id=1' }) } }, toMerchant () { wx.navigateTo({ url: '/packageMerchant/pages/merchant/orders/orders?id=' + this.data.checkData.merchant_id + '&is_super_admin=' + this.data.checkData.is_super_admin }) }, toMerchant1 () { wx.navigateTo({ url: '/packageMerchant/pages/merchant/accounts/accounts?id=' + this.data.checkData.merchant_id }) }, onShareAppMessage: function (val) { return _request.share({ sc: 'xcx_user' }) }, getqcode: function () { var that = this var url = 'v1/customer_service/qrcode' var params = {} var success = function (res) { that.setData({ kfqr: res.data }) } _request.$get(url, params, success) }, tiggerQR:function(){ this.setData({ showqr: !this.data.showqr }) }, catchtapQR:function(){ console.log('catchtapQR'); } })