CNLiveMineInputViewController.swift
15.5 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
//
// 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 //企业认证
case agency //机构认证
}
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_12
tipLabel.isHidden = true
tipLabel.textAlignment = .center
return tipLabel
}()
lazy var sendButton: UIButton = {
let sendButton = UIButton()
sendButton.setTitle("下一步", for: .normal)
sendButton.setTitleColor(.white, for: .normal)
sendButton.titleLabel?.font = Font_18
sendButton.layer.cornerRadius = 22
sendButton.layer.masksToBounds = true
sendButton.isHidden = true
sendButton.backgroundColor = HexColor("#1961FE")
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")
}
lazy var bgImgView :UIImageView = {
let iconImgView = UIImageView()
iconImgView.image = UIImage(named: "auth_blueBg")
return iconImgView
}()
lazy var yuanmaLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.textColor = .white
titleLabel.text = "元码数字认证"
titleLabel.font = Font_24
titleLabel.adjustsFontSizeToFitWidth=true
return titleLabel
}()
lazy var yuanmaDescLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.textColor = .white
titleLabel.text = "真我,连接世界\n实名认证,让信任搭建沟通的桥梁"
titleLabel.numberOfLines = 2
titleLabel.font = Font_13
return titleLabel
}()
lazy var whiteBgView :UIView = {
let whiteBgView = UIView()
whiteBgView.backgroundColor = .white
whiteBgView.layer.cornerRadius = 12
whiteBgView.clipsToBounds = true
return whiteBgView
}()
lazy var whiteTopBgView :UIImageView = {
let whiteBgView = UIImageView()
whiteBgView.image = UIImage(named: "realName_bg")
return whiteBgView
}()
lazy var whiteTopBgZGWView :UIImageView = {
let whiteBgView = UIImageView()
whiteBgView.image = UIImage(named: "realName_zgw")
return whiteBgView
}()
lazy var whiteTopBgSFZView :UIImageView = {
let whiteBgView = UIImageView()
whiteBgView.image = UIImage(named: "realName_jumin")
return whiteBgView
}()
lazy var tishiDescLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.textColor = HexColor("#748DC1")
titleLabel.text = "公安部推出的法定身份证件,由中国网元码根据国家相关法律法规要求,由特定行政机关签发,请放心使用"
titleLabel.numberOfLines = 2
titleLabel.font = Font_12
titleLabel.adjustsFontSizeToFitWidth = true
return titleLabel
}()
override func viewDidLoad() {
super.viewDidLoad()
navigationBarHidden = false
titleName = _listModel.name ?? "元码数字认证"
view.backgroundColor = HexColor("#F7F8FA")
loadStandInfoData()
// setupWithSendBtnStatue(statue: false)
self.view.backgroundColor = .white
self.view.addSubview(self.bgImgView)
self.bgImgView.snp.makeConstraints { make in
make.top.equalTo(KNavigationHeight)
make.left.right.equalToSuperview()
make.height.equalTo(KSreenWidth*457/375)
}
self.view.addSubview(self.yuanmaLabel)
self.yuanmaLabel.snp.makeConstraints { make in
make.top.equalTo(KNavigationHeight+adapt_length(length: 45))
make.left.equalTo(adapt_length(length: 30))
}
self.view.addSubview(self.yuanmaDescLabel)
self.yuanmaDescLabel.snp.makeConstraints { make in
make.top.equalTo(self.yuanmaLabel.snp.bottom).offset(adapt_length(length: 10))
make.left.equalTo(adapt_length(length: 30))
}
self.view.addSubview(self.whiteBgView)
self.whiteBgView.snp.makeConstraints { make in
make.top.equalTo(self.yuanmaDescLabel.snp.bottom).offset(adapt_length(length: 31))
make.bottom.equalToSuperview()
make.left.equalTo(15)
make.right.equalToSuperview().offset(-15)
}
self.whiteBgView.addSubview(self.whiteTopBgView)
self.whiteTopBgView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview()
make.width.equalTo(KSreenWidth*235/375)
make.height.equalTo(KSreenWidth*45/375)
}
self.whiteTopBgView.addSubview(self.whiteTopBgZGWView)
self.whiteTopBgZGWView.snp.makeConstraints { make in
// make.left.equalTo(KSreenWidth*44.5/375)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
make.width.equalTo(KSreenWidth*40.5/375)
make.height.equalTo(KSreenWidth*30/375)
}
// self.whiteTopBgView.addSubview(self.whiteTopBgSFZView)
// self.whiteTopBgSFZView.snp.makeConstraints { make in
// make.right.equalToSuperview().offset(-KSreenWidth*44.5/375)
// make.centerY.equalToSuperview()
// make.width.equalTo(KSreenWidth*84.5/375)
// make.height.equalTo(KSreenWidth*25.5/375)
// }
self.whiteBgView.addSubview(self.tishiDescLabel)
self.tishiDescLabel.snp.makeConstraints { make in
make.top.equalTo(self.whiteTopBgView.snp.bottom).offset(10)
make.left.equalTo(15)
make.right.equalToSuperview().offset(-15)
make.height.equalTo(33)
}
self.whiteBgView.addSubview(self.tableView)
self.tableView.snp.makeConstraints { make in
make.top.equalTo(self.tishiDescLabel.snp.bottom).offset(10)
make.left.equalToSuperview()
make.right.equalToSuperview()
make.height.equalTo(122*2+50)
}
view.addSubview(sendButton)
sendButton.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-42)
make.left.equalToSuperview().offset(15)
make.right.equalToSuperview().offset(-15)
make.height.equalTo(44)
}
view.addSubview(tipLabel)
tipLabel.snp.makeConstraints { make in
make.top.equalTo(sendButton.snp.bottom).offset(10)
make.centerX.equalToSuperview()
make.left.right.equalToSuperview()
}
}
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, isAddPerson: false) {[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
}
}