CNIDCardView.swift
6.78 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
//
// 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), placeholder: UIImage(named: "homePage_idCardBG"))
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)
// if cardArray.count > 0{
// for i in (0..<cardArray.count){
// let idCardModel = cardArray[i] as! MineStandInfoModel
// let siBianGap:CGFloat = 17
// let labelsGap:CGFloat = 10
//
// let keyLabel = UILabel.init()
// keyLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")
// keyLabel.textAlignment = .left
// keyLabel.font = Font(15)
// keyLabel.backgroundColor = .clear
// keyLabel.text = idCardModel.name ?? ""
// keyLabel.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: 70, height: 21)
// keyLabel.adjustsFontSizeToFitWidth = true
// keyLabel.tag = 10000+i
// self.addSubview(keyLabel)
//
// 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: keyLabel.right+labelsGap+siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: self.width-keyLabel.right-labelsGap-siBianGap-5, height: 21)
// valueLabel.adjustsFontSizeToFitWidth = true
// valueLabel.tag = 20000+i
// self.addSubview(valueLabel)
//
// }
// }else{
// //没数据
// }
}
}
}
func cardUIWithArray(cardArr:NSMutableArray){
self.subviews.forEach { view in
if view.tag >= 10000{
view.removeFromSuperview()
}
}
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
let keyLabel = UILabel.init()
keyLabel.textColor = HexColor(_idModel?.backgroundColor ?? "")
keyLabel.textAlignment = .left
keyLabel.font = Font(15)
keyLabel.backgroundColor = .clear
keyLabel.text = idCardModel.name ?? ""
keyLabel.frame = CGRect(x: siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: 70, height: 21)
keyLabel.adjustsFontSizeToFitWidth = true
keyLabel.tag = 10000+i
self.addSubview(keyLabel)
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: keyLabel.right+labelsGap+siBianGap, y: siBianGap+CGFloat(i)*21+CGFloat(i)*labelsGap, width: self.width-keyLabel.right-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
}()
}