Commit 7a9d4f0a authored by David黄金龙's avatar David黄金龙

完善 活动报名 逻辑

parent 3fe70e89
......@@ -74,9 +74,17 @@ class YHActivityDetailViewController: YHBaseViewController {
bottomView.block = { tag in
YHApplyActivityAlert.showApplyActivityAlertView { tag in
let vc = YHApplyActivityResultViewController()
self.navigationController?.pushViewController(vc)
YHApplyActivityAlert.showApplyActivityAlertView { (tag,name,number,phone) in
if tag {
printLog(tag)
printLog(name)
printLog(number)
printLog(phone)
return
let vc = YHApplyActivityResultViewController()
self.navigationController?.pushViewController(vc)
}
}
}
......
......@@ -7,10 +7,12 @@
//
import UIKit
import IQKeyboardManagerSwift
class YHApplyActivityAlert: UIView {
typealias Block = (Bool) -> ()
typealias Block = (Bool,String,Int,String) -> ()
var block: Block?
var centerView: UIView!
var titleLabel: UILabel!
......@@ -18,6 +20,15 @@ class YHApplyActivityAlert: UIView {
var agreeButton: UIButton!
private let contentViewH : CGFloat = 386.0
private var applyName : String = ""
private var applyNumber : Int = 1
private var applyPhone : String = ""
private var needCheckFlag : Bool = false
lazy var nameTextField:UITextField = {
let textField = UITextField()
textField.backgroundColor = .clear
......@@ -26,7 +37,7 @@ class YHApplyActivityAlert: UIView {
textField.tintColor = UIColor.brandMainColor
textField.textColor = UIColor.mainTextColor
textField.clearButtonMode = .whileEditing
// textField.addTarget(self, action: #selector(textFieldChanged(textField:)), for: .editingChanged)
textField.addTarget(self, action: #selector(textFieldChanged(textField:)), for: .editingChanged)
textField.delegate = self
return textField
}()
......@@ -37,10 +48,12 @@ class YHApplyActivityAlert: UIView {
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 14)
button.contentHorizontalAlignment = .center
button.setImage(UIImage(named: "activity_sub_0"), for: .normal)
button.setImage(UIImage(named: "activity_sub_0"), for: .disabled)
button.setImage(UIImage(named: "activity_sub_1"), for: .selected)
button.setImage(UIImage(named: "activity_sub_1"), for: .highlighted)
button.setTitleColor( UIColor(hex:0xffffff), for: .normal)
button.layer.cornerRadius = kCornerRadius3
button.addTarget(self, action: #selector(agree), for: .touchUpInside)
button.addTarget(self, action: #selector(clickSubBtn), for: .touchUpInside)
return button
}()
......@@ -51,10 +64,12 @@ class YHApplyActivityAlert: UIView {
button.contentHorizontalAlignment = .center
button.setImage(UIImage(named: "activity_add_0"), for: .normal)
button.setImage(UIImage(named: "activity_add_0"), for: .disabled)
button.setImage(UIImage(named: "activity_add_1"), for: .selected)
button.setImage(UIImage(named: "activity_add_1"), for: .highlighted)
button.setTitleColor( UIColor(hex:0xffffff), for: .normal)
button.layer.cornerRadius = kCornerRadius3
button.addTarget(self, action: #selector(agree), for: .touchUpInside)
button.addTarget(self, action: #selector(clickAddBtn), for: .touchUpInside)
return button
}()
......@@ -62,15 +77,16 @@ class YHApplyActivityAlert: UIView {
lazy var applyNumberTextField:UITextField = {
let textField = UITextField()
textField.backgroundColor = .clear
textField.attributedPlaceholder = NSAttributedString(string: "请输入您的姓名".local, attributes: [NSAttributedString.Key.foregroundColor : UIColor.yhGreyColor])
textField.attributedPlaceholder = NSAttributedString(string: "".local, attributes: [NSAttributedString.Key.foregroundColor : UIColor.yhGreyColor])
textField.font = UIFont.PFSC_M(ofSize: 14)
textField.tintColor = UIColor.brandMainColor
textField.textColor = UIColor.mainTextColor
textField.textAlignment = .center
// textField.clearButtonMode = .whileEditing
textField.text = "10"
// textField.addTarget(self, action: #selector(textFieldChanged(textField:)), for: .editingChanged)
textField.text = "1"
textField.addTarget(self, action: #selector(textFieldChanged(textField:)), for: .editingChanged)
textField.addTarget(self, action: #selector(textFieldEditEnd(textField:)), for: .editingDidEnd)
textField.delegate = self
textField.keyboardType = .numberPad
return textField
}()
......@@ -82,9 +98,8 @@ class YHApplyActivityAlert: UIView {
textField.font = UIFont.PFSC_M(ofSize: 14)
textField.tintColor = UIColor.brandMainColor
textField.textColor = UIColor.mainTextColor
// textField.clearButtonMode = .whileEditing
// textField.text = ""
// textField.addTarget(self, action: #selector(textFieldChanged(textField:)), for: .editingChanged)
textField.clearButtonMode = .whileEditing
textField.addTarget(self, action: #selector(textFieldChanged(textField:)), for: .editingChanged)
textField.delegate = self
return textField
}()
......@@ -95,6 +110,7 @@ class YHApplyActivityAlert: UIView {
lable.textAlignment = .left
lable.font = UIFont.PFSC_R(ofSize:12)
lable.text = "手机号不能为空"
lable.isHidden = true
return lable
}()
......@@ -116,6 +132,11 @@ class YHApplyActivityAlert: UIView {
}()
lazy var line4 : UIView = {
let line4 = UIView()
line4.backgroundColor = UIColor.separatorColor
return line4
}()
//类方法 - 展示
static func showApplyActivityAlertView(callBack: @escaping Block) {
......@@ -134,24 +155,205 @@ class YHApplyActivityAlert: UIView {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
if needCheckFlag {
if applyPhone.isEmpty {
phoneTipsLable.isHidden = false
line4.snp.remakeConstraints { make in
make.left.equalTo(20)
make.right.equalTo(-20)
make.height.equalTo(1)
make.top.equalTo(phoneTipsLable.snp.bottom).offset(16)
}
} else {
phoneTipsLable.isHidden = true
line4.snp.remakeConstraints { make in
make.left.equalTo(20)
make.right.equalTo(-20)
make.height.equalTo(1)
make.top.equalTo(phoneTextField.snp.bottom).offset(16)
}
}
} else {
phoneTipsLable.isHidden = true
line4.snp.remakeConstraints { make in
make.left.equalTo(20)
make.right.equalTo(-20)
make.height.equalTo(1)
make.top.equalTo(phoneTextField.snp.bottom).offset(16)
}
}
}
}
extension YHApplyActivityAlert {
func handleSubAndAddButtonUI() {
if applyNumber > 9 {
subButton.isEnabled = true
addButton.isEnabled = false
subButton.isSelected = true
addButton.isSelected = false
} else if applyNumber > 1 {
subButton.isEnabled = true
addButton.isEnabled = true
subButton.isSelected = true
addButton.isSelected = true
}
else {
subButton.isEnabled = false
addButton.isEnabled = true
subButton.isSelected = false
addButton.isSelected = true
}
setNeedsLayout()
layoutIfNeeded()
}
@objc func textFieldChanged(textField:UITextField) {
printLog(textField.text)
if textField == nameTextField {
applyName = textField.text ?? ""
} else if textField == applyNumberTextField {
if let tf = textField.text {
if tf.isEmpty {
applyNumber = 1
} else {
applyNumber = Int(tf) ?? 1
}
}
} else if textField == phoneTextField {
applyPhone = textField.text ?? ""
} else {
}
setNeedsLayout()
layoutIfNeeded()
}
@objc func textFieldEditEnd(textField:UITextField) {
printLog(textField.text)
if textField == nameTextField {
} else if textField == applyNumberTextField {
if let tf = textField.text {
if tf.isEmpty {
textField.text = "1"
applyNumber = 1
}
} else {
textField.text = "1"
applyNumber = 1
}
handleSubAndAddButtonUI()
} else if textField == phoneTextField {
} else {
}
}
@objc func clickSubBtn() {
applyNumber = applyNumber - 1
applyNumberTextField.text = String(applyNumber)
handleSubAndAddButtonUI()
}
@objc func clickAddBtn() {
applyNumber = applyNumber + 1
applyNumberTextField.text = String(applyNumber)
handleSubAndAddButtonUI()
}
@objc func clickCloseBtn() {
dismiss()
}
@objc func clickSubmitBtn() {
subButton.isEnabled = false
needCheckFlag = true
DispatchQueue.main.async {
self.subButton.isEnabled = true
if self.allDataIsOK() {
self.block?(true,self.applyName,self.applyNumber,self.applyPhone)
self.clickCloseBtn()
} else {
self.handleSubAndAddButtonUI()
}
}
}
@objc func agree() {
block?(true,"",0,"")
}
@objc func disagree() {
block?(false,"",0,"")
dismiss()
}
func dismiss() {
removeNotify()
removeFromSuperview()
}
@objc func tapButton(gestureRecognizer:UITapGestureRecognizer) {
endEditing(true)
}
func allDataIsOK() -> Bool {
if applyPhone.isEmpty {
return false
}
return true
}
func setView() {
backgroundColor = UIColor.mainTextColor50
addKeyBoardNotify()
centerView = {
let view = UIView()
view.backgroundColor = .white
view.layer.cornerRadius = kCornerRadius8
view.clipsToBounds = true
return view
}()
addSubview(centerView)
let viewH = 386.0
centerView.snp.makeConstraints { make in
make.bottom.equalToSuperview()
make.width.equalTo(KScreenWidth)
make.height.equalTo(viewH)
make.height.equalTo(contentViewH)
}
centerView.layoutIfNeeded()
let corner = UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue)
let path = UIBezierPath(roundedRect:centerView.bounds,byRoundingCorners: corner,cornerRadii:CGSizeMake(kCornerRadius6, kCornerRadius6))
let layer = CAShapeLayer()
layer.frame = centerView.bounds
layer.path = path.cgPath
centerView.layer.mask = layer
//1.0
......@@ -208,7 +410,7 @@ class YHApplyActivityAlert: UIView {
}
centerView.addSubview(nameTextField)
nameTextField.text = "黄金龙"
nameTextField.text = ""
nameTextField.snp.makeConstraints { make in
make.left.equalTo(nameLable.snp.right).offset(48)
make.centerY.equalTo(nameLable.snp.centerY)
......@@ -230,7 +432,7 @@ class YHApplyActivityAlert: UIView {
let redStarImagV = UIImageView()
redStarImagV.backgroundColor = .red
redStarImagV.image = UIImage(named: "activity_red_star")
redStarImagV.contentMode = .scaleAspectFit
redStarImagV.contentMode = .scaleAspectFill
centerView.addSubview(redStarImagV)
redStarImagV.snp.makeConstraints { make in
make.left.equalTo(20)
......@@ -262,7 +464,8 @@ class YHApplyActivityAlert: UIView {
applyNumberTextField.snp.makeConstraints { make in
make.left.equalTo(subButton.snp.right).offset(2)
make.centerY.equalTo(numberLable.snp.centerY)
make.width.height.equalTo(28)
make.width.equalTo(42)
make.height.equalTo(28)
}
applyNumberTextField.layer.cornerRadius = kCornerRadius6
applyNumberTextField.backgroundColor = UIColor(hex: 0xf5f5f5, alpha: 1.0)
......@@ -318,13 +521,9 @@ class YHApplyActivityAlert: UIView {
make.left.equalTo(subButton.snp.left)
make.height.equalTo(20)
make.centerY.equalTo(phoneLable)
make.right.equalTo(20)
make.right.equalTo(-20)
}
let line4 = UIView()
line4.backgroundColor = .separatorColor
centerView.addSubview(line4)
line4.snp.makeConstraints { make in
make.left.equalTo(20)
......@@ -351,48 +550,90 @@ class YHApplyActivityAlert: UIView {
make.height.equalTo(48)
make.bottom.equalToSuperview().offset(-42)
}
}
@objc func clickCloseBtn() {
dismiss()
}
@objc func clickSubmitBtn() {
block?(true)
clickCloseBtn()
}
@objc func agree() {
block?(true)
}
@objc func disagree() {
block?(false)
dismiss()
}
func dismiss() {
removeFromSuperview()
subButton.isEnabled = false
addButton.isEnabled = true
addButton.isSelected = true
let tap : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapButton(gestureRecognizer:)))
addGestureRecognizer(tap)
let tap1 : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapButton(gestureRecognizer:)))
centerView.addGestureRecognizer(tap1)
}
}
extension YHApplyActivityAlert: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if string.isEmpty{ // 点击删除
return true
}
// if string.isEmpty == true { // 点击删除
// return true
// }
//
// let newText = (textField.text! as NSString).replacingCharacters(in: range, with: string)
// if newText.count > Self.maxWordsCount {
// YHHUD.flash(message: "搜索限制最多\(Self.maxWordsCount)个字符")
// return false
// }
let newText = (textField.text! as NSString).replacingCharacters(in: range, with: string)
if textField == nameTextField {
if newText.count > 20 {
return false
}
} else if textField == applyNumberTextField {
if !string.isNumeric {
YHHUD.flash(message: "请输入数字")
return false
}
if let item = Int(newText),item > 10 {
textField.text = "10"
YHHUD.flash(message: "最多添加10人")
return false
}
} else if textField == phoneTextField {
if newText.count > 20 {
return false
}
} else {
}
return true
}
}
extension YHApplyActivityAlert {
func addKeyBoardNotify() {
IQKeyboardManager.shared.enable = false
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
func removeNotify() {
IQKeyboardManager.shared.enable = true
NotificationCenter.default.removeObserver(self)
}
@objc func handleKeyboardNotification(_ notification: Notification) {
if notification.userInfo != nil {
guard let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue else {return }
let isKeyboardShow = notification.name == UIResponder.keyboardWillShowNotification
let bottomMargin = (isKeyboardShow ? -keyboardFrame.height : 0)
centerView.snp.updateConstraints { make in
make.bottom.equalToSuperview().offset(bottomMargin)
}
handleSubAndAddButtonUI()
}
}
}
......@@ -5,12 +5,12 @@
"scale" : "1x"
},
{
"filename" : "步进器-加号&增加@2x.png",
"filename" : "Frame 18253@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "步进器-加号&增加@3x.png",
"filename" : "Frame 18253@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
......
......@@ -5,12 +5,12 @@
"scale" : "1x"
},
{
"filename" : "步进器-减号&减少@2x.png",
"filename" : "Frame 18254@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "步进器-减号&减少@3x.png",
"filename" : "Frame 18254@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment