details.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. },
  24. //点击收藏
  25. favorites: function () {
  26. this.setData({
  27. favoritesFlag: !this.data.favoritesFlag
  28. })
  29. httpRequestApi.getDetailsFavorites({
  30. targetCode: this.data.courseId,
  31. title: this.data.title,
  32. iconImg: this.data.iconImg
  33. }).success((res)=>{
  34. })
  35. },
  36. //点击添加到播放记录
  37. addHistory: function () {
  38. //console.log('播放',currentTarget.dataset);
  39. httpRequestApi.addPlayLogList({
  40. "title": this.data.title,
  41. "courseId": this.data.courseId,
  42. "courseWareId": this.data.courseWareId
  43. }).success(res => {
  44. })
  45. },
  46. //点击出现选集
  47. commentAnthology: function () {
  48. this.setData({
  49. anthologyHide: !this.data.anthologyHide
  50. })
  51. },
  52. //出现详情页
  53. commentDetails: function () {
  54. this.setData({
  55. detailsHide: !this.data.detailsHide
  56. })
  57. },
  58. //点击评论
  59. pinglun: function () {
  60. this.setData({
  61. hide: !this.data.hide
  62. })
  63. },
  64. //点击取消
  65. no: function () {
  66. this.setData({
  67. hide: !this.data.hide,
  68. str: ''
  69. })
  70. },
  71. //点击确定评论
  72. yes: function () {
  73. if(this.data.str === '') {
  74. wx.showModal({
  75. title: '提示',
  76. content: '请输入内容'
  77. })
  78. return false;
  79. }
  80. httpRequestApi.getDetailsPosts({
  81. columnId: this.data.courseId,
  82. columnNames: this.data.title,
  83. detailDesc: this.data.str
  84. }).success((res)=>{
  85. if(res.data.success){
  86. wx.showToast({
  87. title: '评论成功'
  88. })
  89. this.setData({
  90. hide: !this.data.hide,
  91. str: ''
  92. })
  93. //获取评论列表
  94. this.getPostsList(this.data.courseId);
  95. }
  96. })
  97. },
  98. //获取输入值
  99. focus: function ({detail}) {
  100. this.setData({
  101. str: detail.value
  102. })
  103. },
  104. /**
  105. * 生命周期函数--监听页面加载
  106. */
  107. onLoad: function (options) {
  108. const courseId = options.id;
  109. httpRequestApi.getCourseDetails(courseId).success((res)=>{
  110. console.log('课程详情', res);
  111. const data = res.data.data;
  112. this.setData({
  113. favoritesFlag: data.isFavorites,
  114. title: data.course.title,
  115. iconImg: data.course.iconImg,
  116. courseId,
  117. summary: data.course.summary,
  118. courseWareList: data.courseWareList,
  119. playUrl: data.courseWareList[0].playUrl,
  120. courseWareId: data.courseWareList[0].id
  121. })
  122. })
  123. //获取评论列表
  124. this.getPostsList(courseId);
  125. },
  126. //获取评论列表
  127. getPostsList: function (courseId) {
  128. httpRequestApi.getPostsList({
  129. courseId,
  130. pageNo: 1,
  131. pageSize: 10
  132. }).success((res)=>{
  133. console.log('评论列表', res);
  134. const dateArr = [];
  135. res.data.data.list.forEach(item => {
  136. dateArr.push(util.formatTime(new Date(item.gmtCreated)));
  137. });
  138. this.setData({
  139. postsList: res.data.data.list,
  140. dateArr
  141. })
  142. })
  143. },
  144. /**
  145. * 生命周期函数--监听页面初次渲染完成
  146. */
  147. onReady: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面显示
  151. */
  152. onShow: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面隐藏
  156. */
  157. onHide: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面卸载
  161. */
  162. onUnload: function () {
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom: function () {
  173. },
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage: function () {
  178. }
  179. })