无故事王国
2023-10-18 e86e19e5e5909f46e09adec1df430e0214a81590
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//
//  CourseDetailVC.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/9.
//
 
import UIKit
import QMUIKit
import JQTools
 
class CourseDetailVC: BaseVC {
 
    @IBOutlet weak var view_banner: CommonBannerView!
        //    @IBOutlet weak var img_cover: UIImageView!
    @IBOutlet weak var label_title: UILabel!
    @IBOutlet weak var label_local: UILabel!
    @IBOutlet weak var label_distance: UILabel!
    @IBOutlet weak var label_listenWeek: UILabel!
    @IBOutlet weak var view_listen: UIView!
    @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_courseType: UILabel!
    @IBOutlet weak var label_vaildTime: UILabel!
    @IBOutlet weak var view_vaildTime: UIView!
    @IBOutlet weak var view_handle: 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!
    @IBOutlet weak var cons_handleHei: NSLayoutConstraint!
    @IBOutlet weak var btn_enroll: UIButton!
    @IBOutlet weak var view_tag: UIView!
    
    private var id = 0
 
    private var signUpCourseModel:SignUpCourseItemDetailModel?
    private var detailModel:CourseDetailModel?{
        didSet{
 
            if let m = detailModel{
                label_title.text = m.name
                label_distance.text = String(format: "距离我%.2lfkm", m.distance)
                label_local.text = String(format: "%@(%@)", m.storeName,m.storeAddress)
                label_listenWeek.text = "每" + m.weeks.joined(separator: "、")
                label_listenTime.text = m.times.joined(separator: "|")
                label_vaildTime.text = m.time
                label_courseType.text = m.type.strTitle
                label_courseType.isHidden = m.type == .none
                view_vaildTime.isHidden = m.type == .normal
                label_price.isHidden = (m.list.first?.paymentPrice ?? 0) == 0
 
                let w = String.jq_getWidth(text: m.type.strTitle, height: 25, font: 14)
                label_courseType.jq_cornerPartWithNib(byRoundingCorners: [.topLeft,.bottomLeft], radii: 8, size: CGSize(width: w, height: 25))
                label_courseType.layoutIfNeeded()
 
                img_1.sd_setImage(with: URL(string: m.introduceDrawing)) { image, error, type, url in
                    let radio = image!.size.width / image!.size.height
                    self.cons_img1Height.constant = JQ_ScreenW / radio
                }
 
                view_banner.setImages(images: m.detailDrawing.components(separatedBy: ","), type: .URL) { index in
 
                }
 
                label_price.text = m.list.first!.paymentPrice.currency()
                if let subM = m.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 == 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 subM.vipPrice != 0{
                        let vipAttribute = AttributedStringbuilder.build()
                            .add(string: "会员价:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                            .add(string: subM.vipPrice.currency(), withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313"))
                        label_vipPrice.attributedText = vipAttribute.mutableAttributedString
                    }
                }
 
                if m.type == .experience{
                    label_price.text = (m.list.first?.paymentPrice ?? 0).currency()
                    label_vaildTime.text = "购买当天有效"
                    label_originPrice.alpha = 0
                    label_vipPrice.alpha = 0
                    view_listen.alpha = 0
                    view_listen.isHidden = true
                    label_price.isHidden = (m.list.first?.paymentPrice ?? 0) == 0
                }
 
                    //体验课,假期课不展示
                if m.type != .normal && signUpCourseModel != nil{
                    view_handle.isHidden = true
                    cons_handleHei.constant = 0
                }
            }
        }
    }
 
    required init(id:Int,signUpCourseModel:SignUpCourseItemDetailModel? = nil) {
        super.init(nibName: nil, bundle: nil)
        self.id = id
        self.signUpCourseModel = signUpCourseModel
    }
 
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "课程详情"
 
        if signUpCourseModel?.payStatus == 1{
            btn_enroll.setTitle("待支付", for: .normal)
        }else if signUpCourseModel?.payStatus == 2{
            btn_enroll.setTitle("续课", for: .normal)
        }
 
        Services.queryCourseInfo(id: id).subscribe(onNext: { data in
            if let m = data.data{
                self.detailModel = m
            }
        }).disposed(by: disposeBag)
    }
    
    override func setUI() {
 
    }
 
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let w = String.jq_getWidth(text: detailModel?.type.strTitle ?? "", height: 25, font: 14) + 16
        view_tag.jq_addCorners(corner: [.topLeft,.bottomLeft], radius: 4, width: w, height: 25)
    }
 
    @IBAction func applyAction(_ sender: UIButton) {
 
        //待支付订单
        if let m = signUpCourseModel,m.payStatus == 1{
 
 
            return
        }
 
 
        if let m = detailModel{
            let vc = CourseDetailApplyVC(detailModel: m,isExtend: true)
           push(vc: vc)
        }
    }
    
    
    @IBAction func localAction(_ sender: UIButton) {
        if let m = detailModel{
            JQ_MapNavigationTool.startNav(CLLocationCoordinate2D(latitude: m.lat.toDouble, longitude: m.lon.toDouble), distanceName: m.storeAddress, scheme: "weparklife")
        }
    }
}