| | |
| | | class AddStudentVC: BaseVC { |
| | | |
| | | @IBOutlet weak var img_profile: UIImageView! |
| | | @IBOutlet weak var tf_name: UITextField! |
| | | @IBOutlet weak var tf_name: QMUITextField! |
| | | @IBOutlet weak var tf_gender: UITextField! |
| | | @IBOutlet weak var tf_idCard: UITextField! |
| | | @IBOutlet weak var tf_height: QMUITextField! |
| | |
| | | var profileImg:UIImage? |
| | | |
| | | var studentModel = StudentProfileModel() |
| | | |
| | | var studentInfo:StudentProfile1Model? |
| | | var type:ItemType! |
| | | |
| | | var verifyIdCard:Bool = false |
| | | |
| | | init(type:ItemType) { |
| | | init(type:ItemType,studentInfo:StudentProfile1Model? = nil) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.type = type |
| | | self.studentInfo = studentInfo |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | |
| | | super.viewDidLoad() |
| | | if type == .course{ |
| | | title = "添加学员" |
| | | if studentInfo != nil{ |
| | | title = "编辑学员" |
| | | tf_name.text = studentInfo!.stuName |
| | | tf_idCard.text = studentInfo!.idCard |
| | | tf_height.text = String(format: "%.0lf", studentInfo!.stuHeight) |
| | | tf_weight.text = String(format: "%.0lf", studentInfo!.stuWeight) |
| | | tf_phone.text = studentInfo!.stuPhone |
| | | tf_birthday.text = studentInfo!.birthday |
| | | img_profile.sd_setImage(with: URL(string: studentInfo!.stuHeadImg)) |
| | | studentModel.headImg = studentInfo!.stuHeadImg |
| | | studentModel.stuId = studentInfo!.stuId |
| | | } |
| | | }else{ |
| | | title = "添加人员" |
| | | } |
| | |
| | | |
| | | |
| | | @IBAction func completeAction(_ sender: UIButton) { |
| | | guard profileImg != nil else {alertError(msg: "请上传学员头像");return} |
| | | if studentInfo == nil{ |
| | | guard profileImg != nil else {alertError(msg: "请上传学员头像");return} |
| | | } |
| | | |
| | | guard !tf_name.text!.isEmpty else {alertError(msg: tf_name.placeholder!);return} |
| | | guard !tf_birthday.text!.isEmpty else {alertError(msg: "请选择生日");return} |
| | | guard !tf_height.text!.isEmpty else {alertError(msg: tf_height.placeholder!);return} |
| | |
| | | guard tf_weight.text != "0" else {alertError(msg: "请输入正确的体重");return} |
| | | |
| | | if !tf_phone.isEmpty{ |
| | | #if DEBUG |
| | | guard tf_phone.text!.jq_isPhone else {alertError(msg: "请输入正确的手机号");return} |
| | | #endif |
| | | } |
| | | |
| | | if !tf_idCard.isEmpty{ |
| | | #if DEBUG |
| | | guard tf_idCard.text!.jq_idCard() else {alertError(msg: "请输入正确的身份证号码");return} |
| | | #endif |
| | | } |
| | | |
| | | |
| | | studentModel.birthday = tf_birthday.text! |
| | | studentModel.name = tf_name.text! |
| | |
| | | studentModel.idCard = tf_idCard.text! |
| | | studentModel.name = tf_name.text! |
| | | |
| | | if studentModel.headImg.isEmpty{ |
| | | if profileImg != nil{ |
| | | showHUD("正在上传头像") |
| | | profileImg!.uploadImgToService().subscribe(onNext: { [weak self] imgUrl in |
| | | guard let weakSelf = self else { return } |
| | |
| | | |
| | | private func addStudent(){ |
| | | if type == .course{ |
| | | Services.addStudent(studentModel).subscribe(onNext: { [weak self] data in |
| | | self?.addStudentSuccess() |
| | | }).disposed(by: disposeBag) |
| | | if studentInfo == nil{ |
| | | Services.addStudent(studentModel).subscribe(onNext: { [weak self] data in |
| | | self?.addStudentSuccess(text: "编辑成功") |
| | | }).disposed(by: disposeBag) |
| | | }else{ |
| | | Services.editStu(studentModel).subscribe(onNext: {[weak self]data in |
| | | self?.addStudentSuccess(text: "添加成功") |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | |
| | | }else{ |
| | | Services.addParticipant(studentModel).subscribe(onNext: {[weak self] data in |
| | | self?.addStudentSuccess() |
| | | self?.addStudentSuccess(text: "添加成功") |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } |
| | | |
| | | private func addStudentSuccess(){ |
| | | alertSuccess(msg: "添加成功") |
| | | private func addStudentSuccess(text:String){ |
| | | alertSuccess(msg: text) |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) { |
| | | self.navigationController?.popViewController() |
| | | NotificationCenter.default.post(name: StudentUpdate_Nofi, object: nil) |