CNLiveTVHomeViewController.swift
34.5 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
//
// CNLiveTVHomeViewController.swift
// metaCode
//
// Created by zx on 2025/2/17.
// 忽必烈电视剧改版首页
import Foundation
import QMUIKit
import MJRefresh
import CNLiveShareToolKit
class CNLiveTVHomeViewController:CNLiveBaseViewController, UITableViewDataSource, UITableViewDelegate{
let kCNLiveHomeYingshiBannerCellIdentifier = "kCNLiveHomeYingshiBannerCellIdentifier"
let kCNLiveHomeLanmuCellIdentifier = "kCNLiveHomeLanmuCellIdentifier"
let kCNLiveHomeOneBigTwoSmallCellIdentifier = "kCNLiveHomeOneBigTwoSmallCellIdentifier"
let kCNLiveHomeADCellIdentifier = "kCNLiveHomeADCellIdentifier"
let kCNLiveHomeTwoDuanjuCellIdentifier = "kCNLiveHomeTwoDuanjuCellIdentifier"
let kCNLiveHomeFollowCellIdentifier = "kCNLiveHomeFollowCellIdentifier"
let kCNLiveHomeTwoShopCellIdentifier = "kCNLiveHomeTwoShopCellIdentifier"
let kCNLiveHomeShopCategoryCellIdentifier = "kCNLiveHomeShopCategoryCellIdentifier"
let group = DispatchGroup()
let queue = DispatchQueue.global(qos: .default)
var homePageStyleListMdls:[CNLiveHomePageStyleListModel] = [CNLiveHomePageStyleListModel]()//频道mdls
lazy var tableView : UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.dataSource = self
tableView.delegate = self
tableView.separatorStyle = .none
tableView.register(CNLiveHomeYingshiBannerCell.self, forCellReuseIdentifier: kCNLiveHomeYingshiBannerCellIdentifier)
tableView.register(CNLiveHomeLanmuCell.self, forCellReuseIdentifier: kCNLiveHomeLanmuCellIdentifier)
tableView.register(CNLiveHomeFollowCell.self, forCellReuseIdentifier: kCNLiveHomeFollowCellIdentifier)
tableView.register(CNLiveHomeOneBigTwoSmallCell.self, forCellReuseIdentifier: kCNLiveHomeOneBigTwoSmallCellIdentifier)
tableView.register(CNLiveHomeADCell.self, forCellReuseIdentifier: kCNLiveHomeADCellIdentifier)
tableView.register(CNLiveHomeTwoDuanjuCell.self, forCellReuseIdentifier: kCNLiveHomeTwoDuanjuCellIdentifier)
tableView.register(CNLiveHomeTwoShopCell.self, forCellReuseIdentifier: kCNLiveHomeTwoShopCellIdentifier)
tableView.register(CNLiveHomeShopCategoryCell.self, forCellReuseIdentifier: kCNLiveHomeShopCategoryCellIdentifier)
tableView.backgroundColor = .clear
return tableView
}()
lazy var iconBgImgView :UIImageView = {
let iconImgView = UIImageView(frame: CGRect(x: 0, y: 0, width: KSreenWidth, height: 295*KSreenWidth/375))
iconImgView.image = UIImage(named: "yingshibg")
iconImgView.contentMode = .scaleAspectFill
return iconImgView
}()
lazy var iconImgView :UIImageView = {
let iconImgView = UIImageView(frame: CGRect(x: 15, y: KStatusBarHeight+10, width: 74, height: 32))
iconImgView.image = UIImage(named: "yingshiicon")
iconImgView.contentMode = .scaleAspectFill
return iconImgView
}()
lazy var searBarView :QMUISearchBar = {
let iconImgView = QMUISearchBar(frame: CGRect(x: iconImgView.right+10, y: KStatusBarHeight+10, width: KSreenWidth-iconImgView.right-10-15, height: 32))
iconImgView.backgroundColor = .white
iconImgView.searchTextField.backgroundColor = .white
iconImgView.searchTextField.clearButtonMode = .always
iconImgView.searchTextField.font = Font_13
iconImgView.searchTextField.textColor = HexColor("#333333")
iconImgView.clipsToBounds = true
iconImgView.layer.cornerRadius = 16
return iconImgView
}()
lazy var searchBtn: QMUIButton = {
let playBtn = QMUIButton.init(type: .custom)
playBtn.frame = self.searBarView.bounds
playBtn.clipsToBounds = true
playBtn.layer.cornerRadius = 16
playBtn.addTarget(self, action: #selector(searBarViewAction), for: .touchUpInside)
return playBtn
}()
lazy var pageStyleBtn1: QMUIButton = {
let playBtn = QMUIButton.init(type: .custom)
playBtn.frame = CGRect(x: 10, y: self.searBarView.bottom+20, width: 80, height: 25)
playBtn.setTitle("影视剧", for: .normal)
playBtn.setTitleColor(HexColor("#000102"), for: .normal)
playBtn.titleLabel?.font = BoldFont_18
playBtn.addTarget(self, action: #selector(pageStyleBtn1Action), for: .touchUpInside)
return playBtn
}()
lazy var pageStyleBtn2: QMUIButton = {
let playBtn = QMUIButton.init(type: .custom)
playBtn.frame = CGRect(x: pageStyleBtn1.right, y: self.searBarView.bottom+20, width: 60, height: 25)
playBtn.setTitle("影视剧", for: .normal)
playBtn.setTitleColor(HexColor("#919191"), for: .normal)
playBtn.titleLabel?.font = Font_14
playBtn.addTarget(self, action: #selector(pageStyleBtn2Action), for: .touchUpInside)
playBtn.isHidden = true
return playBtn
}()
lazy var pageStyleBtn3: QMUIButton = {
let playBtn = QMUIButton.init(type: .custom)
playBtn.frame = CGRect(x: pageStyleBtn2.right, y: self.searBarView.bottom+20, width: 80, height: 25)
playBtn.setTitle("影视剧", for: .normal)
playBtn.setTitleColor(HexColor("#919191"), for: .normal)
playBtn.titleLabel?.font = Font_14
playBtn.addTarget(self, action: #selector(pageStyleBtn3Action), for: .touchUpInside)
playBtn.isHidden = true
return playBtn
}()
lazy var pageStyleBtn4: QMUIButton = {
let playBtn = QMUIButton.init(type: .custom)
playBtn.frame = CGRect(x: pageStyleBtn3.right, y: self.searBarView.bottom+20, width: 80, height: 25)
playBtn.setTitle("影视剧", for: .normal)
playBtn.setTitleColor(HexColor("#919191"), for: .normal)
playBtn.titleLabel?.font = Font_14
playBtn.addTarget(self, action: #selector(pageStyleBtn4Action), for: .touchUpInside)
playBtn.isHidden = true
return playBtn
}()
//share gift
lazy var shareGiftBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .clear
expandBtn.frame = CGRect(x: 0, y: 0, width: 90, height: 20)
expandBtn.setTitle("好看送好礼", for: .normal)
expandBtn.setTitle("好看送好礼", for: .selected)
expandBtn.setTitleColor(HexColor("#333333"), for: .normal)
expandBtn.setImage(UIImage(named: "home_shareGift"), for: .normal)
expandBtn.setImage(UIImage(named: "home_shareGift"), for: .selected)
expandBtn.titleLabel?.font = Font_11
expandBtn.setupButtonImageAndTitlePossitionWith(padding: 4, style: .left)
expandBtn.addTarget(self, action: #selector(shareGiftBtnAction), for: .touchUpInside)
expandBtn.backgroundColor = HexColor("#FFEFE9")
expandBtn.clipsToBounds = true
expandBtn.layer.cornerRadius = 10
return expandBtn
}()
///数据源
lazy var dataArray: NSMutableArray = {
var dataArray = NSMutableArray()
return dataArray
}()
var currStyleIndex = 0
// var giftModel:CNLiveHomePageHuBiLieGiftModel?//送礼分享model
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
view.addSubview(iconBgImgView)
view.addSubview(iconImgView)
iconImgView.snp.makeConstraints { make in
make.left.equalTo(15)
make.top.equalTo(KStatusBarHeight+10)
make.width.equalTo(74)
make.height.equalTo(32)
}
view.addSubview(searBarView)
searBarView.snp.makeConstraints { make in
make.left.equalTo(self.iconImgView.snp.right).offset(10)
make.top.equalTo(self.iconImgView.snp.top)
make.right.equalToSuperview().offset(-15)
make.height.equalTo(32)
}
searBarView.addSubview(searchBtn)
searchBtn.snp.makeConstraints { make in
make.top.left.right.bottom.equalToSuperview()
}
view.addSubview(pageStyleBtn1)
view.addSubview(pageStyleBtn2)
view.addSubview(pageStyleBtn3)
view.addSubview(pageStyleBtn4)
view.addSubview(shareGiftBtn)
shareGiftBtn.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-15)
make.width.equalTo(90)
make.height.equalTo(20)
make.centerY.equalTo(self.pageStyleBtn1.snp.centerY)
}
shareGiftBtn.isHidden = true
view.addSubview(tableView)
tableView.frame = CGRect(x: 0, y: self.pageStyleBtn1.bottom+10, width: KSreenWidth, height: KSreenHeight-KTabBarHeight-self.pageStyleBtn1.bottom-10)
self.getHomePageTopConfigListApi()
self.addRefreshView()
}
deinit {
}
////
@objc func searBarViewAction(){
let homePageStyleListMdl = self.homePageStyleListMdls[self.currStyleIndex]
if homePageStyleListMdl.id == "3337"{
//电商搜索页面
let urlString = "https://managemall.cnlive.com/html/mall/1/#/pages/goods/search/search?uid=\(UserInfoManager.shared.userInfo.uid)&scene=app"
CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: kCNDownSlideContentsModelModelProduct , contentId: "" , pid: "" , shareUrl: "" , thirdUrl: urlString , title: "" , s_to: "" ,trailerId: "" , controller: nil, slideModel: nil)
}else {
//跳转原生搜索页面
currentViewController()?.navigationController?.pushViewController(CNLiveHomeSearchController(), animated: false)
}
}
@objc func pageStyleBtn1Action(){
self.changeBtnHighLight(idx: 0)
}
@objc func pageStyleBtn2Action(){
self.changeBtnHighLight(idx: 1)
}
@objc func pageStyleBtn3Action(){
self.changeBtnHighLight(idx: 2)
}
@objc func pageStyleBtn4Action(){
self.changeBtnHighLight(idx: 3)
}
func changeBtnHighLight(idx:Int){
if self.currStyleIndex == idx {
return
}
if idx == 0{
self.changeBtn(btn: self.pageStyleBtn1, isHighLight: true)
self.changeBtn(btn: self.pageStyleBtn2, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn3, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn4, isHighLight: false)
}else if idx == 1{
self.changeBtn(btn: self.pageStyleBtn1, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn2, isHighLight: true)
self.changeBtn(btn: self.pageStyleBtn3, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn4, isHighLight: false)
}else if idx == 2{
self.changeBtn(btn: self.pageStyleBtn1, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn2, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn3, isHighLight: true)
self.changeBtn(btn: self.pageStyleBtn4, isHighLight: false)
}else if idx == 3{
self.changeBtn(btn: self.pageStyleBtn1, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn2, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn3, isHighLight: false)
self.changeBtn(btn: self.pageStyleBtn4, isHighLight: true)
}else{
}
let homePageStyleListMdl = self.homePageStyleListMdls[idx]
// self.group.enter()
self.currStyleIndex = idx
self.dataArray.removeAllObjects()
self.getPageApi(pageID: homePageStyleListMdl.pageId)
}
func changeBtn(btn:QMUIButton,isHighLight:Bool){
if isHighLight{
btn.setTitleColor(HexColor("#000102"), for: .normal)
btn.titleLabel?.font = BoldFont_18
}else{
btn.setTitleColor(HexColor("#919191"), for: .normal)
btn.titleLabel?.font = Font_14
}
}
@objc func shareGiftBtnAction(){
let shareTitle = metaAppDelegate.giftModel?.data?.share_app_banner?.share_title
let shareDesc = metaAppDelegate.giftModel?.data?.share_app_banner?.share_content
let shareImage = metaAppDelegate.giftModel?.data?.share_app_banner?.share_icon
let shareUrl = metaAppDelegate.giftModel?.data?.share_app_banner?.jumpUrl
CNLiveShareManager.showShareViewWithParam(forShareTitle: shareTitle, shareUrl: shareUrl, shareDesc: shareDesc, shareImage: shareImage, screenFull: false, hiddenWjj: true, hiddenQQ: true, hiddenWB: true, hiddenLifeCircle: true, hiddenWechatCircle: false, hiddenWechat: false, hiddenSafari: true, formVC: currentViewController(), topImage: [], topTitles: [], platformType: .all) { title in
} completerBlock: { resultType, platformType, typeString in
if resultType == .succ{
print("succ")
}
}
}
// MARK: - UITableViewDelegate
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row < self.dataArray.count{
if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{
if slideModel.type == SlideModelTypeRecommend1{
//banner
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeYingshiBannerCellIdentifier) as? CNLiveHomeYingshiBannerCell
else {
let cell = CNLiveHomeYingshiBannerCell()
return cell
}
cell.slideModel = slideModel
return cell
}else if slideModel.type == SlideModelTypeLanmu22{
//栏目
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeLanmuCellIdentifier) as? CNLiveHomeLanmuCell
else {
let cell = CNLiveHomeLanmuCell()
return cell
}
cell.slideModel = slideModel
cell.imgClickBlock = { slideContentMdl in
let urlString = slideContentMdl.thirdUrl
if let url = URL(string: urlString){
// 使用 URLComponents 解析 URL
let components = URLComponents(url: url, resolvingAgainstBaseURL: false)!
// 获取查询项数组
let queryItems = components.queryItems
// 遍历查询项数组,查找 pageId 的值
var pageId = ""
for queryItem in queryItems ?? [] {
if queryItem.name == "pageId" {
pageId = queryItem.value ?? ""
break
}
}
if pageId.count > 0{
let vc = CNLiveHomeLanmuController()
vc.slideContentModel = slideContentMdl
vc.pageId = pageId
currentViewController()?.navigationController?.pushViewController(vc, animated: true)
}else{
//跳转webView
CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: slideContentMdl.model, contentId: slideContentMdl.contentId, pid: slideContentMdl.pid, shareUrl: slideContentMdl.shareUrl, thirdUrl: slideContentMdl.thirdUrl, title: slideContentMdl.title, s_to: slideContentMdl.s_to, trailerId: slideContentMdl.trailerId, controller: self, slideModel: nil)
}
}
}
return cell
}else if slideModel.type == SlideModelTypeTVOneBigTwoSmall2{
//
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeOneBigTwoSmallCellIdentifier) as? CNLiveHomeOneBigTwoSmallCell
else {
let cell = CNLiveHomeOneBigTwoSmallCell()
return cell
}
cell.slideModel = slideModel
return cell
}else if slideModel.type == SlideModelTypeAD31{
//广告
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeADCellIdentifier) as? CNLiveHomeADCell
else {
let cell = CNLiveHomeADCell()
return cell
}
cell.slideModel = slideModel
return cell
}else if slideModel.type == SlideModelTypeTwoDuanJu5{
//一排3个
guard let cell = tableView.dequeueReusableCell (withIdentifier: kCNLiveHomeTwoDuanjuCellIdentifier) as? CNLiveHomeTwoDuanjuCell
else {
let cell = CNLiveHomeTwoDuanjuCell()
return cell
}
cell.slideModel = slideModel
return cell
}else if slideModel.type == SlideModelTypeShop29{
//官方周边 一排2个
guard let cell = tableView.dequeueReusableCell (withIdentifier: kCNLiveHomeTwoShopCellIdentifier) as? CNLiveHomeTwoShopCell
else {
let cell = CNLiveHomeTwoShopCell()
return cell
}
cell.slideModel = slideModel
return cell
}else{
return UITableViewCell()
}
}else if let followModel = self.dataArray[indexPath.row] as? CNLiveHomeFollowModel{
//正在追
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeFollowCellIdentifier) as? CNLiveHomeFollowCell
else {
let cell = CNLiveHomeFollowCell()
return cell
}
cell.followModel = followModel
return cell
}else if let categoryModel = self.dataArray[indexPath.row] as? CNLiveHomeShopCategoryModel{
//电商分类 一排三个
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomeShopCategoryCellIdentifier) as? CNLiveHomeShopCategoryCell
else {
let cell = CNLiveHomeShopCategoryCell()
return cell
}
cell.slideModel = categoryModel
return cell
}else{
}
}else{
}
return UITableViewCell()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row < self.dataArray.count{
if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{
//非短剧
let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel
if slideModel.type == SlideModelTypeFollow77{
return 0.0//追剧 占位数据
}
return CGFloat(slideModel.cellH)
}else if let slideModel = self.dataArray[indexPath.row] as? CNLiveHomeFollowModel{
//正在追
return 50.0+15.0//80
}else if let slideModel = self.dataArray[indexPath.row] as? CNLiveHomeShopCategoryModel{
//商品分类 一排三个
let maxCount = slideModel.group.count > 4 ? 4 : slideModel.group.count
// let hangNum = Int(ceil(Double(maxCount)/3.0))
// let imgW = (KSreenWidth-15*4)/3.0
// let imgH = imgW*32.0/105.0
let imgWH = 44.0
let titleH = 22.0
let rowH = imgWH+titleH+15.0
// let height = CGFloat(hangNum)*rowH
let height = rowH
return height
}else{
}
}else{
}
return 60
}
func addRefreshView() {
tableView.mj_header = MJRefreshNormalHeader.init(refreshingBlock: {[weak self] in
self!.getHomePageTopConfigListApi()
})
}
func getHomePageTopBannerGift(){
CNLiveHomePageViewModel.requestGetHomePageTopBannerGift{[weak self] result, status in
guard let self = self else { return }
if status == .success{
let giftModel = result as! CNLiveHomePageHuBiLieGiftModel
metaAppDelegate.giftModel = giftModel
}
}
}
//MARK: - 获取首页配置
func getHomePageTopConfigListApi(){
// self.getHomePageTopBannerGift()
// CNLiveHomePageViewModel.requestGetHomePageTopBannerGift{[weak self] result, status in
// guard let self = self else { return }
// let giftModel = result as! CNLiveHomePageHuBiLieGiftModel
// metaAppDelegate.giftModel = giftModel
CNLiveHomePageViewModel.requestGetHomePageTopConfigList{[weak self] result, status in
guard let self = self else { return }
if status == .success{
let dataModelArr = result as! [CNLiveHomePageHuBiLieModel]
let dataModel = dataModelArr.first!
let img = dataModel.img
if img.count > 0{
self.iconImgView.kf.setImage(with: URL(string: img))
self.iconImgView.isHidden = false
self.iconImgView.snp.remakeConstraints { make in
make.left.equalTo(15)
make.top.equalTo(KStatusBarHeight+10)
make.width.equalTo(74)
make.height.equalTo(32)
}
self.searBarView.snp.remakeConstraints { make in
make.left.equalTo(self.iconImgView.snp.right).offset(10)
make.top.equalTo(self.iconImgView.snp.top)
make.right.equalToSuperview().offset(-15)
make.height.equalTo(32)
}
}else{
self.iconImgView.isHidden = true
self.iconImgView.image = nil
self.iconImgView.snp.remakeConstraints { make in
make.left.equalTo(15)
make.top.equalTo(KStatusBarHeight+10)
make.width.equalTo(0)
make.height.equalTo(32)
}
self.searBarView.snp.remakeConstraints { make in
make.left.equalTo(self.iconImgView.snp.right)
make.top.equalTo(self.iconImgView.snp.top)
make.right.equalToSuperview().offset(-15)
make.height.equalTo(32)
}
}
let homePageListMdls = dataModel.pageStyleList
self.homePageStyleListMdls = homePageListMdls
for (idx,mdl) in homePageListMdls.enumerated() {
if idx == 0{
self.pageStyleBtn1.setTitle(mdl.showName, for: .normal)
var width = 60
if mdl.showName.count <= 2{
width = 60
}else if mdl.showName.count == 3{
width = 80
}else{
width = 100
}
//x10 3字80 2字60 高25 y:self.searBarView.bottom+20
self.pageStyleBtn1.snp.makeConstraints { make in
make.left.equalTo(10)
make.width.equalTo(width)
make.height.equalTo(25)
make.top.equalTo(self.searBarView.snp.bottom).offset(20)
}
self.changeBtn(btn: self.pageStyleBtn1, isHighLight: true)
self.pageStyleBtn1.isHidden = false
// self.group.enter()
self.getPageApi(pageID: mdl.pageId)
}else if idx == 1{
self.pageStyleBtn2.setTitle(mdl.showName, for: .normal)
var width = 60
if mdl.showName.count <= 2{
width = 60
}else if mdl.showName.count == 3{
width = 80
}else{
width = 100
}
self.pageStyleBtn2.snp.makeConstraints { make in
make.left.equalTo(self.pageStyleBtn1.snp.right)
make.width.equalTo(width)
make.height.equalTo(self.pageStyleBtn1.snp.height)
make.top.equalTo(self.pageStyleBtn1.snp.top)
}
self.changeBtn(btn: self.pageStyleBtn2, isHighLight: false)
self.pageStyleBtn2.isHidden = false
}else if idx == 2{
self.pageStyleBtn3.setTitle(mdl.showName, for: .normal)
var width = 60
if mdl.showName.count <= 2{
width = 60
}else if mdl.showName.count == 3{
width = 80
}else{
width = 100
}
self.pageStyleBtn3.snp.makeConstraints { make in
make.left.equalTo(self.pageStyleBtn2.snp.right)
make.width.equalTo(width)
make.height.equalTo(self.pageStyleBtn1.snp.height)
make.top.equalTo(self.pageStyleBtn1.snp.top)
}
self.changeBtn(btn: self.pageStyleBtn3, isHighLight: false)
self.pageStyleBtn3.isHidden = false
}else if idx == 3{
self.pageStyleBtn4.setTitle(mdl.showName, for: .normal)
var width = 60
if mdl.showName.count <= 2{
width = 60
}else if mdl.showName.count == 3{
width = 80
}else{
width = 100
}
self.pageStyleBtn4.snp.makeConstraints { make in
make.left.equalTo(self.pageStyleBtn3.snp.right)
make.width.equalTo(width)
make.height.equalTo(self.pageStyleBtn1.snp.height)
make.top.equalTo(self.pageStyleBtn1.snp.top)
}
self.changeBtn(btn: self.pageStyleBtn4, isHighLight: false)
self.pageStyleBtn4.isHidden = false
}else{
}
}
// self.group.notify(queue: .main) {
// // 所有网络请求都已完成,在这里执行你的任务
// self.tableView.mj_header?.endRefreshing()
// self.tableView.reloadData()
// }
}else{
self.getHomePageTopConfigListApi()
}
}
}
func getHomePageShopCategoryApi(shop_id:String){
CNLiveHomePageViewModel.requestGetHomePageShopCategoryApi(shop_id: shop_id){[weak self] result, status in
guard let self = self else { return }
if status == .success{
var cateMdl = result as! CNLiveHomeShopCategoryModel
var followIdx = 0
for (idx,mdl) in self.dataArray.enumerated(){
if let lanmuMdl = mdl as? CNLiveDownSlideModel{
if lanmuMdl.type == SlideModelTypeShopCategory78{
//商品分类
followIdx = idx
}
}
}
if cateMdl.group.count == 0{
//不显示分类
self.dataArray.removeObject(at: followIdx)
}else{
let model = CNLiveHomeShopCategoryGroupModel()
model.title = "全部商品"
cateMdl.group.insert(model, at: 0)
self.dataArray.replaceObject(at: followIdx, with: cateMdl)
}
}else{
}
self.tableView.mj_header?.endRefreshing()
self.tableView.reloadData()
self.tableView.scrollToTop(animated: false)
}
}
func getHomePageFollowApi(sid:String){
CNLiveHomePageViewModel.requestGetHomePageFollow(sid: sid){[weak self] result, status in
guard let self = self else { return }
if status == .success{
//插入数据到栏目下一位
let followMdl = result as! CNLiveHomeFollowModel
// if self.dataArray.count >= 2{
// self.dataArray.insert(followMdl, at: 2)
// }
var followIdx = 0
for (idx,mdl) in self.dataArray.enumerated(){
if let lanmuMdl = mdl as? CNLiveDownSlideModel{
if lanmuMdl.type == SlideModelTypeFollow77{
//正在追
followIdx = idx
}
}
}
self.dataArray.replaceObject(at: followIdx, with: followMdl)
// self.group.leave()
}else{
//没有在追
// self.group.leave()
}
self.tableView.mj_header?.endRefreshing()
self.tableView.reloadData()
self.tableView.scrollToTop(animated: false)
}
}
//MARK: - 网络请求获取区块详情页
func getPageApi(pageID:String)
{
showLoading(message: "")
CNLiveDownSlideViewModel.requestGetPage(pageId: pageID as NSString) {[weak self] result, status in
hiddenLoading()
guard let self = self else { return }
if status == .success{
self.shareGiftBtn.isHidden = !metaAppDelegate.isGift
self.shareGiftBtn.setTitle(metaAppDelegate.giftModel?.data?.share_app_banner?.home_top_button_name ?? "好看送好礼", for: .normal)
self.shareGiftBtn.setTitle(metaAppDelegate.giftModel?.data?.share_app_banner?.home_top_button_name ?? "好看送好礼", for: .selected)
self.dataArray.removeAllObjects()
let array = result as! [Any]
let newDataArray = NSMutableArray()
var isRefreshTable = true
for slideModel in array {
if let model = slideModel as? CNLiveDownSlideModel{
let layout = CNLiveDownSlideModelLayout.init(model: model)
let cellModel = layout.getCellHModel()
if cellModel.type == SlideModelTypeBanner1 && metaAppDelegate.isGift{
//banner 写死第一个gift
let giftType = metaAppDelegate.giftModel?.type ?? SlideModelTypeApp_ext_info
let giftMineImageUrl = metaAppDelegate.giftModel?.data?.share_app_banner?.mine_image ?? "https://wjj.ys1.cnliveimg.com/download/mc/extInfoData/ver-001/mine_banner_bg.jpg"
let giftBannerImageUrl = metaAppDelegate.giftModel?.data?.share_app_banner?.home_image ?? "https://wjj.ys1.cnliveimg.com/download/mc/extInfoData/ver-001/home_banner_bg.jpg"
let giftJumpUrl = metaAppDelegate.giftModel?.data?.share_app_banner?.jumpUrl ?? "http://wjjh5.cnlive.com/cnYmHbl.html?channelName=ymhbl"
let giftContentMdl = CNLiveDownSlideContentsModel()
giftContentMdl.poster = giftBannerImageUrl
giftContentMdl.model = giftType
giftContentMdl.title = "忽必烈电视剧"
giftContentMdl.shareUrl = giftJumpUrl
cellModel.contents.insert(giftContentMdl, at: 0)
}
newDataArray.addObjects(from: [cellModel])
if model.type == SlideModelTypeFollow77{
// self.group.enter()
if metaAppDelegate.isLogin{
self.getHomePageFollowApi(sid: UserInfoManager.shared.userInfo.uid)
isRefreshTable = false
}else{
}
}else if model.type == SlideModelTypeShopCategory78{
if model.contents.count > 0{
let shop_id = model.contents[0].contentId
self.getHomePageShopCategoryApi(shop_id: shop_id)
isRefreshTable = false
}
}else{
}
}
}
self.dataArray.addObjects(from: newDataArray as! [Any])
if isRefreshTable{
//需要刷新table
self.tableView.mj_header?.endRefreshing()
self.tableView.reloadData()
self.tableView.scrollToTop(animated: false)
}else{
//后面接口刷新table
}
}else if (status == .failed){
// self.NetApiStatus = .apiError
}else if (status == .noNetwork){
// self.NetApiStatus = .notNetwork
}
// self.group.leave()
}
//
}
}