AddressEditorVC.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // AddressEditorVC.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/10/31.
  6. //
  7. import UIKit
  8. //import MJRefresh
  9. import RxSwift
  10. import RxCocoa
  11. import RxAlamofire
  12. import Alamofire
  13. import HandyJSON
  14. class AddressEditorVC: ADHBaseVC {
  15. var shopcartId : NSNumber?{
  16. didSet{
  17. self.viewModel.AddAddressRModel.shopcartId = shopcartId
  18. }
  19. }
  20. @IBOutlet weak var topContent: NSLayoutConstraint!
  21. @IBOutlet weak var nameF: UITextField!
  22. @IBOutlet weak var phoneF: UITextField!
  23. @IBOutlet weak var postF: UITextField!
  24. @IBOutlet weak var streeF: UITextView!
  25. @IBOutlet weak var detailAddF: UITextView!
  26. @IBOutlet weak var isDefualBtn: UIButton!
  27. let defualModel = AddAddressResultMeal()
  28. let viewModel : AddresViewModel = AddresViewModel.init()
  29. let diposableBag = DisposeBag()
  30. override func viewDidLoad() {
  31. super.viewDidLoad()
  32. let navStyle = MCNavBarStyle()
  33. navStyle.styleForBackImage = UIImage.init(named: "黑色返回")!
  34. navStyle.styleForTitleColor = UIColor.black
  35. self.navBar = MCNavBarView.init(title: LanguagesUtil.createTextBy(Ctext: "添加收货地址", Etext: "Add the shipping address"), subTitle: nil,style: navStyle)
  36. self.topContent.constant = kNavAndStatuHeight
  37. self.navBar?.backgroundColor = UIColor.white
  38. // self.navBarHeightConstraint? = self.topContent
  39. self.nameF.text = "\(self.defualModel.receiving ?? "")"
  40. self.detailAddF.text = "\(self.defualModel.detailAddress ?? "")"
  41. self.streeF.text = "\(self.defualModel.street ?? "")"
  42. self.postF.text = "\(self.defualModel.postcode ?? "")"
  43. self.phoneF.text = "\(self.defualModel.phoneNum ?? "")"
  44. if (self.defualModel.isDefault ?? "") == "1"{
  45. self.isDefualBtn.isSelected = true
  46. }else{
  47. self.isDefualBtn.isSelected = false
  48. }
  49. self.nameF.inputText(maxLength: 30) {
  50. self.viewModel.AddAddressRModel.receiving = self.nameF.text
  51. }
  52. self.phoneF.inputNumber(maxLength: 20) {
  53. self.viewModel.AddAddressRModel.phoneNum = self.phoneF.text
  54. }
  55. self.postF.inputNumber(maxLength: 20) {
  56. self.viewModel.AddAddressRModel.postcode = self.postF.text
  57. }
  58. self.detailAddF.inputText(maxLength: 300) {[weak self] in
  59. self?.viewModel.AddAddressRModel.detailAddress = self?.detailAddF.text
  60. }
  61. self.streeF.inputText(maxLength: 300) {[weak self] in
  62. self?.viewModel.AddAddressRModel.street = self?.streeF.text
  63. }
  64. }
  65. func configDefualData(model : AddressModel){
  66. self.defualModel.id = model.id
  67. self.defualModel.detailAddress = model.detailAddress
  68. self.defualModel.receiving = model.receiving
  69. self.defualModel.phoneNum = model.phoneNum
  70. self.defualModel.postcode = model.postcode
  71. self.defualModel.street = model.street
  72. self.defualModel.isDefault = model.isDefault
  73. self.defualModel.shopcartId = model.shopcartId
  74. self.viewModel.AddAddressRModel.id = model.id
  75. self.viewModel.AddAddressRModel.detailAddress = model.detailAddress
  76. self.viewModel.AddAddressRModel.receiving = model.receiving
  77. self.viewModel.AddAddressRModel.phoneNum = model.phoneNum
  78. self.viewModel.AddAddressRModel.postcode = model.postcode
  79. self.viewModel.AddAddressRModel.street = model.street
  80. self.viewModel.AddAddressRModel.isDefault = model.isDefault
  81. self.viewModel.AddAddressRModel.shopcartId = model.shopcartId
  82. }
  83. @IBAction func backAction(_ sender: UIButton) {
  84. self.navigationController?.popViewController(animated: true)
  85. }
  86. @IBAction func setDefualAction(_ sender: UIButton) {
  87. sender.isSelected = !sender.isSelected
  88. if sender.isSelected{
  89. self.viewModel.AddAddressRModel.isDefault = "1"
  90. }else{
  91. self.viewModel.AddAddressRModel.isDefault = "0"
  92. }
  93. }
  94. @IBAction func saveAction(_ sender: UIButton) {
  95. if (self.viewModel.AddAddressRModel.receiving ?? "").isEmptyStr{
  96. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入姓名", Etext: "Please enter your name"))
  97. return
  98. }
  99. if (self.viewModel.AddAddressRModel.phoneNum ?? "").isEmptyStr{
  100. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入电话", Etext: "Please enter phone number"))
  101. return
  102. }
  103. if (self.viewModel.AddAddressRModel.postcode ?? "").isEmptyStr{
  104. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入邮编", Etext: "Please enter postal code"))
  105. return
  106. }
  107. if (self.viewModel.AddAddressRModel.street ?? "").isEmptyStr{
  108. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入街道", Etext: "Please enter street"))
  109. return
  110. }
  111. if (self.viewModel.AddAddressRModel.detailAddress ?? "").isEmptyStr{
  112. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入详细地址", Etext: "Please enter the full address"))
  113. return
  114. }
  115. self.viewModel.signalSaveAddress()?.on(success: { dd in
  116. self.hud.showSuccess("保存成功")
  117. let model = AddressModel()
  118. NotificationCenter.default.post(name: NSNotification.Name("刷新个人中心"), object: self, userInfo:nil)
  119. self.navigationController?.popViewController(animated: true)
  120. }, error: { error in
  121. self.hud.showFailure("获取时间范围失败")
  122. })
  123. }
  124. }