无故事王国
2023-09-18 b395e5ea758b24803743535f86bf443765237551
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
//
//  CourseDetailVC.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/9.
//
 
import UIKit
import QMUIKit
import JQTools
 
class CourseDetailVC: BaseVC {
 
    @IBOutlet weak var img_cover: UIImageView!
    @IBOutlet weak var label_title: UILabel!
    @IBOutlet weak var btn_local: QMUIButton!
    @IBOutlet weak var label_distance: UILabel!
    @IBOutlet weak var label_listenWeek: UILabel!
    @IBOutlet weak var label_listenTime: UILabel!
    @IBOutlet weak var img_1: UIImageView!
    @IBOutlet weak var img_2: UIImageView!
    @IBOutlet weak var cons_img1Height: NSLayoutConstraint!
    @IBOutlet weak var cons_img2Height: NSLayoutConstraint!
    @IBOutlet weak var label_type: UILabel!
    @IBOutlet weak var label_courseType: UILabel!
    @IBOutlet weak var label_vaildTime: UILabel!
    @IBOutlet weak var view_vaildTime: UIView!
    
    @IBOutlet weak var label_price: UILabel!
    @IBOutlet weak var label_originPrice: UILabel!
    @IBOutlet weak var label_vipPrice: UILabel!
    @IBOutlet weak var label_coin: UILabel!
 
    private var id = 0
    private var detailModel:CourseDetailModel!{
        didSet{
            img_cover.sd_setImage(with: URL(string: detailModel.coverDrawing))
            label_title.text = detailModel.name
            label_distance.text = String(format: "距离我%.2lfkm", detailModel.distance)
            btn_local.setTitle(detailModel.storeAddress, for: .normal)
            label_listenWeek.text = detailModel.weeks.joined(separator: "、")
            label_listenTime.text = detailModel.times.joined(separator: "|")
            label_vaildTime.text = detailModel.time
            label_courseType.text = detailModel.type.strTitle
            label_courseType.isHidden = detailModel.type == .none
            view_vaildTime.isHidden = detailModel.type == .normal
 
            img_1.sd_setImage(with: URL(string: detailModel.introduceDrawing)) { image, error, type, url in
                let radio = image!.size.width / image!.size.height
                self.cons_img1Height.constant = JQ_ScreenH * radio
 
            }
 
            img_2.sd_setImage(with: URL(string: detailModel.detailDrawing)) { image, error, type, url in
                let radio = image!.size.width / image!.size.height
                self.cons_img2Height.constant = JQ_ScreenH * radio
            }
 
            label_price.text = detailModel.list.first!.paymentPrice.currency()
            if let subM = detailModel.list.first {
                label_originPrice.isHidden = subM.originalPrice == nil || subM.originalPrice == 0
                label_coin.isHidden = subM.playPaiCoin == nil || subM.playPaiCoin == 0
                label_vipPrice.isHidden = subM.vipPrice == nil || subM.vipPrice == 0
 
                    //原价
                if let originPrice =  subM.originalPrice{
                    let attribute = AttributedStringbuilder.build().add(string: originPrice.currency(), withFont: UIFont.systemFont(ofSize: 16, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58)).delLine(color: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58))
                    label_originPrice.attributedText = attribute.mutableAttributedString
                }
 
 
                    //玩湃币
                if let paiCoin = subM.playPaiCoin{
                    let coinAttribute = AttributedStringbuilder.build()
                        .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                        .add(string: "\(paiCoin)币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313"))
                    label_coin.attributedText = coinAttribute.mutableAttributedString
                }
 
                //会员价
                if let vipPrice = subM.vipPrice{
                    let vipAttribute = AttributedStringbuilder.build()
                        .add(string: "会员价:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                        .add(string: vipPrice.currency(), withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313"))
                    label_vipPrice.attributedText = vipAttribute.mutableAttributedString
                }
            }
 
            if detailModel.type == .experience{
                label_courseType.text = "购买当天有效"
                label_price.text = (detailModel.list.first?.originalPrice ?? 0).currency()
                label_originPrice.isHidden = true
                label_vipPrice.isHidden = true
            }
        }
    }
 
    required init(id:Int) {
        super.init(nibName: nil, bundle: nil)
        self.id = id
    }
 
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "课程详情"
 
        Services.queryCourseInfo(id: id).subscribe(onNext: { data in
            if let m = data.data{
                self.detailModel = m
            }
        }).disposed(by: disposeBag)
    }
    
    override func setUI() {
        btn_local.imagePosition = .left
        btn_local.spacingBetweenImageAndTitle = 5
    }
 
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        label_type.jq_addCorners(corner: [.topLeft,.bottomLeft], radius: 4, width: 58, height: 25)
    }
 
    @IBAction func applyAction(_ sender: UIButton) {
        if let m = detailModel{
            let vc = CourseDetailApplyVC(detailModel: m)
           push(vc: vc)
        }
    }
    
    
    @IBAction func localAction(_ sender: QMUIButton) {
        JQ_MapNavigationTool.startNav(CLLocationCoordinate2D(latitude: detailModel.lat.toDouble, longitude: detailModel.lon.toDouble), distanceName: detailModel.storeAddress, scheme: "weparklife")
    }
}