CNLiveShopConsoleController.swift
7.62 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
//
// CNLiveShopConsoleController.swift
// metaCode
//
// Created by zx on 2023/10/27.
//
import Foundation
class CNLiveShopConsoleController: CNLiveBaseViewController, UICollectionViewDelegate, UICollectionViewDataSource {
let kCNLiveShopConsoleCellKey = "kCNLiveShopConsoleCellKey"
let kCNLiveShopConsoleCollectionReusableHeaderViewID = "kCNLiveShopConsoleCollectionReusableHeaderViewID"
let kCNLiveShopConsoleCollectionReusableFooterViewID = "kCNLiveShopConsoleCollectionReusableFooterViewID"
lazy var collectionView: UICollectionView = {
let gap = CGFloat(15)
let layout = UICollectionViewFlowLayout.init()
layout.itemSize = CGSize(width: (KSreenWidth - gap*2-10)/2, height: 72)
layout.sectionInset = .init(top: gap, left: gap, bottom: gap, right: gap)
layout.headerReferenceSize = CGSize(width: KSreenWidth, height: 20)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = .clear
collectionView.register(CNLiveShopConsoleHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: kCNLiveShopConsoleCollectionReusableHeaderViewID)
collectionView.register(CNLiveShopConsoleCell.self, forCellWithReuseIdentifier: kCNLiveShopConsoleCellKey)
return collectionView
}()
lazy var dataModel: CNLiveShopConsoleModel = {
let dataModel = CNLiveShopConsoleModel()
return dataModel
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .clear
self.getPageApi()
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 {
return self.dataModel.list.count
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let listMdl = self.dataModel.list[section]
return listMdl.list.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveShopConsoleCellKey, for: indexPath) as! CNLiveShopConsoleCell
let listMdl = self.dataModel.list[indexPath.section]
let model = listMdl.list[indexPath.item]
cell.shopListContentModel = model
return cell
}
// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
// if (section == 0) {
// return CGSizeMake(self.view.width, 33);
// }else {
// return CGSizeMake(self.view.width, 33);
// }
// }
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if (kind == UICollectionView.elementKindSectionHeader){
let sectionMdl = self.dataModel.list[indexPath.section]
let headerView:CNLiveShopConsoleHeaderView = collectionView .dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: kCNLiveShopConsoleCollectionReusableHeaderViewID, for: indexPath) as! CNLiveShopConsoleHeaderView
headerView.height = 24
headerView.title = sectionMdl.title
return headerView
}else {
let footer = collectionView .dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: kCNLiveShopConsoleCollectionReusableFooterViewID, for: indexPath)
return footer
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let listMdl = self.dataModel.list[indexPath.section]
let itemModel = listMdl.list[indexPath.item]
if itemModel.type == CNLiveShopConsoleType.XZSP.rawValue{
//商城新增商品
currentViewController()?.navigationController?.pushViewController(CNLiveShopNewProductController.init(), animated: false)
}else if itemModel.type == CNLiveShopConsoleType.SPGL.rawValue{
//商城商品管理
currentViewController()?.navigationController?.pushViewController(CNLiveShopProductManagerController.init(), animated: false)
}else if itemModel.type == CNLiveShopConsoleType.XZYHQ.rawValue{
//新增优惠券
}else if itemModel.type == CNLiveShopConsoleType.GLYHQ.rawValue{
//优惠券管理
}else if itemModel.type == CNLiveShopConsoleType.CreateShopClassify.rawValue{
//创建店铺分类
let vc = CNLiveCreateShopClassifyViewController()
vc.classifyType = .oneLevelClassify
currentViewController()?.navigationController?.pushViewController(vc, animated: false)
}else if itemModel.type == CNLiveShopConsoleType.ShopClassifyManager.rawValue{
//店铺分类管理
currentViewController()?.navigationController?.pushViewController(CNLiveShopClassilyManageViewController.init(), animated: false)
}else if itemModel.type == CNLiveShopConsoleType.FBDT.rawValue{
//发布动态
}else if itemModel.type == CNLiveShopConsoleType.DTGL.rawValue{
//动态管理
}else if itemModel.type == CNLiveShopConsoleType.DDGL.rawValue{
//订单管理
currentViewController()?.navigationController?.pushViewController(CNLiveShopOrderViewController.init(), animated: false)
}
// else if itemModel.type == CNLiveShopConsoleType.SH.rawValue{
// //退款/售后
//
// }
else if itemModel.type == CNLiveShopConsoleType.JYJL.rawValue{
//交易记录
self.navigationController?.pushViewController(CNLiveShopTransViewController.init(), animated: true)
}else if itemModel.type == CNLiveShopConsoleType.OnManagerment.rawValue{
//直播管理
let webVC = CNWebViewController()
webVC.url = URL(string: "http://wjjh5.cnlive.com/apkdownloadShop.php")
currentViewController()?.navigationController?.pushViewController(webVC, animated: false)
}
}
//MARK: - 网络请求获取详情页
func getPageApi()
{
showLoading(message: "")
CNLiveShopConsoleViewModel.requestUserInfo() { result, status in
hiddenLoading()
if status == .success{
let shopUserModel = result as! CNLiveShopUserInfoModel
DSUserInfoManager.cacheDSUserInfo(dsUserInfo: shopUserModel)
if shopUserModel.type != "3"{
//type 1商家或者8达人
let shopConsoleModel = CNLiveShopConsoleModel()
shopConsoleModel.initDataSource()
self.dataModel = shopConsoleModel
self.collectionView.reloadData()
}
}else if (status == .failed){
// self.NetApiStatus = .apiError
}else if (status == .noNetwork){
// self.NetApiStatus = .notNetwork
}
}
//
}
}