OOMeetingAcceptViewModel.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // OOMeetingAcceptViewModel.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/1/22.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. class OOMeetingAcceptViewModel: NSObject {
  10. //HTTP API
  11. private let o2MeetingAPI = OOMoyaProvider<O2MeetingAPI>()
  12. //所有文件夹及文件列表
  13. private var meetings:[OOMeetingInfo] = []
  14. //回调块类型定义
  15. typealias CallbackBlockDefine = (_ msg:String?) -> Void
  16. //回调块定义
  17. var callbackExecutor:CallbackBlockDefine?
  18. override init() {
  19. super.init()
  20. }
  21. }
  22. extension OOMeetingAcceptViewModel{
  23. func loadMeetingRoomById(_ roomId:String,completed:@escaping (_ room:OOMeetingRoomInfo?) -> Void){
  24. o2MeetingAPI.request(.roomItemById(roomId)) { (result) in
  25. let myResult = OOResult<BaseModelClass<OOMeetingRoomInfo>>(result)
  26. if myResult.isResultSuccess() {
  27. let item = myResult.model?.data
  28. completed(item)
  29. }else{
  30. completed(nil)
  31. }
  32. }
  33. }
  34. // MARK:- 读取待同意的会议和我发起的会议
  35. func loadAcceptListByIndex(_ index: Int){
  36. self.meetings.removeAll()
  37. if index == 0{
  38. //接收到的邀请
  39. o2MeetingAPI.request(.meetingListByAccept) { (result) in
  40. let myResult = OOResult<BaseModelClass<[OOMeetingInfo]>>(result)
  41. if myResult.isResultSuccess() {
  42. if let model = myResult.model?.data {
  43. model.forEach({ (item) in
  44. self.meetings.append(item)
  45. })
  46. }
  47. }
  48. guard let block = self.callbackExecutor else {
  49. return
  50. }
  51. if myResult.isResultSuccess() {
  52. block(nil)
  53. }else{
  54. block(myResult.error?.errorDescription)
  55. }
  56. }
  57. }else if index == 1{
  58. //发送出去的邀请
  59. o2MeetingAPI.request(.meetingListByApplied) { (result) in
  60. let myResult = OOResult<BaseModelClass<[OOMeetingInfo]>>(result)
  61. if myResult.isResultSuccess() {
  62. if let model = myResult.model?.data {
  63. model.forEach({ (item) in
  64. self.meetings.append(item)
  65. })
  66. }
  67. }
  68. guard let block = self.callbackExecutor else {
  69. return
  70. }
  71. if myResult.isResultSuccess() {
  72. block(nil)
  73. }else{
  74. block(myResult.error?.errorDescription)
  75. }
  76. }
  77. }
  78. }
  79. }
  80. // MARK:- UITableView DataSource
  81. extension OOMeetingAcceptViewModel{
  82. func numberOfSections() -> Int {
  83. return 1
  84. }
  85. func numberOfRowsInSection(_ section: Int) -> Int {
  86. return meetings.count
  87. }
  88. func nodeForIndexPath(_ indexPath:IndexPath) -> OOMeetingInfo? {
  89. return meetings[indexPath.row]
  90. }
  91. // func headerHeightOfSection(_ section:Int) -> CGFloat {
  92. // return <#height#>
  93. // }
  94. //
  95. // func footerHeightOfSection(_ section:Int) -> CGFloat {
  96. // return <#height#>
  97. // }
  98. //
  99. }