宽窄优行-由【嘉易行】项目成品而来
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
//
//  MineCouponsDetailVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/15.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
import RxCocoa
import RxSwift
 
class MineCouponsDetailVC: YYViewController {
 
    @IBOutlet weak var priceL: UILabel!
    @IBOutlet weak var nameL: UILabel!
    @IBOutlet weak var infoL: UILabel!
    @IBOutlet weak var info1L: UILabel!
    @IBOutlet weak var merchantImg: UIImageView!
    @IBOutlet weak var merchantNameL: UILabel!
    @IBOutlet weak var merchantAddressL: UILabel!
    @IBOutlet weak var userNameL: UILabel!
    @IBOutlet weak var phoneL: UILabel!
    @IBOutlet weak var qrCodeImg: UIImageView!
    @IBOutlet weak var couponBgImg: UIImageView!
 
    var couponState:CouponStateType = .overdue
 
    public var myMerchantCouponModel:MyMerchantCouponModel?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "我的优惠券"
 
        priceL.adjustsFontSizeToFitWidth = true
        priceL.minimumScaleFactor = 0.5
        view.backgroundColor = UIColor(hexString: "#F3F4F5")
 
        if myMerchantCouponModel != nil{
 
            if myMerchantCouponModel!.type == .goods{
                priceL.attributedText = AttributedStringbuilder.build()
                    .add(string: "领取券", withFont: UIFont.init(name: Semibold, size: 30)!, withColor: UIColor.white).mutableAttributedString
                info1L.text = myMerchantCouponModel!.content.filterHTML()
            }else{
                info1L.text = String(format: "店铺购买满%@元使用", myMerchantCouponModel!.fullAmount.ld_formatFloat)
 
                priceL.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
            }
 
            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)
                }
            }
 
            merchantImg.load(url: myMerchantCouponModel!.headImg)
            merchantNameL.text = myMerchantCouponModel!.merchantName
            merchantAddressL.text = "商家地址:\(myMerchantCouponModel!.address)"
            userNameL.text = "姓名:\(myMerchantCouponModel!.contactName)"
            phoneL.text = "电话:\(myMerchantCouponModel!.contactPhone)"
            qrCodeImg.image = createQRForString(qrString: "merchantCoupon:\(myMerchantCouponModel!.code)", qrImageName: nil)
        }
 
        switch couponState{
            case .unuse:
                couponBgImg.image = UIImage(named: "coupon_bg_front")
            case .overdue,.used:
                couponBgImg.image = UIImage(named: "bg_gray_front")
        }
    }
}