宽窄优行-由【嘉易行】项目成品而来
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
//
//  PlatformMessageVC.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/17.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
 
/// 平台公告
class PlatformMessageVC: YYTableViewController {
    
    
    let viewModel = SystemMessageViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        viewModel.type.accept(1)
    }
    
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(cellName: "PlatformMessageCell", identifier: "item")
        viewModel.configure(tableView: tableView)
        tableView.beginRefreshing()
    }
    
    
    //MARK: - Layouts
    override func defineLayouts() {
        super.defineLayouts()
        tableView.snp.remakeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
    
    //MARK: - Rx
    override func bindRx() {
        super.bindRx()
        viewModel.delSystemNoticeSubject
            .subscribe(onNext: { (state) in
                switch state{
                case .loading:
                    self.show()
                    break
                case .success(_):
                    self.hide()
                    var data = self.viewModel.dataSource.value
                    data.remove(at: self.viewModel.row.value)
                    self.viewModel.dataSource.accept(data)
                    self.tableView.reloadData()
                    break
                case .error(let error):
                    self.hide()
                    alert(text: error.localizedDescription)
                    break
                }
            }).disposed(by: disposeBag)
    }
}
 
 
// MARK: - UITableViewDelegate
extension PlatformMessageVC:UITableViewDelegate{
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let vc = YYWebView()
        vc.name = "公告详情"
        vc.url = viewModel.dataSource.value[indexPath.row].content
        yy_push(vc: vc)
    }
    
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    // 设置确认删除按钮的文字
    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
        return "删除"
    }
    
    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        return .delete
    }
    
    
    
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        self.viewModel.row.accept(indexPath.row)
        self.viewModel.id.accept(viewModel.dataSource.value[indexPath.row].id)
        self.viewModel.delSystemNotice()
    }
}
 
// MARK: - UITableViewDelegate
extension PlatformMessageVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel.dataSource.value.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "item", for: indexPath) as! PlatformMessageCell
        cell.configure(model: viewModel.dataSource.value[indexPath.row])
        cell.selectionStyle = .none
        return cell
    }
    
    
}