mediaDetail.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. const pages = require('../../mixin/pages')
  2. const { postvideoGood, postVideoComment } = require('./api/index')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. ...pages.data(),
  9. listUrl: '/api/user/video/comment/list',
  10. searchForm: {
  11. 'video_id': ''
  12. },
  13. videoConfig: {},
  14. form: {
  15. comment: ''
  16. },
  17. booLock: false
  18. },
  19. ...pages.methods,
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. const { videoConfig } = options
  25. if (videoConfig) {
  26. const temp = JSON.parse(videoConfig)
  27. this.setData({
  28. videoConfig: temp,
  29. 'searchForm.video_id': temp.id
  30. }, () => {
  31. this.fetchOrderList()
  32. })
  33. }
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady() {
  39. },
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow() {
  44. },
  45. /**
  46. * 生命周期函数--监听页面隐藏
  47. */
  48. onHide() {
  49. },
  50. /**
  51. * 生命周期函数--监听页面卸载
  52. */
  53. onUnload() {
  54. },
  55. /**
  56. * 页面相关事件处理函数--监听用户下拉动作
  57. */
  58. onPullDownRefresh() {
  59. if (this.data.freshing) {
  60. return
  61. }
  62. this.setData({
  63. freshing: true
  64. })
  65. this.bindCallBack()
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom() {
  71. this.fetchOrderList()
  72. },
  73. bindCallBack() {
  74. this.refreshOrderList()
  75. },
  76. onShareAppMessage(options) {
  77. const { video_name, video_cover_url } = this.data.videoConfig
  78. return {
  79. title: video_name,
  80. path: 'pages/mediaDetail/mediaDetail?videoConfig=' + JSON.stringify(this.data.videoConfig),
  81. imageUrl: video_cover_url
  82. }
  83. },
  84. setComment(event) {
  85. const { value } = event.detail
  86. this.setData({
  87. 'form.comment': value.trim()
  88. })
  89. },
  90. // 点赞
  91. async addvideoGood() {
  92. const { id } = this.data.videoConfig
  93. this.setData({
  94. booLock: true
  95. })
  96. try {
  97. const { status, msg } = await postvideoGood(id)
  98. if (status) {
  99. wx.showToast({
  100. title: '点赞成功',
  101. icon: 'none'
  102. })
  103. } else {
  104. wx.showToast({
  105. title: msg,
  106. icon: 'none'
  107. })
  108. }
  109. } catch (err) {}
  110. this.setData({
  111. booLock: false
  112. })
  113. },
  114. // 评论
  115. async addVideoComment() {
  116. const { id } = this.data.videoConfig
  117. const { comment } = this.data.form
  118. if (!comment) {
  119. wx.showToast({
  120. title: '说点什么吧...',
  121. icon: 'none'
  122. })
  123. return
  124. }
  125. this.setData({
  126. booLock: true
  127. })
  128. try {
  129. const { status, msg } = await postVideoComment(id, comment)
  130. if (status) {
  131. wx.showToast({
  132. title: '评论成功',
  133. icon: 'none'
  134. })
  135. this.setData({
  136. 'form.comment': ''
  137. })
  138. this.bindCallBack()
  139. } else {
  140. wx.showToast({
  141. title: msg,
  142. icon: 'none'
  143. })
  144. }
  145. } catch (err) {}
  146. this.setData({
  147. booLock: false
  148. })
  149. }
  150. })