jwyu 2 سال پیش
والد
کامیت
60b92a1e77
2فایلهای تغییر یافته به همراه107 افزوده شده و 18 حذف شده
  1. 8 4
      api/question.js
  2. 99 14
      pages/video/components/comment.vue

+ 8 - 4
api/question.js

@@ -77,10 +77,11 @@ export const apiCountAudioClick = params=>{
 
 /**
  * 点赞/吐槽
- *  "community_question_id": 35,
+ *  "community_question_id": 35, 问答ID/视频ID
     "op_type": 1, 1-点赞 2-吐槽
     "enable": 1, 0取消 1-有效数据
     "source_agent": 1, 1:小程序,2:小程序 pc 3:弘则研究公众号,4:web pc
+    source:来源:1-问答社区(默认, 传0也是); 2-视频社区
  */
 export const apiSetLike = params => {
    return httpPost('/community/set_like_or_tease',{ source_agent:1,...params })
@@ -89,10 +90,11 @@ export const apiSetLike = params => {
 /**
  * 发布评论
  * @param {*} params 
- * "community_question_id": 35,
+ * "community_question_id": 35, 问答ID/视频ID
     "content": "这里是roc的测试评论",
     "is_show_name": 0,
     "source_agent": 1,
+      source 来源:1-问答社区(默认, 传0也是); 2-视频社区
  */
 export const apiPublishComment = params => {
    return httpPost('/community/comment',{ source_agent:1,...params })
@@ -125,9 +127,10 @@ export const apiDelComment = params => {
 /**
  * 精选留言列表
  * @param {*} params
- * community_question_id 
+ * community_question_id 问答ID/视频ID
  * curr_page
  * page_size
+ * source 来源:1-问答社区(默认, 传0也是); 2-视频社区
  */
 export const apiHotComment = params => {
    return httpGet('/community/comment/hot',params)
@@ -136,9 +139,10 @@ export const apiHotComment = params => {
 /**
  * 我的留言列表
  * @param {*} params
- * community_question_id 
+ * community_question_id 问答ID/视频ID
  * curr_page
  * page_size
+ * source 来源:1-问答社区(默认, 传0也是); 2-视频社区
  */
 export const apiMyComment = params => {
    return httpGet('/community/comment/my',params)

+ 99 - 14
pages/video/components/comment.vue

@@ -1,21 +1,21 @@
 <template>
     <view class="video-comment-wrap">
         <view class="flex action-wrap">
-            <view class="item">
-                <image :src="like_img" mode="aspectFill"/>
-                <text></text>
+            <view class="item" @click="handleSetLike(1)">
+                <image :src="info.op_type===1?like_act_img:like_img" mode="aspectFill"/>
+                <text>{{info.like_total>0?info.like_total:''}}</text>
             </view>
-            <view class="item">
-                <image :src="tease_img" mode="aspectFill"/>
-                <text>10</text>
+            <view class="item" @click="handleSetLike(2)">
+                <image :src="info.op_type===2?tease_act_img:tease_img" mode="aspectFill"/>
+                <text>{{info.tease_total>0?info.tease_total:''}}</text>
             </view>
             <view class="item" @click="showComment">
                 <image :src="comment_img" mode="aspectFill"/>
-                <text>10</text>
+                <text>{{info.comment_total>0?info.comment_total:''}}</text>
             </view>
         </view>
-        <view class="list-commnet-box" v-if="false">
-            <view class="item" v-for="(item,index) in list" :key="index">
+        <view class="list-commnet-box" v-if="info.comment_list.length>0">
+            <view class="item" v-for="(item,index) in info.comment_list" :key="index">
                 <image class="avatar" :src="item.qa_avatar_url" mode="aspectFill" lazy-load="false" :key="index"/>
 				<text :key="index">{{item.comment}}</text>
             </view>
@@ -70,12 +70,14 @@
 </template>
 
 <script>
+import {apiSetLike,apiHotComment,apiMyComment} from '@/api/question'
 export default {
     props:{
-        videoInfo:{}
+        videoInfo:null
     },
     data() {
         return {
+            info:this.videoInfo,
             tease_img: require('@/static/question/tease.png'),
 			tease_act_img: require('@/static/question/tease_act.png'),
 			like_img: require('@/static/question/like.png'),
@@ -86,7 +88,6 @@ export default {
 			comment_cont: '',
 			writeBottom: 50,
 			select_comment_type:1,//默认全部
-			select_question_item: {},
 			comment_obj: {
 				title: '全部评论',
 				total: 0
@@ -99,7 +100,6 @@ export default {
         /* 关闭评论弹窗 */
         closeCommentHandle() {
             this.isShowComment = false;
-            this.select_question_item = {};
             this.comment_cont = '';
             this.select_comment_type = 1;//默认全部
         },
@@ -109,13 +109,64 @@ export default {
             if(type === this.select_comment_type) return
             this.commentList = [];
             this.select_comment_type = type;
-            // this.getComment();
+            this.getComment();
         },
 
         showComment(){
+            this.getComment()
             this.isShowComment=true
         },
 
+        // 获取评论
+        async getComment(flag){
+            const params={
+                community_question_id:this.info.community_video_id,
+                curr_page: 1,
+                page_size: 10000,
+                source:2
+            }
+            const { code,data } = this.select_comment_type===1 ? await apiHotComment(params) : await apiMyComment(params);
+            if(code !== 200) return
+            this.commentList = data.list || [];
+            this.comment_obj = {
+                title: this.select_comment_type === 1 ? '全部评论' : '我的评论',
+                total: data.paging.totals
+            }
+
+            // 如果flag='refresh' 则获取一次全部留言 更新到列表上面去
+            if(flag==='refresh'){
+                const res=await apiHotComment(params)
+                const arr=res.data.list||[]
+                this.info.comment_list=arr.map(item=>{
+                    return {
+                        comment:item.content,
+                        qa_avatar_url:item.qa_avatar_url
+                    }
+                })
+            }
+        },
+
+        //删除我的评论
+        delCommentHandle(){
+            wx.showModal({
+                title: "",
+                content: "评论删除后不可恢复,确认删除吗?",
+                confirmColor: "#EE3636",
+                cancelColor: '#333',
+                success:  async(res) => {
+                    if( res.cancel) return
+                    // const { code } = await apiDelComment({ community_question_comment_id });
+                    // if( code !== 200 ) return
+                    
+                    // this.commentList.splice(index,1)
+                    // this.comment_obj.total--
+                                
+                    // wx.showToast({title: '删除成功'});
+                    // this.refreshPage()
+                }
+            })
+        },
+
         setWritePosition(val=50) {
             console.log(val)
             this.writeBottom = val < 50 ? 50 : val-8;
@@ -123,7 +174,41 @@ export default {
 
         checkNickHandle(e){
             this.setWritePosition(e.detail.height);
-        }
+        },
+
+        //发布留言
+        async publishMessageHandle(){
+            if(!this.comment_cont) return wx.showToast({title: '请输入留言内容',icon: 'none'})
+            const { code } = await apiPublishComment({
+                content: this.comment_cont,
+                community_question_id: this.info.community_video_id,
+                source:2,
+            })
+            if(code===200){
+                wx.showToast({title: '发布成功'});
+                this.comment_cont = '';
+                this.getComment('refresh')
+            }
+        },
+
+        //吐槽/点赞
+        async handleSetLike(type){
+            const res=await apiSetLike({
+                community_question_id:this.info.community_video_id,
+                op_type: type,
+                enable: type === 1 ? Number(this.info.op_type!==1) : Number(this.info.op_type!==2),
+                source:2
+            })
+            if(res.code===200){
+                const { enabled,op_type,like_total,tease_total } = res.data;
+                this.info.tease_total = tease_total;
+                this.info.like_total = like_total;
+                this.info.op_type = enabled === 0 ? 0 : op_type ;
+                uni.showToast({
+                    title: enabled === 0 ? '取消成功' : op_type=== 1 ? '点赞成功' : '吐槽成功'
+                })
+            }
+        },
     },
 }
 </script>