// pages/activity/index.js var app = getApp() import util from "../../../utils/util" import commonApi from "../../../utils/https/common" Page({ /** * 页面的初始数据 */ data: { selectDay:new Date().getTime(), days: ['日','一','二','三','四','五','六'], weeks:[], pageNo:1, list:[], date:null, total:1, areas:['姑苏','吴江','苏州'], area:0, type:1 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let d = new Date(); let month = d.getMonth() + 1,day = d.getDate(); month = month>10?month:("0"+month); day = day>10?day:("0"+day); this.setData({ selectDay:d.getTime(), date:d.getFullYear()+"-"+month+"-"+day }) this.getWeekDay(); commonApi._post("pbservice/Other/getSuzhouAreas").then(res=>{ res.data.unshift({ area_code:"", area_name:"苏州" }) this.setData({ areas:res.data }) this.getList() }) }, changeType:function(e){ this.setData({ type:e.currentTarget.dataset.type, list:[], total:1, pageNo:1 }) this.getList(); }, changeArea:function(e){ this.setData({ area:e.detail.value, list:[], total:1, pageNo:1 }) this.getList() }, // 获取当前选择日期的一周日期范围 getWeekDay:function(){ var myDate = this.data.selectDay, daySecond = 24 * 60 * 60 * 1000,reslist=[]; for (let i = myDate - daySecond * 3; i <= myDate + daySecond * 3; i = i + daySecond){ let day = new Date(i),putDate = day.getDate(); putDate = putDate>=10?putDate:'0'+putDate let item = { times:i, day:this.data.days[day.getDay()], date:putDate, isSelect:i==myDate }; reslist.push(item); } this.setData({ weeks: reslist }) }, // picker修改日期 bindDateChange:function(e){ console.log(e) this.setData({ selectDay: new Date(e.detail.value).getTime(), list:[], pageNo:1, total:1, date:e.detail.value }) this.getWeekDay(); this.getList(); }, // 点击修改日期 changeDate:function(e){ let times = e.currentTarget.dataset.times,d = new Date(times); let month = d.getMonth()+1,day = d.getDate(); month = month>10?month:('0'+month); day = day>10?day:('0'+day); this.setData({ selectDay: times, date:d.getFullYear()+"-"+month+"-"+day, list:[], pageNo:1, total:1 }) this.getList(); }, getList:function(){ let list = this.data.list; if(list.length>=this.data.total) return; commonApi._post(this.data.type==1?'pbservice/Actcalendar/getActList':'pbservice/Actcalendar/getInfoList',{ page_no:this.data.pageNo, date:this.data.date, area_key:this.data.areas[this.data.area].area_code, page_num:10 }).then(res=>{ this.setData({ total:res.data.total, list:list.concat(res.data.rows), pageNo:this.data.pageNo+1 }) }) }, gotoDetail:function(e){ let item = e.currentTarget.dataset.item; if(this.data.type==1){ wx.navigateTo({ url: '/pages/info/activityInfo/index?id='+item.id, }) } else { wx.navigateTo({ url: '/pages/info/newsInfo/index?id='+item.id, }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getList() }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })