showVideoList.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.queryList();
  46. },
  47. /**
  48. * 生命周期函数--监听页面隐藏
  49. */
  50. onHide: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面卸载
  54. */
  55. onUnload: function () {
  56. },
  57. /**
  58. * 页面相关事件处理函数--监听用户下拉动作
  59. */
  60. onPullDownRefresh: function () {
  61. this.setData({
  62. list: []
  63. })
  64. this.queryList()
  65. },
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom: function () {
  70. if (this.data.hasNextPage) {
  71. let pn = this.data.pageNum
  72. this.setData({ loading: '加载中', 'pageNum': ++pn })
  73. this.queryList()
  74. }
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {
  80. },
  81. selectIndex: function (i) {
  82. this.setData({ index: i.detail, list: [], pageNum: 0 })
  83. this.queryList()
  84. },
  85. queryList: function () {
  86. const urls = urlDef.urls;
  87. let stu = wx.getStorageSync('student');
  88. if (stu) {
  89. this.setData({ curStu: stu })
  90. let url = urls.person_video_list;
  91. let params = { 'q.personType': this.data.personType, 'q.orgId': stu.orgId, 'q.doPersonId': stu.studentId };
  92. if (this.data.index == 0) {
  93. params['q.sortBy'] = 'goodCount'// 最热 按点赞量来
  94. } else if (this.data.index == 1) {
  95. params['q.sortBy'] = 'createDate'
  96. } else if (this.data.index == 2) {
  97. params['q.goodPersonId'] = stu.studentId
  98. } else if (this.data.index == 3) {
  99. params['q.personId'] = stu.studentId
  100. }
  101. params.pageNum = this.data.pageNum
  102. util.apiPost(url, params).then(rs => {
  103. let list = rs.list
  104. this.setData({
  105. 'hasNextPage': rs.hasNextPage,
  106. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  107. 'list': this.data.list.concat(list)
  108. })
  109. let that = this;
  110. list.map(v => {
  111. util.apiPost(urls.video_loadInfo + v.videoId).then((rs) => {
  112. v.imgUrl = rs.img
  113. v.playUrl = rs.url
  114. that.reloadVideos(v)
  115. })
  116. })
  117. wx.stopPullDownRefresh()
  118. })
  119. }
  120. },
  121. reloadVideos: function (v) {
  122. this.data.list.map(o => {
  123. if (o.videoId == v.videoId) {
  124. o = v
  125. }
  126. })
  127. this.setData({ list: this.data.list })
  128. },
  129. doThumbsUp: function (o) {
  130. const urls = urlDef.urls;
  131. let pid = this.data.curStu.studentId;
  132. let pt = o.detail.personType;
  133. let vid = o.detail.videoId;
  134. let entity = {
  135. videoId: vid,
  136. personId: pid,
  137. personType: pt,
  138. actionType: 1
  139. };
  140. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  141. this.data.list.map(o => {
  142. if (o.videoId == vid) {
  143. o.goodCount += 1
  144. }
  145. })
  146. this.setData({
  147. 'list': this.data.list
  148. })
  149. }).catch(e => {
  150. console.log(e);
  151. })
  152. }
  153. })