details.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // pages/details/details.js
  2. import httpRequestApi from '../../utils/APIRequest';
  3. import util from '../../utils/util';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. anthologyHide: true,
  10. detailsHide: true,
  11. hide: true,
  12. str: '',
  13. summary: '',
  14. courseWareList: [],
  15. courseId: '',
  16. favoritesFlag: false,
  17. title: '',
  18. iconImg: '',
  19. postsList: [],
  20. dateArr: [],
  21. playUrl: '',
  22. courseWareId: '',
  23. currentVideo: 0
  24. },
  25. //点击收藏
  26. favorites: function () {
  27. this.setData({
  28. favoritesFlag: !this.data.favoritesFlag
  29. })
  30. httpRequestApi.getDetailsFavorites({
  31. targetCode: this.data.courseId,
  32. title: this.data.title,
  33. iconImg: this.data.iconImg
  34. }).success((res)=>{
  35. })
  36. },
  37. //点击添加到播放记录
  38. addHistory: function () {
  39. //console.log('播放',currentTarget.dataset);
  40. httpRequestApi.addPlayLogList({
  41. "title": this.data.title,
  42. "courseId": this.data.courseId,
  43. "courseWareId": this.data.courseWareId,
  44. "courseIcon": this.data.iconImg
  45. }).success(res => {
  46. })
  47. },
  48. //视频播放结束
  49. endplay: function () {
  50. const index = this.data.currentVideo + 1;
  51. this.setData({
  52. playUrl: this.data.courseWareList[index].playUrl,
  53. courseWareId: this.data.courseWareList[index].id,
  54. currentVideo: index
  55. })
  56. },
  57. //点击出现选集
  58. commentAnthology: function () {
  59. this.setData({
  60. anthologyHide: !this.data.anthologyHide
  61. })
  62. },
  63. //选择视频播放
  64. Anthology: function ({ currentTarget }) {
  65. const index = currentTarget.dataset.index;
  66. this.setData({
  67. playUrl: this.data.courseWareList[index].playUrl,
  68. courseWareId: this.data.courseWareList[index].id,
  69. currentVideo: index
  70. })
  71. },
  72. //出现详情页
  73. commentDetails: function () {
  74. this.setData({
  75. detailsHide: !this.data.detailsHide
  76. })
  77. },
  78. //点击评论
  79. pinglun: function () {
  80. this.setData({
  81. hide: !this.data.hide
  82. })
  83. },
  84. //点击取消
  85. no: function () {
  86. this.setData({
  87. hide: !this.data.hide,
  88. str: ''
  89. })
  90. },
  91. //点击确定评论
  92. yes: function () {
  93. if(this.data.str === '') {
  94. wx.showModal({
  95. title: '提示',
  96. content: '请输入内容'
  97. })
  98. return false;
  99. }
  100. httpRequestApi.getDetailsPosts({
  101. columnId: this.data.courseId,
  102. columnNames: this.data.title,
  103. detailDesc: this.data.str
  104. }).success((res)=>{
  105. if(res.data.success){
  106. wx.showToast({
  107. title: '评论成功'
  108. })
  109. this.setData({
  110. hide: !this.data.hide,
  111. str: ''
  112. })
  113. //获取评论列表
  114. this.getPostsList(this.data.courseId);
  115. }
  116. })
  117. },
  118. //获取输入值
  119. focus: function ({detail}) {
  120. this.setData({
  121. str: detail.value
  122. })
  123. },
  124. /**
  125. * 生命周期函数--监听页面加载
  126. */
  127. onLoad: function (options) {
  128. const courseId = options.id;
  129. console.log(courseId)
  130. httpRequestApi.getCourseDetails(courseId).success((res)=>{
  131. console.log('课程详情', res);
  132. const data = res.data.data;
  133. this.setData({
  134. favoritesFlag: data.isFavorites,
  135. title: data.course.title,
  136. iconImg: data.course.iconImg,
  137. courseId,
  138. summary: data.course.description,
  139. courseWareList: data.courseWareList,
  140. playUrl: data.courseWareList[0].playUrl,
  141. courseWareId: data.courseWareList[0].id
  142. })
  143. })
  144. //获取评论列表
  145. this.getPostsList(courseId);
  146. },
  147. //获取评论列表
  148. getPostsList: function (courseId) {
  149. httpRequestApi.getPostsList({
  150. courseId,
  151. pageNo: 1,
  152. pageSize: 10
  153. }).success((res)=>{
  154. console.log('评论列表', res);
  155. const dateArr = [];
  156. res.data.data.list.forEach(item => {
  157. dateArr.push(util.formatTime(new Date(item.gmtCreated)));
  158. });
  159. this.setData({
  160. postsList: res.data.data.list,
  161. dateArr
  162. })
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面初次渲染完成
  167. */
  168. onReady: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面显示
  172. */
  173. onShow: function () {
  174. },
  175. /**
  176. * 生命周期函数--监听页面隐藏
  177. */
  178. onHide: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面卸载
  182. */
  183. onUnload: function () {
  184. },
  185. /**
  186. * 页面相关事件处理函数--监听用户下拉动作
  187. */
  188. onPullDownRefresh: function () {
  189. },
  190. /**
  191. * 页面上拉触底事件的处理函数
  192. */
  193. onReachBottom: function () {
  194. },
  195. /**
  196. * 用户点击右上角分享
  197. */
  198. onShareAppMessage: function (ops) {
  199. if (ops.from === 'button') {
  200. // 来自页面内转发按钮
  201. console.log(ops.target)
  202. }
  203. return {
  204. title: '七彩童年',
  205. path: `pages/details/details?id=` + this.data.courseId,
  206. success: function (res) {
  207. // 转发成功
  208. console.log("转发成功:" + JSON.stringify(res));
  209. // var shareTickets = res.shareTickets;
  210. // if (shareTickets.length == 0) {
  211. // return false;
  212. // }
  213. // //可以获取群组信息
  214. // wx.getShareInfo({
  215. // shareTicket: shareTickets[0],
  216. // success: function (res) {
  217. // console.log(res)
  218. // }
  219. // })
  220. },
  221. fail: function (res) {
  222. // 转发失败
  223. console.log("转发失败:" + JSON.stringify(res));
  224. }
  225. }
  226. }
  227. })