杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//
//  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
 
                                                                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)
 
                                                                var tempSub = m.list.first
                                                                if signUpCourseModel?.chooseHours != nil{
                                                                                for v in m.list{
                                                                                                if v.classHours == signUpCourseModel?.chooseHours{
                                                                                                                tempSub = v;break
                                                                                                }
                                                                                }
                                                                }
 
                                                                if let subM = tempSub {
                                                                                switch subM.payType {
                                                                                                case .coin:
                                                                                                                label_price.text = ""
                                                                                                                label_price.isHidden = true
                                                                                                                label_originPrice.isHidden = true
                                                                                                                label_vipPrice.isHidden = true
                                                                                                                label_coin.isHidden = false
                                                                                                                //玩湃币
                                                                                                                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:
                                                                                                                fallthrough
                                                                                                case .cashCoin:
                                                                                                                if subM.originalPrice == 0 || subM.originalPrice == subM.paymentPrice{
                                                                                                                                label_originPrice.isHidden = true
                                                                                                                }else{
                                                                                                                                label_originPrice.isHidden = false
                                                                                                                }
                                                                                                                label_coin.isHidden = subM.payType == .cash
                                                                                                                //玩湃币
                                                                                                                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{
                                                                                                                                if subM.payType != .coin{
                                                                                                                                                //会员
                                                                                                                                                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 if subM.vipPrice != 0 && subM.paymentPrice != 0{
                                                                                                                                                                //会员价和优惠价一样
                                                                                                                                                                label_price.text = min(subM.vipPrice,subM.paymentPrice).currency()
                                                                                                                                                }else{
                                                                                                                                                                label_price.text = subM.paymentPrice.currency()
                                                                                                                                                }
                                                                                                                                }
                                                                                                                }else{
                                                                                                                                if subM.payType != .coin{
                                                                                                                                                //非会员
                                                                                                                                                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 if subM.originalPrice != 0 && subM.paymentPrice != 0{
                                                                                                                                                                label_price.text = min(subM.originalPrice,subM.paymentPrice).currency()
                                                                                                                                                }else{
                                                                                                                                                                label_price.text = subM.originalPrice.currency()
                                                                                                                                                }
                                                                                                                                }
                                                                                                                }
                                                                                }
                                                                }
 
                                                                if m.type == .experience{
 
                                                                                if  m.list.first?.paymentPrice != 0{
                                                                                                label_price.text = (m.list.first!.paymentPrice).currency()
                                                                                                label_price.isHidden = false
                                                                                }
 
                                                                                label_vaildTime.text = "购买当天有效"
                                                                                label_originPrice.isHidden = true
                                                                                label_vipPrice.isHidden = true
                                                                                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
                                                                }
 
                                                                //                if label_originPrice.isHidden && label_vipPrice.isHidden && label_coin.isHidden{
                                                                //                    label_coin.alpha = 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 == .unPayment{
                                                btn_enroll.setTitle("待支付", for: .normal)
                                }else if signUpCourseModel?.payStatus == .paymented{
                                                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 = detailModel{
                                                let vc = CourseDetailApplyVC(detailModel: m,signUpModel: signUpCourseModel)
                                                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")
                                }
                }
}