OOMeetingInforController.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. //
  2. // OOMeetingInforController.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. import Promises
  11. import CocoaLumberjack
  12. private let meetingIdentifier = "OOMeetingInforItemCell"
  13. class OOMeetingInforController: UIViewController {
  14. @IBOutlet weak var tableView: UITableView!
  15. private var sectionHeight = CGFloat(172.0)
  16. private var hSectionHeight = CGFloat(387.0)
  17. private var sFlag = false
  18. private var currentMonthDay: Date?
  19. private var currentSelectDay: Date?
  20. private var config: OOMeetingConfigInfo? = nil
  21. //指定日期的所有会议
  22. private var theMeetingsByDay: [OOMeetingInfo] = []
  23. private lazy var viewModel: OOMeetingMainViewModel = {
  24. return OOMeetingMainViewModel()
  25. }()
  26. private var headerView: OOMeetingInforHeaderView = {
  27. let view = Bundle.main.loadNibNamed("OOMeetingInforHeaderView", owner: self, options: nil)?.first as! OOMeetingInforHeaderView
  28. return view
  29. }()
  30. private lazy var createView: O2BBSCreatorView = {
  31. let view = Bundle.main.loadNibNamed("O2BBSCreatorView", owner: self, options: nil)?.first as! O2BBSCreatorView
  32. view.iconImage = #imageLiteral(resourceName: "icon_collection_pencil")
  33. view.delegate = self
  34. view.frame = CGRect(x: kScreenW - 50 - 25, y: kScreenH - 50 - 25 - 40, width: 50, height: 50)
  35. return view
  36. }()
  37. override func viewDidLoad() {
  38. super.viewDidLoad()
  39. self.tabBarItem?.selectedImage = O2ThemeManager.image(for: "Icon.icon_huiyi_pro")
  40. tableView.register(UINib.init(nibName: "OOMeetingInforItemCell", bundle: nil), forCellReuseIdentifier: meetingIdentifier)
  41. headerView.delegate = self
  42. //headerView.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 172)
  43. //tableView.tableHeaderView = headerView
  44. tableView.emptyDataSetSource = self
  45. tableView.emptyDataSetDelegate = self
  46. tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {
  47. self.loadData()
  48. })
  49. }
  50. override func viewWillAppear(_ animated: Bool) {
  51. super.viewWillAppear(animated)
  52. loadData()
  53. loadMeetConfig()
  54. }
  55. override func viewWillDisappear(_ animated: Bool) {
  56. super.viewWillDisappear(animated)
  57. createView.removeFromSuperview()
  58. }
  59. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  60. if segue.identifier == "showMeetingDetail" {
  61. if let vc = segue.destination as? OOMeetingDetailViewController {
  62. if let meeting = sender as? OOMeetingInfo {
  63. vc.meetingInfo = meeting
  64. }
  65. }
  66. }
  67. }
  68. func loadMeetConfig() {
  69. viewModel.loadMeetingConfig().then { (config) in
  70. self.config = config
  71. if let c = self.config {
  72. O2UserDefaults.shared.meetingConfig = c
  73. if c.mobileCreateEnable == true {
  74. DispatchQueue.main.async {
  75. UIApplication.shared.windows.first?.addSubview(self.createView)
  76. }
  77. }
  78. }
  79. }.catch { (error) in
  80. DDLogError("会议配置获取异常, \(error)")
  81. }
  82. }
  83. func loadData() {
  84. self.showLoading()
  85. if self.currentMonthDay == nil {
  86. self.currentMonthDay = Date()
  87. }
  88. if self.currentSelectDay == nil {
  89. self.currentSelectDay = Date()
  90. }
  91. all(viewModel.getMeetingsByYearAndMonth(self.currentMonthDay!), viewModel.getMeetingByTheDay(self.currentSelectDay!))
  92. .always {
  93. self.hideLoading()
  94. if self.tableView.mj_header.isRefreshing() {
  95. self.tableView.mj_header.endRefreshing()
  96. }
  97. //self.tableView.reloadData()
  98. }
  99. .then { (result) in
  100. DispatchQueue.main.async {
  101. self.headerView.eventsByDate = result.0 as? [String: [OOMeetingInfo]]
  102. self.viewModel.theMeetingsByDay.removeAll()
  103. self.viewModel.theMeetingsByDay.append(contentsOf: result.1)
  104. self.tableView.reloadData()
  105. }
  106. }.catch { (myerror) in
  107. let customError = myerror as! OOAppError
  108. self.showError(title: customError.failureReason ?? "")
  109. }
  110. }
  111. func loadCurrentMonthCalendar(_ theDate: Date?) {
  112. self.showLoading()
  113. viewModel.getMeetingsByYearAndMonth(theDate ?? Date())
  114. .always {
  115. self.hideLoading()
  116. }
  117. .then { (resultDict) in
  118. self.headerView.eventsByDate = resultDict as? [String: [OOMeetingInfo]]
  119. }.catch { (myerror) in
  120. let customError = myerror as! OOAppError
  121. self.showError(title: customError.failureReason ?? "")
  122. }
  123. }
  124. func loadtheDayMeetingInfo(_ theDate: Date?) {
  125. self.showLoading()
  126. viewModel.getMeetingByTheDay(theDate ?? Date()).always {
  127. self.hideLoading()
  128. }.then { (infos) in
  129. self.viewModel.theMeetingsByDay.removeAll()
  130. self.viewModel.theMeetingsByDay.append(contentsOf: infos)
  131. self.tableView.reloadData()
  132. }.catch { (myerror) in
  133. let customError = myerror as! OOAppError
  134. self.showError(title: customError.failureReason ?? "")
  135. }
  136. }
  137. private func startProcess(processId: String, identity: String) {
  138. viewModel.startProcess(processId: processId, identity: identity).then { (list) in
  139. let taskList = list
  140. DispatchQueue.main.async {
  141. let taskStoryboard = UIStoryboard(name: "task", bundle: Bundle.main)
  142. let todoTaskDetailVC = taskStoryboard.instantiateViewController(withIdentifier: "todoTaskDetailVC") as! TodoTaskDetailViewController
  143. todoTaskDetailVC.todoTask = taskList[0].copyToTodoTask()
  144. todoTaskDetailVC.backFlag = 3
  145. self.navigationController?.pushViewController(todoTaskDetailVC, animated: true)
  146. }
  147. }.catch { (error) in
  148. self.showError(title: "启动会议流程出错!")
  149. }
  150. }
  151. override func didReceiveMemoryWarning() {
  152. super.didReceiveMemoryWarning()
  153. // Dispose of any resources that can be recreated.
  154. }
  155. }
  156. // MARK:- EmptyDataSetSource,EmptyDataSetDelegate
  157. extension OOMeetingInforController: EmptyDataSetSource, EmptyDataSetDelegate {
  158. func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
  159. let text = "您当前还没有会议"
  160. let titleAttributes = [NSAttributedString.Key.foregroundColor: UIColor(hex: "#CCCCCC"), NSAttributedString.Key.font: UIFont.init(name: "PingFangSC-Regular", size: 18)!]
  161. return NSMutableAttributedString(string: text, attributes: titleAttributes)
  162. }
  163. func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
  164. return #imageLiteral(resourceName: "icon_wuhuiyi")
  165. }
  166. func backgroundColor(forEmptyDataSet scrollView: UIScrollView) -> UIColor? {
  167. return UIColor(hex: "#F5F5F5")
  168. }
  169. func emptyDataSetShouldDisplay(_ scrollView: UIScrollView) -> Bool {
  170. return true
  171. }
  172. }
  173. extension OOMeetingInforController: O2BBSCreatorViewDelegate {
  174. func creatorViewClicked(_ view: O2BBSCreatorView) {
  175. if let c = self.config, let pId = c.process?.id {
  176. self.showLoading(title: "Loading")
  177. viewModel.loadMeetingProcess(processId: pId).then { (list) in
  178. self.hideLoading()
  179. if list.count == 1 {
  180. self.startProcess(processId: pId, identity: list[0].distinguishedName!)
  181. } else {
  182. var actions: [UIAlertAction] = []
  183. list.forEach({ (identity) in
  184. let action = UIAlertAction(title: "\(identity.name!)(\(identity.unitName!))", style: .default, handler: { (a) in
  185. self.startProcess(processId: pId, identity: identity.distinguishedName!)
  186. })
  187. actions.append(action)
  188. })
  189. self.showSheetAction(title: "提示", message: "请选择创建会议流程的身份", actions: actions)
  190. }
  191. }.catch { (error) in
  192. DDLogError("\(error)")
  193. self.hideLoading()
  194. // self.performSegue(withIdentifier: "showCreateMeetingSgue", sender: nil)
  195. self.performSegue(withIdentifier: "showMeetingForm", sender: nil)
  196. }
  197. } else {
  198. // self.performSegue(withIdentifier: "showCreateMeetingSgue", sender: nil)
  199. self.performSegue(withIdentifier: "showMeetingForm", sender: nil)
  200. }
  201. }
  202. }
  203. // MARK:- OOMeetingInforHeaderViewDelegate
  204. extension OOMeetingInforController: OOMeetingInforHeaderViewDelegate {
  205. func selectedTheDay(_ theDay: Date?) {
  206. self.currentSelectDay = theDay
  207. loadtheDayMeetingInfo(theDay)
  208. }
  209. func selectedTheMonth(_ theMonth: Date?) {
  210. self.currentMonthDay = theMonth
  211. loadCurrentMonthCalendar(theMonth)
  212. }
  213. }
  214. // MARK:- UITableViewDataSource,UITableViewDelegate
  215. extension OOMeetingInforController: UITableViewDataSource, UITableViewDelegate {
  216. func numberOfSections(in tableView: UITableView) -> Int {
  217. return viewModel.numberOfSections()
  218. }
  219. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  220. return viewModel.numberOfRowsInSection(section)
  221. }
  222. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  223. let cell = tableView.dequeueReusableCell(withIdentifier: meetingIdentifier, for: indexPath)
  224. let uCell = cell as! OOMeetingInforItemCell
  225. uCell.viewModel = viewModel
  226. let item = viewModel.nodeForIndexPath(indexPath)
  227. uCell.config(withItem: item)
  228. return cell
  229. }
  230. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  231. return 116.0
  232. }
  233. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  234. return headerView.calendarManager?.settings.weekModeEnabled == false ? hSectionHeight : sectionHeight
  235. }
  236. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  237. return headerView
  238. }
  239. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  240. let item = viewModel.nodeForIndexPath(indexPath)
  241. self.performSegue(withIdentifier: "showMeetingDetail", sender: item)
  242. }
  243. }