showVideoList.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/showVideoList/showVideoList.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. personType: 0,
  11. index: 0,
  12. switchTitle: ['热门', '最新', '我点赞的', '我发布的'],
  13. list: [
  14. ],
  15. loading: '上拉加载',
  16. flag: 0,
  17. pageNum: 0,
  18. hasNextPage: true,
  19. curStu: null,
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. let personType = options.personType;
  26. if (personType == 1) {
  27. this.setData({ switchTitle: ['热门', '最新', '我点赞的'] })
  28. }
  29. this.setData({ personType: personType })
  30. },
  31. uploadTap: function () {
  32. wx.navigateTo({
  33. url: '/pages/uploadShow/uploadShow',
  34. })
  35. },
  36. /**
  37. * 生命周期函数--监听页面初次渲染完成
  38. */
  39. onReady: function () {
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow: function () {
  45. this.setData({ pageNum: 0, list: [] })
  46. this.queryList();
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function () {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function () {
  62. this.setData({
  63. list: []
  64. })
  65. this.queryList()
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom: function () {
  71. if (this.data.hasNextPage) {
  72. let pn = this.data.pageNum
  73. this.setData({ loading: '加载中', 'pageNum': ++pn })
  74. this.queryList()
  75. }
  76. },
  77. /**
  78. * 用户点击右上角分享
  79. */
  80. onShareAppMessage: function () {
  81. },
  82. selectIndex: function (i) {
  83. this.setData({ index: i.detail, list: [], pageNum: 0 })
  84. this.queryList()
  85. },
  86. queryList: function () {
  87. const urls = urlDef.urls;
  88. let stu = wx.getStorageSync('student');
  89. if (stu) {
  90. this.setData({ curStu: stu })
  91. let url = urls.person_video_list;
  92. let params = { 'q.personType': this.data.personType, 'q.orgId': stu.orgId, 'q.doPersonId': stu.studentId };
  93. if (this.data.index == 0) {
  94. params['q.sortBy'] = 'goodCount'// 最热 按点赞量来
  95. } else if (this.data.index == 1) {
  96. params['q.sortBy'] = 'createDate'
  97. } else if (this.data.index == 2) {
  98. params['q.goodPersonId'] = stu.studentId
  99. } else if (this.data.index == 3) {
  100. params['q.personId'] = stu.studentId
  101. }
  102. params.pageNum = this.data.pageNum
  103. util.apiPost(url, params).then(rs => {
  104. let list = rs.list
  105. this.setData({
  106. 'hasNextPage': rs.hasNextPage,
  107. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  108. 'list': this.data.list.concat(list)
  109. })
  110. let that = this;
  111. list.map(v => {
  112. util.apiPost(urls.video_loadInfo + v.videoId).then((rs) => {
  113. v.imgUrl = rs.img
  114. v.playUrl = rs.url
  115. that.reloadVideos(v)
  116. })
  117. })
  118. wx.stopPullDownRefresh()
  119. })
  120. }
  121. },
  122. reloadVideos: function (v) {
  123. this.data.list.map(o => {
  124. if (o.videoId == v.videoId) {
  125. o = v
  126. }
  127. })
  128. this.setData({ list: this.data.list })
  129. },
  130. doThumbsUp: function (o) {
  131. const urls = urlDef.urls;
  132. let pid = this.data.curStu.studentId;
  133. let pt = o.detail.personType;
  134. let vid = o.detail.videoId;
  135. let entity = {
  136. videoId: vid,
  137. personId: pid,
  138. personType: pt,
  139. actionType: 1
  140. };
  141. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  142. this.data.list.map(o => {
  143. if (o.videoId == vid) {
  144. o.goodCount += 1
  145. }
  146. })
  147. this.setData({
  148. 'list': this.data.list
  149. })
  150. }).catch(e => {
  151. console.log(e);
  152. })
  153. }
  154. })