mediaDetail.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. inputPosition: 'fixed'
  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() {
  86. const sys = wx.getSystemInfoSync()
  87. },
  88. handleBlur() {},
  89. setComment(event) {
  90. const { value } = event.detail
  91. this.setData({
  92. 'form.comment': value.trim()
  93. })
  94. },
  95. // 点赞
  96. async addvideoGood() {
  97. const { id } = this.data.videoConfig
  98. this.setData({
  99. booLock: true
  100. })
  101. try {
  102. const { status, msg } = await postvideoGood(id)
  103. if (status) {
  104. wx.showToast({
  105. title: '点赞成功',
  106. icon: 'none'
  107. })
  108. } else {
  109. wx.showToast({
  110. title: msg,
  111. icon: 'none'
  112. })
  113. }
  114. } catch (err) {}
  115. this.setData({
  116. booLock: false
  117. })
  118. },
  119. // 评论
  120. async addVideoComment() {
  121. const { id } = this.data.videoConfig
  122. const { comment } = this.data.form
  123. if (!comment) {
  124. wx.showToast({
  125. title: '说点什么吧...',
  126. icon: 'none'
  127. })
  128. return
  129. }
  130. this.setData({
  131. booLock: true
  132. })
  133. try {
  134. const { status, msg } = await postVideoComment(id, comment)
  135. if (status) {
  136. wx.showToast({
  137. title: '评论成功',
  138. icon: 'none'
  139. })
  140. this.setData({
  141. 'form.comment': ''
  142. })
  143. this.bindCallBack()
  144. } else {
  145. wx.showToast({
  146. title: msg,
  147. icon: 'none'
  148. })
  149. }
  150. } catch (err) {}
  151. this.setData({
  152. booLock: false
  153. })
  154. }
  155. })