class.js 2.8 KB

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