You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

171 lines
3.6 KiB

// pages/culture/index.js
import commonApi from "../../utils/https/common"
Page({
/**
* 页面的初始数据
*/
data: {
weeks:[],
selectDay:"",
date:null,
days: ['日','一','二','三','四','五','六'],
top:0,
tags:[],
tagKey:"",
page_no:1,
total:1,
list:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let d = new Date(),that = this;
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
})
const query=wx.createSelectorQuery(); //创建节点查询器
query.select("#types").boundingClientRect() //选择toViewid获取位置信息
query.exec(function(res) {
console.log(res)
that.setData({
top:res[0].top
})
})
this.getWeekDay();
// 获取分类
commonApi._post("pbservice/Culture/getCultureCategory",{
}).then(res=>{
this.setData({
tags:res.data,
tagKey:res.data[0].key
})
this.getList()
})
},
// picker修改日期
bindDateChange:function(e){
this.setData({
selectDay: new Date(e.detail.value).getTime(),
list:[],
page_no: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:[],
page_no:1,
total: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
})
},
changeTag:function(e){
this.setData({
tagKey:e.currentTarget.dataset.tag,
page_no:1,
list:[],
total:1
})
this.getList()
},
getList:function(){
if(this.data.total<=this.data.list.length) return;
commonApi._post("pbservice/Culture/getCultureList",{
page_no:this.data.page_no,
page_num:20,
date:this.data.date,
cate_id:this.data.tagKey
}).then(res=>{
this.setData({
total:res.data.total,
list:this.data.list.concat(res.data.rows),
page_no:this.data.page_no+1
})
console.log(res)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.getList()
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})