MeetingAcceptViewController.swift 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // MeetingAcceptViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 16/8/24.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import AlamofireObjectMapper
  10. import AlamofireImage
  11. import Alamofire
  12. import SwiftyJSON
  13. import ObjectMapper
  14. import BWSwipeRevealCell
  15. import CocoaLumberjack
  16. class MeetingAcceptViewController: UIViewController {
  17. @IBOutlet weak var acceptTableView: ZLBaseTableView!
  18. var meetings:[Meeting] = []
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. self.acceptTableView.delegate = self
  22. self.acceptTableView.dataSource = self
  23. self.acceptTableView.emptyTitle = "没有需要你确认的会议"
  24. self.loadAcceptMeetings()
  25. // Do any additional setup after loading the view.
  26. }
  27. override func didReceiveMemoryWarning() {
  28. super.didReceiveMemoryWarning()
  29. // Dispose of any resources that can be recreated.
  30. }
  31. func loadAcceptMeetings(){
  32. ProgressHUD.show("加载中...", interaction: false)
  33. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(MeetingContext.meetingContextKey, query: MeetingContext.meetingListAcceptQuery, parameter: nil)
  34. self.meetings.removeAll()
  35. Alamofire.request(url!,method:.get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseArray(queue: nil, keyPath: "data", context: nil, completionHandler: { (response:DataResponse<[Meeting]>) in
  36. switch response.result {
  37. case .success(let meetings):
  38. self.meetings.append(contentsOf: meetings)
  39. ProgressHUD.showSuccess("加载完成")
  40. case .failure(let err):
  41. DDLogError(err.localizedDescription)
  42. ProgressHUD.showError("加载失败")
  43. }
  44. self.acceptTableView.reloadData()
  45. })
  46. }
  47. func viewWithImageName(_ imageName: String) -> UIView {
  48. let image = UIImage(named: imageName)
  49. let imageView = UIImageView(image: image)
  50. imageView.contentMode = .center
  51. return imageView
  52. }
  53. func tableViewCellUpdate(_ indexPath:IndexPath){
  54. //let meeting = self.meetings[indexPath.row]
  55. self.meetings.remove(at: (indexPath as NSIndexPath).row)
  56. acceptTableView.beginUpdates()
  57. acceptTableView.deleteRows(at: [indexPath], with: .left)
  58. acceptTableView.endUpdates()
  59. }
  60. func acceptMeeting(_ meetingId:String,indexPath:IndexPath){
  61. ProgressHUD.show("提交中...")
  62. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(MeetingContext.meetingContextKey, query: MeetingContext.meetingItemAcceptIdQuery, parameter: ["##id##":meetingId as AnyObject])
  63. Alamofire.request(url!).responseJSON {
  64. response in
  65. switch response.result {
  66. case .success:
  67. self.tableViewCellUpdate(indexPath)
  68. ProgressHUD.showSuccess("提交成功")
  69. case .failure(let err):
  70. DDLogError(err.localizedDescription)
  71. ProgressHUD.showError("提交失败")
  72. }
  73. }
  74. }
  75. func rejectMeeting(_ meetingId:String,indexPath:IndexPath){
  76. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(MeetingContext.meetingContextKey, query: MeetingContext.meetingItemRejectIdQuery, parameter: ["##id##":meetingId as AnyObject])
  77. Alamofire.request(url!).responseJSON { response in
  78. switch response.result {
  79. case .success:
  80. self.tableViewCellUpdate(indexPath)
  81. ProgressHUD.showSuccess("提交成功")
  82. case .failure(let err):
  83. DDLogError(err.localizedDescription)
  84. ProgressHUD.showError("提交失败")
  85. }
  86. }
  87. }
  88. }
  89. extension MeetingAcceptViewController:UITableViewDataSource,UITableViewDelegate{
  90. func numberOfSections(in tableView: UITableView) -> Int {
  91. return 1
  92. }
  93. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  94. return self.meetings.count
  95. }
  96. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  97. let cell = tableView.dequeueReusableCell(withIdentifier: "MeetingAcceptItemCell", for: indexPath) as! MeetingAcceptItemCell
  98. let meeting = self.meetings[(indexPath as NSIndexPath).row]
  99. cell.meeting = meeting
  100. let swipeCell:BWSwipeRevealCell = cell as BWSwipeRevealCell
  101. swipeCell.bgViewLeftImage = UIImage(named:"Done")!.withRenderingMode(.alwaysTemplate)
  102. swipeCell.bgViewLeftColor = UIColor.green
  103. swipeCell.bgViewRightImage = UIImage(named:"Delete")!.withRenderingMode(.alwaysTemplate)
  104. swipeCell.bgViewRightColor = UIColor.red
  105. swipeCell.type = .slidingDoor
  106. swipeCell.delegate = self
  107. return cell
  108. }
  109. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  110. return UIView()
  111. }
  112. }
  113. extension MeetingAcceptViewController:BWSwipeRevealCellDelegate{
  114. @nonobjc func swipeCellWillRelease(_ cell: BWSwipeCell) {
  115. // print("Swipe Cell Will Release")
  116. // if cell.state != .Normal && cell.type != .SlidingDoor {
  117. // let indexPath: NSIndexPath = acceptTableView.indexPathForCell(cell)!
  118. // //self.removeObjectAtIndexPath(indexPath)
  119. // }
  120. }
  121. @nonobjc func swipeCellActivatedAction(_ cell: BWSwipeCell, isActionLeft: Bool) {
  122. print("Swipe Cell Activated Action isActionLeft = \(isActionLeft)")
  123. let indexPath = acceptTableView.indexPath(for: cell)!
  124. let meeting = self.meetings[(indexPath as NSIndexPath).row]
  125. if isActionLeft == true {
  126. self.acceptMeeting(meeting.id!,indexPath: indexPath)
  127. }else{
  128. self.rejectMeeting(meeting.id!,indexPath: indexPath)
  129. }
  130. //self.removeObjectAtIndexPath(indexPath)
  131. }
  132. }