MyShopMenuContent.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // MyShopMenuContent.swift
  3. // xingchuangke
  4. //
  5. // Created by 李晓飞 on 2020/8/23.
  6. // Copyright © 2020 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class MyShopMenuContent: UIView {
  10. let rateArr: NSArray = ["0.52%", "0.53%", "0.54%", "0.55%", "0.56%", "0.57%", "0.58%", "0.59%", "0.6%"]
  11. @IBOutlet weak var startTimeBtn: UIButton!
  12. @IBOutlet weak var endTimeBtn: UIButton!
  13. @IBOutlet weak var minRateBtn: UIButton!
  14. @IBOutlet weak var maxRateBtn: UIButton!
  15. var startTime: String = ""
  16. var endTime: String = ""
  17. var busType: String = ""
  18. var miniRate: String = ""
  19. var maxRate: String = ""
  20. let queryEntity: ShopQueryModel = ShopQueryModel()
  21. var oBackFunc: ShopQueryEntity!
  22. func callBackForSure(backFunc:@escaping ShopQueryEntity) {
  23. oBackFunc = backFunc
  24. }
  25. @IBAction func btnMenuClick(_ sender: Any) {
  26. // 1001 ~ 1008
  27. let btn = (sender as! UIButton)
  28. switch btn.tag {
  29. case 1001: // 开始时间
  30. let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
  31. var defaultDate: Date!
  32. if self.queryEntity.startTime.length() == 0 || self.queryEntity.startTime.length() != 10 {
  33. defaultDate = CommonDate.addMonth(date: Date(), month: 0)
  34. } else {
  35. defaultDate = CommonDate.getDateForString(dateStr: self.queryEntity.startTime, dateFormat: "yyyy-MM-dd")
  36. }
  37. // defaultDate = CommonDate.addMonth(date: Date(), month: -1)
  38. viewDatePicer.datePicker.maximumDate = Date()
  39. viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
  40. self!.queryEntity.startTime = str
  41. self!.startTimeBtn.isSelected = true
  42. self!.startTimeBtn.setTitle(str, for: .selected)
  43. }
  44. break
  45. case 1002: // 结束时间
  46. let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
  47. var defaultDate: Date!
  48. if self.queryEntity.endTime.length() == 0 || self.queryEntity.endTime.length() != 10 {
  49. defaultDate = CommonDate.addMonth(date: Date(), month: 0)
  50. } else {
  51. defaultDate = CommonDate.getDateForString(dateStr: self.queryEntity.endTime, dateFormat: "yyyy-MM-dd")
  52. }
  53. // defaultDate = CommonDate.addMonth(date: Date(), month: -1)
  54. viewDatePicer.datePicker.maximumDate = Date()
  55. viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
  56. self!.queryEntity.endTime = str
  57. self!.endTimeBtn.isSelected = true
  58. self!.endTimeBtn.setTitle(str, for: .selected)
  59. }
  60. break
  61. case 1003: // 个人版
  62. btn.isSelected = true
  63. let oB = self.viewWithTag(1004) as! UIButton
  64. oB.isSelected = false
  65. self.queryEntity.busType = "0"
  66. break
  67. case 1004: // 商户版
  68. btn.isSelected = true
  69. let oB = self.viewWithTag(1003) as! UIButton
  70. oB.isSelected = false
  71. self.queryEntity.busType = "1"
  72. break
  73. case 1005: // 最低费率
  74. let alert = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
  75. for rateStr in rateArr {
  76. let action = UIAlertAction.init(title: (rateStr as! String), style: .default) { (defaultAction) in
  77. self.minRateBtn.isSelected = true
  78. self.minRateBtn.setTitle(defaultAction.title, for: .selected)
  79. self.queryEntity.miniRate = defaultAction.title!
  80. }
  81. alert.addAction(action)
  82. }
  83. let action = UIAlertAction.init(title: "取消", style: .cancel) { (_) in
  84. }
  85. alert.addAction(action)
  86. let curVc = currentViewController()
  87. curVc?.present(alert, animated: true, completion: nil)
  88. break
  89. case 1006: // 最高费率
  90. let alert = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
  91. for rateStr in rateArr {
  92. let action = UIAlertAction.init(title: (rateStr as! String), style: .default) { (defaultAction) in
  93. self.maxRateBtn.isSelected = true
  94. self.maxRateBtn.setTitle(defaultAction.title, for: .selected)
  95. self.queryEntity.maxRate = defaultAction.title!
  96. }
  97. alert.addAction(action)
  98. }
  99. let action = UIAlertAction.init(title: "取消", style: .cancel) { (_) in
  100. }
  101. alert.addAction(action)
  102. let curVc = currentViewController()
  103. curVc?.present(alert, animated: true, completion: nil)
  104. break
  105. case 1007: // 重置
  106. do {
  107. self.queryEntity.startTime = ""
  108. self.queryEntity.endTime = ""
  109. // 商户类型
  110. self.queryEntity.busType = ""
  111. self.queryEntity.miniRate = ""
  112. self.queryEntity.maxRate = ""
  113. resetData()
  114. }
  115. break
  116. case 1008: // 确定
  117. if oBackFunc != nil {
  118. oBackFunc(queryEntity)
  119. }
  120. break
  121. default: break
  122. }
  123. }
  124. func resetData() {
  125. self.startTimeBtn.isSelected = false
  126. self.startTimeBtn.setTitle("请选择开始时间", for: .normal)
  127. self.endTimeBtn.isSelected = false
  128. self.endTimeBtn.setTitle("请选择结束时间", for: .normal)
  129. // self.startTimeBtn.isSelected = false
  130. // self.startTimeBtn.isSelected = false
  131. let perBtn = self.viewWithTag(1003) as! UIButton
  132. let merBtn = self.viewWithTag(1004) as! UIButton
  133. perBtn.isSelected = false
  134. merBtn.isSelected = false
  135. self.minRateBtn.isSelected = false
  136. self.minRateBtn.setTitle("选择最低费率", for: .normal)
  137. self.maxRateBtn.isSelected = false
  138. self.maxRateBtn.setTitle("选择最高费率", for: .normal)
  139. }
  140. /*
  141. // Only override draw() if you perform custom drawing.
  142. // An empty implementation adversely affects performance during animation.
  143. override func draw(_ rect: CGRect) {
  144. // Drawing code
  145. }
  146. */
  147. ///获取当前视图所在导航控制器
  148. func currentViewController() -> UIViewController? {
  149. var n = next
  150. while n != nil {
  151. if (n?.isKind(of: UIViewController.self))! {
  152. return n as? UIViewController
  153. }
  154. n = n?.next
  155. }
  156. return nil
  157. }
  158. }
  159. class ShopQueryModel: NSObject {
  160. // 开通时间
  161. var startTime: String = ""
  162. var endTime: String = ""
  163. // 商户类型
  164. var busType: String = ""
  165. // 商户费率
  166. var miniRate: String = ""
  167. var maxRate: String = ""
  168. }
  169. typealias ShopQueryEntity = (_ entity: ShopQueryModel) -> Void