CNLiveShopGoodsDetailsTableHeaderView.swift
13 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//
// CNLiveShopGoodsDetailsTableHeaderView.swift
// metaCode
//
// Created by zx on 2024/3/13.
//
import Foundation
import YYImage
import BKCycleScrollView
typealias clickGiveGiftCallBackBlock = () -> Void
// MARK: - 顶部轮播图
class CNLiveShopGoodsDetailsTableHeaderView:UIView{
let kCNLliveShopDetailBannerCellID = "kCNLliveShopDetailBannerCellID"
/// 顶部轮播图
lazy var bannerView: BKCycleScrollView = {
let bannerView = BKCycleScrollView(frame: CGRect(x: 0, y: 0, width: self.width, height: self.width))
// bannerView.placeholderImage = [UIImage get1_1PlaceholderImage];
bannerView.isAutoScroll = false
return bannerView
}()
/// 数据
var _detailsModel:CNLiveShopGoodsDetailsModel?
var detailsModel:CNLiveShopGoodsDetailsModel?{
get{
_detailsModel
}
set{
_detailsModel = newValue!
let bannerDataArr = NSMutableArray()
if _detailsModel?.video?.video_url?.count ?? 0 > 0{
let model = BKCycleScrollDataModel()
model.videoUrl = _detailsModel!.video!.video_url!
model.imageUrl = _detailsModel?.video?.video_img ?? ""
model.image = _detailsModel?.video?.video_image ?? UIImage()
bannerDataArr.add(model)
}
for imageModel in detailsModel!.image {
let model = BKCycleScrollDataModel()
model.imageUrl = imageModel.simg ?? ""
bannerDataArr.add(model)
}
self.bannerView.displayDataArr = bannerDataArr as? [BKCycleScrollDataModel]
self.titleLab.text = self.detailsModel?.title
self.titleLab.height = self.titleLab.text?.calculateHeightWith(width: self.titleLab.width, font: self.titleLab.font) ?? 0
self.subtitleLab.text = self.detailsModel?.ads
self.subtitleLab.y = self.titleLab.bottom+15
self.subtitleLab.height = self.subtitleLab.text?.calculateHeightWith(width: self.titleLab.width, font: self.titleLab.font) ?? 0
self.initTopStyleSubUI()
self.initGuigeSubUI()
self.initBottomDescSubUI()
self.height = self.bottomDescView.bottom
}
}
/**
点击送礼回调
*/
var clickGiveGiftBlock:clickGiveGiftCallBackBlock?
lazy var titleLab: UILabel = {
let titleLab = UILabel.init(frame: CGRectMake(20, self.bannerView.bottom+15, self.width-40, 0))
titleLab.textColor = HexColor("#3a3a3a")
titleLab.textAlignment = .center
titleLab.numberOfLines = 0
titleLab.font = Font_17
titleLab.adjustsFontSizeToFitWidth=true
return titleLab
}()
lazy var subtitleLab: UILabel = {
let subtitleLab = UILabel.init(frame: CGRectMake(20, self.titleLab.bottom+15, self.width-40, 0))
subtitleLab.textColor = HexColor("#828282")
subtitleLab.textAlignment = .center
subtitleLab.numberOfLines = 0
subtitleLab.font = Font_14
subtitleLab.adjustsFontSizeToFitWidth=true
return subtitleLab
}()
lazy var topStyleView :UIView = {
let topStyleView = UIView(frame: CGRect(x: 0, y: self.subtitleLab.bottom+15, width: self.width, height: 0))
return topStyleView
}()
lazy var guigeView :UIView = {
let guigeView = UIView(frame: CGRect(x: 0, y: self.topStyleView.bottom, width: self.width, height: 0))
return guigeView
}()
lazy var bottomDescView :UIView = {
let bottomDescView = UIView(frame: CGRect(x: 0, y: self.guigeView.bottom, width: self.width, height: 0))
return bottomDescView
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .white
self.initUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func initUI(){
self.addSubview(self.bannerView)
self.addSubview(self.titleLab)
self.addSubview(self.subtitleLab)
self.addSubview(self.topStyleView)
self.addSubview(self.guigeView)
self.addSubview(self.bottomDescView)
}
func initTopStyleSubUI(){
self.topStyleView.subviews.forEach { $0.removeFromSuperview() }
self.topStyleView.y = (self.detailsModel?.ads?.count ?? 0 > 0 ? self.subtitleLab.bottom : self.titleLab.bottom)+15
let priceLabel = UILabel(frame: CGRect(x: 20, y: 0, width: KSreenWidth-20*2, height: 55))
priceLabel.textColor = HexColor("#ff725c")
priceLabel.font = SystemFont_Fit(45)
priceLabel.text = String(format: "¥%@", self.detailsModel?.price ?? 0)
priceLabel.textAlignment = .center
self.topStyleView.addSubview(priceLabel)
self.topStyleView.height = 55
if self.detailsModel?.prices?.count ?? 0 > 0 && Float(self.detailsModel?.prices ?? "0") ?? 0 > Float(self.detailsModel?.price ?? "0") ?? 0{
let originalPriceLab = UILabel(frame: CGRect(x: 20, y: self.topStyleView.height, width: KSreenWidth-20*2, height: 20))
originalPriceLab.textColor = HexColor("#999999")
originalPriceLab.font = Font_14
originalPriceLab.textAlignment = .center
let originalPrice = NSAttributedString(string: String(format: " ¥%@ ", self.detailsModel?.prices ?? "0"), attributes: [NSAttributedString.Key.strikethroughStyle:NSUnderlineStyle.single ])
originalPriceLab.attributedText = originalPrice
self.topStyleView.addSubview(originalPriceLab)
self.topStyleView.height = self.topStyleView.height+20
}
if self.detailsModel?.is_gift == true{
let fAdsImageView = YYAnimatedImageView(frame: CGRect(x: 0, y: self.topStyleView.height+15, width: self.width, height: 50))
fAdsImageView.clipsToBounds = true
fAdsImageView.contentMode = .scaleAspectFill
fAdsImageView.isUserInteractionEnabled = true
fAdsImageView.kf.setImage(with: URL(string: self.detailsModel?.give_goods_img ?? ""))
self.topStyleView.addSubview(fAdsImageView)
let giveGoodsTap = UITapGestureRecognizer(target: self, action: #selector(giveGoodsTap))
fAdsImageView.addGestureRecognizer(giveGoodsTap)
self.topStyleView.height = self.topStyleView.height + 15 + 50
}
self.topStyleView.height = self.topStyleView.height + 20
let line = YYAnimatedImageView(frame: CGRect(x: 20, y: self.topStyleView.height-DS_RRV_ONE_PIXEL, width: self.topStyleView.width-40, height: DS_RRV_ONE_PIXEL))
line.backgroundColor = HexColor("#e4e4e4")
self.topStyleView.addSubview(line)
}
func initGuigeSubUI(){
self.guigeView.y = self.topStyleView.bottom
self.guigeView.subviews.forEach { $0.removeFromSuperview() }
let titleDataArr = NSMutableArray()
if self.detailsModel?.attr.count ?? 0 > 0{
for i in 0..<(self.detailsModel?.attr.count ?? 0){
let model = self.detailsModel?.attr[i]
if model?.k?.count ?? 0 > 0 && model?.v?.count ?? 0 > 0{
titleDataArr.add(["left":model!.k,"right":model!.v])
}
}
}
if self.detailsModel?.attrArray.count ?? 0 > 0{
for i in 0..<(self.detailsModel?.attrArray.count ?? 0){
let dict = self.detailsModel?.attrArray[i]
let k = dict?["k"] as? String
let v = dict?["v"] as? String
if k?.count ?? 0 > 0 && v?.count ?? 0 > 0{
titleDataArr.add(["left":(dict?["k"] as! String),"right":(dict?["v"] as! String)])
}
}
}
if self.detailsModel?.storageArray.count ?? 0 > 0{
for i in 0..<(self.detailsModel?.storageArray.count ?? 0){
let dict = self.detailsModel?.storageArray[i]
let k = dict?["k"] as? String
let v = dict?["v"] as? String
if k?.count ?? 0 > 0 && v?.count ?? 0 > 0{
titleDataArr.add(["left":(dict?["k"] as! String),"right":(dict?["v"] as! String)])
}
}
}
if titleDataArr.count == 0{
self.guigeView.height = 0
return
}
let markLine = YYAnimatedImageView(frame: CGRect(x: 120, y: 0, width: self.guigeView.width-240, height: DS_RRV_ONE_PIXEL))
markLine.backgroundColor = HexColor("#b4b4b4")
self.guigeView.addSubview(markLine)
let markLab = UILabel(frame: CGRect(x: markLine.left+(markLine.width-87.5)/2, y: 17, width: 87.5, height: 20))
markLab.textColor = HexColor("#666666")
markLab.textAlignment = .center
markLab.numberOfLines = 0
markLab.font = Font_14
markLab.backgroundColor = .white
markLab.text = "已选规格"
self.guigeView.addSubview(markLab)
markLine.centerY = markLab.centerY
var lastView:UIView?
for i in 0..<titleDataArr.count {
let dic = titleDataArr[i] as! Dictionary<String, Any>
let view = UIView(frame: CGRect(x: 20, y: (lastView != nil) ? lastView!.bottom : (markLab.bottom+13), width: self.guigeView.width-40, height: 35))
self.guigeView.addSubview(view)
let leftLab = UILabel(frame: CGRect(x: 25, y: 0, width: 60, height: 35))
leftLab.textColor = HexColor("#6d6d6d")
leftLab.textAlignment = .center
leftLab.numberOfLines = 0
leftLab.font = Font_14
leftLab.text = dic["left"] as? String
view.addSubview(leftLab)
leftLab.height = (leftLab.text?.calculateHeightWith(width: leftLab.width, font:leftLab.font) ?? 0) + 15
let rightLab = UILabel(frame: CGRect(x: 125, y: 0, width: 195, height: 35))
rightLab.textColor = HexColor("#aaaaaa")
rightLab.textAlignment = .center
rightLab.numberOfLines = 0
rightLab.font = Font_14
rightLab.text = dic["right"] as? String
view.addSubview(rightLab)
rightLab.height = (rightLab.text?.calculateHeightWith(width: rightLab.width, font: rightLab.font) ?? 0) + 15
if rightLab.height > leftLab.height{
view.height = rightLab.height
}else{
view.height = leftLab.height
}
let line = YYAnimatedImageView(frame: CGRect(x: 0, y: 0, width: view.width, height: DS_RRV_ONE_PIXEL))
line.backgroundColor = HexColor("#d4d4d4")
view.addSubview(line)
lastView = view
}
let leftLine = YYAnimatedImageView(frame: CGRect(x: lastView!.x, y: markLab.bottom+13, width: DS_RRV_ONE_PIXEL, height: lastView!.bottom-(markLab.bottom+13)))
leftLine.backgroundColor = HexColor("#d4d4d4")
self.guigeView.addSubview(leftLine)
let middleLine = YYAnimatedImageView(frame: CGRect(x: lastView!.x+108, y: markLab.bottom+13, width: DS_RRV_ONE_PIXEL, height: lastView!.bottom-(markLab.bottom+13)))
middleLine.backgroundColor = HexColor("#d4d4d4")
self.guigeView.addSubview(middleLine)
let rightLine = YYAnimatedImageView(frame: CGRect(x: lastView!.right-DS_RRV_ONE_PIXEL, y: markLab.bottom+13, width: DS_RRV_ONE_PIXEL, height: lastView!.bottom-(markLab.bottom+13)))
rightLine.backgroundColor = HexColor("#d4d4d4")
self.guigeView.addSubview(rightLine)
let bottomLine = YYAnimatedImageView(frame: CGRect(x: lastView!.x, y: lastView!.bottom, width: lastView!.width, height: DS_RRV_ONE_PIXEL))
bottomLine.backgroundColor = HexColor("#d4d4d4")
self.guigeView.addSubview(bottomLine)
let line = YYAnimatedImageView(frame: CGRect(x: 20, y: bottomLine.bottom+20, width: self.guigeView.width-40, height: DS_RRV_ONE_PIXEL))
line.backgroundColor = HexColor("#e4e4e4")
self.guigeView.addSubview(line)
self.guigeView.height = line.bottom
}
func initBottomDescSubUI(){
self.bottomDescView.y = self.guigeView.bottom
self.bottomDescView.subviews.forEach { $0.removeFromSuperview() }
let markLine = YYAnimatedImageView(frame: CGRect(x: 120, y: 0, width: self.bottomDescView.width-240, height: DS_RRV_ONE_PIXEL))
markLine.backgroundColor = HexColor("#b4b4b4")
self.bottomDescView.addSubview(markLine)
let markLab = UILabel.init(frame: CGRectMake(markLine.left+(markLine.width-87.5)/2, 17, 87.5, 20))
markLab.textColor = HexColor("#666666")
markLab.textAlignment = .center
markLab.numberOfLines = 0
markLab.font = Font_14
markLab.backgroundColor = .white
markLab.text = "商品详情"
self.bottomDescView.addSubview(markLab)
markLine.centerY = markLab.centerY
self.bottomDescView.height = markLab.bottom+20
}
@objc func giveGoodsTap(){
if (self.clickGiveGiftBlock != nil){
self.clickGiveGiftBlock!()
}
}
}