无故事王国
2023-11-01 b3269976c84d03208f633cd0136a6f78e8dd53f7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
//  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)
    }
}