|
@@ -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("----发布成功")
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|