OOContactSearchResultController.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // OOContactSearchResultController.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/11/28.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. class OOContactSearchResultController: UITableViewController,UISearchResultsUpdating {
  10. lazy var viewModel = {
  11. return OOContactSearchViewModel()
  12. }()
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. viewModel.updateBlock = { msg in
  16. self.tableView.reloadData()
  17. print(msg ?? "")
  18. }
  19. self.tableView.translatesAutoresizingMaskIntoConstraints = false
  20. }
  21. func updateSearchResults(for searchController: UISearchController) {
  22. let searchText = searchController.searchBar.text ?? ""
  23. viewModel.searchRefreshData(searchText)
  24. }
  25. // MARK: - Table view data source
  26. override func numberOfSections(in tableView: UITableView) -> Int {
  27. return viewModel.numberOfSectionsForSearch()
  28. }
  29. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  30. return viewModel.numberOfRowsInSectionForSearch(section)
  31. }
  32. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  33. let cell = tableView.dequeueReusableCell(withIdentifier: "OOContactSearchCell", for: indexPath)
  34. let pCell = cell as! (OOContactSearchCell & Configurable)
  35. let item = viewModel.nodeForIndexPathForSearch(indexPath)
  36. pCell.viewModel = viewModel
  37. pCell.config(withItem: item)
  38. return cell
  39. }
  40. override func didReceiveMemoryWarning() {
  41. super.didReceiveMemoryWarning()
  42. }
  43. override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  44. let headerView = Bundle.main.loadNibNamed("OOContactSearchSectionHeaderView", owner: self, options: nil)![0] as! OOContactSearchSectionHeaderView
  45. let type = viewModel.headerTypeOfSection(section)
  46. headerView.setHeaderType(type)
  47. return headerView
  48. }
  49. override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  50. return viewModel.headerHeightOfSection(section)
  51. }
  52. override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  53. return viewModel.footerHeightOfSection(section)
  54. }
  55. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  56. if indexPath.section == 0 {
  57. var model:Any?
  58. model = viewModel.nodeForIndexPathForSearch(indexPath)
  59. self.performSegue(withIdentifier: "searchShowUnitSegue", sender: model)
  60. }else if indexPath.section == 1 {
  61. let model = viewModel.nodeForIndexPathForSearch(indexPath)
  62. self.performSegue(withIdentifier: "searchShowPersonSegue", sender: model)
  63. }
  64. }
  65. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  66. // print(self.parent)
  67. // let searchController = self.parent as! OOUISearchController
  68. // searchController.isActive = false
  69. if segue.identifier == "searchShowUnitSegue" {
  70. let navVC = segue.destination as! ZLNavigationController
  71. let destVC = navVC.topViewController as! OOListUnitViewController
  72. destVC.isShowSearchControl = false
  73. let model = sender as! OOUnitModel
  74. destVC.unit = model
  75. //let navVC = OOBaseNavigationController(rootViewController: destVC)
  76. }else if segue.identifier == "searchShowPersonSegue" {
  77. let navVC = segue.destination as! ZLNavigationController
  78. let destVC = navVC.topViewController as! OOLinkeManViewController
  79. let model = sender as! OOPersonModel
  80. destVC.currentPerson = model
  81. }
  82. }
  83. }