From fbfd395a979c40c5651fb1f97e7022520a4568d8 Mon Sep 17 00:00:00 2001 From: cheng.xu Date: Fri, 10 Jan 2020 16:58:24 +0800 Subject: [PATCH] 助力首页数据填充及会员中心页面的助力判断 --- pages/user/assistance/assistance.js | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- pages/user/assistance/assistance.wxml | 14 +++++++++----- pages/user/assistance/task_assistance.js | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- pages/user/index/index.js | 19 ++++++++++++++++++- pages/user/index/index.wxml | 7 +++++++ 5 files changed, 206 insertions(+), 57 deletions(-) diff --git a/pages/user/assistance/assistance.js b/pages/user/assistance/assistance.js index 7cfb303..8d29625 100644 --- a/pages/user/assistance/assistance.js +++ b/pages/user/assistance/assistance.js @@ -1,17 +1,20 @@ -var i = require("../../../utils/util.js") -var e = getApp(), - a = e.globalData.setting, - os = a, - t = e.request, - d = e.globalData; +var t = getApp(), + a = t.request, + o = t.globalData.setting, + os = o, + i = require("../../../utils/util.js"), + ut = i, + s = require("../../../utils/common.js"); +var regeneratorRuntime = require('../../../utils/runtime.js'); +var oo = t.globalData.setting; Page({ /** * 页面的初始数据 */ data: { - url: a.url, //接口网址 - iurl: a.imghost, //图片前缀网址 + url: os.url, //接口网址 + iurl: os.imghost, //图片前缀网址 switch_head: 0, //0:我的任务,1:活动说明 zl_act: null, //助力活动 zl_user_list: [], //任务列表 @@ -19,6 +22,9 @@ Page({ cur_page: 1, //页码 page_num: 5, //每页多少个 is_show_more: 0, //是否加载更多 + help_id:"",//助力活动的id + timer:"",//任务列表的定时器 + }, /** @@ -28,54 +34,65 @@ Page({ var th = this; var nav_b = th.selectComponent("#nav_b"); //组件的id nav_b.set_name("助力", ""); + // 助力活动 + this.assistance(); }, /** * 生命周期函数--监听页面显示 */ onShow: function() { - var th = this; - e.request.get("http://172.20.3.102:8022/api/weshop/zl_act", { - success: function(res) { - if (res.data.code == 0) { - th.setData({ - zl_act: res.data.data + var th=this; + this.data.timer= setInterval(function () { + th.get_list(); + + },2000) + + }, + // 助力活动 + async assistance() { + var th=this; + var user_id = getApp().globalData.user_id; + var store_id = os.stoid; + + await getApp().request.promiseGet("/api/weshop/marketing/help/act/judge", { + data: { + storeId: store_id, + userId: user_id + } + }).then(res => { + if (res.data.code == 0) { + + var help_data=res.data.data; + console.log(help_data.id,'数据', res.data.data); + th.setData({ + zl_act:help_data, + help_id:help_data.id }); - } + } }) - this.get_list(); - - - }, - switch_head: function(e) { - var th = this; - var index = e.currentTarget.dataset.index; //获取当前选择的是任务还是活动说明 - var switch_head = th.data.switch_head; //0任务,1活动说明 - if (index != switch_head) { - th.setData({ - switch_head: index - }) - } }, - //关闭导航 - close: function() { + //--点击获取用户任务列表--会员的任务列表 + get_list:function() { var th = this; - var nav_b = th.selectComponent("#nav_b"); //组件的id - nav_b.close_box(); - }, - - //--点击获取用户任务列表-- - get_list: function() { - var th = this; - e.request.get("http://172.20.3.102:8022/api/weshop/zl_user_list", { + var help_id=this.data.help_id; + t.request.get("/api/weshop/marketing/help/help/user/page", { + data: { + userId:getApp().globalData.user_id, + storeId: os.stoid, + helpId: help_id + }, success: function(res) { + clearTimeout(th.data.timer); + if (!th.data.is_load) th.setData({ is_load: 1 }) if (res.data.code == 0) { + var list = th.data.zl_user_list; list = list.concat(res.data.data.pageData) //连接数组 th.setData({ @@ -102,7 +119,26 @@ Page({ //-----跳转到领取礼包的页面------ go_task: function() { - getApp().goto("/pages/user/assistance/task_assistance"); - } + var help_id=this.data.help_id; + + getApp().goto("/pages/user/assistance/task_assistance?help_id="+help_id); + }, + switch_head: function (e) { + var th = this; + var index = e.currentTarget.dataset.index; //获取当前选择的是任务还是活动说明 + var switch_head = th.data.switch_head; //0任务,1活动说明 + if (index != switch_head) { + th.setData({ + switch_head: index + }) + } + }, + + //关闭导航 + close: function () { + var th = this; + var nav_b = th.selectComponent("#nav_b"); //组件的id + nav_b.close_box(); + }, }) \ No newline at end of file diff --git a/pages/user/assistance/assistance.wxml b/pages/user/assistance/assistance.wxml index cafd04a..2fce9ba 100644 --- a/pages/user/assistance/assistance.wxml +++ b/pages/user/assistance/assistance.wxml @@ -1,4 +1,4 @@ - + @@ -11,11 +11,11 @@ 机会总是留给最有行动力的人 - + 活动时间: - {{filter.fm_time(zl_act.begindate)}}-{{filter.fm_time(zl_act.enddate)}} + {{filter.fm_time(zl_act.beginDate)}}-{{filter.fm_time(zl_act.endDate)}} @@ -62,12 +62,15 @@ + 点击加载更多 + + @@ -76,7 +79,7 @@ 已有 - 126 + {{zl_act.countAll}} 人领取了任务 @@ -88,7 +91,8 @@ - {{zl_act.remark}} + + diff --git a/pages/user/assistance/task_assistance.js b/pages/user/assistance/task_assistance.js index 299dc40..8c100df 100644 --- a/pages/user/assistance/task_assistance.js +++ b/pages/user/assistance/task_assistance.js @@ -1,5 +1,6 @@ var auth = require("../../../utils/auth.js"), rq = require("../../../utils/request.js"); -var e = getApp(), app = e, s = e.globalData.setting, os = s, app_d = e.globalData; +var e = getApp(), app = e, i = require("../../../utils/util.js"), + ut = i,s = e.globalData.setting, os = s, app_d = e.globalData; var regeneratorRuntime = require('../../../utils/runtime.js'); Page({ @@ -13,15 +14,7 @@ Page({ activity_data:"25:20:59",//活动剩余时间 task_number:12,//任务数 is_task:0,//历史记录与任务 - aitem:[ - { PrivilegeICOUrl:"https://mshopimg.yolipai.net/public/upload/userqy/ppt/2019/08-19/1e53fef14465c1f4db262fd569e78483.jpg",tite_name:'一页纸活动'},{ - PrivilegeICOUrl: "https://mshopimg.yolipai.net/public/upload/userqy/ppt/2019/08-19/aa50f43dc3b9dceff951cb2145c2df3b.jpg", tite_name: '辉煌活动' - },{ - PrivilegeICOUrl: "https://mshopimg.yolipai.net/public/upload/userqy/ppt/2019/08-19/5c2ff38b48ed350f2c54b19f0b9319e0.jpg", tite_name: '密码活动' - },{ - PrivilegeICOUrl: "https://mshopimg.yolipai.net//miniapp/images/plus/card_one.jpg", tite_name: '啊啊活动' - }, - ],//活动的轮播图 + aitem:"",//活动的轮播图 switch_head: 0, //0:我的任务,1:记录 }, @@ -29,6 +22,8 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { + var help_id=options.help_id; + console.log("是什么鬼",help_id); var th=this; th.close(); }, @@ -74,7 +69,7 @@ Page({ sw_index:ind }) }, - //关闭导航 + //导航球 close: function () { var th = this; var nav_b = th.selectComponent("#nav_b"); //组件的id @@ -93,8 +88,98 @@ Page({ * 生命周期函数--监听页面显示 */ onShow: function () { + var th=this; + /*-----统计-----*/ + rq.get("/api/weshop/zl_task", { + data: { user_id: app_d.user_id, + strod_id:os.stoid + }, + success: function (su) { + + var data=su.data; + console.log('waitlist5555555555' + data.code); + if (data.code!=0){ + getApp().my_warnning(data.msg,0, th); + return false; + } + if (data.code==0){ + //轮播图的数据 + var data_aissa=data.data.pageData; + //当前时间戳 + var nt = ut.gettimestamp(); + + data_aissa.forEach(function (val, ind) { + console.log(nt, "当前时间","结束时间", val.end_time,"开始时间"); + //已开始 + if (val.start_time < nt && val.end_time > nt) data_aissa[ind].status = 0; + //未开始 + else if (val.start_time > nt && val.end_time > nt) data_aissa[ind].status = 1; + //已结束 + + else if (val.start_time < nt && val.end_time < nt) data_aissa[ind].status = 2; + + }); + + console.log("是什么东西2222222222",data_aissa); + + th.setData({ aitem:data_aissa}); + + + } + + } + }) }, + //----助力任务----- + countDown() { + if (!this.data.is_timer) return false; + var th = this; + // 获取当前时间,同时得到活动结束时间数组 + var newTime = ut.gettimestamp(); + var List = this.data.aitem; + for (var j = 0; j < List.length; j++) { + var endTimeList = List[j]; + // 对结束时间进行处理渲染到页面 + for (var i = 0; i < endTimeList.length; i++) { + var o = endTimeList[i]; + var endTime = o.end_time + if (o.status == 0) endTime = o.start_time + + var obj = null; + // 如果活动未结束,对时间进行处理 + if (endTime - newTime > 0) { + var time = (endTime - newTime); + // 获取天、时、分、秒 + var day = parseInt(time / (60 * 60 * 24)); + var hou = parseInt(time % (60 * 60 * 24) / 3600); + var min = parseInt(time % (60 * 60 * 24) % 3600 / 60); + var sec = parseInt(time % (60 * 60 * 24) % 3600 % 60); + obj = { + day: this.timeFormat(day), + hou: this.timeFormat(hou), + min: this.timeFormat(min), + sec: this.timeFormat(sec) + } + } else { + //活动已结束,全部设置为'00' + obj = { + day: '00', + hou: '00', + min: '00', + sec: '00' + } + } + var txt = "aitem[" + j + "][" + i + "].djs"; + th.setData({ + [txt]: obj + }); + } + + } + setTimeout(th.countDown, 1000); + + }, /** * 生命周期函数--监听页面隐藏 diff --git a/pages/user/index/index.js b/pages/user/index/index.js index 7e4dfd7..5763ed0 100644 --- a/pages/user/index/index.js +++ b/pages/user/index/index.js @@ -34,6 +34,7 @@ Page({ giftbagid:"",//生日活动的类型 actId:"",//生日活动的id actImg:"", + is_assistance:0,//助力活动 }, goto_nav: function (e) { var th = this; @@ -51,6 +52,7 @@ Page({ */ onLoad: function (options) { this.birthday(); + this.is_assistance(); }, /** @@ -486,7 +488,22 @@ Page({ getApp().showWarning("请稍后重试"); } - } + }, + // 判断助力活动是不是存在 + is_assistance:function(){ + var th = this; + rq.get("/api/weshop/marketing/help/act/judge", { + data: { storeId: os.stoid, userId: app_d.user_id }, + success: function (res) { + var code = res.data.code; + if (code == 0) { + th.setData({ is_assistance:1}); + } + + } + }) + + } diff --git a/pages/user/index/index.wxml b/pages/user/index/index.wxml index 9b5ab7a..dfde448 100644 --- a/pages/user/index/index.wxml +++ b/pages/user/index/index.wxml @@ -228,6 +228,13 @@ 我的礼包 + + + + 助力活动 + + + -- libgit2 0.21.4