Chris преди 5 години
родител
ревизия
5dc9406b48

+ 63 - 1
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/View/CommunityAllCommentView.swift

@@ -28,6 +28,9 @@ class CommunityAllCommentView: FWPopupView {
         }
     }
     
+    // 视频贴のModel
+    var videoItemModel: CommunityVideoItemModel?
+    
     // 评论
     var communityPostCommentsModel : CommunityPostCommentsModel?
     var communityPostCommentModels = Array<CommunityPostCommentModel>()
@@ -97,7 +100,7 @@ class CommunityAllCommentView: FWPopupView {
         
         commentInputView.commentInputViewClosure = {
             [weak self] text in
-//            self?.communityPostCommentApi(text: text)
+            self?.communityPostCommentApi(text: text)
         }
     }
     
@@ -229,6 +232,65 @@ extension CommunityAllCommentView {
                 self?.noCommentsLabel.isHidden = true
             }
         }
+    }
+    
+    /// 评论
+    func communityPostCommentApi(text:String) {
+        let communityCustomCommnetModel = CommunityCustomCommnetModel()
+        communityCustomCommnetModel.postId = videoItemModel?.id ?? 0
+        communityCustomCommnetModel.content = text
+        if communityPostCommentModel != nil {
+            communityCustomCommnetModel.parentId = communityPostCommentModel?.id
+            communityCustomCommnetModel.replyUid = communityPostCommentModel?.uid
+            communityCustomCommnetModel.replyUsername = communityPostCommentModel?.username
+        }
         
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
+            [weak self] (communityPostCommentIdModel) -> (Void) in
+            
+            let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
+            
+            
+            if self?.communityPostCommentModel == nil { //评
+                let communityPostCommentModel = CommunityPostCommentModel()
+                communityPostCommentModel.avatar = UserModel.shared().getModel()?.avatarurl
+                communityPostCommentModel.content = text
+                communityPostCommentModel.createdAt = "刚刚"
+                communityPostCommentModel.id = communityPostCommentIdModel?.id
+                communityPostCommentModel.username = UserModel.shared().getModel()?.username
+                communityPostCommentModel.uid = UserModel.shared().getModel()?.uid
+                self?.communityPostCommentModels.insert(communityPostCommentModel, at: 0)
+                
+                
+                VirusViewModel.shared.comment(communityVideoItemModel: (self?.videoItemModel)!, id: communityPostCommentIdModel?.id ?? 0)
+                
+                self?.tableView.reloadData()
+                
+            }else { //回评论
+                let communityPostReplyModel = CommunityPostReplyModel()
+                communityPostReplyModel.avatar = UserModel.shared().getModel()?.avatarurl
+                communityPostReplyModel.content = text
+                communityPostReplyModel.createdAt = "刚刚"
+                communityPostReplyModel.id = communityPostCommentIdModel?.id
+                communityPostReplyModel.username = UserModel.shared().getModel()?.username
+                communityPostReplyModel.uid = UserModel.shared().getModel()?.uid
+                let count  = self?.communityPostCommentModel?.replyCount ?? 0 + 1
+                self?.communityPostCommentModel?.replyCount = count
+                if self?.communityPostCommentModel?.reply == nil {
+                    self?.communityPostCommentModel?.reply = Array<CommunityPostReplyModel>()
+                }
+                self?.communityPostCommentModel?.reply?.insert(communityPostReplyModel, at: 0)
+               
+//                VirusViewModel.shared.comment(communityVideoItemModel: (self?.videoItemModel)!, id: communityPostCommentIdModel?.id ?? 0, communityPostCommentModel: <#T##CommunityPostCommentModel?#>, communityPostReplyModel: <#T##CommunityPostReplyModel?#>)
+//
+//                self?.communityPostCommentModel
+                
+                self?.tableView.reloadData()
+            }
+            self?.commentInputView.sendSuccess()
+            
+        }
     }
+    
+    
 }

+ 5 - 3
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/ViewController/CommunityVideoListController.swift

@@ -142,7 +142,7 @@ extension CommunityVideoListController: UICollectionViewDelegateFlowLayout,UICol
             [weak self] (clickType, uid, postId) in
             switch clickType {
             case videoBtnClickType.typeComment:
-                self?.showCommentView(postId: postId)
+                self?.showCommentView(postId: postId, videoItemMdl: (self?.videoItemList?[indexPath.row])!)
                 
             case videoBtnClickType.typeLike:
                 VirusViewModel.shared.praise(communityVideoItemModel: (self?.videoItemList?[indexPath.row])!)
@@ -218,15 +218,17 @@ extension CommunityVideoListController {
         }
     }
     
