OOMeetingCreateFormView.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // OOMeetingCreateFormView.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/1/25.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. protocol OOMeetingCreateFormViewDelegate {
  10. func performPersonSelected()
  11. func performRoomSelected()
  12. }
  13. class OOMeetingCreateFormView: UIView {
  14. private lazy var textItemView:OOFormTextItemView = {
  15. let view = Bundle.main.loadNibNamed("OOFormTextItemView", owner: self, options: nil)![0] as! OOFormTextItemView
  16. return view
  17. }()
  18. private lazy var dateItemView:OOFormDateItemView = {
  19. let view = Bundle.main.loadNibNamed("OOFormTextItemView", owner: self, options: nil)![1] as! OOFormDateItemView
  20. return view
  21. }()
  22. private lazy var dateIntervalItemView:OOFormDateIntervalItemView = {
  23. let view = Bundle.main.loadNibNamed("OOFormTextItemView", owner: self, options: nil)![2] as! OOFormDateIntervalItemView
  24. return view
  25. }()
  26. private lazy var segueItemView:OOFormSegueItemView = {
  27. let view = Bundle.main.loadNibNamed("OOFormTextItemView", owner: self, options: nil)![3] as! OOFormSegueItemView
  28. return view
  29. }()
  30. var delegate:OOMeetingCreateFormViewDelegate?
  31. //model Array
  32. private var _ooFormsModels:[OOFormBaseModel]?
  33. var ooFormsModels:[OOFormBaseModel]? {
  34. get {
  35. return _ooFormsModels
  36. }
  37. set(models){
  38. _ooFormsModels = models
  39. _ooFormsModels?.forEach({ (model) in
  40. switch model.componentType! {
  41. case .textItem:
  42. let view = textItemView
  43. view.configItem(model)
  44. self.addSubview(view)
  45. break
  46. case .dateItem:
  47. let view = dateItemView
  48. view.configItem(model)
  49. self.addSubview(view)
  50. break
  51. case .dateIntervalItem:
  52. let view = dateIntervalItemView
  53. view.configItem(model)
  54. self.addSubview(view)
  55. break
  56. case .segueItem:
  57. let view = segueItemView
  58. view.addTapGesture { (tap) in
  59. self.delegate?.performRoomSelected()
  60. }
  61. view.configItem(model)
  62. self.addSubview(view)
  63. break
  64. }
  65. })
  66. }
  67. }
  68. override init(frame: CGRect) {
  69. super.init(frame: frame)
  70. }
  71. required init?(coder aDecoder: NSCoder) {
  72. super.init(coder: aDecoder)
  73. }
  74. override func awakeFromNib() {
  75. }
  76. //重新布局所有子控件
  77. override func layoutSubviews() {
  78. super.layoutSubviews()
  79. let x:CGFloat = 0
  80. var y:CGFloat = 0
  81. let width:CGFloat = kScreenW
  82. let height:CGFloat = 44
  83. self.subviews.forEach { (view) in
  84. view.frame = CGRect(x: x, y: y, width: width, height: height)
  85. y+=height
  86. }
  87. }
  88. func setSelectedRoom(_ room:OOMeetingRoomInfo){
  89. segueItemView.setBackValueUpdate(room)
  90. }
  91. func getFormDataFormBean() -> (OOMeetingForm?, err: String?) {
  92. let meetingForm = OOMeetingForm()
  93. //标题
  94. guard let title = textItemView.model?.callbackValue as? String else {
  95. return (nil, "请输入会议主题")
  96. }
  97. meetingForm.subject = title
  98. //日期
  99. guard let date = dateItemView.model?.callbackValue as? Date else {
  100. return (nil, "请选择日期")
  101. }
  102. meetingForm.meetingDate = date
  103. //开始时间
  104. let model = dateIntervalItemView.model as! OOFormDateIntervalModel
  105. guard let startTime = model.value1 as? Date else {
  106. return (nil, "请选择开始时间")
  107. }
  108. //结束时间
  109. guard let endTime = model.value2 as? Date else {
  110. return (nil, "请选择结束时间")
  111. }
  112. //判断时间大小
  113. guard startTime.timeIntervalSince1970 < endTime.timeIntervalSince1970 else {
  114. return (nil, "开始时间不能大于结束时间")
  115. }
  116. meetingForm.startTime = startTime
  117. meetingForm.completedTime = endTime
  118. //会议室
  119. guard let room = segueItemView.model?.callbackValue as? OOMeetingRoomInfo else {
  120. return (nil, "请选择会议室")
  121. }
  122. meetingForm.room = room.id
  123. meetingForm.roomName = room.name
  124. return (meetingForm, nil)
  125. }
  126. ///获取日期时间 给选择会议室用
  127. func getFormDataForChooseRoom() -> (OOMeetingForm?, err: String?) {
  128. let meetingForm = OOMeetingForm()
  129. //日期
  130. guard let date = dateItemView.model?.callbackValue as? Date else {
  131. return (nil, "请选择日期")
  132. }
  133. meetingForm.meetingDate = date
  134. //开始时间
  135. let model = dateIntervalItemView.model as! OOFormDateIntervalModel
  136. guard let startTime = model.value1 as? Date else {
  137. return (nil, "请选择开始时间")
  138. }
  139. //结束时间
  140. guard let endTime = model.value2 as? Date else {
  141. return (nil, "请选择结束时间")
  142. }
  143. //判断时间大小
  144. guard startTime.timeIntervalSince1970 < endTime.timeIntervalSince1970 else {
  145. return (nil, "开始时间不能大于结束时间")
  146. }
  147. meetingForm.startTime = startTime
  148. meetingForm.completedTime = endTime
  149. return (meetingForm, nil)
  150. }
  151. }