CNLiveMineInputViewController.swift
6.89 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
//
// CNLiveMineInputViewController.swift
// metaCode
//
// Created by open on 2023/9/11.
//
import Foundation
import EmptyDataSet_Swift
class CNLiveMineInputViewController : CNLiveBaseViewController, UITableViewDelegate, UITableViewDataSource, EmptyDataSetSource, EmptyDataSetDelegate{
let kMineBodyInputAuthCellIdentifier = "kMineBodyInputAuthCellIdentifier"
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.delegate = self
tableView.dataSource = self
tableView.emptyDataSetSource = self
tableView.emptyDataSetDelegate = self
tableView.backgroundColor = HexColor("#F7F8FA")
tableView.tableFooterView = UIView.init()
tableView.contentInsetAdjustmentBehavior = .scrollableAxes
tableView.separatorStyle = .none
tableView.register(MineBodyInputAuthCell.self, forCellReuseIdentifier: kMineBodyInputAuthCellIdentifier)
return tableView
}()
lazy var sendButton: UIButton = {
let sendButton = UIButton(type: .custom)
sendButton.setTitle("添加身份", for: .normal)
sendButton.setTitleColor(.white, for: .normal)
sendButton.titleLabel?.font = BoldFont_16_Fit
sendButton.layer.cornerRadius = 20
sendButton.layer.masksToBounds = true
sendButton.isHidden = true
sendButton.addTarget(self, action: #selector(sendInfoActionMothod), for: .touchUpInside)
return sendButton
}()
lazy var dataArray: NSMutableArray = {
return NSMutableArray.init()
}()
var _listModel:StandListModel!
init(listModel:StandListModel) {
super.init(nibName:nil, bundle:nil)
_listModel = listModel
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
navigationBarHidden = false
titleName = _listModel.name ?? ""
view.backgroundColor = HexColor("#F7F8FA")
loadStandInfoData()
view.addSubview(sendButton)
sendButton.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-get_system_tabbar_ui_offsetHeight() - 20)
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.height.equalTo(40)
}
setupWithSendBtnStatue(statue: false)
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.top.equalTo(get_system_nav_height())
make.left.right.equalToSuperview()
make.bottom.equalTo(sendButton.snp.top).offset(-10)
}
}
private func loadStandInfoData() {
CNLiveMineViewModel.requestsStandInfo(identityId: "\(_listModel.id)") {[weak self] result, respStatue in
if respStatue == .success {
self?.dataArray.addObjects(from: result as! [Any])
self?.tableView.reloadData()
if (self?.dataArray.count)! > 0 {
self?.sendButton.isHidden = false
self?.tableView.tableHeaderView = self?.setupHeaderAndFooter(is_last: false)
self?.tableView.tableFooterView = self?.setupHeaderAndFooter(is_last: true)
}
}
}
}
private func setupWithSendBtnStatue(statue: Bool) {
var alpha = 0.3
if statue {
alpha = 1
}
sendButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: alpha),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: alpha)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
sendButton.isUserInteractionEnabled = statue
}
@objc func sendInfoActionMothod() {
CNLiveMineViewModel.requestsPOSTAuthInfo(identityId: "\(_listModel.id)", infos: self.dataArray) { [self] result, respStatue in
if respStatue == .success {
showMessage(message: "上传成功")
DispatchQueue.main.asyncAfter(deadline: .now()+1) { [self] in
self.navigationController?.pushViewController(CNLiveMineAuthResultViewController.init(listModel: _listModel), animated: true)
}
}
}
}
func setupHeaderAndFooter(is_last: Bool) -> UIView {
let mainView = UIView.init(frame: CGRect(x: 0, y: 0, width: Int(KSreenWidth), height: 10));
mainView.backgroundColor = .clear
let v = UIView.init(frame: CGRect(x: 10, y: 0, width: Int(KSreenWidth) - 20, height: 10))
v.backgroundColor = .white
if !is_last {
v.addCorner(conrners: [.topLeft, .topRight], radius: 10)
} else {
v.addCorner(conrners: [.bottomLeft, .bottomRight], radius: 10)
}
mainView.addSubview(v)
return mainView
}
}
extension CNLiveMineInputViewController {
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 {
let cell = tableView.dequeueReusableCell(withIdentifier: kMineBodyInputAuthCellIdentifier) as! MineBodyInputAuthCell
cell.setListModel(infoModel: self.dataArray[indexPath.row] as! MineStandInfoModel, is_last: indexPath.row == self.dataArray.count - 1) { [weak self] in
let is_result = self?.inspectResult()
self?.setupWithSendBtnStatue(statue: is_result ?? true)
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let infoModel = self.dataArray[indexPath.row] as! MineStandInfoModel
if infoModel.children.count > 0 {
self.view.endEditing(true)
DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
MineStandListAlertView.showStandListView(infos: infoModel.children as NSArray,name: "选择\(infoModel.name ?? "")") {[weak self] text in
infoModel.value = text
self?.tableView.reloadData()
let is_result = self?.inspectResult()
self?.setupWithSendBtnStatue(statue: is_result ?? true)
}
}
}
}
private func inspectResult() -> Bool {
var is_result: Bool = true
for item in self.dataArray {
let listModel = item as! MineStandInfoModel
if (listModel.nonEmpty && listModel.value?.count == 0) {
is_result = false
}
}
return is_result
}
}