宽窄优行-由【嘉易行】项目成品而来
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
//
//  ScanChooseTravelVC.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/16.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
 
/// 选择出行方式
class ScanChooseTravelVC: YYTableViewController {
    
    /// 数据源
    private var dataSource: DriverDetailInfoModel?
    
    init(model: DriverDetailInfoModel) {
        super.init(nibName: nil, bundle: nil)
        self.dataSource = model
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
    }
    
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        navigationItem.title = "选择出行方式"
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "item")
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorColor = UIColor.color(light: UIColor.color(hexString: "#DBDBE7"), dark: UIColor.color(hexString: "#DBDBE7"))
    }
    /// 设置司机模型
    /// - Returns: <#description#>
    func setDriverModel(model:DriverDetailInfoModel)->TravelDriverListModel{
        let drvierModel = TravelDriverListModel()
        drvierModel.headImgUrl = model.avatar
        drvierModel.brand = model.brand
        drvierModel.carColor = model.carColor
        drvierModel.evaluate = model.fraction
        drvierModel.driverId = model.id
        drvierModel.id = model.id
        drvierModel.carLicensePlate = model.licensePlate
        drvierModel.name = model.name
        return drvierModel
    }
    
}
 
 
// MARK: - UITableViewDelegate
extension ScanChooseTravelVC:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         let model = dataSource?.list[indexPath.row]
        guard let data = self.dataSource else{return}
        guard let id = model?.id.wy_toInt() else{return}
        if id == 3 {
            // 获取司机信息,跨城
            let vc = SureTravelInfoController()
            vc.driverId = "\(data.id)"
            vc.travelOrderType = .scan
            vc.model = self.setDriverModel(model: data)
            self.yy_push(vc: vc)
        }else{
            let vc = ScanTravelVC(model: data, type: OrderType(rawValue: id)!)
            self.yy_push(vc: vc)
        }
    }
}
 
// MARK: - UITableViewDelegate
extension ScanChooseTravelVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource?.list.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "item", for: indexPath)
        cell.textLabel?.text = dataSource?.list[indexPath.row].name
        cell.textLabel?.font = Medium(font: 15)
        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: 0)
        cell.selectionStyle = .none
        cell.accessoryType = .disclosureIndicator
        return cell
    }
}