CNIDCardView.swift
7.35 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
//
// CNIDCardView.swift
// metaCode
//
// Created by zx on 2023/9/16.
// 身份认证卡片
import Foundation
class CNIDCardView: UIView{
//IDmodel
var _idModel : StandListModel?
var idModel : StandListModel? {
get{
_idModel
}
set{
_idModel = newValue
self.iDCardBGView.kf.setImage(with: URL(string: _idModel!.cardImg))
if _idModel?.id == 9{
//电商 , 拼接数据
let nameArr = ["公司名称","认证时间","编号"]
let timeStr = NSDate.timeIntervalChangeToYMDTimeStr(timeInterval: Double(_idModel?.shopInfoModel?.addtime ?? "0")!)
let userInfoArr = [_idModel?.shopInfoModel?.commercial_name ?? "" , timeStr , _idModel?.shopInfoModel?.certificates_code ?? ""]
let cardMuteArr = NSMutableArray()
for i in 0..<3{
let standInfoModel = MineStandInfoModel()
standInfoModel.name = nameArr[i]
standInfoModel.userInfo = userInfoArr[i]
cardMuteArr.add(standInfoModel)
}
self.cardUIWithArray(cardArr: cardMuteArr)
}else{
//非电商, 接口数据
self.loadIDDetailData()
}
}
}
override init(frame: CGRect) {
super.init(frame: frame)
self.initUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func initUI()
{
self.addSubview(self.contentView)
self.contentView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
make.width.equalToSuperview()
make.height.equalToSuperview()
}
self.addSubview(self.iDCardBGView)
self.iDCardBGView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
make.width.equalToSuperview()
make.height.equalToSuperview()
}
}
func loadIDDetailData(){
// showLoading(message: "")
CNLiveMineViewModel.requestsStandInfo(identityId: "\(_idModel!.id)", type: .havedate, authType: .person) { [self] result, respStatue in
hiddenLoading()
if respStatue == .success {
let cardArray = result as! NSMutableArray
self.cardUIWithArray(cardArr: cardArray)
}
}
}
func cardUIWithArray(cardArr:NSMutableArray){
self.subviews.forEach { view in
if view.tag >= 10000{
view.removeFromSuperview()
}
}
var maxLblWidth:CGFloat = 0
for model in cardArr {
let idCardMdl = model as! MineStandInfoModel
let keyLabel = UILabel.init()
keyLabel.textAlignment = .left
keyLabel.font = Font(15)
keyLabel.backgroundColor = .clear
keyLabel.text = idCardMdl.name ?? ""
keyLabel.sizeToFit()
let lblWidth = keyLabel.bounds.size.width
if maxLblWidth < lblWidth{
//更新更大的label宽度
maxLblWidth = lblWidth
}
}
let cardArray = NSMutableArray(array: cardArr)
if cardArray.count > 0{
for i in (0..<cardArray.count){
let idCardModel = cardArray[i] as! MineStandInfoModel
let siBianGap:CGFloat = 17
let labelsGap:CGFloat = 10
var keyLblRight:CGFloat = 0
if idCardModel.name?.count == 2{
//2个字特殊处理,2边对齐
let keyLabel1 = UILabel.init()
keyLabel1.textColor = HexColor(_idModel?.backgroundColor ?? "")
keyLabel1.textAlignment = .left
keyLabel1.font = Font(15)
keyLabel1.backgroundColor = .clear
keyLabel1.text = idCardModel.name?.subString(start: 0, length: 1) ?? ""
keyLabel1.sizeToFit()
keyLabel1.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: maxLblWidth, height: keyLabel1.bounds.size.height)
keyLabel1.adjustsFontSizeToFitWidth = true
keyLabel1.tag = 10000+i+100
self.addSubview(keyLabel1)
let keyLabel2 = UILabel.init()
keyLabel2.textColor = HexColor(_idModel?.backgroundColor ?? "")
keyLabel2.textAlignment = .right
keyLabel2.font = Font(15)
keyLabel2.backgroundColor = .clear
keyLabel2.text = idCardModel.name?.subString(start: 1, length: 1) ?? ""
keyLabel2.sizeToFit()
keyLabel2.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: maxLblWidth, height: keyLabel1.bounds.size.height)
keyLabel2.adjustsFontSizeToFitWidth = true
keyLabel2.tag = 10000+i+200
self.addSubview(keyLabel2)
keyLblRight = keyLabel2.right
}else{
//其他字数左对齐
let keyLabel = UILabel.init()
keyLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")
keyLabel.textAlignment = .left
keyLabel.font = Font(15)
keyLabel.backgroundColor = .clear
keyLabel.text = idCardModel.name ?? ""
keyLabel.sizeToFit()
keyLabel.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: keyLabel.bounds.size.width, height: keyLabel.bounds.size.height)
keyLabel.adjustsFontSizeToFitWidth = true
keyLabel.tag = 10000+i
self.addSubview(keyLabel)
keyLblRight = keyLabel.right
}
let valueLabel = UILabel.init()
valueLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")
valueLabel.textAlignment = .left
valueLabel.font = Font(15)
valueLabel.backgroundColor = .clear
valueLabel.text = idCardModel.userInfo ?? ""
valueLabel.frame = CGRect(x: keyLblRight+labelsGap+siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: self.width-keyLblRight-labelsGap-siBianGap-5, height: 21)
valueLabel.adjustsFontSizeToFitWidth = true
valueLabel.tag = 20000+i
self.addSubview(valueLabel)
}
}else{
//没数据
}
}
// MARK: - 懒加载
///视图总容器
lazy var contentView : UIView = {
let contentView = UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0 ))
contentView.backgroundColor = UIColor.clear
return contentView
}()
/// 身份卡片-背景图
lazy var iDCardBGView:UIImageView = {
let iDCardBGView:UIImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
iDCardBGView.backgroundColor = UIColor.clear
return iDCardBGView
}()
}