MeetingFormTimeDuringCell.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // MeetingFormTimeDuringCell.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 DuringTime: NSObject {
  11. var startTime: Date?
  12. var endTime: Date?
  13. }
  14. class MeetingFormTimeDuringCell: Cell<DuringTime>, CellType {
  15. @IBOutlet weak var startTimeLabel: UILabel!
  16. @IBOutlet weak var endTimeLable: UILabel!
  17. override func setup() {
  18. super.setup()
  19. selectionStyle = .none
  20. //点击选择开始时间
  21. self.startTimeLabel.addTapGesture { (tap) in
  22. var start = Date()
  23. if let vS = self.row.value?.startTime {
  24. start = vS
  25. }
  26. self.showDatePicker(pickerStyle: .hourMinuteSecond, callBackResult: { (result) in
  27. let newValue = DuringTime()
  28. newValue.startTime = result
  29. if let v = self.row.value {
  30. newValue.endTime = v.endTime
  31. }
  32. self.row.value = newValue
  33. self.startTimeLabel.text = result.toString("HH时mm分")
  34. }, defaultDate: start)
  35. }
  36. //点击选择结束时间
  37. self.endTimeLable.addTapGesture { (tap) in
  38. var end = Date()
  39. if let eS = self.row.value?.endTime {
  40. end = eS
  41. }
  42. self.showDatePicker(pickerStyle: .hourMinuteSecond, callBackResult: { (result) in
  43. let newValue = DuringTime()
  44. newValue.endTime = result
  45. if let v = self.row.value {
  46. newValue.startTime = v.startTime
  47. }
  48. self.row.value = newValue
  49. self.endTimeLable.text = result.toString("HH时mm分")
  50. }, defaultDate: end)
  51. }
  52. }
  53. override func update() {
  54. super.update()
  55. //数据变化显示到界面
  56. if let value = self.row.value {
  57. self.startTimeLabel.text = value.startTime?.toString("HH时mm分")
  58. self.endTimeLable.text = value.endTime?.toString("HH时mm分")
  59. }
  60. }
  61. private func showDatePicker(pickerStyle: DateStyle, callBackResult:((_ result:Date) -> Void)?, defaultDate: Date = Date()) {
  62. let datePicker = DatePickerView.datePicker(style: pickerStyle, scrollToDate: defaultDate) { date in
  63. guard let date = date else { return }
  64. if let cr = callBackResult {
  65. cr(date)
  66. }
  67. }
  68. datePicker.show()
  69. }
  70. }
  71. final class MeetingFormTimeDuringRow: Row<MeetingFormTimeDuringCell>, RowType {
  72. required init(tag: String?) {
  73. super.init(tag: tag)
  74. cellProvider = CellProvider<MeetingFormTimeDuringCell>(nibName: "MeetingFormTimeDuringCell")
  75. }
  76. }