mediaDetail.js 3.2 KB

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