25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

245 satır
5.4 KiB

  1. const app = getApp()
  2. const config = require("../../config/config")
  3. const Http = require("../../utils/HttpBasics.js")
  4. const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
  5. const convert = require("../../utils/util.js")
  6. Page({
  7. data: {
  8. imgHttps: app.globalData.imgHttps,
  9. column: [],
  10. topFlag: 0,
  11. swiperLsit: [],
  12. inputValue: '',
  13. navigationBarHeight,
  14. deyList: [],//今天推荐
  15. deyPageNum: 1,
  16. classLsit: [],//精选类容
  17. classpageNum: 1,
  18. autho: [],//推荐作者
  19. authoPageNum: 1,
  20. rankingList: [],//热门排行
  21. rankingPageNum: 1,
  22. },
  23. goXq(e) {//跳转详情
  24. let id = e.currentTarget.dataset.id
  25. let title = e.currentTarget.dataset.title
  26. tt.navigateTo({
  27. url: `/pages/classDetails/classDetails?id=${id}&title=${title}` // 指定页面的url
  28. });
  29. },
  30. goPublicity(e) {
  31. let id = e.currentTarget.dataset.id
  32. let type = e.currentTarget.dataset.type
  33. tt.navigateTo({
  34. url: `/pages/publicity/publicity?id=${id}&type=${type}` // 指定页面的url
  35. });
  36. },
  37. getNweDataLsit() {//今天推荐
  38. Http.get({
  39. url: config.api.columnLsit,
  40. data: {
  41. pageNum: this.data.deyPageNum,
  42. pageSize: 4,
  43. sortOrder: "desc"
  44. }
  45. }).then(res => {
  46. let temp = this.data.list
  47. if (this.data.pageNum > 1) {
  48. temp.push(...res.data.list)
  49. } else {
  50. temp = res.data.list
  51. }
  52. temp.map(item => {
  53. item.popularity = convert.moodsText(item.popularity)
  54. })
  55. this.setData({
  56. deyList: temp
  57. })
  58. }).catch(err => {
  59. tt.showToast({
  60. title: err.message, // 内容
  61. icon: "none"
  62. });
  63. })
  64. },
  65. getSwiperLsit() {//获取轮播图
  66. Http.get({
  67. url: config.api.getPublicity,
  68. data: {
  69. pageSize: 7,
  70. pageNum: 1
  71. }
  72. }).then(res => {
  73. console.log(res.data, "轮播图");
  74. this.setData({
  75. swiperLsit: res.data.list
  76. })
  77. }).catch(err => {
  78. tt.showToast({
  79. title: err.message, // 内容
  80. icon: "none"
  81. });
  82. })
  83. },
  84. getClassLsit() {//精选课程
  85. Http.get({
  86. url: config.api.columnLsit,
  87. data: {
  88. pageNum: this.data.classpageNum,
  89. pageSize: 3,
  90. mark: 1,
  91. sortColumn: "markTime",
  92. sortOrder: "desc"
  93. }
  94. }).then(res => {
  95. let temp = this.data.list
  96. if (this.data.pageNum > 1) {
  97. temp.push(...res.data.list)
  98. } else {
  99. temp = res.data.list
  100. }
  101. temp.map(item => {
  102. item.popularity = convert.moodsText(item.popularity)
  103. })
  104. this.setData({
  105. classLsit: temp
  106. })
  107. }).catch(err => {
  108. tt.showToast({
  109. title: err.message, // 内容
  110. icon: "none"
  111. });
  112. })
  113. },
  114. getRanking() {//排行榜
  115. Http.get({
  116. url: config.api.columnLsit,
  117. data: {
  118. pageNum: this.data.rankingPageNum,
  119. pageSize: 6,
  120. sortColumn: "popularity",
  121. sortOrder: "desc"
  122. }
  123. }).then(res => {
  124. let temp = this.data.list
  125. if (this.data.pageNum > 1) {
  126. temp.push(...res.data.list)
  127. } else {
  128. temp = res.data.list
  129. }
  130. temp.map(item => {
  131. item.popularity = convert.moodsText(item.popularity)
  132. })
  133. this.setData({
  134. rankingList: temp
  135. })
  136. }).catch(err => {
  137. tt.showToast({
  138. title: err.message, // 内容
  139. icon: "none"
  140. });
  141. })
  142. },
  143. getAuthor() {//推荐作者
  144. Http.get({
  145. url: config.api.getAuthor,
  146. data: {
  147. pageNum: this.data.authoPageNum,
  148. pageSize: 4,
  149. mark: 1,
  150. sortColumn: "markTime",
  151. sortOrder: "desc"
  152. }
  153. }).then(res => {
  154. let arr = res.data.list
  155. if (arr.length == 0) return
  156. if (res.data.list[0].businessTypes) {
  157. arr.map(item1 => {
  158. let text = ""
  159. JSON.parse(item1.businessTypes).map(item2 => {
  160. text += " " + item2.title
  161. })
  162. item1.authoRemark = text
  163. })
  164. }
  165. console.log(arr);
  166. this.setData({
  167. autho: arr,
  168. })
  169. })
  170. },
  171. search() {
  172. console.log(this.data.inputValue);
  173. },
  174. setTopFlag(e) {
  175. let index = e.currentTarget.dataset.index
  176. let itemId = e.currentTarget.dataset.itemid
  177. console.log(itemId);
  178. this.setData({
  179. topFlag: index
  180. })
  181. tt.navigateTo({
  182. url: `/pages/category/category?itemId=${itemId}` // 指定页面的url
  183. });
  184. },
  185. getColumn() {
  186. Http.get({
  187. url: config.api.getColumn
  188. }).then(res => {
  189. let tempData = res.data
  190. tempData.unshift({
  191. id: "",
  192. title: "推荐"
  193. })
  194. this.setData({
  195. column: tempData
  196. })
  197. }).catch(err => {
  198. tt.showToast({
  199. title: err.message, // 内容
  200. });
  201. })
  202. },
  203. onLoad: function () {
  204. if (app.globalData.token) {
  205. this.getColumn()
  206. this.getNweDataLsit()
  207. this.getClassLsit()
  208. this.getRanking()
  209. this.getAuthor()
  210. this.getSwiperLsit()
  211. } else {
  212. app.tokenCallback = token => {
  213. this.getColumn()
  214. this.getNweDataLsit()
  215. this.getClassLsit()
  216. this.getRanking()
  217. this.getAuthor()
  218. this.getSwiperLsit()
  219. }
  220. }
  221. },
  222. onPullDownRefresh() {
  223. this.getColumn()
  224. this.getNweDataLsit()
  225. this.getClassLsit()
  226. this.getRanking()
  227. this.getAuthor()
  228. this.getSwiperLsit()
  229. tt.stopPullDownRefresh();
  230. },
  231. })