mediaDetail.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. const pages = require('../../mixin/pages')
  2. const { postvideoGood, postVideoComment, postTransferVideo } = 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. this.addTransferVideo()
  80. return {
  81. title: video_name,
  82. path: 'pages/mediaDetail/mediaDetail?videoConfig=' + JSON.stringify(this.data.videoConfig),
  83. imageUrl: video_cover_url
  84. }
  85. },
  86. handleFocus(event) {
  87. const height = event.detail.height
  88. this.setData({ inputBoxStyle: `bottom:${height}px;` })
  89. },
  90. handleBlur() {
  91. this.setData({ inputBoxStyle: `bottom:0;` })
  92. },
  93. setComment(event) {
  94. const { value } = event.detail
  95. this.setData({
  96. 'form.comment': value.trim()
  97. })
  98. },
  99. // 点赞
  100. async addvideoGood() {
  101. const { id } = this.data.videoConfig
  102. this.setData({
  103. booLock: true
  104. })
  105. try {
  106. const { status, msg } = await postvideoGood(id)
  107. if (status) {
  108. wx.showToast({
  109. title: '点赞成功',
  110. icon: 'none'
  111. })
  112. } else {
  113. wx.showToast({
  114. title: msg,
  115. icon: 'none'
  116. })
  117. }
  118. } catch (err) {}
  119. this.setData({
  120. booLock: false
  121. })
  122. },
  123. // 评论
  124. async addVideoComment() {
  125. const { id } = this.data.videoConfig
  126. const { comment } = this.data.form
  127. if (!comment) {
  128. wx.showToast({
  129. title: '说点什么吧...',
  130. icon: 'none'
  131. })
  132. return
  133. }
  134. this.setData({
  135. booLock: true
  136. })
  137. try {
  138. const { status, msg } = await postVideoComment(id, comment)
  139. if (status) {
  140. wx.showToast({
  141. title: '评论成功',
  142. icon: 'none'
  143. })
  144. this.setData({
  145. 'form.comment': ''
  146. })
  147. this.bindCallBack()
  148. } else {
  149. wx.showToast({
  150. title: msg,
  151. icon: 'none'
  152. })
  153. }
  154. } catch (err) {}
  155. this.setData({
  156. booLock: false
  157. })
  158. },
  159. // 转发统计
  160. async addTransferVideo() {
  161. const { id } = this.data.videoConfig
  162. this.setData({
  163. booLock: true
  164. })
  165. try {
  166. await postTransferVideo(id)
  167. } catch (err) {}
  168. this.setData({
  169. booLock: false
  170. })
  171. }
  172. })