showVideoList.js 3.6 KB

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