class.js 3.0 KB

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