南鑫林 пре 5 година
родитељ
комит
4b931016c1

+ 1 - 1
RainbowPlanet/RainbowPlanet/Model/CommunityModel/CommunityFollowFeedModel.swift

@@ -182,7 +182,7 @@ class CommunityFollowPostCommentModel : NSObject, Mappable{
         return CommunityFollowPostCommentModel()
     }
     required init?(map: Map){}
-    private override init(){}
+    override init(){}
     
     func mapping(map: Map)
     {

+ 44 - 1
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Follow/CommunityFollowViewController.swift

@@ -13,6 +13,7 @@ class CommunityFollowViewController: UIViewController {
     
     var cellHeightsDictionary = Dictionary<IndexPath, Any>()
     var communityFollowDataModels = Array<CommunityFollowDataModel>()
+    var communityFollowDataModel : CommunityFollowDataModel?
     /// 关注数组
     var cmsMemberModels = Array<CMSMemberModel>()
     deinit {
@@ -55,6 +56,11 @@ class CommunityFollowViewController: UIViewController {
         return followTableHeaderView
     }()
     
+    lazy var commentInputView: CommentInputView = {
+        let commentInputView = CommentInputView(isHidden: true)
+        return commentInputView
+    }()
+    
     func setupData() {
         //下拉刷新
         tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {
@@ -66,6 +72,10 @@ class CommunityFollowViewController: UIViewController {
             SwiftProgressHUD.shared().showWait()
             self?.communityFollowFeedApi(page: page)
         }
+        commentInputView.commentInputViewClosure = {
+            [weak self] text in
+            self?.communityPostCommentApi(text: text)
+        }
     }
 }
 
@@ -128,6 +138,37 @@ extension CommunityFollowViewController {
         }
     }
     
+    /// 评论
+    func communityPostCommentApi(text:String) {
+        let communityCustomCommnetModel = CommunityCustomCommnetModel()
+        communityCustomCommnetModel.postId = communityFollowDataModel?.relateData?.id ?? 0
+        communityCustomCommnetModel.content = text
+        
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
+            [weak self] (communityPostCommentIdModel) -> (Void) in
+            
+            let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
+            
+            let communityFollowPostCommentModel = CommunityFollowPostCommentModel()
+            communityFollowPostCommentModel.content = text
+            communityFollowPostCommentModel.id = communityPostCommentIdModel?.id
+            communityFollowPostCommentModel.username = UserModel.shared().getModel()?.username
+            
+            if  self?.communityFollowDataModel?.relateData?.postComment?.isEmpty ?? true {
+                self?.communityFollowDataModel?.relateData?.postComment = Array<CommunityFollowPostCommentModel>()
+            }
+            
+            self?.communityFollowDataModel?.relateData?.postComment?.insert(communityFollowPostCommentModel, at: 0)
+            
+            VirusViewModel.shared.comment(communityFollowDataModel:  self?.communityFollowDataModel, id: communityPostCommentIdModel?.id ?? 0)
+            let count = self?.communityFollowDataModel?.relateData?.commentCount ?? 0 + 1
+            self?.communityFollowDataModel?.relateData?.commentCount = count
+            self?.tableView.reloadData()
+            self?.commentInputView.sendSuccess()
+            
+        }
+    }
+    
 }
 
 extension CommunityFollowViewController : UITableViewDelegate,UITableViewDataSource {
@@ -274,7 +315,9 @@ extension CommunityFollowViewController : UITableViewDelegate,UITableViewDataSou
         case 5:
             let cell = CardContentCommnetTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
             cell.addCommnetClosureName = {
-                
+                [weak self] in
+                self?.communityFollowDataModel = self?.communityFollowDataModels[indexPath.section]
+                self?.commentInputView.inputTextView.becomeFirstResponder()
             }
             return cell
         default:

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

@@ -487,6 +487,26 @@ extension VirusViewModel {
         })
     }
     
+    func comment(communityFollowDataModel:CommunityFollowDataModel? = nil,id:Int) {
+        let virueRecordAddParameterModel = VirueRecordAddParameterModel()
+        virueRecordAddParameterModel.behaviorId = (ConfigModel.shared.object()?.virus?.publish ?? "")
+        virueRecordAddParameterModel.behaviorFlag = BehaviorFlagType.publish.rawValue
+        
+        virueRecordAddParameterModel.postId = communityFollowDataModel?.relateData?.id
+        virueRecordAddParameterModel.postAuthorUid = "\(communityFollowDataModel?.relateData?.uid ?? 0)"
+        if communityFollowDataModel?.relateData?.title == nil ||  communityFollowDataModel?.relateData?.title == "" {
+            virueRecordAddParameterModel.postDesc = String(describing: communityFollowDataModel?.relateData?.content!.prefix(20))
+        }else {
+            virueRecordAddParameterModel.postDesc = communityFollowDataModel?.relateData?.title
+        }
+        virueRecordAddParameterModel.postType = communityFollowDataModel?.relateData?.type
+        virueRecordAddParameterModel.postCover = communityFollowDataModel?.relateData?.img
+        virueRecordAddParameterModel.actionId = "\(id)"
+        
+        SwiftMoyaNetWorkServiceVirus.shared().virueRecordAddApi(virueRecordAddParameterModel: virueRecordAddParameterModel, completion: {(data) -> (Void) in
+        })
+    }
+    
 }
 
 // MARK: - 阅读