瀏覽代碼

no message

南鑫林 5 年之前
父節點
當前提交
19c9111bc5

+ 8 - 0
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -199,6 +199,8 @@
 		A770E5E022CF19FA00CBD0A4 /* CommunityRouterModuleType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A770E5DF22CF19FA00CBD0A4 /* CommunityRouterModuleType.swift */; };
 		A770E5E722D3422800CBD0A4 /* CommentInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A770E5E622D3422800CBD0A4 /* CommentInputView.swift */; };
 		A770E5E922D383E500CBD0A4 /* CommunityCustomCommnetModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A770E5E822D383E500CBD0A4 /* CommunityCustomCommnetModel.swift */; };
+		A770E5EB22D424A300CBD0A4 /* CommunityPostCommentIdModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A770E5EA22D424A300CBD0A4 /* CommunityPostCommentIdModel.swift */; };
+		A770E5ED22D4298100CBD0A4 /* CommentReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A770E5EC22D4298100CBD0A4 /* CommentReplyView.swift */; };
 		A771F07C226D4E1C007999DB /* AddressPOITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A771F07B226D4E1C007999DB /* AddressPOITableViewCell.swift */; };
 		A773D02F229FDC3B007A5751 /* DIYEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A773D02E229FDC3B007A5751 /* DIYEmptyView.swift */; };
 		A775CBFE2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A775CBFD2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift */; };
@@ -875,6 +877,8 @@
 		A770E5DF22CF19FA00CBD0A4 /* CommunityRouterModuleType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityRouterModuleType.swift; sourceTree = "<group>"; };
 		A770E5E622D3422800CBD0A4 /* CommentInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentInputView.swift; sourceTree = "<group>"; };
 		A770E5E822D383E500CBD0A4 /* CommunityCustomCommnetModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityCustomCommnetModel.swift; sourceTree = "<group>"; };
+		A770E5EA22D424A300CBD0A4 /* CommunityPostCommentIdModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommunityPostCommentIdModel.swift; sourceTree = "<group>"; };
+		A770E5EC22D4298100CBD0A4 /* CommentReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentReplyView.swift; sourceTree = "<group>"; };
 		A771F07B226D4E1C007999DB /* AddressPOITableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressPOITableViewCell.swift; sourceTree = "<group>"; };
 		A773D02E229FDC3B007A5751 /* DIYEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DIYEmptyView.swift; sourceTree = "<group>"; };
 		A775CBFD2237493600EBDCF8 /* ShoppingMallNavigationBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingMallNavigationBarView.swift; sourceTree = "<group>"; };
@@ -2667,6 +2671,7 @@
 			isa = PBXGroup;
 			children = (
 				A770E5E622D3422800CBD0A4 /* CommentInputView.swift */,
+				A770E5EC22D4298100CBD0A4 /* CommentReplyView.swift */,
 			);
 			path = CommentInputView;
 			sourceTree = "<group>";
@@ -3953,6 +3958,7 @@
 				A72623EA22C4B91900AEF875 /* CommunityPostsModel.swift */,
 				A72623E822C4AFF200AEF875 /* CommunityTopicsModel.swift */,
 				A7AA9F6422C63DCD0086498B /* CommunityFollowFeedModel.swift */,
+				A770E5EA22D424A300CBD0A4 /* CommunityPostCommentIdModel.swift */,
 				A7AA9F6622C640F10086498B /* CommunityRecommendFeedModel.swift */,
 				A71CAB3822C9DF0600D908A8 /* CommunityTopicDetailModel.swift */,
 				A71CAB3A22C9F21100D908A8 /* CommunityMemberFollowTopicListModel.swift */,
@@ -5681,6 +5687,7 @@
 				A72A72BA22321DE000B21995 /* Extension+String.swift in Sources */,
 				BDAF83B222B3B67D0004BCC3 /* RecommendCommentFooter.swift in Sources */,
 				A70B8430228FF6D400882BC5 /* ProductCartCountModel.swift in Sources */,
