无故事王国
2024-03-14 a478b668ca1a5d4f6d2d9b1075d292cbbef90de5
WanPai/Root/Activity/View/StudentUpdateInfoView.swift
@@ -13,6 +13,8 @@
let StudentUpdate_Nofi = Notification.Name.init("StudentUpdate_Nofi")
class StudentUpdateInfoView: UIView,JQNibView{
            @IBOutlet weak var img_profile: UIImageView!
            @IBOutlet weak var view_profile: UIView!
    @IBOutlet weak var view_container: UIView!
    @IBOutlet weak var cons_bottom: NSLayoutConstraint!
    @IBOutlet weak var tf_height: QMUITextField!
@@ -20,13 +22,19 @@
    @IBOutlet weak var tf_phone: QMUITextField!
    private var model:ActivityDetailPartModel?
            private var updateUserProfile:Bool = false
    private let disposeBag = DisposeBag()
            private var profileImg:UIImage?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        cons_bottom.constant = -(JQ_ScreenW / 2)
        alpha = 0
        layoutIfNeeded()
                        let tap = UITapGestureRecognizer(target: self, action: #selector(userImgUploadAction))
                        img_profile.isUserInteractionEnabled = true
                        img_profile.addGestureRecognizer(tap)
        NotificationCenter.default.rx.notification(UIApplication.keyboardWillHideNotification).subscribe(onNext: {noti in
            if let userInfo = noti.userInfo{
@@ -49,9 +57,11 @@
        }).disposed(by: disposeBag)
    }
    
    static func show(_ model:ActivityDetailPartModel){
            static func show(_ model:ActivityDetailPartModel,updateUserProfile:Bool = false){
        let storesView = StudentUpdateInfoView.jq_loadNibView()
        storesView.model = model
                        storesView.updateUserProfile = updateUserProfile
                        storesView.view_profile.isHidden = !updateUserProfile
        storesView.frame = sceneDelegate?.window?.frame ?? .zero
      sceneDelegate?.window?.addSubview(storesView)
        storesView.cons_bottom.constant = 0
@@ -59,10 +69,21 @@
      storesView.tf_height.text = "\(model.height.int)"
      storesView.tf_weight.text = "\(model.weight.int)"
                        if updateUserProfile{
                                    storesView.img_profile.sd_setImage(with: URL(string: model.headImg),placeholderImage: UIImage(named: "btn_add_large_2"))
                        }
        UIView.animate(withDuration: 0.4) {
            storesView.alpha = 1
            storesView.layoutIfNeeded()
        }
            }
            @objc func userImgUploadAction(){
                        JQ_ImagePickerTool.getSharedInstance().singleImage({ [weak self] image in
                                    self?.img_profile.image = image
                                    self?.profileImg = image
                        }, clipSize: CGSize(width: JQ_ScreenW, height: JQ_ScreenW))
    }
@@ -73,8 +94,30 @@
        guard tf_height.text!.int != 0 else {alertError(msg: "请输入正确的身高");return}
        guard tf_weight.text!.int != 0 else {alertError(msg: "请输入正确的体重");return}
                        guard profileImg != nil || !(model?.headImg.isEmpty ?? true) else {
                                    alertError(msg: "请上传头像");return
                        }
        self.endEditing(true)
      Services.editParticipant(id: model!.id, height: tf_height.text!.int ?? 0, weight: tf_weight.text!.int ?? 0, phone: tf_phone.text,isStudent: model!.isStudent).subscribe(onNext: {data in
                        if profileImg != nil{
                                    showHUD("正在上传头像")
                                    profileImg!.uploadImgToService().subscribe(onNext: { [weak self] imgUrl in
                                                guard let weakSelf = self else { return }
                                                weakSelf.model?.headImg = imgUrl
                                                hiddenHUD()
                                                weakSelf.saveEdit()
                                    }, onError: { error in
                                                hiddenHUD()
                                                alertError(msg: error.localizedDescription)
                                    }).disposed(by: disposeBag)
                        }else{
                                    saveEdit()
                        }
            }
            private func saveEdit(){
                        Services.editParticipant(id: model!.id, height: tf_height.text!.int ?? 0, weight: tf_weight.text!.int ?? 0, phone: tf_phone.text,isStudent: model!.isStudent,headImg: model!.headImg).subscribe(onNext: {data in
            alertSuccess(msg: "修改成功")
            DispatchQueue.main.asyncAfter(deadline: .now()+1) {
                NotificationCenter.default.post(name: StudentUpdate_Nofi, object: nil)