OOMeetingRoomViewModel.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // OOMeetingRoomViewModel.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/1/18.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. import Promises
  10. class OOMeetingRoomViewModel: NSObject {
  11. //HTTP API
  12. private let o2MeetingAPI = OOMoyaProvider<O2MeetingAPI>()
  13. //所有文件夹及文件列表
  14. var builds:[OOMeetingBuildInfo] = []
  15. //回调块类型定义
  16. typealias CallbackBlockDefine = (_ msg:String?) -> Void
  17. //回调块定义
  18. var callbackExecutor:CallbackBlockDefine?
  19. override init() {
  20. super.init()
  21. }
  22. }
  23. // MARK:- UITableView DataSource
  24. extension OOMeetingRoomViewModel{
  25. func numberOfSections() -> Int {
  26. return builds.count
  27. }
  28. func numberOfRowsInSection(_ section: Int) -> Int {
  29. return builds[section].roomList?.count ?? 0
  30. }
  31. func nodeForIndexPath(_ indexPath:IndexPath) -> OOMeetingRoomInfo? {
  32. return builds[indexPath.section].roomList?[indexPath.row]
  33. }
  34. func headerHeightOfSection(_ section:Int) -> CGFloat {
  35. return 40
  36. }
  37. func footerHeightOfSection(_ section:Int) -> CGFloat {
  38. return 10
  39. }
  40. func headerViewOfSection(_ section:Int) -> UIView {
  41. let view = Bundle.main.loadNibNamed("OOMeetingRoomMainSectionHeaderView", owner: self, options: nil)?.first as! OOMeetingRoomMainSectionHeaderView
  42. let build = builds[section]
  43. let buildName = build.name
  44. let roomCount = build.roomList?.count ?? 0
  45. view.titleLabel.text = "\(buildName!)(\(roomCount))"
  46. return view
  47. }
  48. func footerViewOfSection(_ section:Int) -> UIView {
  49. let view = UIView()
  50. view.frame = CGRect(x: 0, y: 0, width: kScreenW, height: 10)
  51. view.backgroundColor = UIColor(hex: "#f5f5f5")
  52. return view
  53. }
  54. }
  55. extension OOMeetingRoomViewModel {
  56. func loadAllBuildByDate(_ startDate:String,_ completedDate:String) -> Promise<[OOMeetingBuildInfo]> {
  57. return Promise { fulfill,reject in
  58. self.o2MeetingAPI.request(.buildListByStartAndCompletedDate(startDate, completedDate)) { (result) in
  59. let myResult = OOResult<BaseModelClass<[OOMeetingBuildInfo]>>(result)
  60. if myResult.isResultSuccess() {
  61. if let models = myResult.model?.data {
  62. fulfill(models)
  63. }else{
  64. let customError = OOAppError.common(type: "MeetingRoom load Error", message: "会议室信息读取错误", statusCode: 7002)
  65. reject(customError)
  66. }
  67. }else{
  68. reject(myResult.error!)
  69. }
  70. }
  71. }
  72. }
  73. }