|
- // 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,//是否有地址
- isAddressShow:false,//是否显示完善个人信息弹窗
- getReward:null,
- tipWindow:0,
- hiddenFriendFrame: false,
- userData: null,
- signState:true,
- signData:null,
- totalSignDay:0,
- addressShow: false,
- ani1: null,
- ani2: null,
- ani3: null,
- ani4: null,
- },
- /**
- * 关闭任务窗
- */
- hiddenTask:function(){
- this.setData({
- maskShow: false,
- taskShow: false
- })
- },
- /**
- * 签到
- */
- signIn() {
- app.wxRequest(app.globalData.urlRoot +"task/signToday",{},res=>{
- if (res.code == 200) {
- this.getTaskProgress();
- this.setData({
- signState: 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() {
- app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfo", {}, res => {
- console.log(res);
- if (res.code == 200) {
- if (!app.globalData.certificationInfo) {
- app.globalData.certificationInfo = true;
- wx.setStorageSync("certificationInfo", true);
- }
- app.globalData.certificationState = res.data.certificationState;
- wx.navigateTo({
- url: '/pages/scout/scout'
- })
- } else if (res.code == -307) {
- wx.navigateTo({
- url: '/pages/mobileVerification/mobileVerification'
- })
- } else if (res.code == -308) {
- wx.navigateTo({
- url: '/pages/scout/register/register'
- })
- }
- }, this);
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- app.globalData.nowPage = 2;
- if (app.globalData.userInfoData) {
- this.setData({
- userData: app.globalData.userInfoData
- })
- }
- if (options.shareId) {
- this.data.isFriendShare = options.shareId;
- }
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- },
- loadFun: function () {
- if (!app.globalData.addPageEnterState.everyday) {
- app.addPageEnter("800C896F3ED88D22DDE9C125CE61D0D2");
- app.globalData.addPageEnterState.everyday = true;
- }
- this.getTaskProgress();
- this.getAddress();
- // if (this.data.isFriendShare) {
- // this.useShareId();
- // }else{
-
- // }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (e) {
- if (e.from == "button") {
- return {
- title: '我正在参与“星探计划”,快来帮我解锁拼图吧,共享大奖!',
- imageUrl: this.data.taskImgUrl,
- // 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 => {
- this.getSignInfo();
- if (res.code == 200) {
- this.setData({
- picturlList: res.data.taskData,
- totalSignDay: res.data.totalSignDay
- })
- } 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(){//领取购车券
- if (!this.data.isAddress){
- this.setData({
- isAddressShow:true
- })
- return;
- }
- app.wxRequest(app.globalData.urlRoot + "award/getTaskAward", { awardGiveId: this.data.picturlList[this.data.picturlCurrent]['awardGiveId']},res=>{
- if(res.code==200){
- this.data.picturlList[this.data.picturlCurrent]['awardState'] = -1;
- this.setData({
- getReward:res.data[0],
- picturlList: this.data.picturlList
- })
- // if (res.data.needAddress != 0 && !this.data.isAddress){
- // this.setData({
- // tipWindow: 2
- // })
- // } else if (res.data.needAddress == 0){
- this.setData({
- tipWindow: 1
- })
- // }
- }else{
- wx.showToast({
- title: res.msg,
- icon:"none"
- })
- }
- },this);
- },
- 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.aniFun(500, 0, res.data.popData.childId);
- setTimeout(()=>{
- this.aniFun(500, 1, res.data.popData.childId);
- setTimeout(() => {
- this.aniFun(500, 0, res.data.popData.childId);
- setTimeout(() => {
- this.aniFun(500, 1, res.data.popData.childId);
- setTimeout(() => {
- this.setData({
- signState: false,
- signData: res.data.popData,
- picturlCurrent: res.data.popData.parentId - 1
- })
- }, 500)
- }, 500)
- }, 500)
- }, 500)
- }
- }
- },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
- })
- }
- var taskName = "集齐启辰星【" + res.data.shortName + "】碎片" + res.data.completeNum + "/" + res.data.childTotal;
- this.setData({
- taskName: taskName,
- 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){
- wx.navigateTo({
- url: '/pages/fragmentRule/fragmentRule'
- })
- // this.setData({
- // showRule: e.currentTarget.dataset.state
- // })
- },
- hiddenFriendTip: function () {
- // this.getSignInfo();
- this.setData({
- hiddenFriendFrame:false
- })
- },
- getUserWxMsg: function (e) {
- if (e.detail.errMsg == "getUserInfo:ok") {
- this.setData({
- userData: e.detail.userInfo
- })
- app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
- }
- },
- closeWindow:function(){//
- this.setData({
- tipWindow:0
- })
- },
- lookAddress: function () {
- this.addressControl();
- },
- tipWindow: function () {
- this.setData({
- isAddressShow: false
- })
- },
- addressControl: function () {//跳转到地址管理
- this.setData({
- addressShow: !this.data.addressShow
- })
- if (this.data.addressShow == false){
- this.tipWindow();
- }
- if (this.data.isAddress == false && this.data.addressShow==false) {
- this.getAddress();
- }
- },
- aniFun(duration, opacity,nums,type) {
- var animation = wx.createAnimation({
- duration: duration
- });
- if (type) {
- animation.scale(type).step();
- } else {
- animation.opacity(opacity).step();
- }
- if (nums == 1) {
- this.setData({
- ani1: animation.export()
- })
- } else if (nums == 2) {
- this.setData({
- ani2: animation.export()
- })
- } else if (nums == 3) {
- this.setData({
- ani3: animation.export()
- })
- } else if (nums == 4) {
- this.setData({
- ani4: animation.export()
- })
- }
- }
- })
|