// mycustomer/pages/channelsignup/channelsignup.js const app = getApp(); var utils = require("../../../utils/http"); Page({ /** * 页面的初始数据 */ data: { loginFlag: false, mobileflag: false, canIUseGetUserProfile: false, mobile: true, companyobj: {}, aid: '', detail: { is_poster:2 }, status:'0',//0是授权个人信息,1是授权手机号 codeimg:'', isign:0, useversion:app.globalData.useversion }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } wx.showLoading({ title: '加载中...', }) if (!!options.scene) { options = unescape(options.scene); let arr = options.split('&'); let obj = {}; for (let i = 0; i < arr.length; i++) { let arr1 = arr[i].split('='); obj[arr1[0]] = arr1[1]; } this.setData({ aid: obj.id }) app.globalData.clientype = obj.ctp; } else { this.setData({ aid: options.id }) app.globalData.clientype = options.ctp; } this.channelActivity(); }, /** * 登录 */ logindata: function (type) { var that = this; if(type==1){ that.setData({ loginFlag: false, status:1 }) } wx.login({ success: function (data) { if (data.errMsg == 'login:ok') { utils.$post({ url: app.globalData.webUrl + 'api/users/code2sessionmini', data: { client_type: that.data.clientype, code: data.code, }, success: function (r) { if (r.data.code == '0') { app.globalData.sharepersonobj = r.data.share; app.globalData.token = r.data.token; that.sharecompany(); if (!!r.data.user.phone) { wx.hideLoading(); app.globalData.use_id = r.data.user.id; app.globalData.personMsg = r.data.user; app.globalData.userflag = false; //有个人信息 app.globalData.phone = true; //有手机号 that.setData({ loginFlag: false, status:0, mobileflag:false }) if(type==1){ that.setData({ isign:1 }) that.signUp(); }else{ that.channelmsg(); } } else { that.channelmsg(); wx.hideLoading(); that.setData({ status:0, loginFlag: false, mobileflag: true }) } } } }) } wx.hideLoading(); } }) }, /** * 获取公司信息 */ sharecompany: function () { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/index/content_belong_company', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { client_type: app.globalData.clientype, uid: app.globalData.shareuserid }, success: function (res) { if (res.data.code == '0') { app.globalData.companyobj=res.data.data; that.setData({ companyobj: res.data.data }) } }, complete(res) { wx.hideLoading() } }) }, channelfun(){ const that=this; that.logindata('1'); }, channelmsg() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/huoma/code_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid:app.globalData.personMsg.id }, success: function (res) { // res.data.data.is_sing=0; if (res.data.code == '0') { that.setData({ isign:res.data.data.is_sing }) if (res.data.data.is_sing == '1') { that.setData({ loginFlag: false }) that.signUp('2'); } else { if(that.data.detail.is_poster!=2){ that.setData({ loginFlag: true, mobile:true }) }else{ that.setData({ loginFlag: false, mobile:false }) } } } }, complete(res) { } }) }, /** * 渠道活动信息 */ channelActivity() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/huoma/code_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid }, success: function (res) { if (res.data.code == '0') { // res.data.data.code_data.is_poster=1; that.setData({ detail: res.data.data.code_data, isign:res.data.data.is_sing }) } that.logindata(); }, complete(res) { } }) }, getUserInfoTap:function(res){ var that=this; console.log(res) if(res.detail.errMsg=='getUserInfo:ok'){ utils.$post({ method: "POST", url: app.globalData.webUrl + 'api/users/setUserInfo', data: { encryptedData:res.detail.encryptedData, iv:res.detail.iv, rawData:res.detail.rawData, signature:res.detail.signature, }, header: { 'Authorization':'bearer '+app.globalData.token }, success: function (r) { if(r.data.code=='0'){ that.setData({ status:1 }) app.globalData.userflag=true;//有个人信息 that.logindata('1'); }else{ if(r.data.code=='403'){ that.logindata(); return false } wx.showToast({ title: r.data.msg, icon: "none", duration:2000 }); } } }) } }, getUserProfile:function(){ var that=this; wx.getUserProfile({ lang:'zh_CN', desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) if(res.errMsg=="getUserProfile:ok"){ utils.$post({ method: "POST",//TESTAPIURL APIURL/users/auth url: app.globalData.webUrl + 'api/users/setUserInfo', data: { encryptedData:res.encryptedData, iv:res.iv, rawData:res.rawData, signature:res.signature, }, header: { 'Authorization':'bearer '+app.globalData.token }, success: function (r) { if(r.data.code=='0'){ that.setData({ status:1 }) app.globalData.userflag=true;//有个人信息 that.logindata('1'); }else{ if(r.data.code=='403'){ that.logindata(); return false } wx.showToast({ title: r.data.msg, icon: "none", duration:2000 }); } } }) } } }) }, /** * 报名 */ getPhoneNumberTap (res) { let that = this; console.log(res) if (res.detail.errMsg == 'getPhoneNumber:ok') { utils.$post({ url: app.globalData.webUrl + 'api/users/setUserMobile', data: { encryptedData: res.detail.encryptedData, iv: res.detail.iv }, header: { 'Authorization': 'bearer ' + app.globalData.token }, success: function (r) { if (r.data.code == '0') { app.globalData.phone = true; app.globalData.personMsg.phone = r.data.mobile; that.setData({ status:1 }) that.logindata('1'); } else { wx.showToast({ title: r.data.msg, icon: "none", duration: 2000 }); } } }) } }, /** * 报名 */ signUp() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/huoma/send_qrcode', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid: app.globalData.use_id, mobile: app.globalData.personMsg.phone }, success: function (res) { if (res.data.code == '0') { if(that.data.detail.is_poster!=2){ if(that.data.isign==1){ wx.redirectTo({ url: '/mycustomer/pages/success/success?qrlink=' + encodeURIComponent(res.data.data), }) }else{ that.setData({ codeimg:res.data.data }) } }else{ wx.redirectTo({ url: '/mycustomer/pages/success/success?qrlink=' + encodeURIComponent(res.data.data), }) } } else { wx.showToast({ title: res.data.msg, icon: 'none', duration: 1500 }) } }, complete(res) { wx.hideLoading() } }) wx.hideLoading() }, lookimgtap(){ wx.previewImage({ current: this.data.codeimg, // 当前显示图片的 http 链接 urls: [this.data.codeimg] // 需要预览的图片 http 链接列表 }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareappMessage() { } })