|
@@ -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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|