var app = getApp(); var util = require("../../../../utils/util.js") let wxParse = require("../../../../wxParse/wxParse.js"); let pageid = "" Page({ /** * 页面的初始数据 */ data: { bottomLeft: app.bottomLeft, appAssetsUrl: app.appAssetsUrl, appAssetsUrl2: app.appAssetsUrl2, appAssetsUrl3: app.appAssetsUrl3, maskShow: false, options: {}, detail: {}, member: {}, content: '', vipActivityMessage: '', peopleList: [], people6: [], isMore: true, dotLeft: 0, open: true, schoolInfo: {}, roleList: ['平台管理员', '校园代理人', '行家', '行家;平台管理员', '行家;校园代理人'], dmoney: 0, point: 0, usePoints: 0, isWx: false, activeDetail: '', actualPrice: 0, // 实付价格 isDev: true //审核 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { pageid = this.options.id; let _this = this; let user = util.getUser(); this.setData({ options: { ...options, type: 2, //类型(1兼职 2活动) stuId: user ? user.id : '' } }) _this.loadData(); _this.loadVipSel(); _this.addRead(); _this.env() }, joinVip() { wx.navigateTo({ url: '/pages/myMember/myMember', }) }, collect: function () { let that = this if (util.getUserId()) { app._post_form('favorite/addOrCancelFavorite', "application/json", { sid: that.data.options.id, vipid: that.data.options.stuId, type: 2 //1:兼职 2:活动 }, function (res) { if (res.code == 0) { that.setData({ detail: { ...that.data.detail, collect: !that.data.detail.collect } }) wx.showToast({ title: that.data.detail.collect ? '收藏成功' : '取消收藏', icon: 'success', duration: 2000 }) } }) } else { wx.showToast({ title: '没有登录,操作失败', icon: 'fail', duration: 2000 }) } }, // 获取参与人员 getUser(id) { app._get(`activitystu/list`, { pid: id }, res => { if (res.code === 0) { this.setData({ people6: res.page.list.slice(0, 6), peopleList: res.page.list }) } }) }, //获取支付价格 getPayPrice() { let that = this // let actualPrice = this.data.open ? this.data.detail.money - this.data.dmoney : this.data.detail.money let id = util.getUserId(); app._get(`activity/eventRegistrationPayPrice`, { id: id, activityId: that.data.detail.id // actualPrice: actualPrice }, res => { if (res.code === 0) { this.setData({ actualPrice: res.data.actualPrice, }) } }) }, // 查看地图 goLocal() { let that = this let [latitude, longitude] = [this.data.detail.coordinate.split(',')[0], this.data.detail.coordinate.split(',')[1]] console.log(Number(latitude), Number(longitude)) wx.openLocation({ latitude: Number(longitude), longitude: Number(latitude), name: that.data.title, address: that.data.address, success: function () { console.log("success"); }, }); }, // 校园代理人信息 schoolUser(id) { app._get(`activity/activeCampusAgent`, { activityId: id }, res => { if (res.code === 0) { this.setData({ schoolInfo: res.data }) } }) }, showMore() { this.setData({ isMore: !this.data.isMore }) }, // 查看二维码 seeCode() { let that = this if (!that.data.detail.activityStuYN) { wx.showToast({ title: '报名后查看!', icon: 'none' }) return } this.popup3.showPopup(); this.setData({ maskShow: true }) }, // 报名是否抵扣积分 changeSwitch() { this.setData({ open: !this.data.open }) }, loadData: function () { let _this = this; wx.showLoading({ title: '努力加载中...', }) app._post_form('act/one', "", _this.data.options, function (res) { if (res.code === 0) { _this.setData({ detail: { ...res.data, startDate: res.data.startTime.replace(/-/g, '.').split(' ')[0], endDate: res.data.endTime.replace(/-/g, '.').split(' ')[0], startTime: res.data.startTime.split(' ')[1], endTime: res.data.endTime.split(' ')[1], registrationEnd: res.data.registrationEnd.replace(/-/g, '.'), meetingTime: res.data.meetingTime.replace(/-/g, '.') } }) _this.getUser(res.data.id) _this.schoolUser(res.data.id) _this.getPoint(res.data.id) // _this.getPayPrice() if (res.data.isAppletsRelease == 1) { // let str = Array.from(res.data.appletsDetails) _this.setData({ isWx: true }) } else { _this.setData({ isWx: false }) wxParse.wxParse('content', 'html', res.data.content, _this, 0); // wxParse.wxParse('content', 'html', res.data.content.replace(/</g,'<'), _this, 0); // wxParse.wxParse('content', 'html', res.data.content.replace(/(.*)</,'$1< '), _this, 0); } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { //获得popup组件 this.popup = this.selectComponent("#popup"); this.popup2 = this.selectComponent("#popup2"); this.popup3 = this.selectComponent("#popup3"); // 二维码 this.popup4 = this.selectComponent("#popup4"); // 提示升级开通会员/升级会员 this.popup5 = this.selectComponent("#popup5"); // 报名 this.popup6 = this.selectComponent("#popup6"); // 报名 }, addRead() { app._post_form('read/num', '', { id: this.data.options.id, type: 2 }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.PushVipInfo(); let user = util.getUser(); this.setData({ options: { ...this.data.options, stuId: user ? user.id : '' } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { return let _this = this if (_this.data.isyn) { app._post_form('favorite/addFavorite', "application/json", JSON.stringify(_this.data.parm), function (res) { console.log(res) }) } else { app._post_form('favorite/removeFavoriteByVipid', "application/json", JSON.stringify(_this.data .parm), function (res) { console.log(res) }) } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, //查询会员信息 PushVipInfo() { let _this = this; let id = util.getUserId(); if (id) { app._post_form('member/apiSelectMeberInfo', 'application/json', { id }, function ( res) { if (res.code === 0) { _this.setData({ member: res.member }) } }) } }, // 判断是否开发huanjing env() { let that = this app._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json', null, function (res) { if (res.code === 0) { that.setData({ isDev: res.wgFillInfo.isDev }) } } ) }, submit() { // console.log('submit', this.data.detail.statusName) // this.popup4.showPopup(); //报名满了 if (this.data.detail.statusName != '报名中') { wx.showToast({ title: `活动${this.data.detail.statusName}`, icon: 'none' }) return; } let that = this; if (util.UserLoginStatus()) { // 活动,会员免费,用户是会员用户 或者活动金额是0元 直接报名 if (this.data.detail.isNeedVip == 1 && (that.data.member.memberState > 0) || that.data.detail.money == 0) { that.signUp(); // 活动,会员免费,用户是普通用户 } else if (this.data.detail.isNeedVip == 1 && (that.data.member.memberState == 0)) { if (this.data.isDev) { wx.showToast({ title: '暂未开始报名,请关注进度!', icon: 'none', duration: 2000 }) return } that.popup4.showPopup(); } else { // 所有用户付费 that.popup5.showPopup(); } // if((this.data.detail.isNeedVip && (this.data.member.memberState > 0)) || !this.data.detail.isNeedVip){ // wx.showModal({ // title: '提示', // content: '您确定要报名该活动吗', // success (res) { // if (res.confirm) { // that.signUp(); // } // } // }) // that.popup5.showPopup(); // }else if(that.data.detail.isNeedVip == 0 && (that.data.member.memberState == 0)){ // that.popup4.showPopup(); // } // this.setData({ // maskShow: true // }) } }, confirmPay() { this.popup5.hidePopup(); this.singPay() }, singPay() { let that = this; let money = that.data.open ? that.data.actualPrice : that.data.detail.money console.log(money) if (money == 0) { return that.signUp() } wx.showLoading({ title: '提交中...', mask: true, }) let isDeductiblePrice = that.data.open ? 1 : 0 // act/register/wx 支付时用这个 app._post_form('act/register/wx', "", { aid: that.data.options.id, sid: that.data.options.stuId, isDeductiblePrice: isDeductiblePrice }, function (res) { if (res.code === 0) { wx.hideLoading(); if (!res.map) { wx.showToast({ title: "支付参数获取失败", icon: "none", duration: 1500, }); return; } wx.showLoading({ title: "正在处理...", mask: true, }); wx.requestPayment({ timeStamp: res.map.timestamp, nonceStr: res.map.nonce_str, package: "prepay_id=" + res.map.prepay_id, signType: "MD5", paySign: res.map.sign, success: (result) => { if (result.errMsg == "requestPayment:ok") { wx.showLoading({ title: "正在处理...", mask: true, }); // console.log(result, 11111111); wx.hideLoading(); that.popup3.showPopup(); wx.showModal({ title: "温馨提示", content: "报名成功!", showCancel: false, }); // that.loadData(); // setTimeout(()=>{ // wx.redirectTo({ // url: '/pages/my/myPlay/myPlay', // }) // },2000) } else { wx.hideLoading(); wx.showToast({ title: "支付失败!", icon: "none", duration: 1500, }); } }, fail: (error) => { wx.hideLoading(); wx.showToast({ title: "支付失败!", icon: "none", duration: 1500, }); }, }); // wx.showActionSheet({ // itemList: ["微信支付"], // success: (response) => { // if (response.tapIndex === 0) { // } // }, // fail(errors) {}, // }) } else if (res.msg == '请完善资料后进行报名操作') { wx.hideToast(); that.popup2.showPopup(); } else if (res.msg.indexOf('冻结阶段') > -1) { wx.hideToast(); wx.showToast({ title: res.msg, icon: 'none', duration: 3000 }) } else if (res.msg.indexOf('请完善真实姓名资料') > -1) { console.log(111111111111) that.popup6.showPopup(); } }) }, signUp() { let that = this; wx.showLoading({ title: '提交中...', }) let isDeductiblePrice = that.data.open ? 1 : 0 // act/register/wx 支付时用这个 app._post_form('act/register/wx', "", { aid: that.data.options.id, sid: that.data.options.stuId, isDeductiblePrice: isDeductiblePrice }, function (res) { if (res.code === 0) { wx.showToast({ title: "报名成功!", icon: "none", duration: 1500, }); // that.popup5.hidePopup(); that.popup3.showPopup(); // setTimeout(()=>{ // wx.redirectTo({ // url: '/pages/my/myPlay/myPlay', // }) // },2000) } else if (res.msg == '请完善资料后进行报名操作') { wx.hideToast(); that.popup2.showPopup(); } else if (res.msg.indexOf('冻结阶段') > -1) { console.log(res.msg) wx.hideToast(); wx.showToast({ title: res.msg, icon: 'none', duration: 3000 }) } else if (res.msg.indexOf('请完善真实姓名资料') > -1) { // console.log(111111111111) that.popup6.showPopup(); } }) }, loadVipSel() { let _this = this; wx.showLoading({ title: '努力加载中...', }) app._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json', null, function (res) { if (res.code === 0) { setTimeout(function () { wxParse.wxParse('vipActivityMessage', 'html', res.wgFillInfo.vipActivityMessage, _this, 5) }, 300) } } ) }, showShareMenu: function () { wx.showShareMenu(); this.setData({ show: true }) }, // 校园代理人详情 perDetail() { // console.log(e) let that = this let role = that.data.roleList[that.data.schoolInfo.memberRoleStatus - 1] wx.navigateTo({ url: '/expert/agentdetail/agentdetail?id=' + that.data.schoolInfo.id + '&activityId=' + that.data.detail.id + '&name=' + role }) }, hideShareMenu() { wx.hideShareMenu(); this.setData({ show: false }) }, /** * 用户点击右上角分享 */ onShareAppMessage() { this.addScore(); return { title: '活动详情', path: '/pages/home/index/activityDetail/activityDetail?id=' + pageid, desc: '欢迎大家踊跃报名', } }, //统计积分(每日小程序分享) addScore: function () { if (!util.getUserId()) { return; } wx.showLoading({ title: '努力加载中...', }) app._post_form('scoreStu/share', "", { stuId: util.getUserId() }, function (res) { if (res.code === 0) { } }) }, // 查询积分抵扣 getPoint(id) { app._get(`activity/eventRegistrationPayPrice`, { activityId: id, id: util.getUserId() }, res => { if (res.code === 0) { this.setData({ dmoney: res.data.deductiblePrice, point: res.data.remainingPoints, actualPrice: res.data.actualPrice, usePoints: res.data.usePoints, open: res.data.usePoints > 0 ? true : false }) } }) }, //取消事件 _error(e) { this[e.currentTarget.dataset.name].hidePopup(); if (e.currentTarget.dataset.name == 'popup4') { this.popup5.showPopup(); } else { this.setData({ maskShow: false }) } }, _error2(e) { this[e.currentTarget.dataset.name].hidePopup(); this.setData({ maskShow: false }) }, //确认事件 _success(e) { let that = this if (e.currentTarget.dataset.name == 'popup3') { } else if (e.currentTarget.dataset.name == 'popup5') { that.singPay(); } else if (e.currentTarget.dataset.name == 'popup4') { wx.navigateTo({ url: '/pages/myMember/myMember' }) } else if (e.currentTarget.dataset.name == 'popup2' || e.currentTarget.dataset.name == 'popup6') { wx.navigateTo({ // url: '/pages/my/myStudy/myStudy' url: '/pages/my/myData/myData', }) } else { wx.navigateTo({ url: e.currentTarget.dataset.name == 'popup' ? '/pages/myMember/myMember' : '/pages/my/myData/myData', }) } this.setData({ maskShow: false }) this[e.currentTarget.dataset.name].hidePopup(); }, seeBigCode(e) { let arr = [this.data.detail.qrCodePicture]; wx.previewImage({ urls: arr, // 需要预览的图片http链接列表 }); }, })