123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705 |
- 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,
- };
- }
- }
- })
|