宽窄优行-由【嘉易行】项目成品而来
无故事王国
2023-05-25 dc1998fc1ac124f6b9a0e434ccf91103dd936409
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
//
//  TaxiOrderListVC.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/8.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
import RxSwift
import RxRelay
 
/// 出租车订单列表
class TaxiOrderListVC: YYTableViewController {
    
    /// viewModel
    let viewModel = TaxiOrderViewModel()
    
    init(orderType: OrderType) {
        super.init(nibName: nil, bundle: nil)
        viewModel.type.accept(orderType)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
        
        viewModel.configure(tableView: tableView)
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        tableView.mj_header?.beginRefreshing()
    }
 
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(cellName: "TaxiOrderListCell", identifier: "item")
    }
    
    //MARK: - Rx
    override func bindRx() {
        super.bindRx()
        NotificationCenter.default.rx.notification(Notification.Name(rawValue: YYOrderListRefresh), object: nil).subscribe(onNext: {[unowned self] (_) 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)
            } else {
                make.edges.equalToSuperview()
            }
        }
    }
}
 
 
// MARK: - UITableViewDelegate
extension TaxiOrderListVC:UITableViewDelegate{
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let data = viewModel.dataSource.value[indexPath.row]
 
        // 8=待评价,9=已完成
        if data.state == 8 || data.state == 9{
            // 新的界面 有轨迹
            let vc = TaxiOrderDetailsVC.init(orderId: data.orderId, orderType: viewModel.type.value)
            self.yy_push(vc: vc) 
        }else{
            // 订单流程界面
            if self.viewModel.type.value == .special{
 
                var isCarpool:Bool = false
                if data.rideType == .seating{isCarpool = true}
                let vc = YYSpecialCarViewController.init(orderId: data.orderId,isCarpool: isCarpool)
                vc.viewModel.orderType.accept(.special)
                self.yy_push(vc: vc)
            }else if viewModel.type.value == .scenic{
                if data.state == 7{
                    let vc = TravelOrderSuccessVC()
                    vc.id.accept(data.orderId)
                    vc.statusType = .MyOrder
                    yy_push(vc: vc)
                    return
                }
 
                let vc = TravelServiceVC(orderId: data.orderId, orderType: .scenic)
                wy_pushAnimate(vc: vc)
//                let vc = YYSpecialCarViewController.init(orderId: data.orderId)
//                vc.viewModel.orderType.accept(.scenic)
//                self.yy_push(vc: vc)
 
            }else if self.viewModel.type.value == .travel{
                if data.state == 7 {
                    //待支付
                    let vc = TravelOrderSuccessVC()
                    vc.id.accept(data.orderId)
                    vc.statusType = .MyOrder
                    self.yy_push(vc: vc)
                    return
                }
                if data.state == 10 {
                    // 取消
                    let vc = YYSpecialCarViewController.init(orderId: data.orderId)
                    vc.viewModel.orderType.accept(.travel)
                    self.yy_push(vc: vc)
                    return
                }
                let vc = YYSpecialCarViewController.init(orderId: data.orderId)
                vc.viewModel.orderType.accept(.travel)
                self.yy_push(vc: vc)
            }else{
                let vc = TravelServiceVC.init(orderId: data.orderId, orderType: viewModel.type.value)
                self.yy_push(vc: vc)
            }
        }
    }
}
 
// MARK: - UITableViewDelegate
extension TaxiOrderListVC: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! TaxiOrderListCell
        cell.configure(model: viewModel.dataSource.value[indexPath.row])
        cell.selectionStyle = .none
        cell.refreshDelegate.delegate(on: self) { _,_ in
            self.tableView.mj_header?.beginRefreshing()
        }
        return cell
    }
    
    
}