Browse Source

Merge branch 'feature/dev_Chris' into develop

Chris 5 years ago
parent
commit
d9e3c22b15

+ 2 - 0
RainbowPlanet/RainbowPlanet/Model/CommunityModel/CommunityTopicsModel.swift

@@ -33,6 +33,8 @@ class CommunityTopicDataModel : NSObject, Mappable{
     var img : String?
     var name : String?
     
+    // 话题列表 - 是否被选中
+    var isSelected : Bool = false
     
     class func newInstance(map: Map) -> Mappable?{
         return CommunityTopicDataModel()

+ 76 - 10
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishAddTopic/Controller/PublishAddTopicController.swift

@@ -18,7 +18,12 @@ class PublishAddTopicController: BaseViewController {
     
     // 话题组下子话题のModelArr
     var topicListModels = Array<CommunityTopicDataModel>()
+   
+    // 选中的话题
+    var selTopicModelArr: Array<CommunityTopicDataModel>?
     
+    typealias SelTopicsClosure = (_ topicMdlArr: Array<CommunityTopicDataModel>) -> Void
+    var selTopicsClosure : SelTopicsClosure?
     
     
     override func viewDidLoad() {
@@ -31,11 +36,13 @@ class PublishAddTopicController: BaseViewController {
         self.view.backgroundColor = kffffffColor
         
         navigationBar.title = "添加话题"
-        navigationBar.wr_setRightButton(title: "完成(x/5)", titleColor: k7AD489Color)
+        updateFinishButtonStatus()
         navigationBar.onClickRightButton = {
             [weak self] in
-            let vc = PublishSuccessController()
-            self?.navigationController?.pushViewController(vc, animated: true)
+            if let selTopicsClosure = self?.selTopicsClosure {
+                selTopicsClosure(self!.selTopicModelArr!)
+            }
+            self?.navigationController?.popViewController(animated: true)
         }
         
         view.addSubview(tableView)
@@ -46,14 +53,10 @@ class PublishAddTopicController: BaseViewController {
     }
     
     override func setupData() {
-        
+        // 话题组
         communityTopicCategoryApi(page:1)
-        
-//        // 上啦加载
-//        tableView.addFooterWithWithHeader(withAutomaticallyRefresh: false) {
-//            [weak self] (page) in
-//            self?.communityTopicCategoryApi(page:page)
-//        }
+        // 子话题
+        communityTopicsApi(isSuggest: 1, categoryId: 0, page: 1)
     }
     
     lazy var tableView: UITableView = {
@@ -107,12 +110,40 @@ extension PublishAddTopicController : UITableViewDelegate, UITableViewDataSource
         case 1:
             let titleCell = PublishTopicItemCell.cellWith(tableView: tableView, indexPath: indexPath)
             titleCell.subTopicModel = topicListModels[indexPath.row]
+            titleCell.isChoosed = topicListModels[indexPath.row].isSelected
             return titleCell
         default:
             return UITableViewCell()
         }
     }
     
+    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        let selTopicMdl: CommunityTopicDataModel = topicListModels[indexPath.row]
+        
+        if selTopicModelArr!.count >= 5 && selTopicMdl.isSelected == false {
+            SwiftProgressHUD.shared().showText("最多只能选择5个话题")
+            return
+        }
+        
+        if selTopicMdl.isSelected {
+            // 点击的已被选中,移除
+            selTopicMdl.isSelected = false
+            for (index, topicMdl) in selTopicModelArr!.enumerated() {
+                if selTopicMdl.id == topicMdl.id {
+                    selTopicModelArr!.remove(at: index)
+                    break
+                }
+            }
+        } else {
+            // 未被选中过,添加选中
+            selTopicMdl.isSelected = true
+            selTopicModelArr!.append(selTopicMdl)
+        }
+        tableView.reloadData()
+        
+        updateFinishButtonStatus()
+    }
+    
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
         switch indexPath.section {
         case 0:
@@ -135,6 +166,15 @@ extension PublishAddTopicController : UITableViewDelegate, UITableViewDataSource
     func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
         if section == 0 {
             let headerView = PublishTopicHeaderView(frame: CGRect.zero)
+            headerView.selTopicModels = selTopicModelArr
+            headerView.deleteTransClosure = {
+                [weak self] (index) in
+                // 移除选中 -> 校正列表选中状态 -> 刷新table -> 刷新完成btn
+                self?.selTopicModelArr!.remove(at: index)
+                self?.fixTopicSelectedStatus()
+                self?.tableView.reloadData()
+                self?.updateFinishButtonStatus()
+            }
             headerView.layoutIfNeeded()
             headerView.reloadData()
             return headerView
@@ -192,6 +232,8 @@ extension PublishAddTopicController {
                     self?.topicListModels.removeAll()
                 }
                 self?.topicListModels = (self?.topicListModels)! + (communityTopicsModel?.data!)!
+                // 更新选中状态
+                self?.fixTopicSelectedStatus()
                 self?.tableView.reloadData()
                 if  self?.topicListModels.count ?? 0 >= communityTopicsModel?.pagination?.total ?? 0 {
                     self?.tableView.isHiddenFooter(true)
@@ -202,4 +244,28 @@ extension PublishAddTopicController {
         }
     }
     
+    // 校正选中状态
+    func fixTopicSelectedStatus() {
+        for topicMdl in topicListModels {
+            topicMdl.isSelected = false
+            for selTopicMdl in selTopicModelArr! {
+                if topicMdl.id == selTopicMdl.id {
+                    topicMdl.isSelected = true
+                    break
+                }
+            }
+        }
+    }
+    
+    func updateFinishButtonStatus() {
+        let selCount = selTopicModelArr!.count
+        if selCount == 0 {
+            navigationBar.wr_setRightButton(title: "完成(\(selCount)/5)", titleColor: k999999Color)
+            navigationBar.rightButton.isUserInteractionEnabled = false
+        } else {
+            navigationBar.wr_setRightButton(title: "完成(\(selCount)/5)", titleColor: k7AD489Color)
+            navigationBar.rightButton.isUserInteractionEnabled = true
+        }
+    }
+    
 }

+ 13 - 3
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishAddTopic/View/PublishSelTopicCollectionCell.swift

@@ -13,6 +13,15 @@ class PublishSelTopicCollectionCell: UICollectionViewCell {
     
     let disposeBag = DisposeBag()
     
+    var subTopicModel: CommunityTopicDataModel? {
+        didSet {
+            titleLabel.text = self.subTopicModel?.name
+        }
+    }
+    
+    typealias DeleteClosure = (_ index: Int) -> Void
+    var deleteClosure : DeleteClosure?
+    
     class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> PublishSelTopicCollectionCell {
         let ID = "PublishSelTopicCollectionCell"
         collectionView.register(PublishSelTopicCollectionCell.self, forCellWithReuseIdentifier: ID)
@@ -73,8 +82,7 @@ class PublishSelTopicCollectionCell: UICollectionViewCell {
     }()
     
     private lazy var titleLabel: UILabel = {
-        let titleLabel = UILabel()
-        titleLabel.text = "运动健身"
+        let titleLabel = UILabel()        
         titleLabel.textColor = k666666Color
         titleLabel.font = kRegularFont13
         titleLabel.textAlignment = .left
@@ -85,7 +93,9 @@ class PublishSelTopicCollectionCell: UICollectionViewCell {
         let deleteButton = UIButton(type: UIButton.ButtonType.custom)
         deleteButton.setImage(kImage(name: "edit_topic_delete"), for: UIControl.State.normal)
         deleteButton.rx.tap.subscribe(onNext: { (data) in
-            print("----点击删除")
+            if let deleteClosure = self.deleteClosure {
+                deleteClosure(self.indexPath!.row)
+            }
         }).disposed(by: disposeBag)
         return deleteButton
     }()

+ 21 - 2
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishAddTopic/View/PublishTopicHeaderView.swift

@@ -10,6 +10,18 @@ import UIKit
 
 class PublishTopicHeaderView: BaseView {
     
+    var selTopicCount: Int = 0
+    // 选中话题のModelArr
+    var selTopicModels: Array<CommunityTopicDataModel>? {
+        didSet {
+            selTopicCount = self.selTopicModels?.count ?? 0
+            collectionView.reloadData()
+        }
+    }
+    
+    typealias DeleteTransClosure = (_ index: Int) -> Void
+    var deleteTransClosure : DeleteTransClosure?
+    
     override func setupViews() {
         self.backgroundColor = kf7f8faColor
         
@@ -66,11 +78,18 @@ extension PublishTopicHeaderView: UICollectionViewDelegateFlowLayout,UICollectio
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return 5
+        return selTopicCount
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         let cell = PublishSelTopicCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+        cell.subTopicModel = selTopicModels?[indexPath.row]
+        cell.deleteClosure = {
+            [weak self] (index) in
+            if let deleteTransClosure = self?.deleteTransClosure {
+                deleteTransClosure(index)
+            }
+        }
         return cell
     }
     
@@ -79,7 +98,7 @@ extension PublishTopicHeaderView: UICollectionViewDelegateFlowLayout,UICollectio
     }
     
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        print("点击了collection----\(indexPath.row)")
+        
     }
     
 }

+ 6 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishAddTopic/View/PublishTopicItemCell.swift

@@ -17,6 +17,12 @@ class PublishTopicItemCell: UITableViewCell {
         }
     }
     
+    var isChoosed: Bool? {
+        didSet {
+            selImageView.isHidden = !(self.isChoosed ?? false)
+        }
+    }
+    
     class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PublishTopicItemCell {
         let ID = "PublishTopicItemCell"
         tableView.register(PublishTopicItemCell.self, forCellReuseIdentifier: ID)

+ 0 - 3
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishAddTopic/View/PublishTopicTypeItemCollectionCell.swift

@@ -20,9 +20,6 @@ class PublishTopicTypeItemCollectionCell: UICollectionViewCell {
         }
     }
     
-    typealias DelPicBlock = (_ idxRow:Int?) -> Void
-    var delPicBlock : DelPicBlock?
-    
     class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> PublishTopicTypeItemCollectionCell {
         let ID = "PublishTopicTypeItemCollectionCell"
         collectionView.register(PublishTopicTypeItemCollectionCell.self, forCellWithReuseIdentifier: ID)

+ 43 - 17
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/Controller/PublishEditController.swift

@@ -38,8 +38,12 @@ class PublishEditController: BaseViewController {
         }
     }
     
-    // 话题id
-    var topic_ids: String = ""
+    // 选中的话题
+    var selTopicModelArr: Array<CommunityTopicDataModel> = []
+    // 已选话题id
+    var selTopicIdArr: Array<String> = []
+    // 已选话题name
+    var selTopicName: String = ""
     // 标题
     var pubTitle: String = ""
     // 内容
@@ -58,24 +62,23 @@ class PublishEditController: BaseViewController {
         setupViews()
         setupData()
         
-        if mediaType == .video {
-            subLabel.text = "视频正在上传中(0/1)..."
-            communityVideoUploadAuthApi()
-            print("----上传视频")
-        }
-    }
-    
-    override func viewWillAppear(_ animated: Bool) {
         // imageUrlArray每次进入页面需置空
         imageUrlArray = []
         rightButton.isEnabled = false
         rightButton.backgroundColor = kd8d8d8Color
         
+        if mediaType == .video {
+            subLabel.text = "视频正在上传中(0/1)..."
+            communityVideoUploadAuthApi()
+            print("----上传视频")
+        }
         if mediaType == .image {
             subLabel.text = "图片正在上传中(0/\(imageArr?.count ?? 0))..."
             uploadAllImages(totalTimes: 0)
         }
-        
+    }
+    
+    override func viewWillAppear(_ animated: Bool) {
         
 //        let serialQueue = DispatchQueue(label: "serial_queue")
 //        serialQueue.async {
@@ -238,6 +241,8 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
             return desCell
         case 3:
             let topicCell = PublishEditAddTopicCell.cellWith(tableView: tableView, indexPath: indexPath)
+            topicCell.isTopicsNull = selTopicIdArr.count == 0 ? true : false
+            topicCell.selTopicName = selTopicName
             return topicCell
         case 4:
             let addrCell = PublishEditAddAddressCell.cellWith(tableView: tableView, indexPath: indexPath)
@@ -251,6 +256,25 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
         switch indexPath.row {
         case 3:
             let vc = PublishAddTopicController()
+            vc.selTopicModelArr = self.selTopicModelArr
+            vc.selTopicsClosure = {
+                [weak self] (topicMdlArr) in
+                self?.selTopicModelArr = topicMdlArr
+                self?.selTopicName = ""
+                self?.selTopicIdArr.removeAll()
+                
+                for (index,topicModel) in (topicMdlArr.enumerated()) {
+                    let strTopicId: String = String(format: "%d", topicModel.id ?? 0)
+                    self?.selTopicIdArr.append(strTopicId)
+                    
+                    if index == 0 {
+                        self?.selTopicName.append(topicModel.name!)
+                    } else {
+                        self?.selTopicName.append(", \(topicModel.name!)")
+                    }
+                }
+                self?.tableView.reloadData()
+            }
             self.navigationController?.pushViewController(vc, animated: true)
         case 4:
             let vc = PublishAddAddressController()
@@ -342,6 +366,11 @@ extension PublishEditController {
             return
         }
         
+        if selTopicIdArr.count == 0 {
+            SwiftProgressHUD.shared().showText("还没选择话题哟")
+            return
+        }
+        
         var typeStr: String = ""
         if mediaType == .image {
             typeStr = "image"
@@ -349,15 +378,12 @@ extension PublishEditController {
             typeStr = "video"
         }
         
-        let simuTopicIds: Array<String> = ["1","2"]
-        let simuTopicJsonStr = JSON(simuTopicIds).description
-//        SwiftProgressHUD.shared().showText("还没选择话题哟")
-        
+        let topicJsonStr = JSON(selTopicIdArr).description
         let imgsJsonStr = JSON(imageUrlArray).description
         
-        print("----mediaType == \(typeStr)\n----pubTitle = \(pubTitle)\n----simuTopicJsonStr == \(simuTopicJsonStr)\n----imgsJsonStr == \(imgsJsonStr)")
+        print("----mediaType == \(typeStr)\n----pubTitle = \(pubTitle)\n----topicJsonStr == \(topicJsonStr)\n----imgsJsonStr == \(imgsJsonStr)")
         
-        SwiftMoyaNetWorkServiceCommunity.shared().communityPublishApi(type: typeStr, img: majorImageUrl ?? "", topic_ids: simuTopicJsonStr, video: paraVideo, title: pubTitle, content: pubContent, location: "", imgs: imgsJsonStr) {
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPublishApi(type: typeStr, img: majorImageUrl ?? "", topic_ids: topicJsonStr, video: paraVideo, title: pubTitle, content: pubContent, location: "", imgs: imgsJsonStr) {
             [weak self] (communityPublishModel) -> (Void) in
             let communityPublishModel = communityPublishModel as? CommunityPublishModel
             print("----发布成功")

+ 16 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishEditController/View/PublishEditAddTopicCell.swift

@@ -10,6 +10,22 @@ import UIKit
 
 class PublishEditAddTopicCell: UITableViewCell {
     
+    var isTopicsNull: Bool? {
+        didSet {
+            if !(self.isTopicsNull ?? true) {
+                iconImageView.image = kImage(name: "edit_ico_topic_pre")
+            }
+        }
+    }
+    
+    var selTopicName: String? {
+        didSet {
+            if self.selTopicName != "" {
+                subLabel.text = self.selTopicName
+            }
+        }
+    }
+    
     class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PublishEditAddTopicCell {
         let ID = "PublishEditAddTopicCell"
         tableView.register(PublishEditAddTopicCell.self, forCellReuseIdentifier: ID)

+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/CommunityModule.xcassets/edit_ico_address_pre.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "edit_ico_address_pre@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "edit_ico_address_pre@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/CommunityModule.xcassets/edit_ico_address_pre.imageset/edit_ico_address_pre@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/CommunityModule.xcassets/edit_ico_address_pre.imageset/edit_ico_address_pre@3x.png