MeetingFormChoosePersonCell.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // MeetingFormChoosePersonCell.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2020/11/25.
  6. // Copyright © 2020 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Eureka
  10. class MeetingFormChoosePersonCell: Cell<[OOPersonModel]>, CellType {
  11. @IBOutlet weak var cellTitle: UILabel!
  12. @IBOutlet weak var personsView: UICollectionView!
  13. private var persons: [OOPersonModel] = []
  14. var viewModel:OOMeetingCreateViewModel?
  15. var isUpdate = false // 更新会议只能增加不能删除
  16. override func setup() {
  17. super.setup()
  18. selectionStyle = .none
  19. self.personsView.dataSource = self
  20. self.personsView.delegate = self
  21. self.personsView.register(UINib.init(nibName: "OOMeetingPersonCell", bundle: nil), forCellWithReuseIdentifier: "OOMeetingPersonCell")
  22. self.personsView.register(UINib.init(nibName: "OMeetingPersonActionCell", bundle: nil), forCellWithReuseIdentifier: "OOMeetingPersonActionCell")
  23. }
  24. override func update() {
  25. super.update()
  26. textLabel?.text = nil //去掉默认标题
  27. self.cellTitle.text = row.title ?? ""
  28. if #available(iOS 13.0, *) {
  29. self.cellTitle.textColor = row.isDisabled ? .tertiaryLabel : .label
  30. } else {
  31. self.cellTitle.textColor = row.isDisabled ? .gray : .black
  32. }
  33. self.persons.removeAll()
  34. if let list = row.value {
  35. self.persons = list
  36. }
  37. self.personsView.reloadData()
  38. }
  39. //会更新数据?
  40. func resetValue(persons: [OOPersonModel]) {
  41. self.row.value = persons
  42. self.row.updateCell()
  43. print("reset Value........")
  44. }
  45. }
  46. extension MeetingFormChoosePersonCell: UICollectionViewDataSource,UICollectionViewDelegate {
  47. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  48. return self.persons.count + 1
  49. }
  50. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  51. var cell:UICollectionViewCell?
  52. if indexPath.row == 0 {
  53. cell = collectionView.dequeueReusableCell(withReuseIdentifier: "OOMeetingPersonActionCell", for: indexPath)
  54. let uCell = cell as! OOMeetingPersonActionCell
  55. uCell.delegate = self
  56. }else {
  57. cell = collectionView.dequeueReusableCell(withReuseIdentifier: "OOMeetingPersonCell", for: indexPath) as! OOMeetingPersonCell
  58. let uCell = cell as! (OOMeetingPersonCell & Configurable)
  59. let person = self.persons[indexPath.row - 1]
  60. uCell.viewModel = self.viewModel
  61. uCell.setupModel(p: person, ishiddenDelBtn: isUpdate)
  62. }
  63. return cell!
  64. }
  65. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  66. if indexPath.row != 0 && !isUpdate {
  67. self.persons.remove(at: indexPath.row - 1)
  68. self.resetValue(persons: self.persons)
  69. }
  70. }
  71. }
  72. extension MeetingFormChoosePersonCell: UICollectionViewDelegateFlowLayout {
  73. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  74. return CGSize(width: 60, height: 75)
  75. }
  76. }
  77. extension MeetingFormChoosePersonCell: OOMeetingPersonActionCellDelegate {
  78. func addPersonActionClick(_ sender: UIButton) {
  79. //已经选择的人员
  80. var alreadyChoosePersons: [String] = []
  81. if !self.persons.isEmpty && !self.isUpdate {
  82. self.persons.forEach { (model) in
  83. if let dn = model.distinguishedName {
  84. alreadyChoosePersons.append(dn)
  85. }
  86. }
  87. }
  88. if let v = ContactPickerViewController.providePickerVC(
  89. pickerModes: [ContactPickerType.person],
  90. multiple: true,
  91. initUserPickedArray: alreadyChoosePersons,
  92. pickedDelegate: { (result: O2BizContactPickerResult) in
  93. if let users = result.users {
  94. var persons :[OOPersonModel] = []
  95. users.forEach({ (item) in
  96. let pm = OOPersonModel()
  97. pm.id = item.id
  98. pm.name = item.name
  99. pm.genderType = item.genderType
  100. pm.distinguishedName = item.distinguishedName
  101. persons.append(pm)
  102. })
  103. if !persons.isEmpty {
  104. if !self.persons.isEmpty && self.isUpdate {
  105. self.persons.forEach { (model) in
  106. persons.append(model)
  107. }
  108. }
  109. self.resetValue(persons: persons)
  110. }
  111. }
  112. }) {
  113. self.formViewController()?.navigationController?.pushViewController(v, animated: true)
  114. }
  115. }
  116. }
  117. final class MeetingFormChoosePersonCellRow: Row<MeetingFormChoosePersonCell>, RowType {
  118. required init(tag: String?) {
  119. super.init(tag: tag)
  120. cellProvider = CellProvider<MeetingFormChoosePersonCell>(nibName: "MeetingFormChoosePersonCell")
  121. }
  122. }