topic-list.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. Page({
  2. data: {
  3. backgrop: ["navbar-item-active"],
  4. navbarArray: [],
  5. navbarShowIndexArray: 0,
  6. navigation: !1,
  7. windowWidth: 375,
  8. scrollNavbarLeft: 0,
  9. currentChannelIndex: 0,
  10. articlesHide: !1
  11. },
  12. onLoad: function(a) {
  13. getApp().page.onLoad(this, a);
  14. var t = this,
  15. e = a.type;
  16. void 0 !== e && e && t.setData({
  17. typeid: e
  18. }), t.loadTopicList({
  19. page: 1,
  20. reload: !0
  21. }), getApp().core.getSystemInfo({
  22. success: function(a) {
  23. t.setData({
  24. windowWidth: a.windowWidth
  25. })
  26. }
  27. })
  28. },
  29. dis: function () {
  30. wx.redirectTo({
  31. url: '/pages/index/index?go=' + 'nd',
  32. })
  33. },
  34. loadTopicList: function(i) {
  35. var r = this;
  36. r.data.is_loading || i.loadmore && !r.data.is_more || (r.setData({
  37. is_loading: !0
  38. }), getApp().request({
  39. url: getApp().api.default.topic_type,
  40. success: function(a) {
  41. 0 == a.code && r.setData({
  42. navbarArray: a.data.list,
  43. navbarShowIndexArray: Array.from(Array(a.data.list.length).keys()),
  44. navigation: "" != a.data.list
  45. }), getApp().request({
  46. url: getApp().api.default.topic_list,
  47. data: {
  48. page: i.page
  49. },
  50. success: function(a) {
  51. if (0 == a.code)
  52. if (void 0 !== r.data.typeid) {
  53. for (var t = 0, e = 0; e < r.data.navbarArray.length && (t += 66, r.data.navbarArray[e].id != r.data.typeid); e++);
  54. r.setData({
  55. scrollNavbarLeft: t
  56. }), r.switchChannel(parseInt(r.data.typeid)), r.sortTopic({
  57. page: 1,
  58. type: r.data.typeid,
  59. reload: !0
  60. })
  61. } else i.reload && r.setData({
  62. list: a.data.list,
  63. page: i.page,
  64. is_more: 0 < a.data.list.length
  65. }), i.loadmore && r.setData({
  66. list: r.data.list.concat(a.data.list),
  67. page: i.page,
  68. is_more: 0 < a.data.list.length
  69. })
  70. },
  71. complete: function() {
  72. r.setData({
  73. is_loading: !1
  74. })
  75. }
  76. })
  77. }
  78. }))
  79. },
  80. onShow: function() {
  81. getApp().page.onShow(this)
  82. },
  83. onPullDownRefresh: function() {
  84. getApp().page.onPullDownRefresh(this);
  85. var a = this.data.currentChannelIndex;
  86. this.switchChannel(parseInt(a)), this.sortTopic({
  87. page: 1,
  88. type: parseInt(a),
  89. reload: !0
  90. }), getApp().core.stopPullDownRefresh()
  91. },
  92. onReachBottom: function() {
  93. getApp().page.onReachBottom(this);
  94. var a = this.data.currentChannelIndex;
  95. this.switchChannel(parseInt(a)), this.sortTopic({
  96. page: this.data.page + 1,
  97. type: parseInt(a),
  98. loadmore: !0
  99. })
  100. },
  101. onTapNavbar: function(i) {
  102. var r = this;
  103. if ("undefined" == typeof my) {
  104. var a = i.currentTarget.offsetLeft;
  105. r.setData({
  106. scrollNavbarLeft: a - 85
  107. })
  108. } else {
  109. var n = r.data.navbarArray,
  110. s = !0;
  111. n.forEach(function(a, t, e) {
  112. i.currentTarget.id == a.id && (s = !1, 1 <= t ? r.setData({
  113. toView: n[t - 1].id
  114. }) : r.setData({
  115. toView: -1
  116. }))
  117. }), s && r.setData({
  118. toView: "0"
  119. })
  120. }
  121. getApp().core.showLoading({
  122. title: "正在加载",
  123. mask: !0
  124. }), r.switchChannel(parseInt(i.currentTarget.id)), r.sortTopic({
  125. page: 1,
  126. type: i.currentTarget.id,
  127. reload: !0
  128. })
  129. },
  130. sortTopic: function(t) {
  131. var e = this;
  132. getApp().request({
  133. url: getApp().api.default.topic_list,
  134. data: t,
  135. success: function(a) {
  136. 0 == a.code && (t.reload && e.setData({
  137. list: a.data.list,
  138. page: t.page,
  139. is_more: 0 < a.data.list.length
  140. }), t.loadmore && e.setData({
  141. list: e.data.list.concat(a.data.list),
  142. page: t.page,
  143. is_more: 0 < a.data.list.length
  144. }), getApp().core.hideLoading())
  145. }
  146. })
  147. },
  148. switchChannel: function(i) {
  149. var a = this.data.navbarArray,
  150. t = new Array; - 1 == i ? t[1] = "navbar-item-active" : 0 == i && (t[0] = "navbar-item-active"), a.forEach(function(a, t, e) {
  151. a.type = "", a.id == i && (a.type = "navbar-item-active")
  152. }), this.setData({
  153. navbarArray: a,
  154. currentChannelIndex: i,
  155. backgrop: t
  156. })
  157. },
  158. onShareAppMessage: function() {
  159. getApp().page.onShareAppMessage(this);
  160. var a = this,
  161. t = {
  162. path: "/pages/topic-list/topic-list?user_id=" + a.data.__user_info.id + "&type=" + (a.data.typeid ? a.data.typeid : ""),
  163. success: function(a) {}
  164. };
  165. return console.log(t.path), t
  166. }
  167. });