123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- //
- // selectAddressView.swift
- // ADHTuanCan
- //
- // Created by 敖德亨 on 2023/11/4.
- //
- import UIKit
- import RxSwift
- import RxCocoa
- class selectAddressView: UIView {
- @IBOutlet weak var blackView: UIView!
- @IBOutlet weak var tableView: UITableView!
- /// hud 提示
- lazy var hud : MCHud! = {
- return MCHud()
- }()
-
- let viewModel : AddresViewModel = AddresViewModel.init()
- let diposableBag = DisposeBag()
- var addressModel : AddressModel?
-
- var saveBlock : ((_ model : AddressModel)->Void)?
- var editAddressBlock : ((_ model : AddressModel)->Void)?
- var addAddressBlock : (()->Void)?
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- _ = NotificationCenter.default.rx.notification(Notification.Name(rawValue: "刷新确认订单收货人")).takeUntil(self.rx.deallocated).subscribe(onNext:{[weak self] (notification) in
- self?.getAllAddress()
- })
-
- tableView.register(withType: OrderAddressCell.self)
- tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
-
- self.tableView.ly_emptyView = LYEmptyView.emptyActionView(with: UIImage.init(named: "暂无数据"), titleStr: "暂无数据", detailStr: "", btnTitleStr: "点击刷新", btnClick: {[weak self] in
- self?.getAllAddress()
- })
-
- self.getAllAddress()
- }
-
- func getAllAddress(){
- self.hud.showLoading()
- self.viewModel.signalGetAllAddress()?.on(success: { dd in
- self.hud.hidden()
- self.tableView.reloadData()
- }, error: { error in
- self.hud.showFailure("获取收货地址失败")
- })
- }
-
-
- public func show(){
- kAppDelegateWindow.addSubview(self)
- self.blackView.alpha = 0
- self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
- UIView.animate(withDuration: 0.5) {
- self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
- self.layoutIfNeeded()
- }
- DELAY(0.5) {
- self.blackView.alpha = 0.3
- }
- }
-
-
- //新增地址
- @IBAction func addAddressAction(_ sender: UIButton) {
- if self.addAddressBlock != nil{
- self.addAddressBlock!()
- }
- self.hidden()
- }
-
- /// 隐藏
- public func hidden(){
- self.blackView.alpha = 0
- UIView.animate(withDuration: 0.5) {
- self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
- self.layoutIfNeeded()
- }
- DELAY(0.5) {
- self.removeFromSuperview()
- }
- }
- @IBAction func backAction(_ sender: UIButton) {
- self.hidden()
- }
- }
- extension selectAddressView : UITableViewDelegate,UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.viewModel.addressListModel?.count ?? 0
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "OrderAddressCell") as! OrderAddressCell;
- let model : AddressModel = self.viewModel.addressListModel![indexPath.row]
- cell.configModel(model: model)
- cell.editBlock = {[unowned self] in
- self.addressModel = model
- if self.editAddressBlock != nil{
- self.editAddressBlock!(self.addressModel!)
- }
- self.hidden()
- }
- return cell
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 0.01
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 0.01
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let model : AddressModel = self.viewModel.addressListModel![indexPath.row]
- for item in self.viewModel.addressListModel!{
- let dto : AddressModel = item
- dto.isDefault = "0"
- }
- model.isDefault = "1"
- self.addressModel = model
- self.tableView.reloadData()
-
- if self.addressModel != nil{
- if self.saveBlock != nil{
- self.saveBlock!(self.addressModel!)
- }
- self.hidden()
- }
- }
-
- }
|