| | |
| | | import { fetchHome } from '../../services/home/home'; |
| | | import { fetchGoodsList } from '../../services/good/fetchGoods'; |
| | | import Toast from 'tdesign-miniprogram/toast/index'; |
| | | const app = getApp() |
| | | Page({ |
| | | data: { |
| | | imgSrcs: [], |
| | | tabList: [], |
| | | goodsList: [], |
| | | goodsListLoadStatus: 0, |
| | | tabList: [], //目录 |
| | | pageLoading: false, |
| | | current: 1, |
| | | autoplay: true, |
| | | duration: '500', |
| | | interval: 5000, |
| | | navigation: { type: 'dots' }, |
| | | swiperImageProps: { mode: 'scaleToFill' }, |
| | | bannerList: [], |
| | | current: 1,//轮播图参数 |
| | | autoplay: true, //轮播图参数 |
| | | duration: '500',//轮播图参数 |
| | | interval: 5000,//轮播图参数 |
| | | navigation: { type: 'dots' },//轮播图参数 |
| | | bannerList: [], //轮播图列表 |
| | | specialSubjectList: [],//专题讨论 |
| | | courseList: [], |
| | | booksList: [], |
| | | textbookList: [] |
| | | }, |
| | | |
| | | goodListPagination: { |
| | |
| | | |
| | | onShow() { |
| | | this.getTabBar().init(); |
| | | this.loadHomePage(); |
| | | this.getBannerList() |
| | | }, |
| | | |
| | |
| | | }, |
| | | |
| | | onReachBottom() { |
| | | if (this.data.goodsListLoadStatus === 0) { |
| | | this.loadGoodsList(); |
| | | } |
| | | }, |
| | | |
| | | onPullDownRefresh() { |
| | | this.init(); |
| | | }, |
| | | |
| | | init() { |
| | | this.loadHomePage(); |
| | | this.getSubjectList(); |
| | | this.getCourseList(); |
| | | }, |
| | | getBannerList() { |
| | | const list = [] |
| | |
| | | }) |
| | | console.log('轮播图', this.data.bannerList); |
| | | }, |
| | | loadHomePage() { |
| | | wx.stopPullDownRefresh(); |
| | | |
| | | this.setData({ |
| | | pageLoading: true, |
| | | }); |
| | | fetchHome().then(({ swiper, tabList }) => { |
| | | this.setData({ |
| | | tabList, |
| | | imgSrcs: swiper, |
| | | pageLoading: false, |
| | | }); |
| | | this.loadGoodsList(true); |
| | | }); |
| | | }, |
| | | |
| | | tabChangeHandle(e) { |
| | | this.privateData.tabIndex = e.detail; |
| | | this.loadGoodsList(true); |
| | | }, |
| | | |
| | | onReTry() { |
| | | this.loadGoodsList(); |
| | | }, |
| | | |
| | | async loadGoodsList(fresh = false) { |
| | | if (fresh) { |
| | | wx.pageScrollTo({ |
| | | scrollTop: 0, |
| | | }); |
| | | } |
| | | |
| | | this.setData({ goodsListLoadStatus: 1 }); |
| | | |
| | | const pageSize = this.goodListPagination.num; |
| | | let pageIndex = this.privateData.tabIndex * pageSize + this.goodListPagination.index + 1; |
| | | if (fresh) { |
| | | pageIndex = 0; |
| | | } |
| | | |
| | | try { |
| | | const nextList = await fetchGoodsList(pageIndex, pageSize); |
| | | this.setData({ |
| | | goodsList: fresh ? nextList : this.data.goodsList.concat(nextList), |
| | | goodsListLoadStatus: 0, |
| | | }); |
| | | |
| | | this.goodListPagination.index = pageIndex; |
| | | this.goodListPagination.num = pageSize; |
| | | } catch (err) { |
| | | this.setData({ goodsListLoadStatus: 3 }); |
| | | } |
| | | }, |
| | | |
| | | goodListClickHandle(e) { |
| | | const { index } = e.detail; |
| | | const { spuId } = this.data.goodsList[index]; |
| | | wx.navigateTo({ |
| | | url: `/pages/goods/details/index?spuId=${spuId}`, |
| | | }); |
| | | }, |
| | | |
| | | goodListAddCartHandle() { |
| | | Toast({ |
| | | context: this, |
| | | selector: '#t-toast', |
| | | message: '点击加入购物车', |
| | | }); |
| | | }, |
| | | |
| | | //搜索 |
| | | navToSearchPage() { |
| | | wx.navigateTo({ url: '/pages/goods/search/index' }); |
| | | }, |
| | | |
| | | //轮播图跳转 |
| | | navToActivityDetail({ detail }) { |
| | | |
| | | const data = this.data.bannerList[detail.index] |
| | | console.log('跳转', data.link); |
| | | // const { index: promotionID = 0 } = detail || {}; |
| | |
| | | // url: `/pages/promotion-detail/index?promotion_id=${promotionID}`, |
| | | // }); |
| | | }, |
| | | //获取目录 |
| | | loadHomePage() { |
| | | wx.stopPullDownRefresh(); |
| | | this.setData({ |
| | | pageLoading: true, |
| | | }); |
| | | fetchHome().then(({ tabList }) => { |
| | | this.setData({ |
| | | tabList, |
| | | pageLoading: false, |
| | | }); |
| | | }); |
| | | }, |
| | | //点击目录 |
| | | toPages(item) { |
| | | let info = item.target.dataset.info |
| | | if (info.url) { |
| | | wx.navigateTo({ |
| | | url: info.url |
| | | }) |
| | | } else { |
| | | wx.showToast({ |
| | | title: "建设中", |
| | | icon: 'none', |
| | | duration: 2000 |
| | | }) |
| | | } |
| | | }, |
| | | //专题讨论 |
| | | getSubjectList() { |
| | | const obj = { |
| | | storeInfo: "jsek_seminar", |
| | | path: 'jsek_homepageSeminar', |
| | | coverSize: { |
| | | width: 400 |
| | | }, |
| | | paging: { |
| | | start: 0, |
| | | size: 3 |
| | | }, |
| | | fields: { |
| | | liveTime: [], |
| | | lecturer: [], |
| | | startTime: [], |
| | | jsek_link: [] |
| | | } |
| | | } |
| | | app.MG.store.getProductList(obj).then((res) => { |
| | | this.setData({ |
| | | specialSubjectList: res.datas |
| | | }) |
| | | }) |
| | | }, |
| | | //精选课程列表 |
| | | getCourseList(item) { |
| | | const obj = { |
| | | storeInfo: "app.config.goodsStore", |
| | | path: 'jsek_homepageDigitalTextbooks', |
| | | coverSize: { |
| | | width: 260 |
| | | }, |
| | | paging: { |
| | | start: 0, |
| | | size: 4 |
| | | }, |
| | | fields: { |
| | | courseLeader: [], |
| | | affiliatedUnit: [], |
| | | publishingUnit: [], |
| | | classHours: [] |
| | | } |
| | | } |
| | | app.MG.store.getProductList(obj).then((res) => { |
| | | this.setData({ |
| | | courseList: res.datas |
| | | }) |
| | | }) |
| | | } |
| | | }); |