MeetingFormAttachmentCell.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // MeetingFormAttachmentCell.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 MeetingFormAttachmentCell: Cell<[OOMeetingAttachmentList]>, CellType {
  11. @IBOutlet weak var uploadBtn: UIButton!
  12. @IBOutlet weak var attachmentListView: UITableView!
  13. /// 编辑模式 可以上传和删除
  14. var editMode = false
  15. var attachmentList: [OOMeetingAttachmentList] = []
  16. /// 上传按钮点击事件
  17. var uploadAction: (() -> Void)? = nil
  18. var deleteAction: ((OOMeetingAttachmentList) -> Void)? = nil
  19. var openFileAction: ((OOMeetingAttachmentList) -> Void)? = nil
  20. override func setup() {
  21. super.setup()
  22. selectionStyle = .none
  23. self.attachmentListView.delegate = self
  24. self.attachmentListView.dataSource = self
  25. self.attachmentListView.register(UINib.init(nibName: "MeetingFormAttachmentItemCell", bundle: nil), forCellReuseIdentifier: "MeetingFormAttachmentItemCell")
  26. self.attachmentListView.tableFooterView = UIView()
  27. }
  28. override func update() {
  29. super.update()
  30. print("更新 MeetingFormAttachmentCell")
  31. textLabel?.text = nil //去掉默认标题
  32. if editMode {
  33. self.uploadBtn.isHidden = false
  34. self.uploadBtn.addTapGesture { (tap) in
  35. self.uploadAction?()
  36. }
  37. }
  38. if let value = row.value {
  39. print("有值。。。。。")
  40. self.attachmentList = value
  41. self.attachmentListView.reloadData()
  42. }
  43. }
  44. }
  45. extension MeetingFormAttachmentCell: UITableViewDelegate, UITableViewDataSource {
  46. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  47. return attachmentList.count
  48. }
  49. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  50. if let cell = tableView.dequeueReusableCell(withIdentifier: "MeetingFormAttachmentItemCell", for: indexPath) as? MeetingFormAttachmentItemCell {
  51. cell.flushData(atta: self.attachmentList[indexPath.row], editMode: self.editMode)
  52. return cell
  53. }
  54. return UITableViewCell()
  55. }
  56. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  57. let item = self.attachmentList[indexPath.row]
  58. if self.editMode {
  59. self.deleteAction?(item)
  60. } else {
  61. self.openFileAction?(item)
  62. }
  63. tableView.deselectRow(at: indexPath, animated: false)
  64. }
  65. }
  66. final class MeetingFormAttachmentCellRow: Row<MeetingFormAttachmentCell>, RowType {
  67. required init(tag: String?) {
  68. super.init(tag: tag)
  69. cellProvider = CellProvider<MeetingFormAttachmentCell>(nibName: "MeetingFormAttachmentCell")
  70. }
  71. }