showVideoList.js 3.7 KB

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