123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- const pages = require('../../mixin/pages')
- const { postvideoGood, postVideoComment, postTransferVideo } = require('./api/index')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- ...pages.data(),
- listUrl: '/api/user/video/comment/list',
- searchForm: {
- 'video_id': ''
- },
- videoConfig: {},
- form: {
- comment: ''
- },
- booLock: false,
- inputBoxStyle: 'bottom:0;'
- },
- ...pages.methods,
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- const { videoConfig } = options
- if (videoConfig) {
- const temp = JSON.parse(videoConfig)
- this.setData({
- videoConfig: temp,
- 'searchForm.video_id': temp.id
- }, () => {
- this.fetchOrderList()
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- if (this.data.freshing) {
- return
- }
- this.setData({
- freshing: true
- })
- this.bindCallBack()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- this.fetchOrderList()
- },
- bindCallBack() {
- this.refreshOrderList()
- },
- onShareAppMessage(options) {
- const { video_name, video_cover_url } = this.data.videoConfig
- this.addTransferVideo()
- return {
- title: video_name,
- path: 'pages/mediaDetail/mediaDetail?videoConfig=' + JSON.stringify(this.data.videoConfig),
- imageUrl: video_cover_url
- }
- },
- handleFocus(event) {
- const height = event.detail.height
- this.setData({ inputBoxStyle: `bottom:${height}px;` })
- },
- handleBlur() {
- this.setData({ inputBoxStyle: `bottom:0;` })
- },
- setComment(event) {
- const { value } = event.detail
- this.setData({
- 'form.comment': value.trim()
- })
- },
- // 点赞
- async addvideoGood() {
- const { id } = this.data.videoConfig
- this.setData({
- booLock: true
- })
- try {
- const { status, msg } = await postvideoGood(id)
- if (status) {
- wx.showToast({
- title: '点赞成功',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- this.setData({
- booLock: false
- })
- },
- // 评论
- async addVideoComment() {
- const { id } = this.data.videoConfig
- const { comment } = this.data.form
- if (!comment) {
- wx.showToast({
- title: '说点什么吧...',
- icon: 'none'
- })
- return
- }
- this.setData({
- booLock: true
- })
- try {
- const { status, msg } = await postVideoComment(id, comment)
- if (status) {
- wx.showToast({
- title: '评论成功',
- icon: 'none'
- })
- this.setData({
- 'form.comment': ''
- })
- this.bindCallBack()
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- this.setData({
- booLock: false
- })
- },
- // 转发统计
- async addTransferVideo() {
- const { id } = this.data.videoConfig
- this.setData({
- booLock: true
- })
- try {
- await postTransferVideo(id)
- } catch (err) {}
- this.setData({
- booLock: false
- })
- }
- })
|