Chris лет назад: 5
Родитель
Сommit
f427021122

+ 92 - 20
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/Controller/PublishEditController.swift

@@ -11,21 +11,45 @@ import RxSwift
 import SwiftyJSON
 import Photos
 
+enum PublishMediaType {
+    case image
+    case video
+}
+
 class PublishEditController: BaseViewController {
     
+    var mediaType: PublishMediaType = .image
+    
     var imgCount: Int = 0
+    var majorImageUrl: String?
+    var imageUrlArray: Array<String> = []
     var imageArr: Array<UIImage>? {
         didSet {
             imgCount = self.imageArr?.count ?? 0
         }
     }
     
+    // 话题id
+    var topic_ids: String = ""
+    // 标题
+    var pubTitle: String = ""
+    // 内容
+    var pubContent: String = ""
+    // 位置
+    var location: String = ""
+    
+    // MARK: 控制器生命周期
     override func viewDidLoad() {
         super.viewDidLoad()
         setupViews()
         setupData()
     }
     
+    override func viewWillAppear(_ animated: Bool) {
+        // imageUrlArray每次进入页面需置空
+        imageUrlArray = []
+    }
+    
     override func setupViews() {
         self.view.backgroundColor = kffffffColor
         
@@ -34,6 +58,8 @@ class PublishEditController: BaseViewController {
         navigationBar.onClickRightButton = {
             [weak self] in
             print("----点击了发布")
+            
+            self?.uploadAllImages(totalTimes: 0)
         }
         
         navigationBar.wr_setLeftButton(image: kImage(name: "navbar_back_black")!)
@@ -101,14 +127,17 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
             return picCell
         case 1:
             let titleCell = PublishEditTitleCell.cellWith(tableView: tableView, indexPath: indexPath)
+            titleCell.topicTextClosure = {
+                [weak self] (text) in
+                self?.pubTitle = text
+            }
             return titleCell
         case 2:
             let desCell = PublishEditDescribeCell.cellWith(tableView: tableView, indexPath: indexPath)
-//            actCell.allSelectBlock = {
-//                [weak self] (isAllSel) in
-//                self?.isAllSelected = isAllSel
-//                self?.allSelectedAction(isAllSel)
-//            }
+            desCell.commentTextViewClosure = {
+                [weak self] (text) in
+                self?.pubContent = text
+            }
             return desCell
         case 3:
             let topicCell = PublishEditAddTopicCell.cellWith(tableView: tableView, indexPath: indexPath)
@@ -123,20 +152,6 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
     
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         switch indexPath.row {
-//        case 0:
-//            let picCell = PublishEditAddPicCell.cellWith(tableView: tableView, indexPath: indexPath)
-//            return picCell
-//        case 1:
-//            let titleCell = PublishEditTitleCell.cellWith(tableView: tableView, indexPath: indexPath)
-//            return titleCell
-//        case 2:
-//            let desCell = PublishEditDescribeCell.cellWith(tableView: tableView, indexPath: indexPath)
-//            //            actCell.allSelectBlock = {
-//            //                [weak self] (isAllSel) in
-//            //                self?.isAllSelected = isAllSel
-//            //                self?.allSelectedAction(isAllSel)
-//            //            }
-//            return desCell
         case 3:
             let vc = PublishAddTopicController()
             self.navigationController?.pushViewController(vc, animated: true)
@@ -144,7 +159,7 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
             let vc = PublishAddAddressController()
             self.navigationController?.pushViewController(vc, animated: true)
         default:
-            print("----点击了-\(indexPath.row)")
+            break
         }
     }
     
@@ -181,5 +196,62 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
 // MARK: - 逻辑处理
 extension PublishEditController {
     
+    func uploadAllImages(totalTimes: Int) {
+        
+        var curTimes: Int = totalTimes
+        
+        print("-----StartUpload,totalTimes == \(totalTimes)")
+        SwiftMoyaNetWorkServiceConfig.shared().configUploadSingleImgApi(imageArray: [imageArr![totalTimes]]) {
+            [weak self] (imgUrl) -> (Void) in
+            let urlStr: String = imgUrl as! String
+            self?.imageUrlArray.append(urlStr)
+            if curTimes == 0 {
+                // 设置主图
+                self?.majorImageUrl = urlStr
+            }
+            print("-----FinishUpload,Times == \(curTimes)")
+            curTimes += 1
+            if curTimes < self?.imageArr?.count ?? 0 {
+                self?.uploadAllImages(totalTimes: curTimes)
+            } else {
+                self?.communityPublishApi()
+            }
+        }
+    }
+    
+    // 发布Api
+    func communityPublishApi() {
+        
+        if pubTitle.count > 20 {
+            SwiftProgressHUD.shared().showText("标题最多输入20个字符")
+            return
+        }
+        
+        if pubContent.count == 0 {
+            SwiftProgressHUD.shared().showText("还没输入描述内容")
+            return
+        }
+        
+        var typeStr: String = ""
+        if mediaType == .image {
+            typeStr = "image"
+        } else {
+            typeStr = "video"
+        }
+        
+        let simuTopicIds: Array<String> = ["1","2"]
+        let simuTopicJsonStr = JSON(simuTopicIds).description
+//        SwiftProgressHUD.shared().showText("还没选择话题哟")
+        
+        let imgsJsonStr = JSON(imageUrlArray).description
+        
+        print("----mediaType == \(typeStr)\n----pubTitle = \(pubTitle)\n----simuTopicJsonStr == \(simuTopicJsonStr)\n----imgsJsonStr == \(imgsJsonStr)")
+        
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPublishApi(type: typeStr, img: majorImageUrl ?? "", topic_ids: simuTopicJsonStr, video: "", title: pubTitle, content: pubContent, location: "", imgs: imgsJsonStr) {
+            [weak self] (communityPublishModel) -> (Void) in
+            let communityPublishModel = communityPublishModel as? CommunityPublishModel
+            print("----发布成功")
+        }
+    }
     
 }

+ 2 - 2
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/View/PublishEditDescribeCell.swift

@@ -74,8 +74,8 @@ extension PublishEditDescribeCell: UITextViewDelegate {
     func textViewDidChange(_ textView: UITextView) {
         if textView == cmtTextView {
             var fullStr = textView.text ?? ""
-            if textView.text?.count ?? 0 > 180 {
-                fullStr = String(fullStr.prefix(150)) as String
+            if textView.text?.count ?? 0 > 1020 {
+                fullStr = String(fullStr.prefix(1000)) as String
                 textView.text = fullStr
             }
             

+ 32 - 11
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/View/PublishEditTitleCell.swift

@@ -13,8 +13,14 @@ class PublishEditTitleCell: UITableViewCell {
     
     let disposeBag = DisposeBag()
     
-    typealias EditTextFieldClosure = (_ text: String,_ indexPath:IndexPath) -> Void
-    var editTextFieldClosure : EditTextFieldClosure?
+    typealias TopicTextClosure = (_ text: String) -> Void
+    var topicTextClosure : TopicTextClosure?
+    
+    var titleStr: String? {
+        didSet {
+            editTextField.text = self.titleStr
+        }
+    }
     
     class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PublishEditTitleCell {
         let ID = "PublishEditTitleCell"
@@ -68,16 +74,8 @@ class PublishEditTitleCell: UITableViewCell {
         editTextField.font = kRegularFont14
         editTextField.tintColor = kEnabledButtonColor
         editTextField.clearButtonMode = .whileEditing
-//        editTextField.placeholder = "标题吸引人,收豆不求人(标题20字,内容详情页不限)"
         editTextField.attributedPlaceholder = NSAttributedString.init(string:"标题吸引人,收豆不求人(标题20字,内容详情页不限)", attributes: [NSAttributedString.Key.font:kRegularFont14 as Any, NSAttributedString.Key.foregroundColor:kDDDDDDColor])
-        editTextField.rx.text.orEmpty.changed.subscribe(onNext: {
-            [weak self] (text) in
-            self?.editTextField.text = String(describing: text.prefix(11))
-            if let editTextFieldClosure = self?.editTextFieldClosure {
-                editTextFieldClosure(self?.editTextField.text ?? "",(self?.indexPath!)!)
-            }
-            
-        }).disposed(by: disposeBag)
+        editTextField.delegate = self
         return editTextField
     }()
     
@@ -88,3 +86,26 @@ class PublishEditTitleCell: UITableViewCell {
     }()
     
 }
+
+extension PublishEditTitleCell: UITextFieldDelegate {
+    
+    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
+        if textField == editTextField {
+            textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: UIControl.Event.editingChanged)
+        }
+        return true
+    }
+    
+    @objc func textFieldDidChange(_ textField: UITextField) {
+        var fullStr = textField.text ?? ""
+        if textField.text?.count ?? 0 > 40 {
+            fullStr = String(fullStr.prefix(20)) as String
+            textField.text = fullStr
+        }
+        
+        if let topicTextClosure = self.topicTextClosure {
+            topicTextClosure(self.editTextField.text ?? "")
+        }
+    }
+    
+}

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

@@ -130,7 +130,7 @@ public class SwiftMoyaNetWorkServiceCommunity: NSObject {
     ///   - imgs: 图集,type为image是必填,json字符串
     ///   - page: 分页
     ///   - completion: 回调
-    func communityPublishApi(type:String = "", img:String = "", topic_ids:String = "", video:String = "", title:String = "", content:String = "", location:String = "", imgs:String = "", page:Int = 1, completion: @escaping apiCallBack) {
+    func communityPublishApi(type:String = "", img:String = "", topic_ids:String = "", video:String = "", title:String = "", content:String = "", location:String = "", imgs:String = "", completion: @escaping apiCallBack) {
         var parameters = Dictionary<String,Any>()
         parameters.updateValue(type, forKey: "type")
         parameters.updateValue(img, forKey: "img")
@@ -140,7 +140,6 @@ public class SwiftMoyaNetWorkServiceCommunity: NSObject {
         parameters.updateValue(content, forKey: "content")
         parameters.updateValue(location, forKey: "location")
         parameters.updateValue(imgs, forKey: "imgs")
-        parameters.updateValue(page, forKey: "page")
         SwiftProgressHUD.shared().showWait()
         SwiftMoyaNetWorkManager.shared.requestObject(CommunityPublishModel.self, target: MultiTarget(SwiftMoyaServiceCommunityApi.communityPublish(parameters: parameters))) { (CommunityPublishModel) in
             SwiftProgressHUD.shared().hide()