CNLiveMineInputViewController.swift
10.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//
// CNLiveMineInputViewController.swift
// metaCode
//
// Created by open on 2023/9/11.
//
import Foundation
import EmptyDataSet_Swift
import HXPHPicker
import APButton
enum CNLiveMineInputAuthType {
case person//个人认证
case enterprise//企业认证
}
typealias resultUploadImageBlock = (_ url: String) -> Void
class CNLiveMineInputViewController : CNLiveBaseViewController, UITableViewDelegate, UITableViewDataSource, EmptyDataSetSource, EmptyDataSetDelegate, PhotoPickerControllerDelegate{
static 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
return tableView
}()
lazy var tipLabel: UILabel = {
let tipLabel = UILabel.init()
tipLabel.textColor = HexColor("#999999")
tipLabel.text = "请填写真实信息,提交完成后,不可更改!"
tipLabel.font = Font_11_Fit
tipLabel.isHidden = true
tipLabel.textAlignment = .center
return tipLabel
}()
lazy var sendButton: APButton = {
let sendButton = APButton()
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.activityIndicator.color = .white
sendButton.addTarget(self, action: #selector(sendInfoActionMothod), for: .touchUpInside)
return sendButton
}()
lazy var dataArray: NSMutableArray = {
return NSMutableArray.init()
}()
var select_image: UIImage!
var _listModel:StandListModel!
var tempCell:MineBodyInputAuthCell!
var _authType:CNLiveMineInputAuthType!
init(listModel:StandListModel,authType:CNLiveMineInputAuthType) {
super.init(nibName:nil, bundle:nil)
_listModel = listModel
_authType = authType
}
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)
}
view.addSubview(tipLabel)
tipLabel.snp.makeConstraints { make in
make.bottom.equalTo(sendButton.snp.top).offset(-10)
make.centerX.equalToSuperview()
make.left.right.equalToSuperview()
}
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(tipLabel.snp.top).offset(-10)
}
}
private func loadStandInfoData() {
showLoading(message: "")
CNLiveMineViewModel.requestsStandInfo(identityId: "\(_listModel.id)", type: .nodate, authType: _authType) {[weak self] result, respStatue in
if respStatue == .success {
self?.dataArray.addObjects(from: result as! [Any])
if (self?.dataArray.count)! > 0 {
self?.sendButton.isHidden = false
self?.tipLabel.isHidden = false
self?.tableView.tableHeaderView = self?.setupHeaderAndFooter(is_last: false)
self?.tableView.tableFooterView = self?.setupHeaderAndFooter(is_last: true)
for i in 0..<(self?.dataArray.count)! {
self?.tableView.register(MineBodyInputAuthCell.self, forCellReuseIdentifier: CNLiveMineInputViewController.kMineBodyInputAuthCellIdentifier+"\(i)")
}
}
self?.tableView.reloadData()
}
}
}
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() {
setupWithContentUploadImage { [self] url in
if (self.tempCell != nil) {
self.tempCell._infoModel?.value = url
}
sendButton.startAnimating()
CNLiveMineViewModel.requestsPOSTAuthInfo(identityId: "\(_listModel.id)", infos: self.dataArray) { [self] result, respStatue in
if respStatue == .success {
showMessage(message: "上传成功")
sendButton.stopAnimating()
DispatchQueue.main.asyncAfter(deadline: .now()+1) { [self] in
self.navigationController?.pushViewController(CNLiveMineAuthResultViewController.init(_listModel,show_type: .result_success, authType: _authType), animated: true)
}
}
}
}
}
private func setupWithContentUploadImage(resultUploadImageBlock: @escaping resultUploadImageBlock) {
if select_image != nil {
_ = UploadManager.uploadImage(imageData: select_image.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in
print("获取进度==>\(progress)")
}, successBlock: { key,url in
resultUploadImageBlock(url)
})
} else {
resultUploadImageBlock("")
}
}
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: CNLiveMineInputViewController.kMineBodyInputAuthCellIdentifier+"\(indexPath.row)") as! MineBodyInputAuthCell
cell.setListModel(infoModel: self.dataArray[indexPath.row] as! MineStandInfoModel, is_last: indexPath.row == self.dataArray.count - 1) {[weak self] type in
if type == .end {
let is_result = self?.inspectResult()
self?.setupWithSendBtnStatue(statue: is_result ?? true)
}
if type == .select {
var crop = PhotoCroppingConfiguration.init()
crop.isRoundCrop = true
let configuration = PhotoEditorConfiguration()
configuration.state = .cropping
configuration.cropping = crop
configuration.fixedCropState = true
let config = PhotoTools.getWXPickerConfig()
config.selectMode = .single
config.selectOptions = .photo
config.photoEditor = configuration
config.maximumSelectedPhotoCount = 1
let pickerController = PhotoPickerController(picker: config)
pickerController.pickerDelegate = self
pickerController.isOriginal = false
self?.navigationController?.present(pickerController, animated: true, completion: nil)
self?.tempCell = cell
}
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let infoModel = self.dataArray[indexPath.row] as! MineStandInfoModel
if infoModel.inputType == 6 {
return adapt_length(length: 70)
} else if infoModel.inputType == 16 {
return adapt_length(length: 150)
} else {
return adapt_length(length: 50)
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let infoModel = self.dataArray[indexPath.row] as! MineStandInfoModel
if infoModel.inputType == 3 || infoModel.inputType == 4 {
let show_type: CNLiveStandListAlertShowType = infoModel.children.count > 0 ? .custom : .date
self.view.endEditing(true)
DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
MineStandListAlertView.showStandListView(infos: infoModel.children as NSArray,name: "选择\(infoModel.name ?? "")", show_type: show_type) {[weak self] text in
infoModel.value = text as? String
self?.tableView.reloadData()
let is_result = self?.inspectResult()
self?.setupWithSendBtnStatue(statue: is_result ?? true)
}
}
}
}
func pickerController(_ pickerController: PhotoPickerController,
didFinishSelection result: PickerResult) {
result.getImage { [weak self] (image, photoAsset, index) in
if let image = image {
self?.select_image = image
}else {
print("failed")
}
} completionHandler: { [weak self] (images) in
self?.tempCell.iconView.image = images.first
}
}
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
}
}