// pages/everyday/everyday.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { imgUrl: app.globalData.urlStatic,//图片路径 showRule:false,//是否显示游戏规则 showClose:true, maskShow: false, taskShow: false, taskName:'', taskImgUrl:'', isSign:false, isShare:false, picturlList: [], picturlCurrent:0, shareId:null, isFriendShare:false,//是否朋友分享过来的 isAddress:false,//是否有地址 getReward:null, tipWindow:0, hiddenFriendFrame:false, }, /** * 关闭任务窗 */ hiddenTask:function(){ this.setData({ maskShow: false, taskShow: false }) }, /** * 签到 */ signIn() { app.wxRequest(app.globalData.urlRoot +"task/signToday",{},res=>{ if (res.code == 200) { this.getShareId(); this.setData({ maskShow: false, isSign: false, isShare: false, showClose: true }) }else{ wx.showToast({ title: res.msg, icon:"none" }) } },this,"POST"); }, /** * 下个碎片 */ nextPicturl(){ var max = this.data.picturlList.length-1; var current = this.data.picturlCurrent + 1; if (current <= max){ this.setData({ picturlCurrent: current }) } }, //上一个碎片 prevPicturl(){ var current = this.data.picturlCurrent - 1; if (current >= 0) { this.setData({ picturlCurrent: current }) } }, /** * 星探任务 */ goScout(){ wx.navigateTo({ url: '../scout/scout' }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { app.globalData.nowPage = 2; if (options.shareId) { this.data.isFriendShare = options.shareId; } if (app.globalData.openid) { this.loadFun(); } else { app.globalData.openidSuccessFuc = this.loadFun; } }, loadFun: function () { this.getTaskProgress(); this.getAddress(); if (this.data.isFriendShare) { this.useShareId(); }else{ this.getSignInfo(); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function (e) { if (e.from == "button") { return { title: '我正在参与“星探计划”,快来帮我解锁拼图吧,共享大奖!', imageUrl: this.data.imgUrl + "/shareImgs/" + Math.floor(Math.random() * 8 + 1) + ".jpg", path: this.data.shareId ? "/pages/everyday/everyday?shareId=" + this.data.shareId : "/pages/everyday/everyday" } }else{ return app.sharePack(); } }, getTaskProgress: function () {//获取任务完成度 app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: 1 }, res => { if (res.code == 200) { this.setData({ picturlList: res.data }) } else { wx.showToast({ title: res.msg, icon: "none" }) } }, this); }, receive:function(){//领取购车红包 this.getTaskAward(); }, getAddress: function () {//获取地址 app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => { if (res.code == 200) { if(res.data){ this.data.isAddress = true; } } else { wx.showToast({ title: res.msg, icon: "none" }) } }, this); }, getTaskAward:function(){//领取购车券 wx.wxRequest(app.globalData.urlRoot + "task/getTaskAward", { awardGiveId: this.data.picturlList[this.data.picturlCurrent]['awardGiveId']},res=>{ if(res.code==200){ this.setData({ getReward:res.data }) if (res.data.needAddress && this.data.isAddress) { this.setData({ tipWindow:2 }) } else if (res.data.needAddress==0){ this.setData({ tipWindow: 2 }) } else if (res.data.needAddress && !this.data.isAddress){ this.setData({ tipWindow: 1 }) } }else{ wx.showToast({ title: res.msg, icon:"none" }) } },this); }, receive:function(){ wx.redirectTo({ url: '/pages/myCenter/myCenter' }) }, userRegister: function () { wx.navigateTo({ url: '/pages/address/address', }) }, getSignInfo: function () {//查看当日是否签到 app.wxRequest(app.globalData.urlRoot + "task/getSignInfo", {}, res => { if(res.code==200){ if (res.data.state==0) {//未签到 this.setData({ showClose: false, maskShow: true, taskShow: true, isSign: true }) }else{ this.getShareId(); } } },this) }, getShareId: function () {//获取分享id(查询今日是否已被助力) app.wxRequest(app.globalData.urlRoot + "task/getShareId", {}, res => { if (res.code == 200) { if (res.data.shareId){ this.setData({ showClose: true, maskShow: true, taskShow: true, isShare: true }) } this.setData({ taskName: "集齐启辰星【" + res.data.shortName+"】碎片1/4", taskImgUrl: res.data.popPicUrl, }) this.data.shareId = res.data.shareId; } }, this) }, useShareId: function (shareId) {//发起助力 app.wxRequest(app.globalData.urlRoot + "task/useShareId", { shareId: this.data.isFriendShare}, res => { if(res.code==200){ this.setData({ hiddenFriendFrame: true, useShareData: res.data, maskShow: false }) } else { this.getSignInfo(); // wx.showToast({ // title: res.msg, // icon:"none" // }) } }, this,"POST") }, swiperChange(e) {//通过鼠标滑动改变swiper时 if (e.detail.source == "touch") { this.setData({ picturlCurrent: e.detail.current, }) } }, ruleControl:function(e){ this.setData({ showRule: e.currentTarget.dataset.state }) }, hiddenFriendTip: function () { this.getSignInfo(); this.setData({ hiddenFriendFrame:false }) } })