-    func showCommentView(postId: Int) {
+    func showCommentView(postId: Int, videoItemMdl: CommunityVideoItemModel) {
         
-        AlertSheetView.commentAlertSheetView(postId: postId, cancelClosure: {
+        AlertSheetView.commentAlertSheetView(postId: postId, videoItemMdl: videoItemMdl, cancelClosure: {
             [weak self] in
             
         }) {
             [weak self] (payType) in
             print("----\(payType)")
         }
+        
+       
     }
     
 }

+ 3 - 1
RainbowPlanet/RainbowPlanet/Tools/AlertSheetView/AlertSheetView.swift

@@ -114,9 +114,11 @@ class AlertSheetView: NSObject {
     }
     
     /// 自定义评论View
-    class func commentAlertSheetView(postId:Int, cancelClosure:@escaping () -> Void, sureClosure:@escaping (_ pType: PayType) -> Void) {
+    class func commentAlertSheetView(postId:Int, videoItemMdl: CommunityVideoItemModel, cancelClosure:@escaping () -> Void, sureClosure:@escaping (_ pType: PayType) -> Void) {
         let commentView = CommunityAllCommentView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: kSafeTabBarHeight + 500))
         commentView.postId = postId
+        commentView.videoItemModel = videoItemMdl
+        
         let vProperty = FWPopupViewProperty()
         vProperty.popupCustomAlignment = .bottomCenter
         vProperty.popupAnimationType = .frame

+ 31 - 0
RainbowPlanet/RainbowPlanet/ViewModel/Virus/VirusViewModel.swift

@@ -465,6 +465,37 @@ extension VirusViewModel {
         })
     }
     
+    func comment(communityVideoItemModel:CommunityVideoItemModel,id:Int,communityPostCommentModel:CommunityPostCommentModel? = nil,communityPostReplyModel:CommunityPostReplyModel? = nil) {
+        let virueRecordAddParameterModel = VirueRecordAddParameterModel()
+        virueRecordAddParameterModel.behaviorId = (ConfigModel.shared.object()?.virus?.publish ?? "")
+        virueRecordAddParameterModel.behaviorFlag = BehaviorFlagType.publish.rawValue
+        
+        virueRecordAddParameterModel.postId = communityVideoItemModel.id
+        virueRecordAddParameterModel.postAuthorUid = "\(communityVideoItemModel.uid!)"
+        if communityVideoItemModel.title == nil ||  communityVideoItemModel.title == "" {
+            virueRecordAddParameterModel.postDesc = String(describing: communityVideoItemModel.content!.prefix(20))
+        }else {
+            virueRecordAddParameterModel.postDesc = communityVideoItemModel.title
+        }
+        virueRecordAddParameterModel.postType = communityVideoItemModel.type
+        virueRecordAddParameterModel.postCover = communityVideoItemModel.img
+        virueRecordAddParameterModel.targetId = "\((UserModel.shared().getModel()?.uid)!)"
+        
+        virueRecordAddParameterModel.actionId = "\(id)"
+        
+        virueRecordAddParameterModel.commentId = communityPostCommentModel?.id
+        virueRecordAddParameterModel.commentContent = communityPostCommentModel?.content
+        
+        virueRecordAddParameterModel.parentCommentId = communityPostReplyModel?.id
+        virueRecordAddParameterModel.parentCommentContent = communityPostReplyModel?.content
+        virueRecordAddParameterModel.parentCommentUid = communityPostReplyModel?.uid
+        virueRecordAddParameterModel.parentCommentTime = communityPostReplyModel?.createdAt
+        
+        
+        SwiftMoyaNetWorkServiceVirus.shared().virueRecordAddApi(virueRecordAddParameterModel: virueRecordAddParameterModel, completion: {(data) -> (Void) in
+        })
+    }    
+    
     func comment(communityRecommendDataModel:CommunityRecommendDataModel? = nil,id:Int) {
         let virueRecordAddParameterModel = VirueRecordAddParameterModel()
         virueRecordAddParameterModel.behaviorId = (ConfigModel.shared.object()?.virus?.publish ?? "")