index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. console.log(
  77. currentTarget.dataset
  78. );
  79. wx.navigateTo({
  80. url: `/pages/reading/index?videoId=${currentTarget.dataset.id}`
  81. })
  82. },
  83. bindscrolltolower() {
  84. this.loadMore()
  85. },
  86. })