CNLiveDownShopDetailController.swift
6.81 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
//
// CNLiveDownShopDetailController.swift
// metaCode
//
// Created by zx on 2023/10/31.
//
import Foundation
class CNLiveDownShopDetailController:CNLiveBaseViewController, UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
let kCNLiveShopDetailDefaultCellID = "kCNLiveShopDetailDefaultCellID"
let kCNLiveShopDetailHeaderViewID = "kCNLiveShopDetailHeaderViewID"
let kCNLiveShopDetailBannerCellID = "kCNLiveShopDetailBannerCellID"
lazy var shopDetailModel: CNLiveShopDetailModel = {
let shopDetailModel = CNLiveShopDetailModel()
return shopDetailModel
}()
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout.init()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = .white
// collectionView.register(CNLiveShopConsoleHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: kCNLiveShopConsoleCollectionReusableHeaderViewID)
collectionView.register(CNLliveShopDetailBannerCell.self, forCellWithReuseIdentifier: kCNLiveShopDetailBannerCellID)
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: kCNLiveShopDetailDefaultCellID)
return collectionView
}()
override func viewDidLoad() {
super.viewDidLoad()
self.getShopDetailApi()
self.view.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(KNavigationHeight)
make.left.bottom.right.equalToSuperview()
}
}
// MARK: - UICollectionViewDelegate
func numberOfSections(in collectionView: UICollectionView) -> Int {
if self.shopDetailModel.is_seller != nil{
if self.shopDetailModel.is_seller == true{
return 5
}else{//非商家,不处理
return 3
}
}else{
return 1
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if self.shopDetailModel.is_seller != nil {
if (self.shopDetailModel.is_seller == true) {
if (section == 4) {
let count = self.shopDetailModel.dynamic.count
return count == 0 ? 1 : count
}else {
return 1
}
}else {
return 1
}
}else{
return 1
}
}
// func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
// if (kind == UICollectionView.elementKindSectionHeader){
// let headerView:CNLiveShopConsoleHeaderView = collectionView .dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: kCNLiveShopDetailHeaderViewID, for: indexPath) as! CNLiveShopConsoleHeaderView
//
// return headerView
// }else{
// return
// }
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch indexPath.section {
case 0:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailBannerCellID, for: indexPath) as! CNLliveShopDetailBannerCell
cell.shopDetailModel = self.shopDetailModel
return cell
// case 1:
//
// case 2:
// case 3:
// case 4:
default:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailDefaultCellID, for: indexPath)
return cell
}
}
// MARK: - UICollectionViewDelegateFlowLayout
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if (self.shopDetailModel.is_seller != nil && self.shopDetailModel.is_seller == true) {
switch (indexPath.section) {
case 0:
return CGSize(width: KSreenWidth, height: CNLiveAdaptTool.adaptLength(length: 210))
case 1:
return CGSize(width: KSreenWidth, height: 50)
case 2:
return CGSize(width: KSreenWidth, height: 50)
case 3:
return CGSize(width: KSreenWidth, height: 50)
case 4:
return CGSize(width: KSreenWidth, height: 50)
default:
return CGSizeZero
}
}else {
return CGSizeZero
// switch (indexPath.section) {
// case 0:
// {
// if (self.mainHPModel.is_show_btn) {
// return CGSizeMake(self.view.width, DS_adapt_length(262));
// }else {
// return CGSizeMake(self.view.width, DS_adapt_length(262) - DS_adapt_length(50));
// }
// }
// break;
// case 1:
// {
// if (self.mainHPModel.is_show_btn) {
// return CGSizeMake(self.view.width, DS_adapt_length(145));
// }else {
// return CGSizeMake(self.view.width, 0.000001);
// }
// }
// break;
// case 2:
// {
// if (self.mainHPModel.is_show_user) {
// return CGSizeMake(self.view.width, DS_adapt_length(191));
// }else {
// return CGSizeMake(self.view.width, 0.000001);
// }
// }
// break;
// default:
// {
// return CGSizeZero;
// }
// break;
// }
}
}
//MARK: - 网络请求获取店铺详情
func getShopDetailApi()
{
showLoading(message: "")
CNLiveShopDetailViewModel.requestShopDetailInfo(storeId: "") { result, status in
hiddenLoading()
if status == .success{
let model = result as! CNLiveShopDetailModel
self.shopDetailModel = model
self.collectionView.reloadData()
}else if (status == .failed){
// self.NetApiStatus = .apiError
}else if (status == .noNetwork){
// self.NetApiStatus = .notNetwork
}
}
}
}