details.js 3.6 KB

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