AddressEditorVC.swift 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. /// 街区号
  24. @IBOutlet weak var blockNumTF: UITextField!
  25. /// 街道名称
  26. @IBOutlet weak var streeTF: UITextField!
  27. /// 建筑名称
  28. @IBOutlet weak var buildNameTF: UITextField!
  29. /// 楼层门牌号
  30. @IBOutlet weak var unitNumTF: UITextField!
  31. @IBOutlet weak var postF: UITextField!
  32. @IBOutlet weak var detailAddF: UITextView!
  33. @IBOutlet weak var isDefualBtn: UIButton!
  34. let defualModel = AddAddressResultMeal()
  35. let viewModel : AddresViewModel = AddresViewModel.init()
  36. let diposableBag = DisposeBag()
  37. var addressCallBackBlock : ((_ addr : AddressModel)->Void)?
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. let navStyle = MCNavBarStyle()
  41. navStyle.styleForBackImage = UIImage.init(named: "黑色返回")!
  42. navStyle.styleForTitleColor = UIColor.black
  43. self.navBar = MCNavBarView.init(title: LanguagesUtil.createTextBy(Ctext: "添加收货地址", Etext: "Add the shipping address"), subTitle: nil,style: navStyle)
  44. self.topContent.constant = kNavAndStatuHeight
  45. self.navBar?.backgroundColor = UIColor.white
  46. // self.navBarHeightConstraint? = self.topContent
  47. self.nameF.text = "\(self.defualModel.receiving ?? "")"
  48. self.detailAddF.text = "\(self.defualModel.addressRemark ?? "")"
  49. self.streeTF.text = "\(self.defualModel.street ?? "")"
  50. self.postF.text = "\(self.defualModel.postcode ?? "")"
  51. self.phoneF.text = "\(self.defualModel.phoneNum ?? "")"
  52. self.blockNumTF.text = "\(self.defualModel.blockNum ?? "")"
  53. self.buildNameTF.text = "\(self.defualModel.buildName ?? "")"
  54. self.unitNumTF.text = "\(self.defualModel.unitNum ?? "")"
  55. if (self.defualModel.isDefault ?? "") == "1"{
  56. self.isDefualBtn.isSelected = true
  57. }else{
  58. self.isDefualBtn.isSelected = false
  59. }
  60. self.nameF.inputText(maxLength: 30) {
  61. self.viewModel.AddAddressRModel.receiving = self.nameF.text
  62. }
  63. self.phoneF.inputFigure(maxLength: 20) {
  64. self.viewModel.AddAddressRModel.phoneNum = self.phoneF.text
  65. }
  66. self.postF.inputFigure(maxLength: 20) {
  67. self.viewModel.AddAddressRModel.postcode = self.postF.text
  68. }
  69. self.detailAddF.inputText(maxLength: 300) {[weak self] in
  70. self?.viewModel.AddAddressRModel.addressRemark = self?.detailAddF.text
  71. }
  72. self.streeTF.inputText(maxLength: 50) {[weak self] in
  73. self?.viewModel.AddAddressRModel.street = self?.streeTF.text
  74. }
  75. self.blockNumTF.inputText(maxLength: 50) {[weak self] in
  76. self?.viewModel.AddAddressRModel.blockNum = self?.blockNumTF.text
  77. }
  78. self.buildNameTF.inputText(maxLength: 50) {[weak self] in
  79. self?.viewModel.AddAddressRModel.buildName = self?.buildNameTF.text
  80. }
  81. self.unitNumTF.inputText(maxLength: 50) {[weak self] in
  82. self?.viewModel.AddAddressRModel.unitNum = self?.unitNumTF.text
  83. }
  84. }
  85. func configDefualData(model : AddressModel){
  86. self.defualModel.id = model.id
  87. self.defualModel.addressRemark = model.addressRemark
  88. self.defualModel.receiving = model.receiving
  89. self.defualModel.phoneNum = model.phoneNum
  90. self.defualModel.postcode = model.postcode
  91. self.defualModel.street = model.street
  92. self.defualModel.isDefault = model.isDefault
  93. self.defualModel.shopcartId = model.shopcartId
  94. self.defualModel.unitNum = model.unitNum
  95. self.defualModel.buildName = model.buildName
  96. self.defualModel.blockNum = model.blockNum
  97. self.viewModel.AddAddressRModel.id = model.id
  98. self.viewModel.AddAddressRModel.addressRemark = model.addressRemark
  99. self.viewModel.AddAddressRModel.receiving = model.receiving
  100. self.viewModel.AddAddressRModel.phoneNum = model.phoneNum
  101. self.viewModel.AddAddressRModel.postcode = model.postcode
  102. self.viewModel.AddAddressRModel.street = model.street
  103. self.viewModel.AddAddressRModel.isDefault = model.isDefault
  104. self.viewModel.AddAddressRModel.shopcartId = model.shopcartId
  105. self.viewModel.AddAddressRModel.unitNum = model.unitNum
  106. self.viewModel.AddAddressRModel.buildName = model.buildName
  107. self.viewModel.AddAddressRModel.blockNum = model.blockNum
  108. }
  109. @IBAction func backAction(_ sender: UIButton) {
  110. self.navigationController?.popViewController(animated: true)
  111. }
  112. @IBAction func setDefualAction(_ sender: UIButton) {
  113. sender.isSelected = !sender.isSelected
  114. if sender.isSelected{
  115. self.viewModel.AddAddressRModel.isDefault = "1"
  116. }else{
  117. self.viewModel.AddAddressRModel.isDefault = "0"
  118. }
  119. }
  120. @IBAction func saveAction(_ sender: UIButton) {
  121. if (self.viewModel.AddAddressRModel.receiving ?? "").isEmptyStr{
  122. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入姓名", Etext: "Please enter your name"))
  123. return
  124. }
  125. if (self.viewModel.AddAddressRModel.phoneNum ?? "").isEmptyStr{
  126. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入电话", Etext: "Please enter phone number"))
  127. return
  128. }
  129. if (self.viewModel.AddAddressRModel.postcode ?? "").isEmptyStr{
  130. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入邮编", Etext: "Please enter postal code"))
  131. return
  132. }
  133. if (self.viewModel.AddAddressRModel.street ?? "").isEmptyStr{
  134. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入街道名称", Etext: "Please enter the street name"))
  135. return
  136. }
  137. if (self.viewModel.AddAddressRModel.blockNum ?? "").isEmptyStr{
  138. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入街区号", Etext: "Please enter the block number"))
  139. return
  140. }
  141. if (self.viewModel.AddAddressRModel.buildName ?? "").isEmptyStr{
  142. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入建筑名称", Etext: "Please enter the building name"))
  143. return
  144. }
  145. if (self.viewModel.AddAddressRModel.unitNum ?? "").isEmptyStr{
  146. self.hud.showWarning(LanguagesUtil.createTextBy(Ctext: "请输入楼层门牌号", Etext: "Please enter the unitNum"))
  147. return
  148. }
  149. self.viewModel.signalSaveAddress()?.on(success: { dd in
  150. self.hud.showSuccess("保存成功")
  151. let model = AddressModel()
  152. ///刷新订单
  153. if self.addressCallBackBlock != nil{
  154. self.addressCallBackBlock!(model)
  155. }
  156. ///刷新购物车
  157. NotificationCenter.default.post(name: NSNotification.Name("刷新默认地址"), object: self, userInfo:nil)
  158. self.navigationController?.popViewController(animated: true)
  159. }, error: { error in
  160. self.hud.showFailure("获取时间范围失败")
  161. })
  162. }
  163. }