123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- //
- // MyShopMenuContent.swift
- // xingchuangke
- //
- // Created by 李晓飞 on 2020/8/23.
- // Copyright © 2020 Virgil. All rights reserved.
- //
- import UIKit
- class MyShopMenuContent: UIView {
- let rateArr: NSArray = ["0.52%", "0.53%", "0.54%", "0.55%", "0.56%", "0.57%", "0.58%", "0.59%", "0.6%"]
- @IBOutlet weak var startTimeBtn: UIButton!
- @IBOutlet weak var endTimeBtn: UIButton!
- @IBOutlet weak var minRateBtn: UIButton!
- @IBOutlet weak var maxRateBtn: UIButton!
- var startTime: String = ""
- var endTime: String = ""
- var busType: String = ""
- var miniRate: String = ""
- var maxRate: String = ""
- let queryEntity: ShopQueryModel = ShopQueryModel()
- var oBackFunc: ShopQueryEntity!
- func callBackForSure(backFunc:@escaping ShopQueryEntity) {
- oBackFunc = backFunc
- }
- @IBAction func btnMenuClick(_ sender: Any) {
- // 1001 ~ 1008
- let btn = (sender as! UIButton)
- switch btn.tag {
- case 1001: // 开始时间
- let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
- var defaultDate: Date!
- if self.queryEntity.startTime.length() == 0 || self.queryEntity.startTime.length() != 10 {
- defaultDate = CommonDate.addMonth(date: Date(), month: 0)
- } else {
- defaultDate = CommonDate.getDateForString(dateStr: self.queryEntity.startTime, dateFormat: "yyyy-MM-dd")
- }
- // defaultDate = CommonDate.addMonth(date: Date(), month: -1)
- viewDatePicer.datePicker.maximumDate = Date()
- viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
- self!.queryEntity.startTime = str
- self!.startTimeBtn.isSelected = true
- self!.startTimeBtn.setTitle(str, for: .selected)
- }
- break
- case 1002: // 结束时间
- let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
- var defaultDate: Date!
- if self.queryEntity.endTime.length() == 0 || self.queryEntity.endTime.length() != 10 {
- defaultDate = CommonDate.addMonth(date: Date(), month: 0)
- } else {
- defaultDate = CommonDate.getDateForString(dateStr: self.queryEntity.endTime, dateFormat: "yyyy-MM-dd")
- }
- // defaultDate = CommonDate.addMonth(date: Date(), month: -1)
- viewDatePicer.datePicker.maximumDate = Date()
- viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
- self!.queryEntity.endTime = str
- self!.endTimeBtn.isSelected = true
- self!.endTimeBtn.setTitle(str, for: .selected)
- }
- break
- case 1003: // 个人版
- btn.isSelected = true
- let oB = self.viewWithTag(1004) as! UIButton
- oB.isSelected = false
- self.queryEntity.busType = "0"
- break
- case 1004: // 商户版
- btn.isSelected = true
- let oB = self.viewWithTag(1003) as! UIButton
- oB.isSelected = false
- self.queryEntity.busType = "1"
- break
- case 1005: // 最低费率
- let alert = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
- for rateStr in rateArr {
- let action = UIAlertAction.init(title: (rateStr as! String), style: .default) { (defaultAction) in
- self.minRateBtn.isSelected = true
- self.minRateBtn.setTitle(defaultAction.title, for: .selected)
- self.queryEntity.miniRate = defaultAction.title!
- }
- alert.addAction(action)
- }
- let action = UIAlertAction.init(title: "取消", style: .cancel) { (_) in
- }
- alert.addAction(action)
- let curVc = currentViewController()
- curVc?.present(alert, animated: true, completion: nil)
- break
- case 1006: // 最高费率
- let alert = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
- for rateStr in rateArr {
- let action = UIAlertAction.init(title: (rateStr as! String), style: .default) { (defaultAction) in
- self.maxRateBtn.isSelected = true
- self.maxRateBtn.setTitle(defaultAction.title, for: .selected)
- self.queryEntity.maxRate = defaultAction.title!
- }
- alert.addAction(action)
- }
- let action = UIAlertAction.init(title: "取消", style: .cancel) { (_) in
- }
- alert.addAction(action)
- let curVc = currentViewController()
- curVc?.present(alert, animated: true, completion: nil)
- break
- case 1007: // 重置
- do {
- self.queryEntity.startTime = ""
- self.queryEntity.endTime = ""
- // 商户类型
- self.queryEntity.busType = ""
- self.queryEntity.miniRate = ""
- self.queryEntity.maxRate = ""
- resetData()
- }
- break
- case 1008: // 确定
- if oBackFunc != nil {
- oBackFunc(queryEntity)
- }
- break
- default: break
- }
- }
- func resetData() {
- self.startTimeBtn.isSelected = false
- self.startTimeBtn.setTitle("请选择开始时间", for: .normal)
- self.endTimeBtn.isSelected = false
- self.endTimeBtn.setTitle("请选择结束时间", for: .normal)
- // self.startTimeBtn.isSelected = false
- // self.startTimeBtn.isSelected = false
- let perBtn = self.viewWithTag(1003) as! UIButton
- let merBtn = self.viewWithTag(1004) as! UIButton
- perBtn.isSelected = false
- merBtn.isSelected = false
- self.minRateBtn.isSelected = false
- self.minRateBtn.setTitle("选择最低费率", for: .normal)
- self.maxRateBtn.isSelected = false
- self.maxRateBtn.setTitle("选择最高费率", for: .normal)
- }
- /*
- // Only override draw() if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- override func draw(_ rect: CGRect) {
- // Drawing code
- }
- */
- ///获取当前视图所在导航控制器
- func currentViewController() -> UIViewController? {
- var n = next
- while n != nil {
- if (n?.isKind(of: UIViewController.self))! {
- return n as? UIViewController
- }
- n = n?.next
- }
- return nil
- }
- }
- class ShopQueryModel: NSObject {
- // 开通时间
- var startTime: String = ""
- var endTime: String = ""
- // 商户类型
- var busType: String = ""
- // 商户费率
- var miniRate: String = ""
- var maxRate: String = ""
- }
- typealias ShopQueryEntity = (_ entity: ShopQueryModel) -> Void
|