+				A770E5ED22D4298100CBD0A4 /* CommentReplyView.swift in Sources */,
 				A77F2CA02231FE45001BD3F6 /* BaseWebViewController.swift in Sources */,
 				BDAF83B422B3B6DF0004BCC3 /* RecommendMajorCommentCell.swift in Sources */,
 				BD20F1D52283D15500677D8E /* OrderFinishPayFailureCell.swift in Sources */,
@@ -6256,6 +6263,7 @@
 				BD61231222C36E0B00D3F513 /* AliyunLibraryMusicImport.m in Sources */,
 				BD1FC18822B0A30300D55081 /* CommunityMajorCommentCell.swift in Sources */,
 				BD6EDF48229007EA009A20FE /* OrderApplyRefundModel.swift in Sources */,
+				A770E5EB22D424A300CBD0A4 /* CommunityPostCommentIdModel.swift in Sources */,
 				A72A7388223396CB00B21995 /* ApiMacro.swift in Sources */,
 				A72A72B922321DE000B21995 /* Extension+Array.swift in Sources */,
 				A70B2C492288416F00B2449F /* ProductDetailHotSellCollectionViewCell.swift in Sources */,

+ 48 - 0
RainbowPlanet/RainbowPlanet/Model/CommunityModel/CommunityPostCommentIdModel.swift

@@ -0,0 +1,48 @@
+//
+//	CommunityPostCommentIdModel.swift
+//	Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport
+
+import Foundation 
+import ObjectMapper
+
+
+class CommunityPostCommentIdModel : NSObject, NSCoding, Mappable{
+
+	var id : Int?
+
+
+	class func newInstance(map: Map) -> Mappable?{
+		return CommunityPostCommentIdModel()
+	}
+	required init?(map: Map){}
+	private override init(){}
+
+	func mapping(map: Map)
+	{
+		id <- map["id"]
+		
+	}
+
+    /**
+    * NSCoding required initializer.
+    * Fills the data from the passed decoder
+    */
+    @objc required init(coder aDecoder: NSCoder)
+	{
+         id = aDecoder.decodeObject(forKey: "id") as? Int
+
+	}
+
+    /**
+    * NSCoding required method.
+    * Encodes mode properties into the decoder
+    */
+    @objc func encode(with aCoder: NSCoder)
+	{
+		if id != nil{
+			aCoder.encode(id, forKey: "id")
+		}
+
+	}
+
+}

+ 1 - 0
RainbowPlanet/RainbowPlanet/Model/UserModel/UserModel.swift

@@ -50,6 +50,7 @@ class UserModel : NSObject, NSCoding, Mappable{
         unionId <- map["union_id"]
         isFollowSuggestTopic <- map["is_follow_suggest_topic"]
         isNewMember <- map["is_new_member"]
+        username <- map["username"]
 		
 	}
 

+ 1 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/Controller/CommunityRecommendController.swift

@@ -352,6 +352,7 @@ extension CommunityRecommendController: UITableViewDataSource, UITableViewDelega
                 return cell
             }else {
                 let cell = RecommendMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
+                cell.postId = id
                 cell.communityPostCommentModel = communityPostCommentModels[indexPath.row]
                 cell.frame = tableView.bounds
                 cell.layoutIfNeeded()

+ 4 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/AllCommentCell/RecommendMajorCommentCell.swift

@@ -170,6 +170,9 @@ class RecommendMajorCommentCell: UITableViewCell {
             timeLabel.text = communityPostCommentModel?.createdAt
         }
     }
+    
+    /// 帖子Id
+    var postId : Int?
 }
 
 
@@ -197,6 +200,7 @@ extension RecommendMajorCommentCell: UITableViewDataSource, UITableViewDelegate
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         let vc = CommunitySubCommentController()
         vc.communityPostCommentModel = communityPostCommentModel
+        vc.postId = postId
         findViewController()?.navigationController?.pushViewController(vc, animated: true)
     }
     

+ 30 - 22
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunitySubComment/ViewController/CommunitySubCommentController.swift

