|
@@ -1,5 +1,5 @@
|
|
|
const pages = require('../../mixin/pages')
|
|
|
-const { postFollowUser } = require('./api/index')
|
|
|
+const { postFollowUser, postAddComment, postGood } = require('./api/index')
|
|
|
|
|
|
Page({
|
|
|
|
|
@@ -24,8 +24,16 @@ Page({
|
|
|
}
|
|
|
],
|
|
|
active: '1',
|
|
|
- booLock: false
|
|
|
+ booLock: false,
|
|
|
+ autoFocus: false,
|
|
|
+ inputBoxStyle: 'bottom:0;',
|
|
|
+ form: {
|
|
|
+ track_comment: '' // 评论内容
|
|
|
+ },
|
|
|
+ placeholderText: '评论',
|
|
|
+ booPopop: false
|
|
|
},
|
|
|
+ currentItem: {}, // 当前选中的动态
|
|
|
...pages.methods,
|
|
|
|
|
|
/**
|
|
@@ -130,6 +138,131 @@ Page({
|
|
|
booLock: false
|
|
|
})
|
|
|
},
|
|
|
+ showPopop(e) {
|
|
|
+ const { item, index } = e.currentTarget.dataset
|
|
|
+
|
|
|
+ this.currentItem = {
|
|
|
+ ...item,
|
|
|
+ _index: index
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ booPopop: true
|
|
|
+ })
|
|
|
+
|
|
|
+ const timer = setTimeout(() => {
|
|
|
+ clearTimeout(timer)
|
|
|
+ this.setData({
|
|
|
+ autoFocus: true
|
|
|
+ })
|
|
|
+ }, 500)
|
|
|
+ },
|
|
|
+ hidePopop() {
|
|
|
+ this.setData({
|
|
|
+ booPopop: false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ 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.track_comment': value.trim()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 评论
|
|
|
+ async addComment() {
|
|
|
+ const { track_comment } = this.data.form
|
|
|
+ const postData = {
|
|
|
+ 'track_id': this.currentItem.id,
|
|
|
+ 'track_comment': track_comment
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!track_comment) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请输入评论内容',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.data.booLock) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ booLock: true
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ const { status, msg } = await postAddComment(postData)
|
|
|
+ if (status) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '已评论',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+
|
|
|
+ this.refreshOrderList()
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ 'form.track_comment': '',
|
|
|
+ booPopop: false
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ booLock: false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 点赞、取消点赞
|
|
|
+ async trackGood(e) {
|
|
|
+ const { item, index } = e.currentTarget.dataset
|
|
|
+ const postData = {
|
|
|
+ 'track_id': item.id,
|
|
|
+ 'type': item.good_status === 0 ? 1 : 2 // 类型(1点赞2取消点赞)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.data.booLock) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ booLock: true
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ const { status, msg } = await postGood(postData)
|
|
|
+ if (status) {
|
|
|
+ wx.showToast({
|
|
|
+ title: item.good_status === 0 ? '已点赞' : '已取消点赞',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ ['listData[' + index + '].good_status']: item.good_status === 0 ? 1 : 0,
|
|
|
+ ['listData[' + index + '].good_count']: item.good_status === 0 ? item.good_count + 1 : item.good_count - 1
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ booLock: false
|
|
|
+ })
|
|
|
+ },
|
|
|
jumpAddNews() {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/addNews/addNews'
|