CNLiveDigitalFirstCell.swift
10.6 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
//
// CNLiveDigitalFirstCell.swift
// metaCode
//
// Created by zx on 2024/6/17.
// 数字资产-实名/未实名cell
import Foundation
import Kingfisher
import SnapKit
//typealias SelectBlock = (_ currentCell: CNLiveDigitalAuthCell ,_ identitiesId:String) -> Void
class CNLiveDigitalFirstCell: UITableViewCell {
lazy var whiteView :UIView = {
let whiteView = UIView(frame: CGRect(x: 15, y:adapt_length(length: 20), width: KSreenWidth-30, height: adapt_length(length: 121)))
whiteView.backgroundColor = .white
whiteView.layer.cornerRadius = 12
whiteView.clipsToBounds = true
return whiteView
}()
lazy var unAuthTitleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.textColor = HexColor("#333333")
titleLabel.textAlignment = .center
titleLabel.text = "数字认证前,你实名了吗?"
titleLabel.font = BoldFont_17
return titleLabel
}()
lazy var authBtn: UIButton = {
let closeBtn = UIButton(type: .custom)
closeBtn.frame = CGRect(x: 0, y: 0, width: 86, height: 34)
closeBtn.setTitle("立即实名", for: .normal)
closeBtn.setTitleColor(.white, for: .normal)
closeBtn.layer.cornerRadius = 6
closeBtn.clipsToBounds = true
// fillCode
let bgLayer1 = CAGradientLayer()
bgLayer1.colors = [UIColor(red: 0.17, green: 0.41, blue: 0.99, alpha: 1).cgColor, UIColor(red: 0.27, green: 0.68, blue: 0.99, alpha: 1).cgColor]
bgLayer1.locations = [0, 1]
bgLayer1.frame = closeBtn.bounds
bgLayer1.startPoint = CGPoint(x: 0.5, y: 1)
bgLayer1.endPoint = CGPoint(x: 0, y: 0)
closeBtn.layer.addSublayer(bgLayer1)
closeBtn.addTarget(self, action: #selector(authBtnAction), for: .touchUpInside)
return closeBtn
}()
//已认证 名字
lazy var authNameTitleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.textColor = HexColor("#333333")
titleLabel.textAlignment = .center
titleLabel.text = ""
titleLabel.font = BoldFont_24
return titleLabel
}()
lazy var changePersonBtn: UIButton = {
let closeBtn = UIButton(type: .custom)
closeBtn.backgroundColor = HexColor("#FFF8DB")
closeBtn.layer.cornerRadius = 3
closeBtn.clipsToBounds = true
closeBtn.setTitle("实名对象切换 ▶", for: .normal)
closeBtn.setTitleColor(HexColor("#F2A62E"), for: .normal)
closeBtn.titleLabel?.font = Font_12
closeBtn.addTarget(self, action: #selector(changePersonBtnAction), for: .touchUpInside)
return closeBtn
}()
lazy var phoneTitleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.textColor = HexColor("#999999")
titleLabel.textAlignment = .left
titleLabel.text = "男 | xx岁 | 10000000000"
titleLabel.font = Font_14
return titleLabel
}()
lazy var realNameView :UIView = {
let bottomNavView = UIView(frame: CGRect(x: 0, y: 0, width: adapt_length(length: 80), height: adapt_length(length: 106)))
bottomNavView.clipsToBounds = true
bottomNavView.layer.cornerRadius = 44
bottomNavView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
// fillCode
let bgLayer1 = CAGradientLayer()
bgLayer1.colors = [UIColor(red: 0.25, green: 0.27, blue: 0.4, alpha: 1).cgColor, UIColor(red: 0.56, green: 0.64, blue: 0.78, alpha: 1).cgColor]
bgLayer1.locations = [0, 1]
bgLayer1.frame = bottomNavView.bounds
bgLayer1.startPoint = CGPoint(x: 0.5, y: -0.37)
bgLayer1.endPoint = CGPoint(x: 0.71, y: 0.71)
bottomNavView.layer.addSublayer(bgLayer1)
let iconImgView = UIImageView(frame: CGRect(x: adapt_length(length: 6), y: adapt_length(length: 32), width: adapt_length(length: 68), height: adapt_length(length: 68)))
iconImgView.image = UIImage(named: "auth_realIcon")
bottomNavView.addSubview(iconImgView)
let titleLabel = UILabel(frame: CGRect(x: 0, y: adapt_length(length: 10), width: adapt_length(length: 80), height: 17))
titleLabel.textColor = HexColor("#FFFFFE")
titleLabel.textAlignment = .center
titleLabel.text = "去实名认证"
titleLabel.font = Font_12
bottomNavView.addSubview(titleLabel)
bottomNavView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(realNameViewAction)))
return bottomNavView
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.contentView.backgroundColor = .clear
self.backgroundColor = .clear
self.selectionStyle = .none
if UserInfoManager.shared.userInfo.userMsgUsers?.verifyUsers.count ?? 0 > 0{
//实名认证过
self.contentView.addSubview(self.whiteView)
self.whiteView.addSubview(self.authNameTitleLabel)
self.authNameTitleLabel.snp.makeConstraints { make in
make.left.equalTo(adapt_length(length: 15))
make.top.equalTo(adapt_length(length: 20))
}
self.authNameTitleLabel.text = UserInfoManager.shared.userInfo.currentUser?.name
self.whiteView.addSubview(self.changePersonBtn)
self.changePersonBtn.snp.makeConstraints { make in
make.left.equalTo(self.authNameTitleLabel.snp.right).offset(adapt_length(length: 5))
make.centerY.equalTo(self.authNameTitleLabel.snp.centerY)
make.width.equalTo(adapt_length(length: 91))
make.height.equalTo(adapt_length(length: 21))
}
self.whiteView.addSubview(self.phoneTitleLabel)
self.phoneTitleLabel.snp.makeConstraints { make in
make.left.equalTo(adapt_length(length: 15))
make.top.equalTo(self.authNameTitleLabel.snp.bottom).offset(adapt_length(length: 8))
}
let (gender, age) = self.extractGenderAndAge(fromIDCardNumber: UserInfoManager.shared.userInfo.currentUser?.idNo ?? "")
let ageStr = String(format: "%d", age ?? 0)
self.phoneTitleLabel.text = gender+" | "+ageStr+"岁"+" | "+UserInfoManager.shared.userInfo.mobile
self.whiteView.addSubview(self.realNameView)
self.realNameView.snp.makeConstraints { make in
make.right.equalToSuperview().offset(adapt_length(length: -35))
make.top.equalToSuperview()
make.width.equalTo(adapt_length(length: 80))
make.height.equalTo(adapt_length(length: 106))
}
}else{
//未实名认证
self.contentView.addSubview(self.whiteView)
self.whiteView.addSubview(self.unAuthTitleLabel)
self.whiteView.addSubview(self.authBtn)
self.unAuthTitleLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(30)
make.left.equalTo(5)
make.right.equalToSuperview().offset(-5)
}
self.authBtn.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.width.equalTo(86)
make.height.equalTo(34)
make.top.equalTo(self.unAuthTitleLabel.snp.bottom).offset(12)
}
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//身份证号提取 性别和年龄
func extractGenderAndAge(fromIDCardNumber idCardNumber: String) -> (gender: String, age: Int?) {
guard idCardNumber.count == 18 else {
return ("未知", nil)
}
// 提取出生年份(身份证号码的第7位到第14位)
let birthYearStr = idCardNumber.subString(start: 6, length: 4)
guard let birthYear = Int(birthYearStr) else {
return ("未知", nil)
}
// 计算年龄
let currentYear = Calendar.current.component(.year, from: Date())
let age = currentYear - birthYear
// 提取性别(身份证号码的第17位,奇数代表男,偶数代表女)
let genderCode = Int(String(idCardNumber[idCardNumber.index(idCardNumber.startIndex, offsetBy: 16)]))
let gender = genderCode != nil && genderCode! % 2 == 0 ? "女" : "男"
return (gender, age >= 0 ? age : nil)
}
//未认证
@objc func authBtnAction(){
let vc = CNLiveRealNameAuthController()
vc.channelId = UserInfoManager.shared.userInfo.currentChannelId
vc.vsid = UserInfoManager.shared.userInfo.currentUser?.vsid ?? ""
vc.sid = UserInfoManager.shared.userInfo.uid
currentViewController()?.navigationController?.pushViewController(vc, animated: true)
}
//已认证
//切换实名身份
@objc func changePersonBtnAction(){
var infoArr = Array<String>()
UserInfoManager.shared.userInfo.userMsgUsers?.verifyUsers.forEach({ userMdl in
infoArr.append(userMdl.name)
})
MineStandListAlertView.showStandListView(infos: infoArr as NSArray,name: "实名对象切换", show_type: .string, isAddPerson: true) {text in
let seleText = text as? String
let tempArr = UserInfoManager.shared.userInfo.userMsgUsers?.verifyUsers
if tempArr?.count == 0{
return
}
tempArr?.forEach({ userMdl in
if userMdl.name == seleText{
let userInfo = UserInfoManager.shared.userInfo
userInfo.currentUser = userMdl
UserInfoManager.cacheUserInfo(userInfo: userInfo)
CNLiveMineViewModel.requestsGETAuthInfoList(page: 1) { result, respStatue in
}
self.authNameTitleLabel.text = userMdl.name
let (gender, age) = self.extractGenderAndAge(fromIDCardNumber: UserInfoManager.shared.userInfo.currentUser?.idNo ?? "")
let ageStr = String(format: "%d", age ?? 0)
self.phoneTitleLabel.text = gender+" | "+ageStr+"岁"+" | "+UserInfoManager.shared.userInfo.mobile
}
})
}
}
//实名认证页面
@objc func realNameViewAction(){
navigationViewController().pushViewController(CNLiveDigitalMineRealNameController(), animated: true)
}
}