index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {
  2. getCategoryWorks
  3. } from '~/api/works'
  4. import reachBottom from '~/mixins/reachBottom'
  5. Page({
  6. behaviors: [reachBottom],
  7. data: {
  8. // class为二级,search为搜索
  9. type: 'class',
  10. categoryList: [],
  11. childType: '',
  12. currentIndex: 0,
  13. scrollTop: 0,
  14. text: '',
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. let title = '分类'
  21. console.log(options);
  22. // 没有二级分类
  23. if (options.id) {
  24. this.setData({
  25. childType: options.id
  26. })
  27. title = options.title
  28. this.resetData()
  29. } else if (options.list) {
  30. let categoryList = JSON.parse(decodeURIComponent(options.list))
  31. this.setData({
  32. categoryList
  33. })
  34. title = this.data.categoryList[this.data.currentIndex].title
  35. this.resetData()
  36. }
  37. wx.setNavigationBarTitle({
  38. title
  39. })
  40. this.setData({
  41. type: options.type,
  42. })
  43. },
  44. // 获取分类的内容
  45. loadMore() {
  46. let columnId = this.data.childType ? this.data.childType : this.data.categoryList[this.data.currentIndex].id
  47. this.getData(getCategoryWorks, {
  48. columnId
  49. })
  50. },
  51. setClass({
  52. currentTarget
  53. }) {
  54. this.setData({
  55. scrollTop: 0,
  56. currentIndex: currentTarget.dataset.index
  57. })
  58. wx.setNavigationBarTitle({
  59. title: this.data.categoryList[this.data.currentIndex].title
  60. })
  61. this.resetData()
  62. },
  63. setSearch({
  64. detail
  65. }) {
  66. this.setData({
  67. text: detail.value
  68. })
  69. },
  70. search() {
  71. console.log("搜索");
  72. },
  73. goRead({
  74. currentTarget
  75. }) {
  76. wx.navigateTo({
  77. // url: `/pages/reading/index?videoId=${currentTarget.dataset.id}&readingType=pk`
  78. url: `/pages/reading/index?videoId=1610706272332508`
  79. })
  80. },
  81. bindscrolltolower() {
  82. this.loadMore()
  83. },
  84. })