|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- // 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,//是否有地址
- },
- /**
- * 关闭任务窗
- */
- hiddenTask:function(){
- this.setData({
- maskShow: false,
- taskShow: false
- })
- },
- /**
- * 签到
- */
- signIn() {
- app.wxRequest(app.globalData.urlRoot +"task/signToday",{},res=>{
- if (res.code == 200) {
- if (!this.data.shareId) {
- this.setData({
- maskShow: false
- })
- } else {
- this.setData({
- isSign: false,
- isShare: true,
- 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.getSignInfo();
- this.getAddress();
- if (this.data.isFriendShare) {
- this.useShareId();
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- 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){
- if (this.data.isAddress){
- wx.redirectTo({
- url: '/pages/myCenter/myCenter'
- })
- }else{
- wx.navigateTo({
- url: '/pages/address/address',
- })
- }
- }else{
- wx.showToast({
- title: res.msg,
- icon:"none"
- })
- }
- },this);
- },
- getSignInfo: function () {//查看当日是否签到
- app.wxRequest(app.globalData.urlRoot + "task/getSignInfo", {}, res => {
- this.getShareId();
- if(res.code==200){
- if (res.data.state==0) {//未签到
- this.setData({
- showClose: false,
- maskShow: true,
- taskShow: true,
- isSign: true
- })
- }
- }
- },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 => {
- console.log(res);
- this.setData({
- maskShow:false
- })
- }, 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
- })
- }
- })
|