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