CNLiveMineAddInfoViewController.swift
10.8 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
//
// CNLiveMineAddInfoViewController.swift
// metaCode
//
// Created by open on 2023/6/7.
//
import Foundation
import EmptyDataSet_Swift
enum CNLiveMineInfoShowType {
case add//添加身份
case info//身份信息
case message//消息中心
}
class CNLiveMineAddInfoViewController : CNLiveBaseViewController, UITableViewDelegate, UITableViewDataSource, UITableViewDragDelegate, UITableViewDropDelegate, EmptyDataSetSource, EmptyDataSetDelegate{
let kCNLiveMineInfoLListTableViewIdentifier = "kCNLiveMineInfoLListTableViewIdentifier"
let kCNLiveMineStandInfoTableViewIdentifier = "kCNLiveMineStandInfoTableViewIdentifier"
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.delegate = self
tableView.dataSource = self
tableView.dragDelegate = self
tableView.dropDelegate = self
tableView.emptyDataSetSource = self
tableView.emptyDataSetDelegate = self
tableView.backgroundColor = HexColor("#F7F8FA")
tableView.tableFooterView = UIView.init()
tableView.rowHeight = 100
tableView.contentInsetAdjustmentBehavior = .scrollableAxes
tableView.separatorStyle = .none
tableView.register(MineInfoLListTableViewCell.self, forCellReuseIdentifier: kCNLiveMineInfoLListTableViewIdentifier)
tableView.register(MineStandInfoTableViewCell.self, forCellReuseIdentifier: kCNLiveMineStandInfoTableViewIdentifier)
return tableView
}()
lazy var dataArray: NSMutableArray = {
var dataArray = NSMutableArray()
if _show_type == .add {
dataArray.add(["image":"mine_header_icon_defult_ava","name":"志愿者身份"])
dataArray.add(["image":"mine_header_icon_defult_ava","name":"退伍军人身份"])
}
if _show_type == .info {
dataArray.add(["image":"mine_header_icon_defult_ava","name":"志愿者身份","number":"证件编号:410800111127954"])
dataArray.add(["image":"mine_header_icon_defult_ava","name":"退伍军人身份","number":"证件编号:410800111127954"])
}
return dataArray
}()
private lazy var listArray: Array<NewsListModel> = {
let listArray = Array<NewsListModel>()
return listArray
}()
lazy var setButton = {
let setButton = UIButton.init(type: .custom)
setButton.frame = CGRectMake(KSreenWidth - 35, (get_system_nav_height() - (get_system_statusBar_height() + 20))/2 + get_system_statusBar_height(), 20, 20)
setButton.backgroundColor = .white
setButton.setImage(UIImage(named: "mine_sub_header_note_set"), for: .normal)
setButton.imageView?.contentMode = .scaleToFill
setButton.addTarget(self, action: #selector(noteSetAction), for: .touchUpInside)
return setButton
}()
lazy var copyButton = {
let copyButton = UIButton.init(type: .custom)
copyButton.frame = CGRectMake(KSreenWidth - 70, (get_system_nav_height() - (get_system_statusBar_height() + 20))/2 + get_system_statusBar_height(), 20, 20)
copyButton.backgroundColor = .white
copyButton.setImage(UIImage(named: "mine_sub_header_back_up_copy"), for: .normal)
copyButton.imageView?.contentMode = .scaleToFill
copyButton.addTarget(self, action: #selector(backCopyAction), for: .touchUpInside)
return copyButton
}()
var network_type: CNLiveMineResponseType!
var _show_type:CNLiveMineInfoShowType!
init(show_type:CNLiveMineInfoShowType) {
super.init(nibName:nil, bundle:nil)
_show_type = show_type
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
switch _show_type {
case .add:
titleName = "添加身份"
case .info:
titleName = "身份信息"
tableView.dragInteractionEnabled = true
case .message:
titleName = "消息中心"
loadData()
// topNavView.addSubview(setButton)
// topNavView.addSubview(copyButton)
case .none:
break
}
navigationBarHidden = false
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.top.equalTo(get_system_nav_height())
make.left.right.bottom.equalToSuperview()
}
}
func loadData() {
CNLiveMineViewModel.requestMessage { [weak self] result, respStatue in
self!.network_type = respStatue
if respStatue == .success {
self!.listArray = (result as! NewsModel).list
self!.tableView.reloadData()
}else{
self!.tableView.reloadEmptyDataSet()
}
}
}
@objc func noteSetAction() {}
@objc func backCopyAction() {}
}
extension CNLiveMineAddInfoViewController {
func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
if network_type == .failed || network_type == .unkonw {
return UIImage(named: "mine_list_source_unusual_failed")
}
if _show_type == .message && listArray.count == 0 {
return UIImage(named: "mine_list_source_unusual_empty")
}
if network_type == .noNetwork {
return UIImage(named: "mine_list_source_unusual_noNet")
}
return UIImage(named: "mine_list_source_unusual_empty")
}
func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
var defult_string = ""
if network_type == .failed || network_type == .unkonw {
defult_string = "接口请求错误,刷新试试~"
}
if network_type == .noNetwork {
defult_string = "网络开小差了,刷新试试~"
}
switch _show_type {
case .add:
defult_string = "暂时没有可添加的身份~"
case .info:
defult_string = "暂时没有身份信息~"
case .message:
if listArray.count == 0 && network_type == .success{
defult_string = "暂时没有可读的消息~"
}
case .none:
break
}
return NSAttributedString(string: defult_string, attributes: [.font: Font_17,.foregroundColor: HexColor("#666666")!])
}
func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? {
if _show_type == .message && (network_type == .failed || network_type == .noNetwork) {
let attributes = [NSAttributedString.Key.font:Font_16_Fit,
NSAttributedString.Key.foregroundColor: HexColor("#609BFF")]
return NSAttributedString(string: "刷新", attributes: attributes as [NSAttributedString.Key : Any])
}
return nil
}
func emptyDataSet(_ scrollView: UIScrollView, didTapView view: UIView) {
loadData()
}
}
extension CNLiveMineAddInfoViewController {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if _show_type == .message {
return listArray.count
}
return dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if _show_type == .add {
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveMineInfoLListTableViewIdentifier) as? MineInfoLListTableViewCell else {
return MineInfoLListTableViewCell()
}
let dict = dataArray[indexPath.row] as! Dictionary<String, Any>
cell.setupWithDataSource(icon: dict["image"] as! String, name: dict["name"] as! String)
cell.userInteractionEnabledWhileDragging = true
return cell
} else if _show_type == .message {
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveMineStandInfoTableViewIdentifier) as? MineStandInfoTableViewCell else {
return MineStandInfoTableViewCell()
}
let listModel = listArray[indexPath.row]
cell.setupWithDataSource(icon: listModel.poster, name: listModel.title,number: listModel.subTitle, time: listModel.createTimeString)
cell.userInteractionEnabledWhileDragging = true
return cell
} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveMineStandInfoTableViewIdentifier) as? MineStandInfoTableViewCell else {
return MineStandInfoTableViewCell()
}
let dict = dataArray[indexPath.row] as! Dictionary<String, Any>
cell.setupWithDataSource(icon: dict["image"] as! String, name: dict["name"] as! String,number: dict["number"] as! String)
cell.userInteractionEnabledWhileDragging = false
return cell
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if _show_type == .message {
let listModel = listArray[indexPath.row]
self.navigationController?.pushViewController(CNLiveMineMessageViewController.init(listModel: listModel), animated: true)
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let item = UIDragItem(itemProvider: NSItemProvider(object: UIImage()))
return [item]
}
// MARK: UITableViewDropDelegate
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {}
func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}
func tableView(_ tableView: UITableView, canHandle session: UIDropSession) -> Bool {
// Only receive image data
return session.canLoadObjects(ofClass: UIImage.self)
}
//移动cell事件
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath,
to destinationIndexPath: IndexPath) {
objc_sync_enter(self)
// let dict: Dictionary = dataArray[sourceIndexPath.row] as! Dictionary<String, Any>
// dataArray.remove(sourceIndexPath.row)
// if destinationIndexPath.row > dataArray.count {
// dataArray.append(dict)
// } else {
// dataArray.insert(dict, at: destinationIndexPath.row)
// }
objc_sync_exit(self)
// tableView.reloadData()
}
}