宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//
//  MineSetUpVC.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/17.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
 
/// 设置
class MineSetUpVC: YYTableViewController {
 
    let viewModel = AgreementViewModel()
    
    /// 取消按钮
    private let button_loginOut: YYButton = {
       let button = YYButton()
        button.setTitle("退出登录", for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#FFFFFF")), for: .normal)
        button.backgroundColor = ThemeColor
        button.layer.cornerRadius = 4
        return button
    }()
    
    /// 数据源
    private let dataSource = [["账户安全","车内录音设置","常见问题","隐私协议","法律条款和平台规则","充值领劵规则","取消订单规则","计价规则","用户指南","用户协议","关于我们"],["清理缓存","当前版本"]]
    
    /// 缓存
    private var label_cache: UILabel?
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
    }
 
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        navigationItem.title = "设置"
        tableView.delegate = self
        tableView.dataSource = self
        tableView.tableFooterView = UIView()
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "item")
        tableView.separatorColor = UIColor.color(light: UIColor.color(hexString: "#F6F6F6"), dark: UIColor.color(hexString: "#F6F6F6"))
        view.addSubview(button_loginOut)
    }
    
    //MARK: - Layouts
    override func defineLayouts() {
        super.defineLayouts()
        tableView.snp.remakeConstraints { (make) in
            if #available(iOS 11.0, *) {
                make.top.equalTo(view.safeAreaLayoutGuide)
            } else {
                make.top.equalToSuperview()
            }
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(-54)
        }
        
        button_loginOut.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.width.equalTo(screenW - 28)
            make.height.equalTo(40)
            make.bottom.equalToSuperview().offset(-(14 + UIDevice.ld_safeEdges.bottom))
        }
    }
    
    //MARK: - Rx
    override func bindRx() {
        super.bindRx()
        button_loginOut.rx.tap.subscribe(onNext: {[unowned self] (_) in
            alert(popup: .double, title: "提示", text: "确定要退出登录吗?", submitTitle: nil, cancelTitle: nil, submitClick: { [unowned self] in
                app.userInfo.clear()
                app.loginInfo.token = ""
                app.loginInfo.clear()
                self.yy_popToRoot()
            }) {}
        }).disposed(by: disposeBag)
        
        
        /// 协议
        viewModel.requestSubject
            .subscribe(onNext: {[unowned self] (status) in
                switch status{
                case .loading:
                    self.show()
                    break
                case .success(let model):
                    self.hide()
                    guard let data: SwitchCityModel = model as? SwitchCityModel else {return}
                    let vc = YYWebView()
                    vc.name = self.viewModel.type.value.title()
                    vc.url = data.content
                    self.yy_push(vc: vc)
                    break
                case .error(let error):
                    self.hide()
                    alert(text: error.localizedDescription)
                    break
                }
            }).disposed(by: disposeBag)
    }
}
// MARK: - UITableViewDelegate
extension MineSetUpVC:UITableViewDelegate{
    func numberOfSections(in tableView: UITableView) -> Int {
        return dataSource.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        if indexPath.section == 0 {
            if indexPath.row == 0 {
                let vc = MineAccountSecurityVC()
                self.yy_push(vc: vc)
            }else if  indexPath.row == 1 {
                let vc = VoiceSettingVC()
                self.yy_push(vc: vc)
            }
            else if  indexPath.row == 2 {
                viewModel.type.accept(.Q_A)
                viewModel.agreement()
            }else if  indexPath.row == 3 {
                viewModel.type.accept(.privacy)
                viewModel.agreement()
            }else if  indexPath.row == 4 {
                viewModel.type.accept(.legalProvisions)
                viewModel.agreement()
            }else if  indexPath.row == 5 {
                viewModel.type.accept(.topUp)
                viewModel.agreement()
            }else if  indexPath.row == 6 {
                viewModel.type.accept(.cancel)
                viewModel.agreement()
            }else if  indexPath.row == 7 {
                viewModel.type.accept(.valuation)
                viewModel.agreement()
            }else if  indexPath.row == 8 {
                viewModel.type.accept(.userGuide)
                viewModel.agreement()
            }else if  indexPath.row == 9 {
                viewModel.type.accept(.userAgreement)
                viewModel.agreement()
            }else if  indexPath.row == 10 {
                viewModel.type.accept(.aboutUs)
                viewModel.agreement()
            }
            return
        }
        switch dataSource[indexPath.section][indexPath.row] {
        case "账户安全":
            let vc = MineAccountSecurityVC()
            self.yy_push(vc: vc)
            break
        case "用户指南":
            viewModel.type.accept(.userGuide)
            viewModel.agreement()
            break
        case "法律条款和平台规则":
            viewModel.type.accept(.legalProvisions)
            viewModel.agreement()
            break
        case "关于我们":
            viewModel.type.accept(.aboutUs)
            viewModel.agreement()
            break
        case "清理缓存":
            alert(popup: .double, title: "提示", text: "确定要清除缓存吗?", submitTitle: nil, cancelTitle: nil, submitClick: {
                CacheFileManager.removeCache()
                self.label_cache?.text = "\(CacheFileManager.getCache())M"
            }) {}
            break
        case "当前版本":
            break
        default:
            break
        }
    }
}
 
// MARK: - UITableViewDelegate
extension MineSetUpVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource[section].count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "item", for: indexPath)
        cell.textLabel?.text = dataSource[indexPath.section][indexPath.row]
        cell.textLabel?.font = Medium(font: 14)
        cell.textLabel?.textColor = UIColor.color(light: UIColor.color(hexString: "#333333"), dark: UIColor.color(hexString: "#333333"))
        cell.separatorInset = UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14)
        cell.accessoryType = indexPath.section == 0 ? .disclosureIndicator : .none
        let label_desc = UILabel()
        label_desc.textColor = UIColor.color(light: UIColor.color(hexString: "#333333",0.4), dark: UIColor.color(hexString: "#333333",0.4))
        label_desc.font = Medium(font: 14)
        cell.contentView.addSubview(label_desc)
        label_desc.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-14)
        }
        label_desc.isHidden = indexPath.section == 0
        if indexPath.section == 1 && indexPath.row == 0{
            label_desc.text = "\(CacheFileManager.getCache())M"
            self.label_cache = label_desc
        }else if indexPath.section == 1 && indexPath.row == 1{
            let infoDictionary : [String : Any] = Bundle.main.infoDictionary!
            let minorVersion = infoDictionary["CFBundleShortVersionString"] as! String
            label_desc.text = "v \(minorVersion)"
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return section == 0 ? 0 : 5
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView()
        view.backgroundColor = UIColor.color(light: UIColor.color(hexString: "#F3F4F5"), dark: UIColor.color(hexString: "#F3F4F5"))
        return view
    }
}