CNLiveVodShopExpandCell.swift
10.4 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
//
// CNLiveVodShopExpandCell.swift
// metaCode
//
// Created by zx on 2025/3/21.
//
import Foundation
class CNLiveVodShopExpandCell: UITableViewCell {
//
var _vodPlayShopModel : [CNLiveVodPlayShopModel]?
var vodPlayShopModel : [CNLiveVodPlayShopModel]? {
get{
_vodPlayShopModel
}
set{
_vodPlayShopModel = newValue!
for obj in contentView.subviews{
if obj.tag > 100{
obj.removeFromSuperview()
}
}
setupNewUI(model: _vodPlayShopModel!)
}
}
//默认电商商品list
var _albumModels : [CNLiveAlbumModel]?
var albumModels : [CNLiveAlbumModel]? {
get{
_albumModels
}
set{
_albumModels = newValue!
for obj in contentView.subviews{
if obj.tag > 100{
obj.removeFromSuperview()
}
}
self.setupNewUI(goodsModels: _albumModels!)
}
}
//MARK: - 懒加载
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
contentView.backgroundColor = .white
contentView.clipsToBounds = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//默认商品
func setupNewUI(goodsModels:[CNLiveAlbumModel]){
//总显示块数/循环数
let totalNum = goodsModels.count
//lieIndex 当前是contents的第0列还是第1列
var lieIndex = 0
//hangIndex 当前是第几行,1...n
var hangIndex = 1
let imgWH = (KSreenWidth-15*3)*0.5
let bottomH = 55.0
let rowH = imgWH+bottomH+15.0
for i in 0..<totalNum{//i是第几行
if lieIndex == 0{
//显示左边的块
let contentMdl = goodsModels[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, CGFloat(hangIndex-1)*rowH, CGFloat(imgWH), CGFloat(imgWH)))
imageView.kf.setImage(with: URL(string:contentMdl.poster))
imageView.tag = i+1000
imageView.layer.cornerRadius = 9
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFill
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
contentView.addSubview(imageView)
let titleStr = contentMdl.title
let subTitleStr = "¥\(contentMdl.numberModel?.price ?? "未知金额")"
let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 21))
titleLbl.font = BoldFont_15
titleLbl.textColor = HexColor("#333333")
titleLbl.text = titleStr
titleLbl.tag = i+1000
contentView.addSubview(titleLbl)
let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom, width: titleLbl.width, height: 24))
subTitleLbl.font = Font_17
subTitleLbl.textColor = HexColor("#E56E32")
subTitleLbl.text = subTitleStr
subTitleLbl.tag = i+1000
contentView.addSubview(subTitleLbl)
lieIndex = 1
}else{
//lieIndex==1显示右边的块
let contentMdl = goodsModels[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(CGFloat(DownSlideRecommendLeftGap*2)+CGFloat(imgWH), CGFloat(hangIndex-1)*rowH, CGFloat(imgWH), CGFloat(imgWH)))
imageView.kf.setImage(with: URL(string:contentMdl.poster))
imageView.tag = i+1000
imageView.layer.cornerRadius = 14
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFill
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
contentView.addSubview(imageView)
let titleStr = contentMdl.title
let subTitleStr = "¥\(contentMdl.numberModel?.price ?? "未知金额")"
let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 21))
titleLbl.font = BoldFont_15
titleLbl.textColor = HexColor("#333333")
titleLbl.text = titleStr
titleLbl.tag = i+1000
contentView.addSubview(titleLbl)
let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom, width: titleLbl.width, height: 24))
subTitleLbl.font = Font_17
subTitleLbl.textColor = HexColor("#E56E32")
subTitleLbl.tag = i+1000
subTitleLbl.text = subTitleStr
contentView.addSubview(subTitleLbl)
lieIndex = 0
hangIndex += 1
}
}
}
func setupNewUI(model:[CNLiveVodPlayShopModel]){
//总显示块数/循环数
let totalNum = model.count
//lieIndex 当前是contents的第0列还是第1列
var lieIndex = 0
//hangIndex 当前是第几行,1...n
var hangIndex = 1
let imgWH = (KSreenWidth-15*3)*0.5
let bottomH = 55.0
let rowH = imgWH+bottomH+15.0
for i in 0..<totalNum{//i是第几行
if lieIndex == 0{
//显示左边的块
let contentMdl = model[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, CGFloat(hangIndex-1)*rowH, CGFloat(imgWH), CGFloat(imgWH)))
imageView.kf.setImage(with: URL(string:contentMdl.img))
imageView.tag = i+1000
imageView.layer.cornerRadius = 9
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFill
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
contentView.addSubview(imageView)
let titleStr = contentMdl.title
let subTitleStr = "¥\(contentMdl.price)"
let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 21))
titleLbl.font = BoldFont_15
titleLbl.textColor = HexColor("#333333")
titleLbl.text = titleStr
titleLbl.tag = i+1000
contentView.addSubview(titleLbl)
let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom, width: titleLbl.width, height: 24))
subTitleLbl.font = Font_17
subTitleLbl.textColor = HexColor("#E56E32")
subTitleLbl.text = subTitleStr
subTitleLbl.tag = i+1000
contentView.addSubview(subTitleLbl)
lieIndex = 1
}else{
//lieIndex==1显示右边的块
let contentMdl = model[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(CGFloat(DownSlideRecommendLeftGap*2)+CGFloat(imgWH), CGFloat(hangIndex-1)*rowH, CGFloat(imgWH), CGFloat(imgWH)))
imageView.kf.setImage(with: URL(string:contentMdl.img))
imageView.tag = i+1000
imageView.layer.cornerRadius = 14
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFill
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
contentView.addSubview(imageView)
let titleStr = contentMdl.title
let subTitleStr = "¥\(contentMdl.price)"
let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 21))
titleLbl.font = BoldFont_15
titleLbl.textColor = HexColor("#333333")
titleLbl.text = titleStr
titleLbl.tag = i+1000
contentView.addSubview(titleLbl)
let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom, width: titleLbl.width, height: 24))
subTitleLbl.font = Font_17
subTitleLbl.textColor = HexColor("#E56E32")
subTitleLbl.tag = i+1000
subTitleLbl.text = subTitleStr
contentView.addSubview(subTitleLbl)
lieIndex = 0
hangIndex += 1
}
}
}
@objc func imgTapAction(ges: UITapGestureRecognizer){
let imageView = ges.view as! UIImageView
let i = imageView.tag-1000
if self.vodPlayShopModel?.count ?? 0 > 0{
let contentMdl = (self.vodPlayShopModel?[i])!
let urlString = hubilieDSHost+"pages/main/detail/detail?"+"id=\(contentMdl.id)&uid=\(UserInfoManager.shared.userInfo.uid)"
CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: kCNDownSlideContentsModelModelProduct , contentId: "" , pid: "" , shareUrl: "" , thirdUrl: urlString , title: contentMdl.title , s_to: "" ,trailerId: "" , controller: nil, slideModel: nil)
}else if self.albumModels?.count ?? 0 > 0{
let contentMdl = (self.albumModels?[i])!
let urlString = hubilieDSHost+"pages/main/detail/detail?"+"id=\(contentMdl.contentId)&uid=\(UserInfoManager.shared.userInfo.uid)"
CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: kCNDownSlideContentsModelModelProduct , contentId: "" , pid: "" , shareUrl: "" , thirdUrl: urlString , title: contentMdl.title , s_to: "" ,trailerId: "" , controller: nil, slideModel: nil)
}
}
}