宽窄优行-由【嘉易行】项目成品而来
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
//
//  MerchantCouponTCell.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/14.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
 
class MerchantCouponTCell: UITableViewCell {
 
    var merchantCouponModel:MerchantCouponModel!{
        didSet{
            nameL.text = merchantCouponModel.name
            infoL.text = String(format: "%ld张券,领取有%ld人,使用%ld人", merchantCouponModel.totalNum,merchantCouponModel.receive,merchantCouponModel.writeOff)
 
            if merchantCouponModel.type == 2{
                moneyL.attributedText = AttributedStringbuilder.build()
                    .add(string: "领取券", withFont: UIFont.init(name: Semibold, size: 30)!, withColor: UIColor.white).mutableAttributedString
                useRuleL.text = merchantCouponModel.content.filterHTML()
            }else{
                moneyL.attributedText = AttributedStringbuilder.build()
                    .add(string: "¥", withFont: UIFont.init(name: Semibold, size: 18)!, withColor: UIColor.white)
                    .add(string: String(format: "%.2lf", merchantCouponModel.discount), withFont: UIFont.init(name: Semibold, size: 33)!, withColor: UIColor.white).mutableAttributedString
                useRuleL.text = String(format: "店铺购买满%@元使用", merchantCouponModel.fullAmount.ld_formatFloat)
            }
            layoutSubviews()
        }
    }
 
    var paymentCouponModel:PaymentCouponModel!{
        didSet{
            self.moneyL.attributedText = AttributedStringbuilder.build()
                .add(string: "¥", withFont: UIFont.init(name: Semibold, size: 18)!, withColor: UIColor.white)
                .add(string: String(format: "%.2lf", self.paymentCouponModel.money), withFont: UIFont.init(name: Semibold, size: 33)!, withColor: UIColor.white).mutableAttributedString
 
 
            infoL.text = String(format: "有效期至 %@", paymentCouponModel.time)
            recordBtn.isHidden = true
            recordImg.isHidden = true
            companyL.isHidden = false
            companyL.text = paymentCouponModel.company
 
            switch paymentCouponModel.userType.rawValue {
                case 0:
                    nameL.text = "通用优惠券"
                    useRuleL.text = "快车/专车、出租车、跨城出行都可使用"
                    image_front_bg.image = UIImage.init(named: "bg_yellow_front")
                    break
                case 1:
                    nameL.text = "快车/专车优惠券"
                    useRuleL.text = "仅限快车使用"
                    image_front_bg.image = UIImage.init(named: "bg_green_front")
                    break
                case 2:
                    nameL.text = "出租车优惠券"
                    useRuleL.text = "仅限出租车使用"
                    image_front_bg.image = UIImage.init(named: "bg_blue_front")
                    break
                case 3:
                    nameL.text = "跨城出行优惠券"
                    useRuleL.text = "仅限跨城出行使用"
                    image_front_bg.image = UIImage.init(named: "bg_red_front")
                    break
                case 4:
                    nameL.text = "小件物流优惠券"
                    useRuleL.text = "仅限小件物流使用"
                    image_front_bg.image = UIImage.init(named: "bg_red_front")
                    break
                default:
                    break
            }
            setNeedsLayout()
        }
    }
 
    var myMerchantCouponModel:MyMerchantCouponModel!{
        didSet{
            nameL.text = myMerchantCouponModel.name
 
            if !myMerchantCouponModel.endTime.isEmpty{
                let days = DateClass.dateDifference(DateClass.timeStringToDate(myMerchantCouponModel.endTime), from:Date())
                if days <= 0{
                    infoL.text = "已到期"
                }else if days > 0 && days <= 1.0{
                    infoL.text = String(format: "距离到期仅剩1天")
                }else{
                    infoL.text = String(format: "距离到期仅剩%.0lf天",days)
                }
            }
 
            if myMerchantCouponModel.type == .goods{
                useRuleL.text = myMerchantCouponModel.content.filterHTML()
                moneyL.attributedText = AttributedStringbuilder.build()
                    .add(string: "领取券", withFont: UIFont.init(name: Semibold, size: 30)!, withColor: UIColor.white).mutableAttributedString
            }else{
                useRuleL.text = String(format: "店铺购买满%@元使用", myMerchantCouponModel.fullAmount.ld_formatFloat)
 
                moneyL.attributedText = AttributedStringbuilder.build()
                    .add(string: "¥", withFont: UIFont.init(name: Semibold, size: 18)!, withColor: UIColor.white)
                    .add(string: String(format: "%.2lf", myMerchantCouponModel.discount), withFont: UIFont.init(name: Semibold, size: 33)!, withColor: UIColor.white).mutableAttributedString
            }
            layoutSubviews()
        }
    }
 
    var type:ActiveStatus = .ongoing{
        didSet{
            if type == .ongoing{
                image_front_bg.image = UIImage(named: "bg_yellow_front")
                invaildImg.isHidden = true
            }else{
                image_front_bg.image = UIImage(named: "bg_gray_front")
                invaildImg.isHidden = false
            }
        }
    }
 
    @IBOutlet weak var image_front_bg: UIImageView!
    @IBOutlet weak var moneyL: UILabel!
    @IBOutlet weak var nameL: UILabel!
    @IBOutlet weak var infoL: UILabel!
    @IBOutlet weak var useRuleL: UILabel!
    @IBOutlet weak var recordBtn: UIButton!
    @IBOutlet weak var recordImg: UIImageView!
    @IBOutlet weak var checkImg: UIImageView!
    @IBOutlet weak var invaildImg: UIImageView!
    @IBOutlet weak var companyL: UILabel!
 
 
    override func awakeFromNib() {
        super.awakeFromNib()
        selectionStyle = .none
    }
 
    override var isSelected: Bool{
        didSet{
            if isSelected{
                checkImg.image = UIImage(named: "icon_raidobutton_selected")
            }else{
                checkImg.image = UIImage(named: "icon_raidobutton")
            }
        }
    }
 
    //    @IBAction func recordAction(_ sender: UIButton) {
    //
    //
    //    }
}