// pages/digitalCourses/index.js const app = getApp() import { setSessionGuid, setNewView, storage } from "../../assets/js/userAction"; Page({ /** * 页面的初始数据 */ data: { barHeight: "", navBarHeight: "", tabPanelstyle: 'display:flex;justify-content:center;align-items:center;', tabList: [], courseList: [], searchValue: '', activeItem: null, loading: false, shoppingCartGetId: [] }, /** * 生命周期函数--监听页面加载 */ 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.getShoppingCartList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, onTabsChange(event) { const value = event.detail.value this.getCourseList(this.data.tabList[value]) }, goBack() { wx.navigateBack(); }, getCourseTypeListList() { this.setData({ loading: true }) const data = { path: '*', filterList: [{ value: 'Normal', field: 'state' }], queryType: '\\', searchList: [], size: '20', start: '0', storeRefCode: app.config.digitalCourses, sort: { type: 'Asc', field: 'LinkOrder' } } app.MG.store.getStoreChannelList(data).then((res) => { // 去除数组最后一个元素 const newData = res.datas.slice(0, res.datas.length - 1) this.setData({ tabList: newData, activeItem: newData[0], loading: false }) this.getCourseList(newData[0]) }) }, getCourseList(item) { let searchObj = {} // let sort = {} // // 搜索框 if (this.data.searchValue) { searchObj = { 'Name*': this.data.searchValue.trim() // '||subtitle*': searchInputValue.value.trim() } } // if (timeSort.value) { // sort = { // CreateDate: timeSort.value || 'Desc' // } // } else { // sort = { // ViewCount: nameSort.value || 'Desc' // } // // 组合的写法 要查询的字段:升序和降序 // // Name: "Desc" // //一般的排序传法 // // type: "Asc", // // field: "CreateDate", // } // courseList.value = []; const obj = { storeInfo: app.config.goodsStore, path: item.pathList + '\\' + item.id, coverSize: { width: 260 }, paging: { start: 0, size: 99 }, filterList: [{ value: 'Normal', field: 'state' }], // sort: sort, fields: { courseLeader: [], affiliatedUnit: [], publishingUnit: [], classHours: [], ViewCount: [], ...searchObj } } app.MG.store.getProductList(obj).then((res) => { console.log(res, '7895') res.datas.forEach(item => { item.price = item.price.toFixed(2) }) this.setData({ courseList: res.datas }) console.log(this.data.courseList); }) }, searchBook() { console.log(this.data.searchValue); this.getCourseList(this.data.activeItem) }, courseDetail(e) { console.log(e); const item = e.currentTarget.dataset.item setNewView('productId', item.id) this.getCourseTypeListList() wx.navigateTo({ url: '/pages/digitalCourses/digitalCoursesDetails/index?id=' + item.id, }) }, getShoppingCartList() { let query = { start: 0, size: 999, filterList: [], searchList: [] } app.MG.store.getShoppingCartProductList(query).then((res) => { let idList = []; res.datas.forEach((item) => { idList.push(item.saleMethod.id) }) this.setData({ shoppingCartGetId: idList }) }) }, addCart(e) { const { item } = e.currentTarget.dataset; wx.showToast({ title: "建设中", icon: 'none', duration: 1000 }) if (wx.getStorageSync(app.config.tokenKey)) { let query = { start: 0, size: 999, filterList: [], searchList: [] } try { if ( this.data.shoppingCartGetId.includes( item.defaultSaleMethodId ) ) { wx.showToast({ title: "该书已在购物车,请勿重复添加空", icon: 'none', duration: 1000 }) } else { let query = { requests: [{ saleMethodId: item.defaultSaleMethodId, storeEventId: null, agentCode: '数字课程' }] } const addRes = app.MG.store.addShoppingCart(query) if (addRes) { wx.showToast({ title: "添加成功", icon: 'success', duration: 1000 }) } this.getShoppingCartList() } } catch (error) { console.error('出错了:', error) } } }, })