class.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. Page({
  6. data: {
  7. fullScreenBtn: false,
  8. playBtn: false,
  9. gesture: true,
  10. videoUrl: '',
  11. title: '',
  12. poster: '',
  13. works: [],
  14. total: '',
  15. title: '',
  16. id: '',
  17. iconImg: '',
  18. pageNo: 1,
  19. totalNo: 0,
  20. collectFlag: false,
  21. },
  22. onLoad: function (option) {
  23. console.log(option);
  24. wx.setNavigationBarTitle({
  25. title: option.title //页面标题为路由参数
  26. })
  27. this.setData({
  28. title: option.title,
  29. id: option.id
  30. })
  31. this.uid = wx.getStorageSync('uid');;
  32. httpRequestApi.getClassDetail(this.uid, option.id).success(res => {
  33. console.log(res);
  34. this.setData({
  35. title: res.data.data.title,
  36. videoUrl: res.data.data.playUrl,
  37. iconImg: res.data.data.iconImg
  38. })
  39. this.getReadInfo(1, 10);
  40. this.checkLike();
  41. })
  42. },
  43. // 检查是否收藏
  44. checkLike: function () {
  45. httpRequestApi.classIsLike(this.uid, {
  46. targetCode: this.data.id
  47. }).success(res => {
  48. this.setData({
  49. collectFlag: res.data.data
  50. })
  51. })
  52. },
  53. goToReading: function () {
  54. let id = this.data.id;
  55. let title = this.data.title;
  56. wx.navigateTo({
  57. url: `../../main/reading/reading?id=${id}`
  58. })
  59. },
  60. goToWorks: function (e) {
  61. this.videoCtx = wx.createVideoContext('myVideo', this);
  62. this.videoCtx.stop();
  63. console.log(e);
  64. let readId = e.target.dataset.uid;
  65. let title = this.data.title;
  66. wx.navigateTo({
  67. url: `../../social/works/works?id=${readId}&tilte=${title}`
  68. })
  69. },
  70. collect: function (e) {
  71. // let uid = wx.getStorageSync('uid');
  72. let data = {
  73. targetCode: this.data.id,
  74. title: this.data.title,
  75. iconImg: this.data.iconImg
  76. }
  77. httpRequestApi.collectClass(this.uid, data).success(res => {
  78. this.setData({
  79. collectFlag: !this.data.collectFlag
  80. })
  81. })
  82. },
  83. getReadInfo: function (pageNo, pageSize) {
  84. // const uid = wx.getStorageSync('uid');
  85. const data = {
  86. lessonId: this.data.id,
  87. pageNo: this.data.pageNo,
  88. pageSize: 1
  89. };
  90. httpRequestApi.getClassRead(this.uid, data).success(res => {
  91. const readInfo = res.data.data.list;
  92. const readTemp = [];
  93. readInfo.forEach(item => {
  94. const temp = {};
  95. temp.nickName = item.user.wechatName;
  96. temp.time = formatDate(item.userRead.gmtModified, 3);
  97. temp.avatar = item.user.avatar;
  98. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  99. temp.uid = item.userRead.uid;
  100. temp.id = item.userRead.id;
  101. this.data.works.push(temp);
  102. });
  103. this.setData({
  104. totalNo: res.data.data.totalNo,
  105. total: res.data.data.totalSize,
  106. works: this.data.works
  107. })
  108. });
  109. },
  110. // 下拉加载
  111. onReachBottom: function(e){
  112. console.log(this.data.totalNo);
  113. this.setData({
  114. pageNo: this.data.pageNo+1
  115. })
  116. if(this.data.pageNo <= this.data.totalNo ){
  117. this.getReadInfo();
  118. }
  119. }
  120. })