无故事王国
2023-10-25 158f3707711ad4be78a55dc73a98aa1c9acda0dd
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
//
//  TroubleListVC.swift
//  BrokerDriver
//
//  Created by 无故事王国 on 2023/5/5.
//
 
import UIKit
 
class TroubleListVC: BaseViewController {
 
    private var orderId:String!
    private var tableView:BaseTableView!
    private var selectIndex:Int = -1
    private let items = ["Appointment cancelled","Appointment expired","Terminal closed","Terminal break","Accident","Container not found","Container line hold","Container custom hold","Container TMF hold","Container Pierpass hold"]
 
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Trouble"
 
        let rightBtn = UIBarButtonItem(target: self, action: #selector(historyAction), image: "btn_time", highImage: "btn_time")
        navigationItem.rightBarButtonItem = rightBtn
 
    }
 
    required init(orderId:String) {
        super.init(nibName: nil, bundle: nil)
        self.orderId = orderId
 
    }
 
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    override func setUI() {
        super.setUI()
        tableView = BaseTableView(frame: .zero, style: .plain)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        tableView.register(UINib(nibName: "TroubleTCell", bundle: nil), forCellReuseIdentifier: "_TroubleTCell")
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview().inset(view.safeAreaInsets)
        }
 
        let footView = TroubleFootView.jq_loadNibView()
        footView.submitClouse { [weak self] text in
            guard let weakSelf = self else { return }
            guard weakSelf.selectIndex != -1 else {alert(msg: "Please select your problem");return}
 
            var model = HomeDetailNoteVC.DetailNotModel()
            model.category = weakSelf.items[weakSelf.selectIndex]
            model.type = .troble
            model.orderId = weakSelf.orderId
            model.describe = text
            Services.addOrderNote(model: model).subscribe(onNext: {data in
                if data.code == 200{
                    alert(msg: "Submit successed")
                    DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
                        self?.navigationController?.popViewController()
                    }
                }else{
                    alert(msg: data.message)
                }
            }) { error in
                alert(msg: error.localizedDescription)
            }.disposed(by: weakSelf.disposeBag)
        }
        tableView.tableFooterView = footView
    }
 
    @objc func historyAction(){
        let vc = TroubleHistoryListVC(orderId: orderId)
        push(vc: vc)
    }
}
 
extension TroubleListVC:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        selectIndex = indexPath.row
        tableView.reloadData()
    }
}   
 
extension TroubleListVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       let item = items[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "_TroubleTCell") as! TroubleTCell
        cell.boxImage.image = UIImage(named: "")
        cell.label_content.text = item
 
        if indexPath.row == selectIndex{
            cell.boxImage.image = UIImage(named: "icon_seletedBox")
        }else{
            cell.boxImage.image = UIImage(named: "icon_box")
        }
        return cell
    }
}