class.js 2.9 KB

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