CNLiveMineInputMessageView.swift
20.4 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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
//
// CNLiveMineInputMessageView.swift
// metaCode
//
// Created by open on 2023/10/11.
//
import Foundation
import SnapKit
import HXPHPicker
typealias changeEndTimeResultBlock = (_ isOn: Bool) ->Void
/// 里面显示样式
class MineInputTextShopCustomView: UIView, UITextViewDelegate, UITextFieldDelegate, PhotoPickerControllerDelegate {
lazy var nameLabel: UILabel = {
let nameLabel = UILabel.init()
nameLabel.backgroundColor = .white
nameLabel.textColor = .black
nameLabel.font = BoldFont_18_Fit
if _dict["title"] as! String != "特殊资质" {
let attribute = NSMutableAttributedString.init(string: _dict["title"] as! String)
attribute.addAttributes([NSAttributedString.Key.foregroundColor: HexColor("#FF725C")!], range: NSRange.init(location: 0, length: 1))
nameLabel.attributedText = attribute
} else {
nameLabel.text = _dict["title"] as? String
}
return nameLabel
}()
lazy var contentTextField: UITextField = {
let contentTextField = UITextField.init()
contentTextField.backgroundColor = .white
contentTextField.font = BoldFont_16_Fit
contentTextField.textAlignment = .right
contentTextField.delegate = self
contentTextField.isHidden = _dict["show_type"] as! String != "2"
contentTextField.keyboardType = .default
contentTextField.clearButtonMode = .whileEditing
contentTextField.placeholder = _dict["placeholder"] as? String
return contentTextField
}()
lazy var contentTextView: UITextView = {
let contentTextView = UITextView.init()
contentTextView.backgroundColor = HexColor("#F7F8FA")
contentTextView.font = BoldFont_16_Fit
contentTextView.keyboardType = .default
contentTextView.text = _dict["subTitle"] as? String
contentTextView.textColor = UIColor.lightGray
contentTextView.delegate = self
contentTextView.isHidden = _dict["show_type"] as! String != "1"
return contentTextView
}()
lazy var moreBtn: UIButton = {
let moreBtn = UIButton(type: .custom)
moreBtn.frame = CGRect(x: 0, y: 0, width: adapt_length(length: 70), height: adapt_length(length: 30))
moreBtn.setTitleColor(HexColor("#B4B4B4"), for: .normal)
moreBtn.titleLabel?.font = BoldFont_16_Fit
moreBtn.contentHorizontalAlignment = .right
moreBtn.isHidden = true
moreBtn.setTitle(_dict["placeholder"] as? String, for: .normal)
if _dict["show_type"] as! String == "3" {
moreBtn.isHidden = false
}
if _dict["show_type"] as! String == "9" {
moreBtn.isHidden = false
}
moreBtn.addTarget(self, action: #selector(checkInAction), for: .touchUpInside)
return moreBtn
}()
lazy var moreView: UIImageView = {
let moreView = UIImageView.init()
moreView.contentMode = .scaleAspectFill
moreView.clipsToBounds = true
moreView.backgroundColor = .white
moreView.image = UIImage(named: "mine_header_message_gray_more")
moreView.isHidden = true
if _dict["show_type"] as! String == "3" {
moreView.isHidden = false
}
if _dict["show_type"] as! String == "9" {
moreView.isHidden = false
}
return moreView
}()
lazy var switchView: UISwitch = {
let switchView = UISwitch.init()
switchView.isOn = false
switchView.onTintColor = HexColor("#609AFF")
switchView.isHidden = _dict["show_type"] as! String != "4"
switchView.addTarget(self, action: #selector(switchInAction), for: .valueChanged)
return switchView
}()
lazy var bigImageBtn: UIButton = {
let bigImageBtn = UIButton(type: .custom)
bigImageBtn.isHidden = true
if _dict["show_type"] as! String == "7" {
bigImageBtn.isHidden = false
if _dict["title"] as! String == "*身份证正面" {
bigImageBtn.setImage(UIImage(named: "mine_header_icon_idcard_zhen"), for: .normal)
}
if _dict["title"] as! String == "*身份证反面" {
bigImageBtn.setImage(UIImage(named: "mine_header_icon_idcard_fan"), for: .normal)
}
}
if _dict["show_type"] as! String == "5" || _dict["show_type"] as! String == "8" {
bigImageBtn.isHidden = false
bigImageBtn.setImage(UIImage(named: "mine_header_icon_sellect"), for: .normal)
}
bigImageBtn.contentMode = .scaleAspectFit
bigImageBtn.backgroundColor = .white
bigImageBtn.layer.cornerRadius = 5
bigImageBtn.layer.masksToBounds = true
bigImageBtn.addTarget(self, action: #selector(selectInAction), for: .touchUpInside)
return bigImageBtn
}()
lazy var changeBtn: UIButton = {
let changeBtn = UIButton(type: .custom)
changeBtn.backgroundColor = UIColor.init(white: 0, alpha: 0.5)
changeBtn.setTitle("更换", for: .normal)
changeBtn.setTitleColor(.white, for: .normal)
changeBtn.titleLabel?.font = Font_14_Fit
changeBtn.isHidden = true
changeBtn.addTarget(self, action: #selector(selectInAction), for: .touchUpInside)
return changeBtn
}()
lazy var descLabel: UILabel = {
let descLabel = UILabel.init()
descLabel.textColor = HexColor("#B4B4B4")
descLabel.font = Font_14_Fit
descLabel.textAlignment = .left
descLabel.isHidden = true
if _dict["show_type"] as! String == "7" {
descLabel.isHidden = false
let attribute = NSMutableAttributedString.init(string: _dict["subTitle"] as! String)
attribute.addAttributes([NSAttributedString.Key.foregroundColor: HexColor("#FF725C")!], range: NSRange.init(location: 9, length: 2))
attribute.addAttributes([NSAttributedString.Key.font: BoldFont_16_Fit], range: NSRange.init(location: 9, length: 2))
descLabel.attributedText = attribute
}
if _dict["show_type"] as! String == "5" || _dict["show_type"] as! String == "8" {
descLabel.isHidden = false
descLabel.text = _dict["subTitle"] as? String
}
descLabel.numberOfLines = 0
descLabel.lineBreakMode = .byWordWrapping
return descLabel
}()
lazy var selectView: UIView = {
let selectView = UIView.init()
selectView.backgroundColor = .white
selectView.isHidden = _dict["show_type"] as! String != "6"
selectView.layer.cornerRadius = 8
selectView.layer.masksToBounds = true
selectView.layer.borderColor = HexColor("#666666")?.cgColor
selectView.layer.borderWidth = 0.5
return selectView
}()
lazy var selectButton : UIButton = {
let selectButton = UIButton(type: .custom)
selectButton.backgroundColor = HexColor("#F5A623")
selectButton.isHidden = _dict["show_type"] as! String != "6"
selectButton.layer.cornerRadius = 5
selectButton.layer.masksToBounds = true
selectButton.setImage(UIImage.imageWithColor(color: HexColor("#F5A623")!, size: CGSizeMake(5, 5)), for: .normal)
return selectButton
}()
lazy var selectLabel : UILabel = {
let selectLabel = UILabel.init()
selectLabel.text = "身份证"
selectLabel.isHidden = _dict["show_type"] as! String != "6"
selectLabel.textColor = HexColor("#333333")
selectLabel.font = Font_16_Fit
selectLabel.textAlignment = .right
return selectLabel
}()
lazy var bottem_line: UILabel = {
let bottem_line = UILabel.init()
bottem_line.backgroundColor = HexColor("#E6E6E6")
return bottem_line
}()
var _dict: NSMutableDictionary!
var _resultBlock: changeEndTimeResultBlock!
init(frame: CGRect, dict: NSMutableDictionary, resultBlock: @escaping changeEndTimeResultBlock) {
super.init(frame: frame)
_dict = dict
_resultBlock = resultBlock
addSubview(nameLabel)
nameLabel.snp.makeConstraints { make in
if _dict["show_type"] as! String == "1" ||
_dict["show_type"] as! String == "5" ||
_dict["show_type"] as! String == "7" ||
_dict["show_type"] as! String == "8" {
make.top.equalToSuperview().offset(10)
make.height.equalTo(25)
} else {
make.centerY.equalToSuperview()
}
make.left.equalToSuperview().offset(10)
make.width.lessThanOrEqualTo(adapt_length(length: 160))
}
addSubview(contentTextField)
contentTextField.snp.makeConstraints { make in
if _dict["show_type"] as! String == "1" {
make.top.equalToSuperview().offset(10)
make.height.equalTo(20)
} else {
make.centerY.equalToSuperview()
make.height.equalTo(40)
}
make.right.equalToSuperview().offset(-10)
make.left.equalTo(nameLabel.snp.right).offset(10)
}
addSubview(bottem_line)
bottem_line.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.height.equalTo(0.5)
make.bottom.equalToSuperview().offset(-0.5)
}
addSubview(contentTextView)
contentTextView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.top.equalTo(nameLabel.snp.bottom).offset(10)
make.bottom.equalTo(bottem_line.snp.top).offset(10)
}
addSubview(moreView)
moreView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.height.equalTo(adapt_length(length: 20))
make.width.equalTo(adapt_length(length: 16))
make.right.equalToSuperview().offset(-adapt_length(length: 10))
}
addSubview(moreBtn)
moreBtn.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalTo(moreView.snp.left).offset(-adapt_length(length: 5))
make.left.equalTo(nameLabel.snp.right).offset(adapt_length(length: 10))
}
addSubview(switchView)
switchView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalToSuperview().offset(-10)
}
addSubview(bigImageBtn)
bigImageBtn.snp.makeConstraints { make in
if _dict["show_type"] as! String == "7" {
make.top.equalTo(nameLabel.snp.bottom).offset(10)
make.left.equalToSuperview().offset(10)
make.right.bottom.equalToSuperview().offset(-10)
} else {
make.top.equalTo(nameLabel.snp.bottom).offset(10)
make.left.equalToSuperview().offset(10)
if _dict["show_type"] as! String == "5" {
make.bottom.equalToSuperview().offset(-10)
make.width.equalTo(100)
}
if _dict["show_type"] as! String == "8" {
make.size.equalTo(200)
}
}
}
bigImageBtn.addSubview(changeBtn)
changeBtn.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.height.equalTo(30)
}
addSubview(descLabel)
descLabel.snp.makeConstraints { make in
if _dict["show_type"] as! String == "7" {
make.centerY.equalTo(nameLabel)
make.left.equalTo(nameLabel.snp.right).offset(10)
make.right.equalToSuperview().offset(-10)
} else {
make.bottom.equalToSuperview().offset(-10)
make.left.equalTo(bigImageBtn.snp.right).offset(10)
make.right.equalToSuperview().offset(-10)
}
}
addSubview(selectLabel)
selectLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalToSuperview().offset(-10)
}
addSubview(selectView)
selectView.snp.makeConstraints { make in
make.centerY.equalTo(nameLabel)
make.right.equalTo(selectLabel.snp.left).offset(-5)
make.size.equalTo(16)
}
selectView.addSubview(selectButton)
selectButton.snp.makeConstraints { make in
make.top.left.equalToSuperview().offset(3)
make.size.equalTo(10)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func textViewDidBeginEditing(_ textView: UITextView) {
if textView.textColor == UIColor.lightGray {
textView.text = nil
textView.textColor = UIColor.black
}
}
func textViewShouldEndEditing(_ textView: UITextView) -> Bool {
if textView.text.isEmpty {
textView.text = _dict["subTitle"] as? String
textView.textColor = UIColor.lightGray
} else {
_dict.setObject(textView.text ?? "", forKey: "content" as NSCopying)
}
return true
}
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
if !textField.text!.isEmpty {
_dict.setObject(textField.text ?? "", forKey: "content" as NSCopying)
}
return true
}
@objc func checkInAction() {
let title = (_dict["title"] as! String)
let index = title.index(title.startIndex, offsetBy: 1)
let dataArray = NSMutableArray.init()
if title == "*经营类目" {
dataArray.addObjects(from: _dict["dataArray"] as! [NSDictionary])
}
contentTextField.resignFirstResponder()
contentTextView.resignFirstResponder()
MineStandListAlertView.showStandListView(infos: dataArray, name:String(title[index...]), show_type:dataArray.count == 0 ? .date : .text, result: { [self] text in
if dataArray.count == 0 {
_dict.setObject((text as! NSString).timeStrChangeTotimeInterval("yyyy-MM-dd"), forKey: "content" as NSCopying)
moreBtn.setTitle(text as? String, for: .normal)
} else {
let dict = text as! NSDictionary
_dict.setObject(dict["id"] as! String, forKey: "content" as NSCopying)
_dict.setObject(dict["title"] as! String, forKey: "category" as NSCopying)
moreBtn.setTitle(dict["title"] as? String, for: .normal)
}
moreBtn.setImage(UIImage(named: "mine_header_message_gray_more"), for: .normal)
moreBtn.setupButtonImageAndTitlePossitionWith(padding: 0, style: .right)
moreBtn.setTitleColor(UIColor.black, for: .normal)
})
}
@objc func switchInAction(sender: UISwitch) {
_resultBlock(sender.isOn)
}
@objc func selectInAction() {
contentTextField.resignFirstResponder()
contentTextView.resignFirstResponder()
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
currentViewController()?.navigationController?.present(pickerController, animated: true, completion: nil)
}
func pickerController(_ pickerController: PhotoPickerController,
didFinishSelection result: PickerResult) {
result.getImage { [self] (image, photoAsset, index) in
if let image = image {
_dict.setObject(image , forKey: "content" as NSCopying)
}else {
print("failed")
}
} completionHandler: { [self] (images) in
self.bigImageBtn.setImage(images.first, for: .normal)
if _dict["show_type"] as! String == "7" || _dict["show_type"] as! String == "5" || _dict["show_type"] as! String == "8" {
self.changeBtn.isHidden = false
}
}
}
}
/// 顶部流程图显示
class MineInputShopHeaderView : UIView {
lazy var headerView : UIImageView = {
let headerView = UIImageView.init()
headerView.backgroundColor = .white
headerView.image = UIImage(named: "mine_header_icon_flow")
headerView.contentMode = .scaleAspectFit
headerView.layer.masksToBounds = true
return headerView
}()
lazy var titleLabel: UILabel = {
let titleLabel = UILabel.init()
titleLabel.text = "营业执照"
titleLabel.textColor = HexColor("#9D9D9D")
titleLabel.font = BoldFont_17_Fit
return titleLabel
}()
var temp_h: Int! = 10
var temp_dict:NSMutableDictionary!
var _showType:CNLiveMineShopResultShowType!
var temp_contentView : MineInputTextShopCustomView!
init(frame: CGRect, array: Array<Any>, showType: CNLiveMineShopResultShowType) {
_showType = showType
super.init(frame: frame)
addSubview(headerView)
headerView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(10)
make.left.right.equalToSuperview()
make.height.equalTo(100)
}
addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.top.equalTo(headerView.snp.bottom).offset(20)
make.left.equalToSuperview().offset(10)
make.height.equalTo(20)
}
for dic in array {
loadContentView(dic: dic as! NSMutableDictionary)
}
}
func loadContentView(dic: NSMutableDictionary) {
var item_h = 60
if dic["show_type"]! as! String == "1" {
item_h = 150
} else if (dic["show_type"]! as! String == "5" || dic["show_type"]! as! String == "8") {
item_h = 200
} else if (dic["show_type"]! as! String == "7") {
item_h = 250
}
let contentView = MineInputTextShopCustomView.init(frame: CGRectZero, dict: dic, resultBlock: { [self] isOn in
if isOn {
temp_dict.setObject("-1", forKey: "content" as NSCopying)
temp_contentView.moreBtn.setTitle("长期", for: .normal)
temp_contentView.moreBtn.setImage(UIImage(named: "mine_header_message_gray_more"), for: .normal)
temp_contentView.moreBtn.setupButtonImageAndTitlePossitionWith(padding: 0, style: .right)
temp_contentView.moreBtn.setTitleColor(UIColor.black, for: .normal)
} else {
temp_dict.setObject("", forKey: "content" as NSCopying)
temp_contentView.moreBtn.setTitle("请选择", for: .normal)
temp_contentView.moreBtn.setImage(UIImage(named: "mine_header_message_gray_more"), for: .normal)
temp_contentView.moreBtn.setupButtonImageAndTitlePossitionWith(padding: 0, style: .right)
temp_contentView.moreBtn.setTitleColor(HexColor("#B4B4B4"), for: .normal)
}
})
contentView.backgroundColor = .white
addSubview(contentView)
contentView.snp.makeConstraints { make in
if _showType == .one {
make.top.equalTo(titleLabel.snp.bottom).offset(temp_h)
}
if _showType == .two || _showType == .three{
make.top.equalToSuperview().offset(temp_h)
}
make.left.right.equalToSuperview()
make.height.equalTo(item_h)
}
if dic["title"]! as! String == "*经营期限(结束)" {
temp_contentView = contentView
temp_dict = dic
}
temp_h += item_h
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}