import Api from '../../model/api' import User from '../../model/user' import {getDataSet, getEventParam, toast} from "../../utils/utils"; import {htmlTypes, liveSources, videoTypes} from "../../model/enum"; import Route from "../../model/route"; const app = getApp(); app.Base({ data: { id: "",//用来区分是否是通过卡片分享进行来的用户,当id存在值的时候是guest homeData: { notice: { noticeContent: '' }, carouselList: [], classInfo: { opened: 0, notYetOpened: 0, history: 0, }, dictList: [], }, tabs: [ {title: "直播课程", icon: '/images/tab_live.png'}, {title: "教材阅读", icon: '/images/tab_book.png', url: "/pages/book/book"}, {title: "精品课程", icon: '/images/tab_course.png', url: "/pages/course/course"}, {title: "社区交流", icon: '/images/tab_exchange.png'} ], active: 0, dictType: '', dictValue: '', showLiveList: false, actions: [], }, async onLoad(options) { const {id, guest} = options; if (guest == 'true') { this.id = id; } const res = await Api.getIndex(); const dictType = res.data.dictList[0].dictType; const dictValue = res.data.dictList[0].dictValue; this.setData({ homeData: res.data, dictType, dictValue }) this.selectComponent('#tabs').resize(); }, async onShow() { if (this.id) { let flag = await User.checkLive(this.id); if (flag){ this.id = ""; } } }, async toNotice(e) { await User.checkLogin(); Route.toNotice() }, toBannerDetail(e) { const item = getEventParam(e, "item"); Route.toNews(htmlTypes.BANNER, item.id, item.articleTitle, "") }, async toClickGrid(e) { const title = getDataSet(e, "title"); if ('直播课程' == title) { await this.findLive(); } else if ('社区交流' == title) { await User.checkLogin(); Route.tocCommunity() } }, toNewsDetail(e) { const item = getDataSet(e, "item"); const title = getDataSet(e, "title"); if (item.isNews) { Route.toNews(htmlTypes.NEWS, item.id, item.title, "") } else { Route.toVideo(item.id, videoTypes.COMMON, title) } }, toSchoolIntrouce() { Route.toSchoolIntrouce(); }, async onChange(e) { const index = getEventParam(e, "index"); const dictType = this.data.homeData.dictList[index].dictType; const dictValue = this.data.homeData.dictList[index].dictValue; this.setData({ active: index, dictType, dictValue }, async () => { this.changeResetData(this); }) }, async requestData() { const res = await Api.getNewsList({ dictType: this.data.dictType, dictValue: this.data.dictValue, pageNum: this.pageNum, pageSize: this.pageSize }); res.data.rows = res.data.rows.map(item => { return { title: item.articleTitle || item.videoName, visitedCount: item.visitedCount, cover: item.articleImg || item.videoImg, id: item.id, isNews: !!item.articleTitle } }); return res; }, async onPullDownRefresh() { const res = await Api.getIndex(true); const dictType = res.data.dictList[0].dictType; const dictValue = res.data.dictList[0].dictValue; this.setData({ homeData: res.data, dictType, dictValue, active: 0 }) this.selectComponent('#tabs').resize(); }, async findLive() { await User.checkLogin(); const res = await Api.getUserLiveId(true); if (res.data && res.data.length > 0) { if (res.data.length == 1) { let item = res.data[0]; let id = item.scheduleId; let eId = item.eStudentId; let eName = item.eduStuName; Route.toLive(liveSources.DEFAULT, item.courseCeremoneyName, id, eId, eName,item.courseThumbnailUrl) } else { this.setData({ actions: res.data.map(item => { item.name = `${item.teamName}-${item.courseCeremoneyName}`; return item; }), showLiveList: true }) } } else { toast("没有进行的直播") } }, onClose() { this.setData({showLiveList: false}); }, async onSelect(e) { const scheduleId = getEventParam(e, "scheduleId"); const eStudentId = getEventParam(e, "eStudentId"); const eduStuName = getEventParam(e, "eduStuName"); const courseCeremoneyName = getEventParam(e, "courseCeremoneyName"); const courseThumbnailUrl = getEventParam(e, "courseThumbnailUrl"); Route.toLive(liveSources.DEFAULT, courseCeremoneyName, scheduleId, eStudentId, eduStuName,courseThumbnailUrl); }, })