|
- // pages/everyday/everyday.js
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- showClose:false,
- maskShow: false,
- taskShow: false,
- taskName:'',
- taskImgUrl:'',
- isSign:false,
- isShare:false,
- picturlList: [],
- picturlCurrent:0,
- isRegister:false,//是否已注册
- 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.getOrderInfo();
- this.getShareId();
- this.getAddress();
- if (this.data.isFriendShare) {
- this.useShareId();
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- 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"
- }
- },
- 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);
- },
- getOrderInfo: function () {//查询是否已注册
- app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
- if (res.code == 200) {
- if (res.data) {
- this.setData({
- isRegister: true
- })
- // app.globalData.isRegister = true;
- app.globalData.userMobile = res.data.mobile;
- }
- } else {
- console.log(res.msg)
- }
- }, 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.isRegister){
- // if (res.data.needAddress) {
- // if (!this.data.isAddress) {
- // wx.navigateTo({
- // url: '../address/address',
- // })
- // }else{
- // wx.redirectTo({
- // url: '../myCenter/myCenter'
- // })
- // }
- // }else{
- wx.redirectTo({
- url: '../myCenter/myCenter'
- })
- // }
- }else{
- wx.navigateTo({
- url: '../receiveRegister/receiveRegister',
- })
- }
- }else{
- wx.showToast({
- title: res.msg,
- icon:"none"
- })
- }
- },this);
- },
- 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{
- if (this.data.shareId){
- this.setData({
- showClose: true,
- maskShow: true,
- taskShow: true,
- isShare: true
- })
- }
- }
- }
- },this)
- },
- getShareId: function () {//获取分享id(查询今日是否已被助力)
- app.wxRequest(app.globalData.urlRoot + "task/getShareId", {}, res => {
- this.getSignInfo();
- if (res.code == 200) {
- 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,
- })
- }
- }
- })
|