BBSReplySubjectViewController.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // BBSReplySubjectViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/11/9.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. import AlamofireObjectMapper
  11. import ObjectMapper
  12. import SwiftyJSON
  13. import CocoaLumberjack
  14. class BBSReplySubjectViewController: UIViewController {
  15. var subject:BBSSubjectData?{
  16. didSet {
  17. }
  18. }
  19. var parentId:String?
  20. var htmlEditorController:ZSSRichTextEditor!
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. htmlEditorController = ZSSRichTextEditor()
  24. htmlEditorController.view.frame = self.view.frame
  25. self.view.addSubview(htmlEditorController.view)
  26. htmlEditorController.alwaysShowToolbar = true
  27. htmlEditorController.placeholder = "请输入回复内容"
  28. self.addChild(htmlEditorController)
  29. }
  30. override func didReceiveMemoryWarning() {
  31. super.didReceiveMemoryWarning()
  32. // Dispose of any resources that can be recreated.
  33. }
  34. @IBAction func closeReplyWindow(_ sender: UIBarButtonItem) {
  35. //print(self.htmlEditorController.getHTML())
  36. self.dismiss(animated: true, completion: nil)
  37. }
  38. @IBAction func replySubjectAction(_ sender: UIBarButtonItem) {
  39. //执行回复提交并返回帖子
  40. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(BBSContext.bbsContextKey, query: BBSContext.itemReplyQuery, parameter: nil)
  41. //参数
  42. var entity = SubjectReplayRequestEntity()
  43. entity.creatorName = O2AuthSDK.shared.myInfo()?.name
  44. self.htmlEditorController.getHTML { (c, err) in
  45. if c is NSString {
  46. entity.content = String(c as! NSString)
  47. }
  48. }
  49. // entity.content = self.htmlEditorController.getHTML()
  50. entity.subjectId = subject?.id
  51. if let pid = parentId {
  52. entity.parentId = pid
  53. }
  54. AF.request(url!, method: .post, parameters: entity.toJSON(), encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  55. switch response.result {
  56. case .success(let val):
  57. let type = JSON(val)["type"]
  58. if type == "success" {
  59. DispatchQueue.main.async {
  60. self.showSuccess(title: "回复成功")
  61. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
  62. self.performSegue(withIdentifier: "backSubjectSegue", sender: nil)
  63. })
  64. }
  65. }else{
  66. DispatchQueue.main.async {
  67. DDLogError(JSON(val).description)
  68. self.showError(title: "回复失败")
  69. }
  70. }
  71. case .failure(let err):
  72. DispatchQueue.main.async {
  73. DDLogError(err.localizedDescription)
  74. self.showError(title: "回复失败")
  75. }
  76. }
  77. }
  78. }
  79. }