|
- const app = getApp()
- const config = require("../../config/config")
- const Http = require("../../utils/HttpBasics.js")
- const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
- const convert = require("../../utils/util.js")
- Page({
- data: {
- imgHttps: app.globalData.imgHttps,
- column: [],
- topFlag: 0,
- swiperLsit: [],
- inputValue: '',
- navigationBarHeight,
- deyList: [],//今天推荐
- deyPageNum: 1,
- classLsit: [],//精选类容
- classpageNum: 1,
- autho: [],//推荐作者
- authoPageNum: 1,
- rankingList: [],//热门排行
- rankingPageNum: 1,
- },
-
- goXq(e) {//跳转详情
- let id = e.currentTarget.dataset.id
- let title = e.currentTarget.dataset.title
- tt.navigateTo({
- url: `/pages/classDetails/classDetails?id=${id}&title=${title}` // 指定页面的url
- });
- },
- goPublicity(e) {
- let id = e.currentTarget.dataset.id
- let type = e.currentTarget.dataset.type
- tt.navigateTo({
- url: `/pages/publicity/publicity?id=${id}&type=${type}` // 指定页面的url
- });
- },
- getNweDataLsit() {//今天推荐
- Http.get({
- url: config.api.columnLsit,
- data: {
- pageNum: this.data.deyPageNum,
- pageSize: 4,
- sortOrder: "desc"
- }
- }).then(res => {
- let temp = this.data.list
- if (this.data.pageNum > 1) {
- temp.push(...res.data.list)
-
- } else {
- temp = res.data.list
- }
- temp.map(item => {
- item.popularity = convert.moodsText(item.popularity)
- })
- this.setData({
- deyList: temp
- })
- }).catch(err => {
- tt.showToast({
- title: err.message, // 内容
- icon: "none"
- });
- })
- },
- getSwiperLsit() {//获取轮播图
- Http.get({
- url: config.api.getPublicity,
- data: {
- pageSize: 7,
- pageNum: 1
- }
- }).then(res => {
- console.log(res.data, "轮播图");
- this.setData({
- swiperLsit: res.data.list
- })
- }).catch(err => {
- tt.showToast({
- title: err.message, // 内容
- icon: "none"
- });
- })
- },
- getClassLsit() {//精选课程
- Http.get({
- url: config.api.columnLsit,
- data: {
- pageNum: this.data.classpageNum,
- pageSize: 3,
- mark: 1,
- sortColumn: "markTime",
- sortOrder: "desc"
- }
- }).then(res => {
- let temp = this.data.list
- if (this.data.pageNum > 1) {
- temp.push(...res.data.list)
-
- } else {
- temp = res.data.list
- }
- temp.map(item => {
- item.popularity = convert.moodsText(item.popularity)
- })
-
- this.setData({
- classLsit: temp
- })
- }).catch(err => {
- tt.showToast({
- title: err.message, // 内容
- icon: "none"
- });
- })
- },
- getRanking() {//排行榜
- Http.get({
- url: config.api.columnLsit,
- data: {
- pageNum: this.data.rankingPageNum,
- pageSize: 6,
- sortColumn: "popularity",
- sortOrder: "desc"
- }
- }).then(res => {
- let temp = this.data.list
- if (this.data.pageNum > 1) {
- temp.push(...res.data.list)
-
- } else {
- temp = res.data.list
- }
- temp.map(item => {
- item.popularity = convert.moodsText(item.popularity)
- })
- this.setData({
- rankingList: temp
- })
- }).catch(err => {
- tt.showToast({
- title: err.message, // 内容
- icon: "none"
- });
- })
- },
- getAuthor() {//推荐作者
- Http.get({
- url: config.api.getAuthor,
- data: {
- pageNum: this.data.authoPageNum,
- pageSize: 4,
- mark: 1,
- sortColumn: "markTime",
- sortOrder: "desc"
- }
- }).then(res => {
-
- let arr = res.data.list
- if (arr.length == 0) return
-
- if (res.data.list[0].businessTypes) {
-
- arr.map(item1 => {
- let text = ""
- JSON.parse(item1.businessTypes).map(item2 => {
- text += " " + item2.title
- })
- item1.authoRemark = text
- })
-
- }
- console.log(arr);
- this.setData({
- autho: arr,
- })
- })
- },
- search() {
- console.log(this.data.inputValue);
- },
-
- setTopFlag(e) {
- let index = e.currentTarget.dataset.index
- let itemId = e.currentTarget.dataset.itemid
- console.log(itemId);
- this.setData({
- topFlag: index
- })
- tt.navigateTo({
- url: `/pages/category/category?itemId=${itemId}` // 指定页面的url
- });
- },
- getColumn() {
- Http.get({
- url: config.api.getColumn
- }).then(res => {
- let tempData = res.data
- tempData.unshift({
- id: "",
- title: "推荐"
- })
- this.setData({
- column: tempData
- })
- }).catch(err => {
- tt.showToast({
- title: err.message, // 内容
-
- });
- })
- },
-
- onLoad: function () {
- if (app.globalData.token) {
- this.getColumn()
- this.getNweDataLsit()
- this.getClassLsit()
- this.getRanking()
- this.getAuthor()
- this.getSwiperLsit()
- } else {
- app.tokenCallback = token => {
- this.getColumn()
- this.getNweDataLsit()
- this.getClassLsit()
- this.getRanking()
- this.getAuthor()
- this.getSwiperLsit()
- }
- }
- },
-
- onPullDownRefresh() {
- this.getColumn()
- this.getNweDataLsit()
- this.getClassLsit()
- this.getRanking()
- this.getAuthor()
- this.getSwiperLsit()
- tt.stopPullDownRefresh();
- },
- })
|