@@ -11,6 +11,7 @@ import IQKeyboardManagerSwift
 
 class CommunitySubCommentController: BaseViewController {
     
+    var postId : Int?
     var communityPostCommentModel : CommunityPostCommentModel?
     var communityPostReplyModels = Array<CommunityPostReplyModel>()
     var communityPostReplyModel : CommunityPostReplyModel?
@@ -19,7 +20,6 @@ class CommunitySubCommentController: BaseViewController {
     override func viewDidLoad() {
         
         super.viewDidLoad()
-        IQKeyboardManager.shared.enable = true
         setupViews()
         setupLayouts()
         setupData()
@@ -31,7 +31,6 @@ class CommunitySubCommentController: BaseViewController {
         
         view.addSubview(tableView)
         view.addSubview(commentInputView)
-//        view.addSubview(cmtKeyboard)
     }
     
     override func setupLayouts() {
@@ -71,7 +70,10 @@ class CommunitySubCommentController: BaseViewController {
             [weak self] text in
             self?.communityPostCommentApi(text: text)
         }
-        
+        commentInputView.keyboardWillHideNotificationClosure = {
+            [weak self] in
+            self?.communityPostReplyModel = nil
+        }
     }
 }
 
@@ -100,24 +102,28 @@ extension CommunitySubCommentController {
     
     func communityPostCommentApi(text:String) {
         let communityCustomCommnetModel = CommunityCustomCommnetModel()
-        communityCustomCommnetModel.postId = communityPostCommentModel?.id ?? 0
+        communityCustomCommnetModel.postId = postId ?? 0
         communityCustomCommnetModel.content = text
-        communityCustomCommnetModel.parentId = communityPostReplyModel?.id
+        communityCustomCommnetModel.parentId = communityPostCommentModel?.id
         communityCustomCommnetModel.replyUid = communityPostReplyModel?.uid
         communityCustomCommnetModel.replyUsername = communityPostReplyModel?.username
         SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
-            [weak self] (data) -> (Void) in
-//            var createdAt : String?
-//            var replyUsername : String?
-//            var uid : Int?
-//            var username : String?
-//            var id : Int?
-//            var height : CGFloat?
-//            var communityPostReplyModel = CommunityPostReplyModel()
-//            communityPostReplyModel.avatar = UserModel.shared().getModel()?.avatarurl
-//            communityPostReplyModel.content = text
-//            self?.communityPostReplyModels.insert(communityPostReplyModel, at: 0)
-            self?.commentInputView.inputTextView.endEditing(true)
+            [weak self] (communityPostCommentIdModel) -> (Void) in
+
+            let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
+            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
+            if self?.communityPostReplyModel != nil {
+                communityPostReplyModel.replyUsername = self?.communityPostReplyModel?.username
+            }
+            self?.communityPostReplyModels.insert(communityPostReplyModel, at: 0)
+            self?.tableView.reloadSections([1], with: UITableView.RowAnimation.none)
+            self?.commentInputView.sendSuccess()
         }
     }
 }
@@ -164,11 +170,13 @@ extension CommunitySubCommentController: UITableViewDataSource, UITableViewDeleg
         case 0:
             break
         default:
-//            communityPostReplyModel = communityPostReplyModels[indexPath.row]
-//            if !commentInputView.iskeyboardVisable {
-//                commentInputView.inputTextView.becomeFirstResponder()
-//                commentInputView.inputTextView.placeholder = "回复:@\(communityPostReplyModel?.username ?? "")"
-//            }
+            communityPostReplyModel = communityPostReplyModels[indexPath.row]
+            AlertSheetView.sheetCommentReplyView(userName: communityPostReplyModel?.username ?? "", content: communityPostReplyModel?.content ?? "") {
+                [weak self] in
+                self?.commentInputView.inputTextView.becomeFirstResponder()
+                self?.communityPostReplyModel = self?.communityPostReplyModels[indexPath.row]
+                self?.commentInputView.inputTextView.placeholder = "回复:@\(self?.communityPostReplyModel?.username ?? "")"
+            }
             break
         }
     }

+ 2 - 2
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceCommunity/SwiftMoyaNetWorkServiceCommunity.swift

