OOMeetingMeetingRoomManageController.swift 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //
  2. // OOMeetingMeetingRoomManageController.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/1/4.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. import EmptyDataSet_Swift
  10. private let reuseIdentifier = "OOMeetingRoomMainCell"
  11. class OOMeetingMeetingRoomManageController: UIViewController {
  12. @IBOutlet weak var tableView: UITableView!
  13. private lazy var cellBackView:UIView = {
  14. let view = Bundle.main.loadNibNamed("OOMeetingBackgroundView", owner: self, options: nil)?.first as! UIView
  15. return view
  16. }()
  17. //开始时间
  18. var startDate:Date = Date()
  19. //结束时间
  20. var endDate:Date = Date()
  21. //当前模式 0--正常 1--被选择 2--被选择多选
  22. var currentMode:Int = 0 {
  23. didSet {
  24. }
  25. }
  26. var delegate:OOCommonBackResultDelegate?
  27. private var selectedMeetingRooms:[OOMeetingRoomInfo] = []
  28. private var selectedCellIndexPaths:[IndexPath] = []
  29. private lazy var headerView:OOMeetingRoomTableHeaderView = {
  30. let view = Bundle.main.loadNibNamed("OOMeetingRoomTableHeaderView", owner: self, options: nil)?.first as! OOMeetingRoomTableHeaderView
  31. view.setDelegate = self
  32. return view
  33. }()
  34. private lazy var viewModel:OOMeetingRoomViewModel = {
  35. return OOMeetingRoomViewModel()
  36. }()
  37. override func viewDidLoad() {
  38. super.viewDidLoad()
  39. title = "会议室"
  40. self.tabBarItem?.selectedImage = O2ThemeManager.image(for: "Icon.icon_huiyishi_pro")
  41. self.view.backgroundColor = UIColor(hex: "#f5f5f5")
  42. headerView.sizeToFit()
  43. headerView.autoresizingMask = .flexibleWidth
  44. //设置选择时间
  45. headerView.setChooseDate(startTime: self.startDate, endTime: self.endDate)
  46. tableView.tableHeaderView = headerView
  47. //tableView.tableHeaderView?.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 44)
  48. tableView.tableFooterView = UIView()
  49. tableView.register(UINib.init(nibName: "OOMeetingRoomMainCell", bundle: nil), forCellReuseIdentifier: reuseIdentifier)
  50. //tableView.emptyDataSetSource = self
  51. tableView.dataSource = self
  52. //tableView.emptyDataSetDelegate = self
  53. tableView.delegate = self
  54. if currentMode != 0 {
  55. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title:"确认", style: .plain, target: self, action: #selector(selectSubmit(_:)))
  56. }
  57. if currentMode == 1 {
  58. self.tableView.allowsSelection = true
  59. }else if currentMode == 2 {
  60. self.tableView.allowsMultipleSelection = true
  61. }
  62. tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {
  63. self.loadAllBuildByDate(self.headerView.startDate, self.headerView.completedDate)
  64. })
  65. loadAllBuildByDate(headerView.startDate, headerView.completedDate)
  66. }
  67. private func loadAllBuildByDate(_ startDate:String,_ endDate:String){
  68. self.showLoading()
  69. viewModel.loadAllBuildByDate(startDate, endDate).then { (builds) in
  70. DispatchQueue.main.async {
  71. self.viewModel.builds.removeAll()
  72. self.viewModel.builds.append(contentsOf: builds)
  73. self.tableView.reloadData()
  74. }
  75. }.always {
  76. self.hideLoading()
  77. if self.tableView.mj_header.isRefreshing() {
  78. self.tableView.mj_header.endRefreshing()
  79. }
  80. }.catch { (myerror) in
  81. let customError = myerror as! OOAppError
  82. self.showError(title: customError.failureReason ?? "")
  83. }
  84. }
  85. @objc func selectSubmit(_ sender:Any) {
  86. guard let block = delegate else {
  87. return
  88. }
  89. var hasReIdle = false
  90. var hasClose = false
  91. if let room = self.selectedMeetingRooms.first {
  92. if room.idle == false {
  93. hasReIdle = true
  94. }
  95. if room.available == false {
  96. hasClose = true
  97. }
  98. }
  99. if hasReIdle {
  100. self.showError(title: "会议室已预约,请选择其它时间段")
  101. return
  102. }
  103. if hasClose {
  104. self.showError(title: "会议室已关闭,请选择其它会议室")
  105. return
  106. }
  107. block.backResult("OOMeetingMeetingRoomManageController", selectedMeetingRooms)
  108. self.popVC()
  109. }
  110. @objc func closeWindow() {
  111. }
  112. override func viewWillAppear(_ animated: Bool) {
  113. //tableView.emptyDataSetSource = self
  114. }
  115. override func didReceiveMemoryWarning() {
  116. super.didReceiveMemoryWarning()
  117. // Dispose of any resources that can be recreated.
  118. }
  119. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  120. if segue.identifier == "showMeetingRoomInfoSegue"{
  121. let destVC = segue.destination as? OOMeetingRoomDetailViewController
  122. let item = sender as? OOMeetingRoomInfo
  123. destVC?.ooMeetingRoomInfo = item
  124. }
  125. }
  126. }
  127. // MARK:- HeaderViewDelegate
  128. extension OOMeetingMeetingRoomManageController:OOMeetingRoomTableHeaderViewDelegate {
  129. func setTheDate(_ startDate: String, _ endDate: String) {
  130. loadAllBuildByDate(startDate, endDate)
  131. }
  132. }
  133. // MARK:- emptyDataSet
  134. extension OOMeetingMeetingRoomManageController:EmptyDataSetSource,EmptyDataSetDelegate {
  135. func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
  136. return NSAttributedString(string: "亲,您当前没有会议地点,请联系管理员!", attributes:[NSAttributedString.Key.foregroundColor:UIColor.init(hex: "#CCCCCC"),NSAttributedString.Key.font:UIFont.init(name: "PingFangSC-Light", size: 16)!])
  137. }
  138. func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
  139. return #imageLiteral(resourceName: "icon_huiyishi_nor")
  140. }
  141. }
  142. // MARK:- TableViewDataSource Delegate
  143. extension OOMeetingMeetingRoomManageController:UITableViewDataSource,UITableViewDelegate {
  144. func numberOfSections(in tableView: UITableView) -> Int {
  145. return viewModel.numberOfSections()
  146. }
  147. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  148. return viewModel.numberOfRowsInSection(section)
  149. }
  150. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  151. let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath)
  152. let uCell = cell as! OOMeetingRoomMainCell
  153. let item = viewModel.nodeForIndexPath(indexPath)
  154. uCell.newConfig(withItem: item, showSelected: self.currentMode == 1)
  155. return cell
  156. }
  157. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  158. return viewModel.headerViewOfSection(section)
  159. }
  160. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  161. return viewModel.footerViewOfSection(section)
  162. }
  163. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  164. let item = viewModel.nodeForIndexPath(indexPath)
  165. if currentMode == 0 {
  166. self.performSegue(withIdentifier: "showMeetingRoomInfoSegue", sender: item)
  167. }else{
  168. self.selectedMeetingRooms.append(item!)
  169. self.selectedCellIndexPaths.append(indexPath)
  170. let cell = tableView.cellForRow(at: indexPath) as? OOMeetingRoomMainCell
  171. cell?.selectRoom(isSelected: true)
  172. }
  173. }
  174. func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
  175. let item = viewModel.nodeForIndexPath(indexPath)
  176. if let index = self.selectedMeetingRooms.firstIndex(of: item!) {
  177. self.selectedMeetingRooms.remove(at: index)
  178. self.selectedCellIndexPaths.remove(at: selectedCellIndexPaths.firstIndex(of: indexPath)!)
  179. }
  180. let cell = tableView.cellForRow(at: indexPath) as? OOMeetingRoomMainCell
  181. cell?.selectRoom(isSelected: false)
  182. }
  183. }