learning.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // pages/learning/learning.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. act:0,
  10. arct:[],
  11. hot_arct:[],
  12. over_arct:[],
  13. conference:[],
  14. over:[],
  15. pre:[],
  16. keyword:'',
  17. array: ['时间正序', '时间倒序'],
  18. val: ['ctime', '-ctime'],
  19. index: 0,
  20. show_tj:0,
  21. page_0:1,
  22. page_1:1,
  23. page_2:1,
  24. total_0:0,
  25. total_1: 0,
  26. total_2: 0,
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. this.getData();
  33. },
  34. getData:function(){
  35. var that=this;
  36. var order_by = this.data.val[this.data.index]
  37. wx.showNavigationBarLoading()
  38. wx.request({
  39. url: host+'/api/recommend',
  40. success:function(res){
  41. wx.hideNavigationBarLoading()
  42. that.setData({
  43. arct: res.data.data.article,
  44. hot_arct: res.data.data.hot_act,
  45. pre_arct: res.data.data.pre_act,
  46. over_arct: res.data.data.over_act
  47. })
  48. }
  49. })
  50. //学术会议
  51. this.getcon()
  52. //活动预告
  53. this.getpre()
  54. //活动回顾
  55. this.getover()
  56. },
  57. //学术会议
  58. next_0: function () {
  59. if (this.data.conference.length < this.data.total_0) {
  60. const page = this.data.page_0 + 1
  61. this.setData({
  62. page_0: page
  63. })
  64. this.getcon()
  65. }
  66. },
  67. getcon: function () {
  68. const conference = this.data.conference;
  69. const order_by = this.data.val[this.data.index]
  70. wx.request({
  71. url: host + '/api/conference/list',
  72. method: 'GET',
  73. data: {
  74. order_by: order_by,
  75. keyword: this.data.keyword,
  76. page: this.data.page_0
  77. },
  78. success: res => {
  79. wx.hideNavigationBarLoading()
  80. if (res.data.code == 0) {
  81. const list = res.data.data.list;
  82. for (let i = 0; i < list.length; i++) {
  83. conference.push(list[i])
  84. }
  85. this.setData({
  86. conference: conference,
  87. total_0: res.data.data.total
  88. })
  89. }
  90. }
  91. })
  92. },
  93. //活动预告
  94. next_1: function () {
  95. if (this.data.pre.length < this.data.total_1) {
  96. const page = this.data.page_1 + 1
  97. this.setData({
  98. page_1: page
  99. })
  100. this.getpre()
  101. }
  102. },
  103. getpre: function () {
  104. const pre = this.data.pre;
  105. const order_by = this.data.val[this.data.index]
  106. wx.request({
  107. url: host + '/api/activity/list',
  108. method: 'GET',
  109. data: {
  110. type: 'pre',
  111. order_by: order_by,
  112. keyword: this.data.keyword,
  113. page: this.data.page_1
  114. },
  115. success: res => {
  116. wx.hideNavigationBarLoading()
  117. if (res.data.code == 0) {
  118. const list = res.data.data.list;
  119. for (let i = 0; i < list.length; i++) {
  120. pre.push(list[i])
  121. }
  122. this.setData({
  123. pre: pre,
  124. total_1: res.data.data.total
  125. })
  126. }
  127. }
  128. })
  129. },
  130. //活动预告
  131. next_2: function () {
  132. if (this.data.over.length < this.data.total_2) {
  133. const page = this.data.page_2 + 1
  134. this.setData({
  135. page_2: page
  136. })
  137. this.getover()
  138. }
  139. },
  140. getover: function () {
  141. const over = this.data.over;
  142. const order_by = this.data.val[this.data.index]
  143. wx.request({
  144. url: host + '/api/activity/list',
  145. method: 'GET',
  146. data: {
  147. type: 'over',
  148. order_by: order_by,
  149. keyword: this.data.keyword,
  150. page: this.data.page_2
  151. },
  152. success: res => {
  153. wx.hideNavigationBarLoading()
  154. if (res.data.code == 0) {
  155. const list = res.data.data.list;
  156. for (let i = 0; i < list.length; i++) {
  157. over.push(list[i])
  158. }
  159. this.setData({
  160. over: over,
  161. total_2: res.data.data.total
  162. })
  163. }
  164. }
  165. })
  166. },
  167. // 查看更多
  168. more:function(e){
  169. var type=e.target.dataset.id;
  170. //精品推荐
  171. if(type == 1){
  172. this.setData({show_tj:1})
  173. }else{
  174. this.setData({ act: type-1 })
  175. }
  176. },
  177. search: function (e) {
  178. wx.navigateTo({
  179. url: '../search/search',
  180. })
  181. },
  182. showmenu: function () {
  183. this.setData({
  184. show: !this.data.show
  185. })
  186. },
  187. check: function (e) {
  188. this.setData({
  189. show: 0,
  190. index: e.target.dataset.id
  191. })
  192. this.getData();
  193. },
  194. tab: function (e) {
  195. this.setData({
  196. act: e.target.dataset.id,
  197. show_tj: 0
  198. })
  199. },
  200. swchange: function (e) {
  201. this.setData({
  202. act: e.detail.current,
  203. show_tj: 0
  204. })
  205. },
  206. /**
  207. * 生命周期函数--监听页面初次渲染完成
  208. */
  209. onReady: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面显示
  213. */
  214. onShow: function () {
  215. this.setData({
  216. show:0
  217. })
  218. },
  219. /**
  220. * 生命周期函数--监听页面隐藏
  221. */
  222. onHide: function () {
  223. },
  224. /**
  225. * 生命周期函数--监听页面卸载
  226. */
  227. onUnload: function () {
  228. },
  229. /**
  230. * 页面相关事件处理函数--监听用户下拉动作
  231. */
  232. onPullDownRefresh: function () {
  233. },
  234. /**
  235. * 页面上拉触底事件的处理函数
  236. */
  237. onReachBottom: function () {
  238. },
  239. /**
  240. * 用户点击右上角分享
  241. */
  242. onShareAppMessage: function () {
  243. }
  244. })