//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, bindTel: false, checkData: {}, merchant: {}, info: {}, show: 0, checkhead:true }, 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(); }, onShow: function () { var that = this; this.info(); if (this.data.bindTel) { this.getBalanceInfo() this.getIntegralInfo() if (that.data.checkData.merchant_id > 0) { that.getmerchant() } } else { this.check() // this.info() } that.checkLogin(); //原登陆检测 }, checkLogin:function(){ var that = this; //2020登陆检测 wx.login({ success: res => { getApp().globalData.try_login = true; var url = 'xcx/login' var params = { code: res.code } var success = function (res) { console.log('pageLogin',res); if(res.data.wx_user){ var userInfo = res.data.wx_user that.setData({ userInfo: userInfo }) //checkwxhead---start console.log('that.data.checkhead',that.data.checkhead); if(res.data.wx_user.full_head == '' && that.data.checkhead){ 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) } }) }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: '加载中' }) _request.sendInfo(val, channel_id, invite, that) that.onShow(); // wx.showToast({ // title: '请绑定手机号~', // icon: 'none', // duration: 2000 // }) // wx.navigateTo({ // url: '/packageUser/pages/user/bind/bind' // }) } }, getVersion: function (val) { this.check() }, info(){ 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.show_invite_mode }) } _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.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 }) } _request.$get(url, params, success) }, getIntegralInfo () { 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 () { wx.navigateTo({ url: '/packageUser/pages/user/invite/invite' }) }, 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' }) } }, toBindOldSys () { let that = this; wx.navigateTo({ url: '/packageUser/pages/user/bindoldsys/bindoldsys?id='+that.data.userInfo.id }) }, 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' }) }, toIntegral () { wx.navigateTo({ url: '/packageUser/pages/user/integral/integral' }) }, 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' }) } })