CNLiveDownShopDetailController.swift
11.9 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
//
// 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"
let kCNLiveShopDetailBtnsCellID = "kCNLiveShopDetailBtnsCellID"
let kCNLiveShopDetailOrderAssetCellID = "kCNLiveShopDetailOrderAssetCellID"
lazy var shopDetailModel: CNLiveShopDetailModel = {
let shopDetailModel = CNLiveShopDetailModel()
return shopDetailModel
}()
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let upSlideView = self.view.superview as! CNUpSlideView
let scrollView = upSlideView.superview as! UIScrollView
scrollView.setContentOffset(CGPoint(x: 0, y: scrollView.height), animated: true)
currentViewController()?.tabBarController?.tabBar.isHidden = false
let metaVC = currentViewController() as! CNMetaCodeHomePageController
let index = metaVC.pageFlowView.currentPageIndex
let customIndexView = metaVC.pageFlowView.viewWithTag(100+index) as! CNCustomIndexView
customIndexView.superScrollView?.isScrollEnabled = true
}
// lazy var closeBtn: UIButton = {
// let closeBtn = UIButton(type: .custom)
// closeBtn.frame = CGRect(x: KSreenWidth-50, y: KStatusBarHeight, width: 50, height: KNavigationHeight-KStatusBarHeight)
// closeBtn.setImage(UIImage(named: "mine_header_icon_close"), for: .normal)
// closeBtn.addTarget(self, action: #selector(closeBtnAction), for: .touchUpInside)
// closeBtn.isUserInteractionEnabled = false
// return closeBtn
// }()
// lazy var navView: UIView = {
// let closeBtn = UIView(frame: CGRect(x: 0, y: KStatusBarHeight, width: KSreenWidth-50, height: KNavigationHeight-KStatusBarHeight))
// closeBtn.backgroundColor = .yellow
// return closeBtn
// }()
lazy var closeBtn: UIImageView = {
let closeBtn = UIImageView(frame: CGRect(x: KSreenWidth-35, y: KStatusBarHeight+(KNavigationHeight-KStatusBarHeight-20)*0.5, width: 20, height: 20))
closeBtn.image = UIImage(named: "mine_header_icon_close")
// closeBtn.isUserInteractionEnabled = true
// let tap = UITapGestureRecognizer.init(target: self, action: #selector(closeBtnAction))
// closeBtn.addGestureRecognizer(tap)
return closeBtn
}()
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)
collectionView.register(CNLiveShopDetailBtnsCell.self, forCellWithReuseIdentifier: kCNLiveShopDetailBtnsCellID)
collectionView.register(CNLiveShopDetailOrderAssetCell.self, forCellWithReuseIdentifier: kCNLiveShopDetailOrderAssetCellID)
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()
}
self.view.addSubview(closeBtn)
// self.view.addSubview(navView)
}
// MARK: BtnAction
@objc func closeBtnAction(){
let upSlideView = self.view.superview as! CNUpSlideView
let scrollView = upSlideView.superview as! UIScrollView
scrollView.setContentOffset(CGPoint(x: 0, y: scrollView.height), animated: true)
currentViewController()?.tabBarController?.tabBar.isHidden = false
let metaVC = currentViewController() as! CNMetaCodeHomePageController
let index = metaVC.pageFlowView.currentPageIndex
let customIndexView = metaVC.pageFlowView.viewWithTag(100+index) as! CNCustomIndexView
customIndexView.superScrollView?.isScrollEnabled = true
// customIndexView.baseScrollView.setContentOffset(CGPoint(x: 0, y: customIndexView.baseScrollView.height), animated: true)
// currentViewController()?.tabBarController?.tabBar.isHidden = false
}
// 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://banner轮播图
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailBannerCellID, for: indexPath) as! CNLliveShopDetailBannerCell
cell.shopDetailModel = self.shopDetailModel
return cell
case 1://btn
if (self.shopDetailModel.is_seller != nil && self.shopDetailModel.is_seller == true) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailBtnsCellID, for: indexPath) as! CNLiveShopDetailBtnsCell
cell.shopDetailModel = self.shopDetailModel
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailDefaultCellID, for: indexPath)
return cell
}
case 2://我的订单
if (self.shopDetailModel.is_seller != nil && self.shopDetailModel.is_seller == true) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailOrderAssetCellID, for: indexPath) as! CNLiveShopDetailOrderAssetCell
cell.displayType = .CNLiveShopDetailDisplayTypeOrder
cell.shopDetailModel = self.shopDetailModel
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailDefaultCellID, for: indexPath)
return cell
}
case 3://我的资产
if (self.shopDetailModel.is_seller != nil && self.shopDetailModel.is_seller == true) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailOrderAssetCellID, for: indexPath) as! CNLiveShopDetailOrderAssetCell
cell.displayType = .CNLiveShopDetailDisplayTypeAsset
cell.shopDetailModel = self.shopDetailModel
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopDetailDefaultCellID, for: indexPath)
return cell
}
// 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://banner
return CGSize(width: KSreenWidth, height: CNLiveAdaptTool.adaptLength(length: 210))
case 1://btn
return CGSize(width: KSreenWidth, height: 10+45+5+17+15)
case 2://我的订单
return CGSize(width: KSreenWidth, height: 10+25+15+CNLiveAdaptTool.adaptLength(length: 128-55)+15)
case 3://我的资产
return CGSize(width: KSreenWidth, height: 10+25+15+CNLiveAdaptTool.adaptLength(length: 128-55)+15)
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
}
}
}
}