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 }) } })