// pages/digitalTextbooks/digitalTextbooks.js const app = getApp() import { getPublicImage } from "../../assets/js/middleGround/tool"; import { setSessionGuid, setNewView, storage } from "../../assets/js/userAction"; Page({ /** * 页面的初始数据 */ data: { barHeight: "", navBarHeight: "", searchValue: "", tabPanelstyle: 'display:flex;justify-content:center;align-items:center;', tabList: [], selectedIndex: 0, digitalTextbooksData: [], // path: "jsek_dTHigherEducation", path: "*", loading: true, sorter: { value: "*", options: [{ value: "*", label: "默认排序", }, { value: "nameAsc", label: "点击量正序", }, { value: "nameDesc", label: "点击量倒序", }, { value: "timeAsc", label: "创建时间正序", }, { value: "timeDesc", label: "创建时间倒序", }, ], }, sortActive: '' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { 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.getCourseTypeListList() this.bookExhibitionGet() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, onShareTimeline() {}, //新加的函数 getCourseTypeListList() { const data = { path: '*', filterList: [{ value: 'Normal', field: 'state' }], queryType: '\\', searchList: [], size: '20', start: '0', storeRefCode: app.config.digitalTextbooks, sort: { type: 'Asc', field: 'LinkOrder' } } app.MG.store.getStoreChannelList(data).then((res) => { // 去除数组最后一个元素 const newData = res.datas.slice(0, res.datas.length - 1) // 遍历数组并添加新的属性 newData.forEach((item) => { item.titleIcon = getPublicImage(item.icon, '', '160') }) newData.unshift({ name: '全部', refCode: '*' }) this.setData({ tabList: newData }) console.log(1, this.data.tabList); }) }, goBack() { wx.navigateBack(); }, selectTab(e) { let index = e.detail.value this.setData({ selectedIndex: index }) this.setData({ path: this.data.tabList[index].refCode }) this.bookExhibitionGet() }, onSort(e) { this.setData({ "sortActive": e.detail.value, }); console.log(e) this.bookExhibitionGet() }, // 获取图片文字列表 bookExhibitionGet(keyword) { // console.log(path.value, '456') // loading.value = true let searchObj = {} let sort = {} // 搜索框 if (keyword) { searchObj = { 'Name*': keyword.trim(), '||subtitle*': keyword.trim() } } if (this.data.sortActive == 'nameAsc') { sort = { ViewCount: 'Asc' } } else if (this.data.sortActive == 'nameDesc') { sort = { ViewCount: 'Desc' } } else if (this.data.sortActive == 'timeAsc') { sort = { CreateDate: 'Asc' } } else if (this.data.sortActive == 'timeDesc') { sort = { CreateDate: 'Desc' } } app.MG.store .getProductList({ storeInfo: 'jsek_digitalTextbooks', path: this.data.path, queryType: '*', paging: { start: 0, size: 99 }, sort: sort, fields: { content: [], subtitle: [], backgroundSelection: [], author: [], viewCount: [], ...searchObj } }).then((res) => { res.datas.forEach(item => item.price = item.price.toFixed(2)) this.setData({ digitalTextbooksData: res.datas, loading: false }) console.log(this.data.digitalTextbooksData); }) }, searchBook: function (e) { const keyword = e.detail.value; this.bookExhibitionGet(keyword) }, jumpDetails(e) { const item = e.currentTarget.dataset.item console.log(item); // 在某个事件处理函数中,比如按钮的点击事件 setNewView('productId', item.id) this.bookExhibitionGet() wx.navigateTo({ url: '/pages/digitalTextbooks/digitalTextbooksDetails/index?id=' + item.id }); } })