selectAddressView.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // selectAddressView.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/4.
  6. //
  7. import UIKit
  8. import RxSwift
  9. import RxCocoa
  10. class selectAddressView: UIView {
  11. @IBOutlet weak var blackView: UIView!
  12. @IBOutlet weak var tableView: UITableView!
  13. /// hud 提示
  14. lazy var hud : MCHud! = {
  15. return MCHud()
  16. }()
  17. let viewModel : AddresViewModel = AddresViewModel.init()
  18. let diposableBag = DisposeBag()
  19. var addressModel : AddressModel?
  20. var saveBlock : ((_ model : AddressModel)->Void)?
  21. var editAddressBlock : ((_ model : AddressModel)->Void)?
  22. var addAddressBlock : (()->Void)?
  23. override func awakeFromNib() {
  24. super.awakeFromNib()
  25. _ = NotificationCenter.default.rx.notification(Notification.Name(rawValue: "刷新确认订单收货人")).takeUntil(self.rx.deallocated).subscribe(onNext:{[weak self] (notification) in
  26. self?.getAllAddress()
  27. })
  28. tableView.register(withType: OrderAddressCell.self)
  29. tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
  30. self.tableView.ly_emptyView = LYEmptyView.emptyActionView(with: UIImage.init(named: "暂无数据"), titleStr: "暂无数据", detailStr: "", btnTitleStr: "点击刷新", btnClick: {[weak self] in
  31. self?.getAllAddress()
  32. })
  33. self.getAllAddress()
  34. }
  35. func getAllAddress(){
  36. self.hud.showLoading()
  37. self.viewModel.signalGetAllAddress()?.on(success: { dd in
  38. self.hud.hidden()
  39. self.tableView.reloadData()
  40. }, error: { error in
  41. self.hud.showFailure("获取收货地址失败")
  42. })
  43. }
  44. public func show(){
  45. kAppDelegateWindow.addSubview(self)
  46. self.blackView.alpha = 0
  47. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  48. UIView.animate(withDuration: 0.5) {
  49. self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  50. self.layoutIfNeeded()
  51. }
  52. DELAY(0.5) {
  53. self.blackView.alpha = 0.3
  54. }
  55. }
  56. //新增地址
  57. @IBAction func addAddressAction(_ sender: UIButton) {
  58. if self.addAddressBlock != nil{
  59. self.addAddressBlock!()
  60. }
  61. self.hidden()
  62. }
  63. /// 隐藏
  64. public func hidden(){
  65. self.blackView.alpha = 0
  66. UIView.animate(withDuration: 0.5) {
  67. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  68. self.layoutIfNeeded()
  69. }
  70. DELAY(0.5) {
  71. self.removeFromSuperview()
  72. }
  73. }
  74. @IBAction func backAction(_ sender: UIButton) {
  75. self.hidden()
  76. }
  77. }
  78. extension selectAddressView : UITableViewDelegate,UITableViewDataSource{
  79. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  80. return self.viewModel.addressListModel?.count ?? 0
  81. }
  82. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  83. let cell = tableView.dequeueReusableCell(withIdentifier: "OrderAddressCell") as! OrderAddressCell;
  84. let model : AddressModel = self.viewModel.addressListModel![indexPath.row]
  85. cell.configModel(model: model)
  86. cell.editBlock = {[unowned self] in
  87. self.addressModel = model
  88. if self.editAddressBlock != nil{
  89. self.editAddressBlock!(self.addressModel!)
  90. }
  91. self.hidden()
  92. }
  93. return cell
  94. }
  95. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  96. return 0.01
  97. }
  98. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  99. return 0.01
  100. }
  101. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  102. let model : AddressModel = self.viewModel.addressListModel![indexPath.row]
  103. for item in self.viewModel.addressListModel!{
  104. let dto : AddressModel = item
  105. dto.isDefault = "0"
  106. }
  107. model.isDefault = "1"
  108. self.addressModel = model
  109. self.tableView.reloadData()
  110. if self.addressModel != nil{
  111. if self.saveBlock != nil{
  112. self.saveBlock!(self.addressModel!)
  113. }
  114. self.hidden()
  115. }
  116. }
  117. }