// // AddressEditorVC.swift // ADHTuanCan // // Created by 敖德亨 on 2023/10/31. // import UIKit //import MJRefresh import RxSwift import RxCocoa import RxAlamofire import Alamofire import HandyJSON class AddressEditorVC: ADHBaseVC { var shopcartId : NSNumber?{ didSet{ self.viewModel.AddAddressRModel.shopcartId = shopcartId } } @IBOutlet weak var topContent: NSLayoutConstraint! @IBOutlet weak var nameF: UITextField! @IBOutlet weak var phoneF: UITextField! @IBOutlet weak var postF: UITextField! @IBOutlet weak var streeF: UITextView! @IBOutlet weak var detailAddF: UITextView! @IBOutlet weak var isDefualBtn: UIButton! let defualModel = AddAddressResultMeal() let viewModel : AddresViewModel = AddresViewModel.init() let diposableBag = DisposeBag() override func viewDidLoad() { super.viewDidLoad() let navStyle = MCNavBarStyle() navStyle.styleForBackImage = UIImage.init(named: "黑色返回")! navStyle.styleForTitleColor = UIColor.black self.navBar = MCNavBarView.init(title: LanguagesUtil.createTextBy(Ctext: "添加收货地址", Etext: "Add the shipping address"), subTitle: nil,style: navStyle) self.topContent.constant = kNavAndStatuHeight self.navBar?.backgroundColor = UIColor.white // self.navBarHeightConstraint? = self.topContent self.nameF.text = "\(self.defualModel.receiving ?? "")" self.detailAddF.text = "\(self.defualModel.detailAddress ?? "")" self.streeF.text = "\(self.defualModel.street ?? "")" self.postF.text = "\(self.defualModel.postcode ?? "")" self.phoneF.text = "\(self.defualModel.phoneNum ?? "")" if (self.defualModel.isDefault ?? "") == "1"{ self.isDefualBtn.isSelected = true }else{ self.isDefualBtn.isSelected = false } self.nameF.inputText(maxLength: 30) { self.viewModel.AddAddressRModel.receiving = self.nameF.text } self.phoneF.inputNumber(maxLength: 20) { self.viewModel.AddAddressRModel.phoneNum = self.phoneF.text } self.postF.inputNumber(maxLength: 20) { self.viewModel.AddAddressRModel.postcode = self.postF.text } self.detailAddF.inputText(maxLength: 300) {[weak self] in self?.viewModel.AddAddressRModel.detailAddress = self?.detailAddF.text } self.streeF.inputText(maxLength: 300) {[weak self] in self?.viewModel.AddAddressRModel.street = self?.streeF.text } } func configDefualData(model : AddressModel){ self.defualModel.id = model.id self.defualModel.detailAddress = model.detailAddress self.defualModel.receiving = model.receiving self.defualModel.phoneNum = model.phoneNum self.defualModel.postcode = model.postcode self.defualModel.street = model.street self.defualModel.isDefault = model.isDefault self.defualModel.shopcartId = model.shopcartId self.viewModel.AddAddressRModel.id = model.id self.viewModel.AddAddressRModel.detailAddress = model.detailAddress self.viewModel.AddAddressRModel.receiving = model.receiving self.viewModel.AddAddressRModel.phoneNum = model.phoneNum self.viewModel.AddAddressRModel.postcode = model.postcode self.viewModel.AddAddressRModel.street = model.street self.viewModel.AddAddressRModel.isDefault = model.isDefault self.viewModel.AddAddressRModel.shopcartId = model.shopcartId } @IBAction func backAction(_ sender: UIButton) { self.navigationController?.popViewController(animated: true) } @IBAction func setDefualAction(_ sender: UIButton) { sender.isSelected = !sender.isSelected if sender.isSelected{ self.viewModel.AddAddressRModel.isDefault = "1" }else{ self.viewModel.AddAddressRModel.isDefault = "0" } } @IBAction func saveAction(_ sender: UIButton) { if (self.viewModel.AddAddressRModel.receiving ?? "").isEmptyStr{ self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入姓名", Etext: "Please enter your name")) return } if (self.viewModel.AddAddressRModel.phoneNum ?? "").isEmptyStr{ self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入电话", Etext: "Please enter phone number")) return } if (self.viewModel.AddAddressRModel.postcode ?? "").isEmptyStr{ self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入邮编", Etext: "Please enter postal code")) return } if (self.viewModel.AddAddressRModel.street ?? "").isEmptyStr{ self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入街道", Etext: "Please enter street")) return } if (self.viewModel.AddAddressRModel.detailAddress ?? "").isEmptyStr{ self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入详细地址", Etext: "Please enter the full address")) return } self.viewModel.signalSaveAddress()?.on(success: { dd in self.hud.showSuccess("保存成功") let model = AddressModel() NotificationCenter.default.post(name: NSNotification.Name("刷新个人中心"), object: self, userInfo:nil) self.navigationController?.popViewController(animated: true) }, error: { error in self.hud.showFailure("获取时间范围失败") }) } }