//
|
// AddressManageVC.swift
|
// DolphinEnglishLearnManager
|
//
|
// Created by 无故事王国 on 2024/5/20.
|
//
|
|
import UIKit
|
import RxSwift
|
|
let AddressManage_Refresh_Noti = Notification.Name.init("AddressManage_Refresh_Noti")
|
|
class AddressManageViewModel:RefreshModel<AddressModel>{
|
override func api() -> (Observable<BaseResponse<[AddressModel]>>)? {
|
Services.addressList()
|
}
|
}
|
|
class AddressManageVC: BaseVC {
|
|
enum AddressManageType{
|
case handle
|
case choose
|
}
|
|
private var tableView:UITableView!
|
private var addressManageType:AddressManageType!
|
private var viewModel = AddressManageViewModel()
|
private var clouse:((AddressModel)->Void)?
|
|
required init(type:AddressManageType) {
|
super.init(nibName: nil, bundle: nil)
|
self.addressManageType = type
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
viewModel.configure(tableView)
|
viewModel.beginRefresh()
|
}
|
|
override func setUI() {
|
super.setUI()
|
var completeBtn:UIButton?
|
if addressManageType == .handle{
|
completeBtn = UIButton(type: .custom)
|
completeBtn!.jq_cornerRadius = 8
|
completeBtn!.addTarget(self, action: #selector(handleAction), for: .touchUpInside)
|
completeBtn!.setTitleColor(.white, for: .normal)
|
completeBtn!.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium)
|
completeBtn!.setTitle("添加地址", for: .normal)
|
completeBtn!.backgroundColor = UIColor(hexStr: "#41A2EB")
|
view.addSubview(completeBtn!)
|
completeBtn!.snp.makeConstraints { make in
|
make.width.equalTo(316)
|
make.centerX.equalToSuperview()
|
make.bottom.equalToSuperview().offset(-31)
|
make.height.equalTo(47)
|
}
|
}
|
|
|
tableView = UITableView(frame: .zero, style: .grouped)
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.backgroundColor = .clear
|
tableView.separatorStyle = .none
|
tableView.register(UINib(nibName: "AddressManageTCell", bundle: nil), forCellReuseIdentifier: "_AddressManageTCell")
|
tableView.jq_addShadows(shadowColor: UIColor(hexStr: "#D9D9D9"), corner: 0, radius: 20, offset: CGSize(width: 0, height: 2), opacity: 1)
|
view.addSubview(tableView)
|
tableView.snp.makeConstraints { make in
|
make.top.equalTo(self.view.safeAreaLayoutGuide).offset(27)
|
make.left.equalTo(239)
|
make.right.equalTo(-239)
|
make.height.equalTo(47)
|
if completeBtn != nil{
|
make.bottom.equalTo(completeBtn!.snp.top).offset(10)
|
}else{
|
make.bottom.equalToSuperview()
|
}
|
}
|
}
|
|
override func setRx() {
|
NotificationCenter.default.rx.notification(AddressManage_Refresh_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] _ in
|
self?.viewModel.beginRefresh()
|
}).disposed(by: disposeBag)
|
}
|
|
@objc func handleAction(){
|
let vc = AddressManageHandleVC()
|
vc.title = "地址管理"
|
JQ_currentViewController().jq_push(vc: vc)
|
}
|
|
func chooseAddress(_ clouse:@escaping(AddressModel)->Void){
|
self.clouse = clouse
|
}
|
}
|
|
extension AddressManageVC:UITableViewDelegate{
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
let model = viewModel.dataSource.value[indexPath.row]
|
clouse?(model)
|
self.navigationController?.popViewController()
|
}
|
}
|
|
extension AddressManageVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let model = viewModel.dataSource.value[indexPath.row]
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_AddressManageTCell") as! AddressManageTCell
|
cell.addressModel = model
|
cell.isFist = indexPath.row == 0
|
cell.isLast = indexPath.row == viewModel.dataSource.value.count - 1
|
|
cell.btn_edit.isHidden = addressManageType == .choose
|
cell.btn_delete.isHidden = addressManageType == .choose
|
cell.img_more.isHidden = addressManageType != .choose
|
cell.btn_default.isHidden = addressManageType == .choose
|
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return viewModel.dataSource.value.count
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 78
|
}
|
}
|