123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- //
- // 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("获取时间范围失败")
- })
- }
-
- }
|