123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- userInfo:{},
- getUserInfo: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onShow: function () {
- this.setData({
- userInfo: app.globalData.userInfo
- })
- if (wx.getUserProfile) {
- this.setData({
- getUserInfo: true
- })
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- wx.stopPullDownRefresh();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: "晋爱人才",
- path: "/pages/home/home/home",
- };
- },
- getUserInfo: function(e) {
- let self = this;
- let userInfo = app.globalData.userInfo ? app.globalData.userInfo : {};
- app.post('user/profile/userInfo',{user_nickname:e.detail.userInfo.nickName,avatar:e.detail.userInfo.avatarUrl},function(res){
- userInfo.user_nickname = e.detail.userInfo.nickName;
- userInfo.avatar = e.detail.userInfo.avatarUrl;
- app.globalData.userInfo = userInfo;
- self.setData({userInfo:userInfo});
- });
- },
- getUserProfile: function(e) {
- let self = this;
- wx.getUserProfile({
- desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (e) => {
- let userInfo = app.globalData.userInfo ? app.globalData.userInfo : {};
- app.post('user/profile/userInfo',{user_nickname:e.userInfo.nickName,avatar:e.userInfo.avatarUrl},function(res){
- userInfo.user_nickname = e.userInfo.nickName;
- userInfo.avatar = e.userInfo.avatarUrl;
- app.globalData.userInfo = userInfo;
- self.setData({userInfo:userInfo});
- });
- }
- })
- },
- uploadAvatar(e) {
- let self = this;
- const { avatarUrl } = e.detail;
- wx.showLoading({
- mask: true,
- });
- var token = wx.getStorageSync('token');
- wx.uploadFile({
- url: app.globalData.api_host + 'user/profile/avatarUpload',
- filePath: avatarUrl,
- name: 'file',
- header: { 'X-Requested-With': 'XMLHttpRequest' , 'XX-Device-Type': 'wxapp' , 'XX-Token': token},
- success(res) {
- var json = JSON.parse(res.data)
- if (json.code == 1) {
- wx.hideLoading();
- self.setData({"userInfo.avatar": json.data});
- app.globalData.userInfo = self.data.userInfo;
- } else {
- wx.showToast({
- title: '上传失败,请重试',
- icon: 'none'
- });
- }
- },
- fail() {
- wx.showToast({
- title: '上传失败,请重试',
- icon: 'none'
- });
- }
- });
- },
- //跳转
- toInfo() {
- if (!this.data.userInfo.user_nickname) {
- app.msg('请先授权登录');
- } else {
- wx.navigateTo({
- url: '/pages/my/info/info',
- })
- }
- },
- toJoin() {
- if (!this.data.userInfo.user_nickname) {
- app.msg('请先授权登录');
- } else {
- wx.navigateTo({
- url: '/pages/my/join/join',
- })
- }
- },
- toBaidu() {
- wx.navigateTo({
- url: '/pages/home/webview/webview',
- })
- },
- toFeedback() {
- if (!this.data.userInfo.user_nickname) {
- app.msg('请先授权登录');
- } else {
- wx.navigateTo({
- url: '/pages/my/feedback/feedback',
- })
- }
- },
- toRob() {
- if (!this.data.userInfo.user_nickname) {
- app.msg('请先授权登录');
- } else {
- wx.navigateTo({
- url: '/pages/my/rob/rob',
- })
- }
- },
- toBind() {
- if (!this.data.userInfo.user_nickname) {
- app.msg('请先授权登录');
- } else {
- wx.navigateTo({
- url: '/pages/my/bind/bind',
- })
- }
- },
- toScore() {
- if (!this.data.userInfo.user_nickname) {
- app.msg('请先授权登录');
- } else {
- wx.navigateTo({
- url: '/pages/my/score/score',
- })
- }
- },
- //扫码
- scan() {
- if (!this.data.userInfo.user_nickname) {
- app.msg('请先授权登录');
- return false;
- }
-
- let self = this;
- wx.scanCode({
- success ({result}) {
- let arr = result.split(':');
- console.log(arr);
- if (arr[0] == 'signin') {
- self.signin(arr[1]);
- } else if (arr[0] == 'business') {
- self.business(arr[1]);
- } else {
- app.msg('未知二维码!');
- }
- },
- fail(res) {
- if (res.errMsg != "scanCode:fail cancel") {
- app.msg('扫码错误,请重新扫码!');
- }
- }
- });
- },
- signin(param) {
- let data = param.split(',');
- app.post('activity/activity/signin',{activity_id:data[0],code:data[1]},function(res){
- app.msg(res.msg);
- });
- },
- business(id) {
- if (!this.data.userInfo.user_nickname) {
- app.msg('请先授权登录');
- return false;
- }
- wx.navigateTo({
- url: '/pages/business/detail/detail?is_scan=1&id='+id,
- })
- }
- })
|