宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-04 38f768d39ba27d303147c59a222655b7c6cdfb25
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
//
//  TravelCardDetailVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/10.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
 
class TravelCardDetailVC: YYViewController {
 
    var id = 0
    var type:OrderType = .taxi
    @IBOutlet weak var titleL: UILabel!
    @IBOutlet weak var nameL: UILabel!
    @IBOutlet weak var infoL: UILabel!
    @IBOutlet weak var info2L: UILabel!
    @IBOutlet weak var noteL: UILabel!
    @IBOutlet weak var usualTimeL: UILabel!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var tableViewHeiCons: NSLayoutConstraint!
 
 
    private var couponListModel:CouponListModel?
 
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "会员卡详情"
        view.backgroundColor = UIColor(hexString: "#F3F4F5")
 
        tableView.delegate = self
        tableView.dataSource = self
        tableView.isScrollEnabled = false
        tableView.backgroundColor = .clear
        tableView.separatorStyle = .none
        tableView.register(cellName: "TravelCouponTCell", identifier: "_TravelCouponTCell")
 
        switch type {
            case .special:titleL.text = "快车/专车"
            case .taxi:titleL.text = "出租车"
            case .travel:titleL.text = "跨城出行"
            case .cityLogistics:titleL.text = "同城物流"
            case .acrossLogistics:titleL.text = "跨城物流"
            default:break
        }
 
        APIManager.shared.provider.rx.request(.getMyTaxiCardInfo(id: id)).map(YYModel<CouponListModel>.self).subscribe(onSuccess: { data in
            if let m = data.data{
                self.couponListModel = m
                self.nameL.text = m.name
 
                self.tableViewHeiCons.constant = Double(98) * Double(m.couponList.count)
 
                var text = [String]()
                var text2 = [String]()
                switch m.type {
                    case .numberOfDiscounts: // 1
                        text.append(String(format: "享%ld次打车打%.1lf折", m.time,m.discounts))
                        text2.append("有效期至:\(m.endTime)")
                        text2.append("还剩\(m.lastTime)次")
                    case .dicountCard: //2
                        text.append(String(format: "每次打车最高抵扣%@元",m.discounts.ld_formatFloat))
                        text2.append("有效期至:\(m.endTime)")
                    case .numberCard: // 3
                        text.append(String(format: "享%ld次打车优惠%@元",m.time,m.discounts.ld_formatFloat))
                        text2.append("有效期至:\(m.endTime)")
                        text2.append("还剩\(m.lastTime)次")
                    case .discountDayCard: //4
                        text.append(String(format: "每次打车打%.1lf折",m.discounts))
                        text2.append("有效期至:\(m.endTime)")
                    case .expressCard: // 5
                        text.append(String(format: "每次寄件打%.1lf折",m.discounts))
                        text2.append("有效期至:\(m.endTime)")
                    case .expressPaket: //6
                        text.append(String(format: "送%ld张优惠券",m.couponNum))
                        text2.append("有效期至:\(m.endTime)")
                }
 
                if !m.cityName.isEmpty{
                    text.append("\(m.cityName)可用")
                }
                self.infoL.text = text.joined(separator: " | ")
                self.info2L.text = text2.filter({!$0.isEmpty}).joined(separator: "|")
 
                if m.timeQuantum.count == 0 || m.timeQuantum.contains("00:00:00 - 23:59:59"){
                    self.usualTimeL.text = "全天可用"
                }else{
                    var temp = Array<String>()
                    for (index,str) in m.timeQuantum.enumerated() {
                        temp.append(str)
                        if (index + 1) % 2 == 0{
                            temp.append("\n")
                        }else{
                            temp.append(" ")
                        }
                    }
                    self.usualTimeL.text = String(format: "%@可用", temp.joined(separator: ""))
                }
                self.noteL.attributedText = m.note.ld_setHtmlAttributedString(font: nil)
                self.tableView.reloadData()
            }
        }) { error in
 
        }.disposed(by: disposeBag)
    }
}
 
extension TravelCardDetailVC:UITableViewDelegate{
 
}
 
extension TravelCardDetailVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let m = couponListModel!.couponList[indexPath.row]
         let cell = tableView.dequeueReusableCell(withIdentifier: "_TravelCouponTCell", for: indexPath) as! TravelCouponTCell
        cell.couponModel = m
        cell.checkImg.isHidden = true
        cell.backgroundColor = .clear
        return cell
    }
 
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        98
    }
 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return couponListModel?.couponList.count ?? 0
    }
}