CNLiveHomeTwoShopCell.swift
8.6 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
//
// CNLiveHomeTwoShopCell.swift
// metaCode
//
// Created by zx on 2025/3/6.
// type29官方周边cell
import Foundation
class CNLiveHomeTwoShopCell: UITableViewCell {
//slideModel
var _slideModel : CNLiveDownSlideModel?
var slideModel : CNLiveDownSlideModel? {
get{
_slideModel
}
set{
_slideModel = newValue!
for obj in contentView.subviews{
if obj.tag > 100{
obj.removeFromSuperview()
}
}
setupNewUI(model: _slideModel!)
}
}
//MARK: - 懒加载
lazy var titleLabel: UILabel = {
let titleLbl = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y: 0, width: KSreenWidth-15-50, height: 25))
titleLbl.font = BoldFont_18
titleLbl.textColor = HexColor("#000102")
return titleLbl
}()
//more
lazy var detailBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .clear
expandBtn.frame = CGRect(x: KSreenWidth-50, y: self.titleLabel.top, width: 50, height: 24)
expandBtn.setImage(UIImage(named: "home_player_more"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_more"), for: .highlighted)
expandBtn.addTarget(self, action: #selector(detailBtnAction), for: .touchUpInside)
return expandBtn
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
contentView.backgroundColor = .clear
self.backgroundColor = .clear
contentView.clipsToBounds = true
contentView.addSubview(self.titleLabel)
contentView.addSubview(self.detailBtn)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupNewUI(model:CNLiveDownSlideModel){
self.titleLabel.text = model.blockName
var titleBottom:CGFloat = 40.0
if model.showType == "1"{
//不展示标题 和按钮
titleBottom = 0.0
self.detailBtn.isHidden = true
self.titleLabel.isHidden = true
}else{
//展示标题
self.titleLabel.isHidden = false
if (model.moreUrl.count > 0) && (model.moreType.count > 0){
//展示更多按钮
self.detailBtn.isHidden = false
titleBottom = 40.0
}else{
//不展示更多按钮
self.detailBtn.isHidden = true
titleBottom = 40.0
}
}
//总块数
let contentsNum = model.contents.count
//model行数
let row = model.rowNum
//总显示块数/循环数
var totalNum = (contentsNum >= row*2) ? row*2 : contentsNum
if row == 0{//row为0 , contents全部显示
totalNum = contentsNum
}
//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.contents[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, titleBottom+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)
var titleStr = contentMdl.title
var subTitleStr = "¥"
if contentMdl.number.count > 0{
if let numberMdl = jsonToModel(contentMdl.number, CNLiveDownSlideContentsNumerModel.self) as? CNLiveDownSlideContentsNumerModel{
subTitleStr = "¥"+numberMdl.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.contents[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(CGFloat(DownSlideRecommendLeftGap*2)+CGFloat(imgWH), CGFloat(titleBottom)+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)
var titleStr = contentMdl.title
var subTitleStr = "¥"
if contentMdl.number.count > 0{
if let numberMdl = jsonToModel(contentMdl.number, CNLiveDownSlideContentsNumerModel.self) as? CNLiveDownSlideContentsNumerModel{
subTitleStr = "¥"+numberMdl.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 detailBtnAction(){
if self.slideModel?.moreType == "1"{
//原生
let vc = CNLiveHomeMoreController()
vc.slideModel = self.slideModel
currentViewController()?.navigationController?.pushViewController(vc, animated: true)
}else if self.slideModel?.moreType == "3"{
//webView moreurl
CNLiveDownSlideTool.pushWebVCWithContentsMdl(model: "3", contentId: "", pid: "", shareUrl: "", thirdUrl: self.slideModel?.moreUrl ?? "", title: "", s_to: "", trailerId: "", controller: nil, slideModel: nil)
}else{
}
}
@objc func imgTapAction(ges: UITapGestureRecognizer){
let imageView = ges.view as! UIImageView
let i = imageView.tag-1000
let contentMdl = (self.slideModel?.contents[i])!
let urlString = "https://managemall.cnlive.com/html/mall/1/#/pages/main/detail/detail?"+"id=\(contentMdl.contentId)&uid=\(UserInfoManager.shared.userInfo.uid)"
CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: contentMdl.model , contentId: contentMdl.contentId , pid: contentMdl.pid , shareUrl: contentMdl.shareUrl , thirdUrl: urlString , title: contentMdl.title , s_to: contentMdl.s_to ,trailerId: contentMdl.trailerId , controller: nil, slideModel: nil)
}
}