// pages/specialDiscussion/index.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { barHeight: "", navBarHeight: "", tabList: [{ name: '即将直播', amount: '' }, { name: '直播回放', amount: 20 }], tabIndex: 0, specialSubjectList: [], now: new Date(), // 假设这是当前时间 formattedDate: '', // 用于存储格式化后的日期时间字符串 batList: [], specialDiscussionList: [], searchValue: '', batListValue: '', loading: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.formatDateTime() const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 this.setData({ barHeight: systInfo.statusBarHeight, navBarHeight: navBarHeight, }); this.ceShiList() this.getCourseTypeListList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() {}, onShareTimeline() {}, goBack() { wx.navigateBack(); }, onTabsChange(event) { console.log(event.detail.value); const value = event.detail.value this.setData({ batListValue: value }) this.specialDiscussionGet(this.data.batList[value]) }, onTabsTap(event) { const index = event.currentTarget.dataset.index console.log(index); this.setData({ tabIndex: index }) this.specialDiscussionGet(this.data.batList[0]) }, // 获取即将开播列表 ceShiList() { this.setData({ loading: true }) let searchObj = {} if (this.data.searchValue) { searchObj = { 'Name*': this.data.searchValue.trim() } } app.MG.store .getProductList({ storeInfo: app.config.seminar, path: '*', queryType: '*', paging: { start: 0, size: 99 }, fields: { content: [], subtitle: [], backgroundSelection: [], author: [], viewCount: [], startTime: [], //开播时间 endTime: [], liveTime: [], lecturer: [], position: [], jsek_link: [], ...searchObj } }) .then((res) => { console.log(res, '000'); const specialSubjectList = [] res.datas.forEach((item) => { item.price = item.price.toFixed(2) const date1 = new Date(this.data.formattedDate) const date2 = new Date(item.endTime) if (date1 < date2) { specialSubjectList.push(item) } }) this.setData({ specialSubjectList, loading: false, "tabList[0].amount": specialSubjectList.length }) }) }, // 格式化日期时间的方法 formatDateTime: function () { let date = new Date(); const year = date.getFullYear(); const month = (date.getMonth() + 1).toString().padStart(2, '0'); const day = date.getDate().toString().padStart(2, '0'); const hour = date.getHours().toString().padStart(2, '0'); const minute = date.getMinutes().toString().padStart(2, '0'); const second = date.getSeconds().toString().padStart(2, '0'); const formattedDate = `${year}-${month}-${day} ${hour}:${minute}:${second}`; this.setData({ formattedDate: formattedDate }); }, onLink(e) { const item = e.currentTarget.dataset.item console.log(item.jsek_link); wx.navigateTo({ url: '/pages/specialDiscussion/webView/index?link=' + item.jsek_link }); }, async getCourseTypeListList() { const quer = { path: '*', filterList: [{ value: 'Normal', field: 'state' }], queryType: '\\', searchList: [], size: '20', start: '0', storeRefCode: app.config.seminar, sort: { type: 'Asc', field: 'LinkOrder' }, } const data = await app.MG.store.getStoreChannelList(quer) let dataList = [] data.datas.forEach(item => { if (item.refCode != "jsek_homepageSeminar") { console.log(item); dataList.push(item) } }) this.setData({ batList: dataList }) this.specialDiscussionGet(data.datas[0]) }, // 获取直播回放 specialDiscussionGet(item) { let searchObj = {} if (this.data.searchValue) { searchObj = { 'Name*': this.data.searchValue.trim() // '||subtitle*': searchInputValue.value.trim() } } const data = [] app.MG.store .getProductList({ storeInfo: 'jsek_seminar', path: item.refCode, queryType: '*', paging: { start: 0, size: 99 }, fields: { content: [], subtitle: [], backgroundSelection: [], author: [], viewCount: [], startTime: [], endTime: [], liveTime: [], lecturer: [], position: [], jsek_link: [], ...searchObj } }) .then((res) => { res.datas.forEach((item) => { item.price = item.price.toFixed(2) const date1 = new Date(this.data.formattedDate) const date2 = new Date(item.endTime) // 比较两个日期 if (date1 > date2) { data.push(item) } }) this.setData({ specialDiscussionList: data, "tabList[1].amount": data.length, }) console.log(this.data.specialDiscussionList); }) }, searchBook() { console.log(this.data.searchValue); this.ceShiList() this.specialDiscussionGet(this.data.batList[this.data.batListValue]) }, })