宽窄优行-由【嘉易行】项目成品而来
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
//
//  VerifiCouponVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/14.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
 
class VerifiCouponVC: YYViewController {
 
    var merchantVerifiCouponModel:MerchantVerifiCouponModel?
    @IBOutlet weak var moneyL: UILabel!
    @IBOutlet weak var nameL: UILabel!
    @IBOutlet weak var infoL: UILabel!
    @IBOutlet weak var userRuleL: UILabel!
    @IBOutlet weak var stateL: UILabel!
    @IBOutlet weak var userNameL: UILabel!
    @IBOutlet weak var phoneL: UILabel!
    @IBOutlet weak var useBtn: UIButton!
    @IBOutlet weak var couponImg: UIImageView!
    @IBOutlet weak var invalidImg: UIImageView!
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        useBtn.backgroundColor = UIColor.gray.withAlphaComponent(0.5)
        useBtn.isEnabled = false
        view.backgroundColor = UIColor(hexString: "#F3F4F5")
 
        if merchantVerifiCouponModel != nil{
            title = merchantVerifiCouponModel!.merchantName
            phoneL.text = merchantVerifiCouponModel!.phone
            nameL.text = merchantVerifiCouponModel!.name
 
            if !merchantVerifiCouponModel!.endTime.isEmpty{
                let days = DateClass.dateDifference(DateClass.timeStringToDate(merchantVerifiCouponModel!.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)
                }
            }
 
 
 
            switch merchantVerifiCouponModel!.status{
                case .agreent: //2
                    stateL.text = "失效"
                    useBtn.isEnabled = false
                    useBtn.backgroundColor = UIColor.gray.withAlphaComponent(0.5)
                    couponImg.image = UIImage(named: "bg_gray_front")
                    invalidImg.isHidden = false
                case .reject: // 3
                    stateL.text = "失效"
                    useBtn.isEnabled = false
                    useBtn.backgroundColor = UIColor.gray.withAlphaComponent(0.5)
                    couponImg.image = UIImage(named: "bg_gray_front")
                    invalidImg.isHidden = false
                case .waiting: //1
                    stateL.text = "有效"
                    useBtn.backgroundColor = UIColor(hexString: "#00BF30")
                    useBtn.isEnabled = true
                    couponImg.image = UIImage(named: "coupon_bg_front")
                    invalidImg.isHidden = true
                case .none:break
            }
 
            if merchantVerifiCouponModel!.type == .goods{
                moneyL.attributedText = AttributedStringbuilder.build()
                    .add(string: "领取券", withFont: UIFont.init(name: Semibold, size: 30)!, withColor: UIColor.white).mutableAttributedString
                userRuleL.text = merchantVerifiCouponModel!.content.filterHTML()
            }else{
                moneyL.attributedText = AttributedStringbuilder.build()
                    .add(string: "¥", withFont: UIFont.init(name: Semibold, size: 18)!, withColor: UIColor.white)
                    .add(string: String(format: "%.2lf", merchantVerifiCouponModel!.discount), withFont: UIFont.init(name: Semibold, size: 33)!, withColor: UIColor.white).mutableAttributedString
 
//                let money = "¥\(merchantVerifiCouponModel!.discount.ld_formatFloat)"
//                let attribute = NSMutableAttributedString(string: money)
//                attribute.addAttribute(.font, value: UIFont.systemFont(ofSize: 40, weight: .medium), range: NSRange(location: 1, length: money.count - 1))
//                moneyL.attributedText = attribute
                userRuleL.text = String(format: "店铺购买满%@元使用", merchantVerifiCouponModel!.fullAmount.ld_formatFloat)
            }
 
 
            userNameL.text = merchantVerifiCouponModel!.userName
        }
    }
 
    @IBAction func useCouponAction(_ sender: UIButton) {
        show()
        APIManager.shared.provider.rx.request(.writeOffMerchantCoupon(code: merchantVerifiCouponModel!.code)).map(YYModel<Nothing>.self).validate().subscribe { data in
            self.hide()
            self.stateL.text = "失效"
            self.merchantVerifiCouponModel!.status = .agreent
            self.invalidImg.isHidden = false
            self.useBtn.isEnabled = false
            self.useBtn.backgroundColor = UIColor.gray.withAlphaComponent(0.5)
            self.couponImg.image = UIImage(named: "bg_gray_front")
            UseCouponSuccessView.show { [weak self] () in
                guard let weakSelf = self else { return }
                var jumpVC:UIViewController?
                var subIndex = 0
                for (index,subVC) in weakSelf.navigationController!.viewControllers.enumerated(){
                    if subVC is MerchantVC{
                        jumpVC = subVC
                        subIndex = index
                        break
                    }
                }
                if jumpVC != nil{
                    weakSelf.yy_popToVC(index: subIndex)
                    NotificationCenter.default.post(name: MerchantListRefresh_Noti, object: 0)
                }else{
                    let vc = MerchantVC()
                    self?.yy_push(vc: vc)
                }
            }
        } onError: { error in
            self.hide()
            alert(text: error.localizedDescription)
        }.disposed(by: disposeBag)
    }
}