fix
无故事王国
2024-06-20 f2e891eecfac25bf6aed38c8eadfdf05704b16b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
//  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
                }
}