宽窄优行-由【嘉易行】项目成品而来
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
//
//  MinePublishSaleListVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/5/6.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
 
class MinePublishSaleListVC: YYTableViewController {
 
    let viewModel = MinePublishSellViewModel()
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
    }
 
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        view.backgroundColor = UIColor(hexString: "#F3F4F5")
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor = .clear
        tableView.register(cellName: "HireCarTCell", identifier: "_HireCarTCell")
 
        emptyType = .empty(image: nil, title: "暂无数据")
 
        viewModel.configure(tableView: tableView)
        tableView.mj_header?.beginRefreshing()
    }
 
    override func bindRx() {
        NotificationCenter.default.rx.notification(Refresh_MinePublish).takeUntil(self.rx.deallocated).subscribe(onNext: {[weak self] noti in
            self?.tableView.mj_header?.beginRefreshing()
        }).disposed(by: disposeBag)
    }
 
    //MARK: - Layouts
    override func defineLayouts() {
        super.defineLayouts()
        tableView.snp.makeConstraints { (make) in
            if #available(iOS 11.0, *) {
                make.edges.equalTo(view.safeAreaLayoutGuide).inset(UIEdgeInsets(top: 3, left: 0, bottom: 0, right: 0))
            } else {
                make.edges.equalToSuperview().inset(UIEdgeInsets(top: 3, left: 0, bottom: 0, right: 0))
            }
        }
    }
}
 
// MARK: - UITableViewDelegate
extension MinePublishSaleListVC:UITableViewDelegate{
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
 
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let m = viewModel.dataSource.value[indexPath.row]
        self.show()
        APIManager.shared.provider.rx.request(.getSellingCarDetail(id: m.id)).map(YYModel<SellCarReqModel>.self).subscribe(onSuccess: {data in
            self.hide()
            let vc = MinePublishSaleDetailVC()
            vc.carSellModel = data.data
            self.yy_push(vc: vc)
        }) { error in
            self.hide()
 
        }.disposed(by: disposeBag)
    }
}
 
// MARK: - UITableViewDelegate
extension MinePublishSaleListVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel.dataSource.value.count
    }
 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let m = viewModel.dataSource.value[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "_HireCarTCell", for: indexPath) as! HireCarTCell
        cell.backgroundColor = .clear
        cell.setCarSellModel(m)
        cell.clouseDel { [weak self] () in
            guard let weakSelf = self else { return }
            APIManager.shared.provider.rx.request(.newlyAddedDel(id: m.id, type: 2)).map(YYModel<Nothing>.self).subscribe(onSuccess: {data in
                weakSelf.tableView.mj_header?.beginRefreshing()
            }) { error in
 
            }.disposed(by: weakSelf.disposeBag)
        }
        cell.topTypeL.backgroundColor = UIColor(hexString: "#00BF30")?.withAlphaComponent(0.79)
        return cell
    }
}