无故事王国
2023-11-01 b3269976c84d03208f633cd0136a6f78e8dd53f7
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//
//  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 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 cons_img1Height: 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
                }
 
                let imgs = m.detailDrawing.components(separatedBy: ",")
                var items = [CommonBannerModel]()
                for (index,img) in imgs.enumerated(){
                    items.append(CommonBannerModel(index: index,resource: img,mediaType: .imageUrl))
                }
                view_banner.setItems(items: items)
 
                if let subM = m.list.first {
                    switch subM.payType {
                        case .coin:
                            label_price.text = ""
                            label_price.isHidden = true
                            label_originPrice.isHidden = true
                            label_vipPrice.isHidden = true
 
                            //玩湃币
                            label_coin.attributedText = AttributedStringbuilder.build()
                                .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                                .add(string: "\(subM.playPaiCoin )币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")).mutableAttributedString
 
                        case .cash:
                            label_coin.isHidden = true;fallthrough
                        case .cashCoin:
                            if subM.originalPrice == 0{label_originPrice.isHidden = true}
                            label_originPrice.isHidden = (subM.paymentPrice == subM.originalPrice && subM.paymentPrice != 0 && subM.originalPrice != 0)
                                //玩湃币
                            label_coin.attributedText = AttributedStringbuilder.build()
                                .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                                .add(string: "\(subM.playPaiCoin )币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")).mutableAttributedString
 
                                //原价
                            let attribute = AttributedStringbuilder.build().add(string: subM.originalPrice.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 UserInfoModel.get()?.isVip == 1{
                                    //会员
                                label_vipPrice.isHidden = true
                                if subM.paymentPrice < subM.vipPrice && subM.paymentPrice != 0{
                                    label_price.text = subM.paymentPrice.currency()
                                }else if subM.vipPrice < subM.paymentPrice && subM.vipPrice != 0{
                                    label_price.text = subM.vipPrice.currency()
                                }else{
                                    label_price.text = subM.paymentPrice.currency()
                                }
                            }else{
                                    //非会员
                                label_vipPrice.isHidden = subM.vipPrice == 0 || subM.vipPrice == subM.paymentPrice
                                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 subM.originalPrice != 0 && subM.paymentPrice == 0{
                                    label_price.text = subM.originalPrice.currency()
                                }else if subM.originalPrice == 0 && subM.paymentPrice != 0{
                                    label_price.text = subM.paymentPrice.currency()
                                }else{
                                    label_price.text = min(subM.originalPrice,subM.paymentPrice).currency()
                                }
                            }
                    }
                }
 
                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)
           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")
        }
    }
}