//
|
// 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)
|
}
|
}
|