OOContactMainViewController.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // ContactMainViewController.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/11/20.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. import EmptyDataSet_Swift
  10. class OOContactMainViewController: UITableViewController {
  11. private lazy var viewModel = {
  12. return OOContactViewModel()
  13. }()
  14. var searchController:OOUISearchController!
  15. private lazy var searchResultController = { () -> UIViewController? in
  16. let searchVC = self.storyboard?.instantiateViewController(withIdentifier: "OOContactSearchController")
  17. return searchVC
  18. }()
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. searchController = OOUISearchController(searchResultsController: searchResultController)
  22. //searchController.dimsBackgroundDuringPresentation = false
  23. searchController.searchResultsUpdater = searchResultController as! UISearchResultsUpdating
  24. self.tableView.emptyDataSetSource = self
  25. self.tableView.emptyDataSetDelegate = self
  26. self.tableView.tableHeaderView = searchController.searchBar
  27. viewModel.updateBlock = { msg in
  28. self.tableView.reloadData()
  29. }
  30. // self.tableView.mj_header.refreshingBlock = {
  31. // self.viewModel.refreshData()
  32. // }
  33. viewModel.refreshData()
  34. }
  35. // MARK: - Table view data source
  36. override func numberOfSections(in tableView: UITableView) -> Int {
  37. return viewModel.numberOfSections()
  38. }
  39. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  40. return viewModel.numberOfRowsInSection(section)
  41. }
  42. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  43. let type = OOContactGroupHeaderType(rawValue: indexPath.section)!
  44. var cell:UITableViewCell!
  45. switch type {
  46. case .department,.company,.group:
  47. cell = tableView.dequeueReusableCell(withIdentifier: "CDLCell", for: indexPath)
  48. var item:DataModel?
  49. item = viewModel.nodeForIndexPath(indexPath)
  50. let uCell = cell as! Configurable
  51. uCell.config(withItem: item ?? nil)
  52. break
  53. case .linkman:
  54. cell = tableView.dequeueReusableCell(withIdentifier: "LinkManCell", for: indexPath) as! OOLinkManCell
  55. var item:DataModel?
  56. item = viewModel.nodeForIndexPath(indexPath)
  57. let pCell = cell as! Configurable
  58. pCell.config(withItem: item ?? nil)
  59. break
  60. }
  61. return cell
  62. }
  63. override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  64. let headerView = Bundle.main.loadNibNamed("OOContactGroupHeaderView", owner: self, options: nil)![0] as! OOContactGroupHeaderView
  65. let type = viewModel.headerTypeOfSection(section)
  66. headerView.setHeaderType(type)
  67. return headerView
  68. }
  69. override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  70. return viewModel.headerHeightOfSection(section)
  71. }
  72. override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  73. return viewModel.footerHeightOfSection(section)
  74. }
  75. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  76. if indexPath.section == 0 || indexPath.section == 1 {
  77. var model:Any?
  78. model = viewModel.nodeForIndexPath(indexPath)
  79. self.performSegue(withIdentifier: "listUnitSegue", sender: model)
  80. }
  81. }
  82. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  83. if segue.identifier == "listUnitSegue" {
  84. let destVC = segue.destination as! OOListUnitViewController
  85. let model = sender as! OOUnitModel
  86. destVC.unit = model
  87. }
  88. }
  89. }
  90. // MARK: - DZN DataSource
  91. extension OOContactMainViewController:EmptyDataSetSource,EmptyDataSetDelegate {
  92. func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage? {
  93. return #imageLiteral(resourceName: "pic_o2_moren1")
  94. }
  95. func title(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString? {
  96. let text = "没有组织及人员"
  97. let titleAttributes = [NSAttributedString.Key.foregroundColor:UIColor.lightText,NSAttributedString.Key.font:UIFont.init(name: "PingFangSC-Regular", size: 18)!]
  98. return NSMutableAttributedString(string: text, attributes: titleAttributes)
  99. }
  100. func backgroundColor(forEmptyDataSet scrollView: UIScrollView!) -> UIColor? {
  101. return UIColor(hex: "#F5F5F5")
  102. }
  103. }