// // 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 blockNumTF: UITextField! /// 街道名称 @IBOutlet weak var streeTF: UITextField! /// 建筑名称 @IBOutlet weak var buildNameTF: UITextField! /// 楼层门牌号 @IBOutlet weak var unitNumTF: UITextField! @IBOutlet weak var postF: UITextField! @IBOutlet weak var detailAddF: UITextView! @IBOutlet weak var isDefualBtn: UIButton! let defualModel = AddAddressResultMeal() let viewModel : AddresViewModel = AddresViewModel.init() let diposableBag = DisposeBag() var addressCallBackBlock : ((_ addr : AddressModel)->Void)? 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.addressRemark ?? "")" self.streeTF.text = "\(self.defualModel.street ?? "")" self.postF.text = "\(self.defualModel.postcode ?? "")" self.phoneF.text = "\(self.defualModel.phoneNum ?? "")" self.blockNumTF.text = "\(self.defualModel.blockNum ?? "")" self.buildNameTF.text = "\(self.defualModel.buildName ?? "")" self.unitNumTF.text = "\(self.defualModel.unitNum ?? "")" 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.inputFigure(maxLength: 20) { self.viewModel.AddAddressRModel.phoneNum = self.phoneF.text } self.postF.inputFigure(maxLength: 20) { self.viewModel.AddAddressRModel.postcode = self.postF.text } self.detailAddF.inputText(maxLength: 300) {[weak self] in self?.viewModel.AddAddressRModel.addressRemark = self?.detailAddF.text } self.streeTF.inputText(maxLength: 50) {[weak self] in self?.viewModel.AddAddressRModel.street = self?.streeTF.text } self.blockNumTF.inputText(maxLength: 50) {[weak self] in self?.viewModel.AddAddressRModel.blockNum = self?.blockNumTF.text } self.buildNameTF.inputText(maxLength: 50) {[weak self] in self?.viewModel.AddAddressRModel.buildName = self?.buildNameTF.text } self.unitNumTF.inputText(maxLength: 50) {[weak self] in self?.viewModel.AddAddressRModel.unitNum = self?.unitNumTF.text } } func configDefualData(model : AddressModel){ self.defualModel.id = model.id self.defualModel.addressRemark = model.addressRemark 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.defualModel.unitNum = model.unitNum self.defualModel.buildName = model.buildName self.defualModel.blockNum = model.blockNum self.viewModel.AddAddressRModel.id = model.id self.viewModel.AddAddressRModel.addressRemark = model.addressRemark 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 self.viewModel.AddAddressRModel.unitNum = model.unitNum self.viewModel.AddAddressRModel.buildName = model.buildName self.viewModel.AddAddressRModel.blockNum = model.blockNum } @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 the street name")) return } if (self.viewModel.AddAddressRModel.blockNum ?? "").isEmptyStr{ self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入街区号", Etext: "Please enter the block number")) return } if (self.viewModel.AddAddressRModel.buildName ?? "").isEmptyStr{ self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入建筑名称", Etext: "Please enter the building name")) return } if (self.viewModel.AddAddressRModel.unitNum ?? "").isEmptyStr{ self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入楼层门牌号", Etext: "Please enter the unitNum")) return } self.viewModel.signalSaveAddress()?.on(success: { dd in self.hud.showSuccess("保存成功") let model = AddressModel() ///刷新订单 if self.addressCallBackBlock != nil{ self.addressCallBackBlock!(model) } ///刷新购物车 NotificationCenter.default.post(name: NSNotification.Name("刷新默认地址"), object: self, userInfo:nil) self.navigationController?.popViewController(animated: true) }, error: { error in self.hud.showFailure("获取时间范围失败") }) } }