const app = getApp(); const utils = require("../../../utils/http"); let time = 0; var timer = null; Page({ /** * 页面的初始数据 */ data: { imgUrl: app.globalData.imgUrl, aid: '', activityobj: {}, collect: 0, loading: false, loginFlag: true, phoneFlag: false, canIUseGetUserProfile: false, articlelogin: true, datashow: false, mobile: false, companyobj: [], show: false, date: '', brokerId: '', aType: '', minDate: new Date(2022, 0, 1).getTime(), maxDate: new Date(2023, 0, 1).getTime(), qrcode: '', qrcodeflag:false, employeeflag:false, top:app.globalData.statusBarHeight, hgt:app.globalData.titleBarHeight, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; wx.hideHomeButton(); time = 0; if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } 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]; } if (!!obj.uid) { app.globalData.shareuserid = obj.uid; } if (!!obj.bid) { this.setData({ brokerId: obj.bid }) } if (!!obj.t) { this.setData({ aType: obj.t }) } app.globalData.clientype = obj.ctp; this.setData({ aid: obj.aid, }) } else { app.globalData.clientype = options.ctp; if (!!options.uid) { app.globalData.shareuserid = options.uid; } if (!!options.bid) { this.setData({ brokerId: options.bid }) } if (!!options.t) { this.setData({ aType: options.t }) } this.setData({ aid: options.aid, }) } that.logindata(); }, 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() } }) }, logindata: function () { var that = this; wx.showLoading(); wx.login({ success: function (data) { if (data.errMsg == 'login:ok') { utils.$post({ url: app.globalData.webUrl + 'api/users/code2sessionmini', data: { code: data.code, share: app.globalData.shareuserid, client_type:app.globalData.clientype }, success: function (r) { if (r.data.code == '0') { app.globalData.sharepersonobj = r.data.share ? r.data.share : r.data.user; app.globalData.token = r.data.token; // that.listfun(); that.sharecompany(); // r.data.user.headimgurl=''; // r.data.user.nickname=''; app.globalData.personMsg = r.data.user; app.globalData.companyname=r.data.company; app.globalData.official_openid = r.data.official_openid; app.globalData.agentEmployeEid = r.data.agent_employee_id; if (!!r.data.user.phone) { app.globalData.use_id = r.data.user.id; app.globalData.personMsg = r.data.user; that.setData({ loginFlag: true, datashow: true, phoneFlag: false, employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false, }) that.unreadMsg(); if (!!r.data.user.binded && r.data.user.binded.state == '在职'){ app.globalData.currentUserId = r.data.user.binded.id; } } else { that.unreadMsg(); wx.hideLoading(); that.setData({ articlelogin: false, loginFlag: true, phoneFlag: true, }) } } } }) } wx.hideLoading(); } }) }, golastap: function () { // wx.navigateBack() wx.navigateBack({ delta: 1, success:function(r){ }, fail:function(r){ wx.reLaunch({ url: '/pages/index/index?state=1', }) }, }) }, goindextap:function(){ if(!this.data.employeeflag){ wx.reLaunch({ url: '/pages/index/index', }) }else{ wx.reLaunch({ url: '/pages/consoledesk/consoledesk', }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, getUserInfoTap: function (res) { var that = this; console.log(res) if (res.detail.errMsg == 'getUserInfo:ok') { utils.$post({ method: "POST",//TESTAPIURL APIURL/users/auth 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({ loginFlag: true, phoneFlag: true }) app.globalData.userflag = true;//有个人信息 } else { 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({ loginFlag: true }) app.globalData.userflag = true;//有个人信息 that.setData({ phoneFlag: true }) } else { wx.showToast({ title: r.data.msg, icon: "none", duration: 2000 }); } } }) } } }) }, getPhoneNumberTap: function (res) { var that = this; if (res.detail.errMsg == 'getPhoneNumber:ok') { wx.showLoading() that.setData({ phoneFlag: false }) utils.$post({ method: "POST",//TESTAPIURL APIURL/users/auth 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.personMsg.phone = r.data.mobile; app.globalData.phone = true; that.bindfun(); } else { that.setData({ phoneFlag: true }) wx.showToast({ title: r.data.msg, icon: "none", duration: 2000 }); } } }) } }, onClose() { this.activitybind(); this.setData({ show: false }) }, onConfirm(event) { this.setData({ show: false, date: this.formatDate(event.detail), }); this.activitybind(); }, formatDate(date) { date = new Date(date); return `${date.getMonth() + 1}/${date.getDate()}`; }, bindfun: function () { wx.showLoading({ title: '报名中...', }) let that = this; that.setData({ loading: true }) if (that.data.aType && that.data.aType == 'b') { utils.$post({ url: app.globalData.webUrl + 'api/agents/add_activity_customer', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { phone: app.globalData.personMsg.phone, aid: that.data.aid, agent_id: that.data.brokerId }, success: function (res) { wx.hideLoading(); if (res.data.code == '0') { let activityobj = that.data.activityobj; activityobj.is_activity = 1; that.setData({ activityobj: activityobj, qrcode:res.data.url, }) setTimeout(() => { that.setData({ loading: false }) },1500) wx.previewImage({ current: res.data.url, // 当前显示图片的 http 链接 urls: [res.data.url] // 需要预览的图片 http 链接列表 }) wx.showToast({ title: '报名成功,请等待专业人员和您联系!', icon: 'none', duration: 2000 }) } else { that.setData({ loading: false }) wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) } } }) } else { utils.$post({ url: app.globalData.webUrl + 'client/activity/activity_sign', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { phone: app.globalData.personMsg.phone, aid: that.data.aid, employee_id: '', uid: app.globalData.shareuserid, date: '', }, success: function (res) { wx.hideLoading(); if (res.data.code == '0') { let activityobj = that.data.activityobj; activityobj.is_activity = 1; that.setData({ activityobj: activityobj, qrcode:res.data.url, }) setTimeout(() => { that.setData({ loading: false }) },1500) wx.previewImage({ current: res.data.url, // 当前显示图片的 http 链接 urls: [res.data.url] // 需要预览的图片 http 链接列表 }) wx.showToast({ title: '报名成功,请等待专业人员和您联系!', icon: 'none', duration: 2000 }) } else { that.setData({ loading: false }) wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) } } }) } }, lookimgtap(){ this.setData({ qrcodeflag:true }) }, closeqrcodetap(){ this.setData({ qrcodeflag:false }) }, unreadMsg: function () { this.setData({ datashow: true }) wx.showLoading({ title: '加载中...', }) this.activityfun(); }, activityfun: function () { var that = this; if (that.data.aType && that.data.aType == 'b') { utils.$post({ url: app.globalData.webUrl + 'api/agents/activity_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid: app.globalData.personMsg.id }, success: function (res) { if (res.data.code == '0') { that.setData({ qrcode:res.data.data.qrcode, activityobj: res.data.data, loginFlag: true, minDate: new Date(res.data.data.start_date.split('-')[0], res.data.data.start_date.split('-')[1] - 1, res.data.data.start_date.split('-')[2]).getTime(), maxDate: new Date(res.data.data.end_date.split('-')[0], res.data.data.end_date.split('-')[1] - 1, res.data.data.end_date.split('-')[2]).getTime(), }) wx.setNavigationBarTitle({ title: res.data.data.title }) if (res.data.data.timestate == 2 && res.data.data.show == 1) { wx.showToast({ title: "本次活动已结束", icon: "none", duration: 2000 }); } else if (res.data.data.show == 0) { wx.showToast({ title: "本次活动已下架", icon: "none", duration: 2000 }); } } setTimeout(function () { wx.hideLoading() }, 300) } }) } else { utils.$post({ url: app.globalData.webUrl + 'client/activity/details', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid: app.globalData.personMsg.id }, success: function (res) { if (res.data.code == '0') { that.setData({ qrcode:res.data.data.qrcode, activityobj: res.data.data, loginFlag: true, minDate: new Date(res.data.data.start_date.split('-')[0], res.data.data.start_date.split('-')[1] - 1, res.data.data.start_date.split('-')[2]).getTime(), maxDate: new Date(res.data.data.end_date.split('-')[0], res.data.data.end_date.split('-')[1] - 1, res.data.data.end_date.split('-')[2]).getTime(), }) wx.setNavigationBarTitle({ title: res.data.data.title }) if (res.data.data.timestate == 2 && res.data.data.show == 1) { wx.showToast({ title: "本次活动已结束", icon: "none", duration: 2000 }); } else if (res.data.data.show == 0) { wx.showToast({ title: "本次活动已下架", icon: "none", duration: 2000 }); } } setTimeout(function () { wx.hideLoading() }, 300) } }) } }, paytap: function () { var that = this; wx.showLoading({ title: '拉起支付中...', }) utils.$post({ url: app.globalData.webUrl + 'client/pay/mini', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, name: app.globalData.personMsg.nickname, phone: app.globalData.personMsg.phone, type: 'activity' }, success: function (rest) { if (rest.data.code == '0') { let activityobj = that.data.activityobj; wx.requestPayment({ timeStamp: rest.data.data.timeStamp, nonceStr: rest.data.data.nonceStr, package: rest.data.data.package, signType: rest.data.data.signType, paySign: rest.data.data.paySign, success(rs) { wx.showToast({ title: '支付成功', icon: 'success', duration: 1000 }) activityobj.had_pay = 1; that.setData({ activityobj: activityobj }) }, fail(r) { console.log(r) }, complete: res => { wx.hideLoading() } }) } } }) }, getpaytap: function () { wx.showToast({ title: '请勿重复交定', icon: 'success', duration: 1000 }) }, activitytap: function () { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, type: 'activity', }, success: function (r) { } }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { timer = setInterval(function () { time = time * 1 + 1; }, 1000) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { if (timer) { clearInterval(timer); } this.visitimefun(); }, visitimefun() { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/index/visit_due_time', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, pipe_type: 'activity', time: time, }, success: function (res) { } }) }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { this.visitimefun(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, dothis(){}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, addsharetap: function (type) { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: '0', type: type, }, success: function (r) {} }) }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (this.data.aType && this.data.aType == 'b') { var img = this.data.activityobj.cover; return { title: this.data.activityobj.title, imageUrl: img, path: '/share/pages/activitymsg/activitymsg?aid=' + this.data.aid + '&bid=' + this.data.brokerId + '&ctp=' + app.globalData.clientype + '&t=b', }; } else { this.addsharetap('toolAll'); let uid = app.globalData.shareuserid ? app.globalData.shareuserid : app.globalData.personMsg.id; var img = this.data.activityobj.poster; return { title: this.data.activityobj.title, imageUrl: img, path: '/share/pages/activitymsg/activitymsg?aid=' + this.data.aid + '&uid=' + uid + '&ctp=' + app.globalData.clientype, }; } } })