//
|
// StudentUpdateInfoView.swift
|
// WanPai
|
//
|
// Created by 杨锴 on 2023/6/14.
|
//
|
|
import UIKit
|
import JQTools
|
import QMUIKit
|
import RxSwift
|
|
let StudentUpdate_Nofi = Notification.Name.init("StudentUpdate_Nofi")
|
class StudentUpdateInfoView: UIView,JQNibView{
|
|
@IBOutlet weak var view_container: UIView!
|
@IBOutlet weak var cons_bottom: NSLayoutConstraint!
|
@IBOutlet weak var tf_height: QMUITextField!
|
@IBOutlet weak var tf_weight: QMUITextField!
|
@IBOutlet weak var tf_phone: QMUITextField!
|
|
private var model:ActivityDetailPartModel?
|
private let disposeBag = DisposeBag()
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
cons_bottom.constant = -(JQ_ScreenW / 2)
|
alpha = 0
|
layoutIfNeeded()
|
|
NotificationCenter.default.rx.notification(UIApplication.keyboardWillHideNotification).subscribe(onNext: {noti in
|
if let userInfo = noti.userInfo{
|
self.cons_bottom.constant = 0
|
let duration = (userInfo["UIKeyboardAnimationDurationUserInfoKey"] as? Double) ?? 0
|
UIView.animate(withDuration: duration) {
|
self.layoutIfNeeded()
|
}
|
}
|
}).disposed(by: disposeBag)
|
|
NotificationCenter.default.rx.notification(UIApplication.keyboardWillShowNotification).subscribe(onNext: { noti in
|
if let userInfo = noti.userInfo{
|
self.cons_bottom.constant = (userInfo["UIKeyboardFrameEndUserInfoKey"] as? CGRect)?.height ?? 0
|
let duration = (userInfo["UIKeyboardAnimationDurationUserInfoKey"] as? Double) ?? 0
|
UIView.animate(withDuration: duration) {
|
self.layoutIfNeeded()
|
}
|
}
|
}).disposed(by: disposeBag)
|
}
|
|
static func show(_ model:ActivityDetailPartModel){
|
let storesView = StudentUpdateInfoView.jq_loadNibView()
|
storesView.model = model
|
storesView.frame = sceneDelegate?.window?.frame ?? .zero
|
sceneDelegate?.window?.addSubview(storesView)
|
storesView.cons_bottom.constant = 0
|
storesView.tf_phone.text = model.phone
|
storesView.tf_height.text = model.height.string
|
storesView.tf_weight.text = model.weight.string
|
|
UIView.animate(withDuration: 0.4) {
|
storesView.alpha = 1
|
storesView.layoutIfNeeded()
|
}
|
}
|
|
|
@IBAction func saveAction(_ sender: UIButton) {
|
guard !tf_height.text!.isEmpty else {alertError(msg: "请输入身高");return}
|
guard !tf_weight.text!.isEmpty else {alertError(msg: "请输入体重");return}
|
|
guard tf_height.text!.int != 0 else {alertError(msg: "请输入正确的身高");return}
|
guard tf_weight.text!.int != 0 else {alertError(msg: "请输入正确的体重");return}
|
|
self.endEditing(true)
|
Services.editParticipant(id: model!.id, height: tf_height.text!.int!, weight: tf_weight.text!.int!, phone: tf_phone.text,isStudent: model!.isStudent).subscribe(onNext: {data in
|
alertSuccess(msg: "修改成功")
|
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
|
NotificationCenter.default.post(name: StudentUpdate_Nofi, object: nil)
|
self.close()
|
}
|
}).disposed(by: disposeBag)
|
}
|
|
|
@IBAction func closeAction(_ sender: UIButton) {
|
close()
|
}
|
|
|
private func close(){
|
self.cons_bottom.constant = -(JQ_ScreenW / 2)
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.layoutIfNeeded()
|
} completion: { _ in
|
self.removeFromSuperview()
|
}
|
}
|
|
override func layoutSubviews() {
|
super.layoutSubviews()
|
view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 20,width: JQ_ScreenW,height: JQ_ScreenW)
|
}
|
}
|