宽窄优行-由【嘉易行】项目成品而来
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
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
156
157
158
159
160
161
162
163
164
165
//
//  TravelCardShopDetailVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/10.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
import RxSwift
 
class TravelCardShopDetailVC: YYViewController {
 
    @IBOutlet weak var scrollView: UIScrollView!
    @IBOutlet weak var contentView: UIView!
    @IBOutlet weak var nameL: UILabel!
    @IBOutlet weak var contentL: UILabel!
    @IBOutlet weak var typeNameL: UILabel!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var originPriceL: UILabel!
    @IBOutlet weak var priceL: UILabel!
    @IBOutlet weak var paymentBtn: UIButton!
    @IBOutlet weak var tableViewHeiCons: NSLayoutConstraint!
    @IBOutlet weak var validUseTimeL: UILabel!
    @IBOutlet weak var richContentL: UILabel!
    @IBOutlet weak var containerViewHeiCons: NSLayoutConstraint!
 
    var id = 0
    var orderType = 0
    var couponListModel:CouponListModel?
 
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .black.withAlphaComponent(0)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.isScrollEnabled = false
        tableView.separatorStyle = .none
        tableView.register(cellName: "TravelCouponTCell", identifier: "_TravelCouponTCell")
        scrollView.contentInset = UIEdgeInsets(top: 190, left: 0, bottom: 0, right: 0)
        switch orderType {
            case 0:typeNameL.text = "通用"
            case 1:typeNameL.text = "快车/专车"
            case 2:typeNameL.text = "出租车"
            case 3:typeNameL.text = "跨城出行"
            case 4:typeNameL.text = "同城物流"
            case 5:typeNameL.text = "跨城物流"
            default:typeNameL.text = "未知"
        }
 
        containerViewHeiCons.constant = SCREEN_HEIGHT - 263
 
        APIManager.shared.provider.rx.request(.getTaxiCardInfo(id: id)).map(YYModel<CouponListModel>.self).validate().subscribe { [unowned self] data in
            guard let m = data.data else {return}
            self.couponListModel = m
            self.nameL.text = m.name
            self.originPriceL.text = String(format: "原价:%.2lf元", m.originalPrice)
            self.priceL.text = String(format: "现价:%.2lf元", m.sellingPrice)
            self.richContentL.attributedText = m.note.ld_setHtmlAttributedString(font: nil)
            var text = [String]()
            switch self.couponListModel!.type {
                case .numberOfDiscounts:
                    text.append(String(format: "享%ld次打车打%@折", self.couponListModel!.time,self.couponListModel!.discounts.ld_formatFloat))
                case .dicountCard:
                    text.append(String(format: "每次打车最高抵扣%@元",self.couponListModel!.discounts.ld_formatFloat))
                case .numberCard:
                    text.append(String(format: "享%ld次打车优惠%@元",self.couponListModel!.time,self.couponListModel!.discounts.ld_formatFloat))
                case .discountDayCard:
                    text.append(String(format: "每次打车打%@折",self.couponListModel!.discounts.ld_formatFloat))
                case .expressCard:
                    text.append(String(format: "每次寄件打%@折",self.couponListModel!.discounts.ld_formatFloat))
                case .expressPaket:
                    text.append(String(format: "送%ld张优惠券",self.couponListModel!.couponNum))
            }
 
            if m.timeQuantum.count == 0 || m.timeQuantum.contains("00:00:00 - 23:59:59"){
                self.validUseTimeL.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.validUseTimeL.text = String(format: "%@可用", temp.joined(separator: ""))
            }
 
            if !self.couponListModel!.cityName.isEmpty{
                text.append("\(self.couponListModel!.cityName)可用")
            }
            self.contentL.text = text.joined(separator: " | ")
            if m.couponList.count <= 2{
                self.containerViewHeiCons.constant = SCREEN_HEIGHT - 203.0
            }else{
                self.containerViewHeiCons.constant = SCREEN_HEIGHT - 263.0 - CGFloat(98 * m.couponList.count)
            }
 
            self.tableViewHeiCons.constant = CGFloat(98 * m.couponList.count)
            self.tableView.reloadData()
            self.paymentBtn.setTitle(String(format: "立即支付%.2lf元", m.sellingPrice), for: .normal)
        } onError: { error in
 
        }.disposed(by: rx.disposeBag)
 
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        UIView.animate(withDuration: 0.2, delay: 0.4, options: .layoutSubviews) {
            self.view.backgroundColor = .black.withAlphaComponent(0.5)
        } completion: { _ in
 
        }
    }
 
    @IBAction func cancelAction(_ sender: Any) {
        UIView.animate(withDuration: 0.2) {
            self.view.backgroundColor = .black.withAlphaComponent(0)
        } completion: { _ in
            self.dismiss(animated: true)
        }
    }
 
    @IBAction func paymentAction(_ sender: UIButton) {
 
        guard couponListModel != nil else {
            alert(text: "数据错误")
            return
        }
 
        let originPrice:Double? = couponListModel!.originalPrice == 0 ? nil:couponListModel!.originalPrice
        let cancelServicePayView = CouponPaymentView.instance(cardId: couponListModel!.id, money: couponListModel!.sellingPrice,originMoney: originPrice)
        cancelServicePayView.show(defaultPayBy: .balance,orderType: orderType) {
            UIView.animate(withDuration: 0.2) {
                self.view.backgroundColor = .black.withAlphaComponent(0)
            } completion: { _ in
                self.dismiss(animated: true)
            }
        }
    }
}
 
extension TravelCardShopDetailVC:UITableViewDelegate{
 
}
 
extension TravelCardShopDetailVC: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
        return cell
    }
 
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        98
    }
 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return couponListModel?.couponList.count ?? 0
    }
}