OOMeetingInforController.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. if c.mobileCreateEnable == true {
  73. DispatchQueue.main.async {
  74. UIApplication.shared.windows.first?.addSubview(self.createView)
  75. }
  76. }
  77. }
  78. }.catch { (error) in
  79. DDLogError("会议配置获取异常, \(error)")
  80. }
  81. }
  82. func loadData() {
  83. self.showLoading()
  84. if self.currentMonthDay == nil {
  85. self.currentMonthDay = Date()
  86. }
  87. if self.currentSelectDay == nil {
  88. self.currentSelectDay = Date()
  89. }
  90. all(viewModel.getMeetingsByYearAndMonth(self.currentMonthDay!), viewModel.getMeetingByTheDay(self.currentSelectDay!))
  91. .always {
  92. self.hideLoading()
  93. if self.tableView.mj_header.isRefreshing() {
  94. self.tableView.mj_header.endRefreshing()
  95. }
  96. //self.tableView.reloadData()
  97. }
  98. .then { (result) in
  99. DispatchQueue.main.async {
  100. self.headerView.eventsByDate = result.0 as? [String: [OOMeetingInfo]]
  101. self.viewModel.theMeetingsByDay.removeAll()
  102. self.viewModel.theMeetingsByDay.append(contentsOf: result.1)
  103. self.tableView.reloadData()
  104. }
  105. }.catch { (myerror) in
  106. let customError = myerror as! OOAppError
  107. self.showError(title: customError.failureReason ?? "")
  108. }
  109. }
  110. func loadCurrentMonthCalendar(_ theDate: Date?) {
  111. self.showLoading()
  112. viewModel.getMeetingsByYearAndMonth(theDate ?? Date())
  113. .always {
  114. self.hideLoading()
  115. }
  116. .then { (resultDict) in
  117. self.headerView.eventsByDate = resultDict as? [String: [OOMeetingInfo]]
  118. }.catch { (myerror) in
  119. let customError = myerror as! OOAppError
  120. self.showError(title: customError.failureReason ?? "")
  121. }
  122. }
  123. func loadtheDayMeetingInfo(_ theDate: Date?) {
  124. self.showLoading()
  125. viewModel.getMeetingByTheDay(theDate ?? Date()).always {
  126. self.hideLoading()
  127. }.then { (infos) in
  128. self.viewModel.theMeetingsByDay.removeAll()
  129. self.viewModel.theMeetingsByDay.append(contentsOf: infos)
  130. self.tableView.reloadData()
  131. }.catch { (myerror) in
  132. let customError = myerror as! OOAppError
  133. self.showError(title: customError.failureReason ?? "")
  134. }
  135. }
  136. private func startProcess(processId: String, identity: String) {
  137. viewModel.startProcess(processId: processId, identity: identity).then { (list) in
  138. let taskList = list
  139. DispatchQueue.main.async {
  140. let taskStoryboard = UIStoryboard(name: "task", bundle: Bundle.main)
  141. let todoTaskDetailVC = taskStoryboard.instantiateViewController(withIdentifier: "todoTaskDetailVC") as! TodoTaskDetailViewController
  142. todoTaskDetailVC.todoTask = taskList[0].copyToTodoTask()
  143. todoTaskDetailVC.backFlag = 3
  144. self.navigationController?.pushViewController(todoTaskDetailVC, animated: true)
  145. }
  146. }.catch { (error) in
  147. self.showError(title: "启动会议流程出错!")
  148. }
  149. }
  150. override func didReceiveMemoryWarning() {
  151. super.didReceiveMemoryWarning()
  152. // Dispose of any resources that can be recreated.
  153. }
  154. }
  155. // MARK:- EmptyDataSetSource,EmptyDataSetDelegate
  156. extension OOMeetingInforController: EmptyDataSetSource, EmptyDataSetDelegate {
  157. func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
  158. let text = "您当前还没有会议"
  159. let titleAttributes = [NSAttributedString.Key.foregroundColor: UIColor(hex: "#CCCCCC"), NSAttributedString.Key.font: UIFont.init(name: "PingFangSC-Regular", size: 18)!]
  160. return NSMutableAttributedString(string: text, attributes: titleAttributes)
  161. }
  162. func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
  163. return #imageLiteral(resourceName: "icon_wuhuiyi")
  164. }
  165. func backgroundColor(forEmptyDataSet scrollView: UIScrollView) -> UIColor? {
  166. return UIColor(hex: "#F5F5F5")
  167. }
  168. func emptyDataSetShouldDisplay(_ scrollView: UIScrollView) -> Bool {
  169. return true
  170. }
  171. }
  172. extension OOMeetingInforController: O2BBSCreatorViewDelegate {
  173. func creatorViewClicked(_ view: O2BBSCreatorView) {
  174. if let c = self.config, let pId = c.process?.id {
  175. self.showLoading(title: "Loading")
  176. viewModel.loadMeetingProcess(processId: pId).then { (list) in
  177. self.hideLoading()
  178. if list.count == 1 {
  179. self.startProcess(processId: pId, identity: list[0].distinguishedName!)
  180. } else {
  181. var actions: [UIAlertAction] = []
  182. list.forEach({ (identity) in
  183. let action = UIAlertAction(title: "\(identity.name!)(\(identity.unitName!))", style: .default, handler: { (a) in
  184. self.startProcess(processId: pId, identity: identity.distinguishedName!)
  185. })
  186. actions.append(action)
  187. })
  188. self.showSheetAction(title: "提示", message: "请选择创建会议流程的身份", actions: actions)
  189. }
  190. }.catch { (error) in
  191. DDLogError("\(error)")
  192. self.hideLoading()
  193. // self.performSegue(withIdentifier: "showCreateMeetingSgue", sender: nil)
  194. self.performSegue(withIdentifier: "showMeetingForm", sender: nil)
  195. }
  196. } else {
  197. // self.performSegue(withIdentifier: "showCreateMeetingSgue", sender: nil)
  198. self.performSegue(withIdentifier: "showMeetingForm", sender: nil)
  199. }
  200. }
  201. }
  202. // MARK:- OOMeetingInforHeaderViewDelegate
  203. extension OOMeetingInforController: OOMeetingInforHeaderViewDelegate {
  204. func selectedTheDay(_ theDay: Date?) {
  205. self.currentSelectDay = theDay
  206. loadtheDayMeetingInfo(theDay)
  207. }
  208. func selectedTheMonth(_ theMonth: Date?) {
  209. self.currentMonthDay = theMonth
  210. loadCurrentMonthCalendar(theMonth)
  211. }
  212. }
  213. // MARK:- UITableViewDataSource,UITableViewDelegate
  214. extension OOMeetingInforController: UITableViewDataSource, UITableViewDelegate {
  215. func numberOfSections(in tableView: UITableView) -> Int {
  216. return viewModel.numberOfSections()
  217. }
  218. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  219. return viewModel.numberOfRowsInSection(section)
  220. }
  221. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  222. let cell = tableView.dequeueReusableCell(withIdentifier: meetingIdentifier, for: indexPath)
  223. let uCell = cell as! OOMeetingInforItemCell
  224. uCell.viewModel = viewModel
  225. let item = viewModel.nodeForIndexPath(indexPath)
  226. uCell.config(withItem: item)
  227. return cell
  228. }
  229. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  230. return 116.0
  231. }
  232. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  233. return headerView.calendarManager?.settings.weekModeEnabled == false ? hSectionHeight : sectionHeight
  234. }
  235. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  236. return headerView
  237. }
  238. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  239. let item = viewModel.nodeForIndexPath(indexPath)
  240. self.performSegue(withIdentifier: "showMeetingDetail", sender: item)
  241. }
  242. }