@@ -356,9 +356,9 @@ public class SwiftMoyaNetWorkServiceCommunity: NSObject {
         var parameters = Dictionary<String,Any>()
         parameters = communityCustomCommnetModel.toJSON()
         SwiftProgressHUD.shared().showWait()
-        SwiftMoyaNetWorkManager.shared.requestAny(target: MultiTarget(SwiftMoyaServiceCommunityApi.communityPostComment(parameters: parameters))) {  (data) in
+        SwiftMoyaNetWorkManager.shared.requestObject(CommunityPostCommentIdModel.self,target: MultiTarget(SwiftMoyaServiceCommunityApi.communityPostComment(parameters: parameters))) {  (communityPostCommentIdModel) in
             SwiftProgressHUD.shared().hide()
-            completion("")
+            completion(communityPostCommentIdModel)
         }
     }
         

+ 18 - 0
RainbowPlanet/RainbowPlanet/Tools/AlertSheetView/AlertSheetView.swift

@@ -198,4 +198,22 @@ extension AlertSheetView {
         }
         view.show()
     }
+    
+    
+    /// 评论回复
+    class func sheetCommentReplyView(userName:String,content:String,replyClosure:@escaping (() -> Void)) {
+        let view = CommentReplyView(userName: userName, content: content)
+        let vProperty = FWPopupViewProperty()
+        vProperty.popupCustomAlignment = .bottomCenter
+        vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
+        vProperty.popupAnimationType = .frame
+        vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
+        vProperty.touchWildToHide = "0"
+        view.vProperty = vProperty
+        view.replyButtonClosure = {
+            replyClosure()
+        }
+        view.show()
+        
+    }
 }

+ 16 - 7
RainbowPlanet/RainbowPlanet/Tools/CommentInputView/CommentInputView.swift

@@ -19,8 +19,6 @@ class CommentInputView: UIView {
     let inputTextViewWidth = kScreenWidth - 14 - 89
     /// 键盘的Y
     var keyboardH : CGFloat = 0
-    /// 键盘是否可见
-    var iskeyboardVisable : Bool = false
     /// 是否隐藏View
     var inputViewIsHidden : Bool = false {
         didSet {
@@ -101,13 +99,19 @@ class CommentInputView: UIView {
                 // 键盘的frame
                 let keyboardFrame = userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
                 self?.keyboardH = (keyboardFrame?.size.height)!
-                // 键盘是否可见
-                self?.iskeyboardVisable = true
+
+                if self?.inputTextView.text.count ?? 0 > 0 {
+                    self?.sendButton.isEnabled = true
+                }else {
+                    self?.sendButton.isEnabled = false
+                }
                 UIView.animate(withDuration: duration ?? 0, animations: {
                     self?.y = kScreenHeight - (keyboardFrame?.size.height)! - (self?.height)! + kSafeTabBarHeight
                 })
             })
         
+        
+        
         //监听键盘隐藏通知
         _ = NotificationCenter.default.rx
             .notification(UIResponder.keyboardWillHideNotification)
@@ -119,9 +123,11 @@ class CommentInputView: UIView {
                 // 键盘的frame
                 let keyboardFrame = userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
                 self?.keyboardH = (keyboardFrame?.size.height)!
-                // 键盘是否可见
-                self?.iskeyboardVisable = false
                 self?.inputTextView.placeholder = "添加评论...";
+                self?.sendButton.isEnabled = false
+                if let keyboardWillHideNotificationClosure = self?.keyboardWillHideNotificationClosure {
+                    keyboardWillHideNotificationClosure()
+                }
                 UIView.animate(withDuration: duration ?? 0, animations: {
                     if self?.inputViewIsHidden ?? true {
                         self?.y = kScreenHeight
@@ -146,12 +152,15 @@ class CommentInputView: UIView {
         self.inputTextView.height = 30
         self.height = 48 + kSafeTabBarHeight
         self.y = kScreenHeight - self.height
-        self.iskeyboardVisable = false
         self.endEditing(true)
     }
+    
+    typealias KeyboardWillHideNotificationClosure = () -> Void
+    var  keyboardWillHideNotificationClosure : KeyboardWillHideNotificationClosure?
 }
 
 extension CommentInputView : UITextViewDelegate {
+    
     func textViewDidChange(_ textView: UITextView) {
         TextLimitTool.restrictionInputTextView(inputTextView, maxNumber: 150)
         if  inputTextView.text.count > 0 {

+ 137 - 0
RainbowPlanet/RainbowPlanet/Tools/CommentInputView/CommentReplyView.swift

@@ -0,0 +1,137 @@
+//
+//  CommentReplyView.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/7/9.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import FWPopupView
+import RxSwift
+
+class CommentReplyView: FWPopupView {
+    
+    let disposeBag = DisposeBag()
+    
+    var userName : String = ""
+    var content : String = ""
+    
+    
+    
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+    }
+    
+    init(userName:String,content:String) {
+        self.init()
+        self.userName = userName
+        self.content = content
+        frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: 150+kSafeTabBarHeight)
+        // fillCode
+        self.configRectCorner(corner: [.topLeft,.topRight], radii: CGSize(width: 8, height: 8))
+        setupViews()
+        setLayouts()
+        setupData()
+
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    func setupViews() {
+        addSubview(titleLabel)
+        addSubview(lineLabel)
+        addSubview(replyButton)
+        addSubview(specLabel)
+        addSubview(cancelButton)
+    }
+    
+    func setLayouts() {
+        titleLabel.snp.makeConstraints { (make) in
+            make.top.equalTo(14)
+            make.left.equalTo(28)
+            make.right.equalTo(-28)
+            make.height.equalTo(20)
+        }
+        lineLabel.snp.makeConstraints { (make) in
+            make.top.equalTo(titleLabel.snp_bottom).offset(14)
+            make.right.left.equalToSuperview()
+            make.height.equalTo(1)
+        }
+        replyButton.snp.makeConstraints { (make) in
+            make.top.equalTo(lineLabel.snp_bottom)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(48)
+        }
+        specLabel.snp.makeConstraints { (make) in
+            make.top.equalTo(replyButton.snp_bottom)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(5)
+        }
+        cancelButton.snp.makeConstraints { (make) in
+            make.top.equalTo(specLabel.snp_bottom)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(48)
+        }
+        
+    }
+    
+    lazy var titleLabel: UILabel = {
+        let titleLabel = UILabel()
+        titleLabel.text = "\(self.userName):\(self.content)"
+        titleLabel.textColor = k999999Color
+        titleLabel.font = kRegularFont14
+        titleLabel.textAlignment = .center
+        return titleLabel
+    }()
+    
+    lazy var lineLabel: UILabel = {
+        let lineLabel = UILabel()
+        lineLabel.backgroundColor = keeeeeeColor
+        return lineLabel
+    }()
+    
+    lazy var replyButton: UIButton = {
+        let replyButton = UIButton(type: UIButton.ButtonType.custom)
+        replyButton.setTitle("回复", for: UIControl.State.normal)
+        replyButton.setTitleColor(k333333Color, for: UIControl.State.normal)
+        replyButton.titleLabel?.font = kRegularFont16
+        return replyButton
+    }()
+    
+    lazy var specLabel: UILabel = {
+        let specLabel = UILabel()
+        specLabel.backgroundColor = kf2f2f2Color
+        return specLabel
+    }()
+    
+    lazy var cancelButton: UIButton = {
+        let cancelButton = UIButton(type: UIButton.ButtonType.custom)
+        cancelButton.setTitle("取消", for: UIControl.State.normal)
+        cancelButton.setTitleColor(k333333Color, for: UIControl.State.normal)
+        cancelButton.titleLabel?.font = kRegularFont16
+
+        return cancelButton
+    }()
+    
+    typealias ReplyButtonClosure = () -> Void
+    var replyButtonClosure: ReplyButtonClosure?
+    
+    func setupData() {
+        cancelButton.rx.tap.subscribe(onNext: {[weak self] (data) in
+            self?.hide()
+        }).disposed(by: disposeBag)
+        
+        replyButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            self?.hide()
+            if let replyButtonClosure = self?.replyButtonClosure {
+                replyButtonClosure()
+            }
+        }).disposed(by: disposeBag)
+        
+    }
+    
+}