CNLiveShopGoodsManageDetailsInputManager.swift
5.41 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
//
// CNLiveShopGoodsManageDetailsInputManager.swift
// metaCode
//
// Created by zx on 2023/11/16.
//
import Foundation
typealias completerDoneBlock = (_ k:String,_ v:String)->Void
class CNLiveShopGoodsManageDetailsInputManager:NSObject{
var modalViewController = CNLiveModalPresentationViewController()
var paramField = UITextField()
var contentField = UITextField()
var completerBlock:completerDoneBlock?
func showCustomParamAlertWithCompleterBlock(completeBlock:@escaping completerDoneBlock){
let contentView = UIView(frame: CGRect(x: 0, y: 0, width: KSreenWidth, height: 230))
contentView.backgroundColor = .white
contentView.layer.cornerRadius = 6
let titleLabel = UILabel(frame: CGRect(x: 0, y: 20, width: KSreenWidth-20, height: 30))
titleLabel.font = Font_16
titleLabel.textAlignment = .center
titleLabel.text = "添加通用参数"
titleLabel.textColor = HexColor("#333333")
titleLabel.backgroundColor = .white
contentView.addSubview(titleLabel)
let paramView = UIView(frame: CGRect(x: 10, y: titleLabel.bottom+10, width: KSreenWidth-40, height: 40))
paramView.backgroundColor = HexColor("#F7F7F7")
paramView.layer.masksToBounds = true
paramView.layer.cornerRadius = 5
contentView.addSubview(paramView)
let paramField = UITextField(frame: CGRect(x: 5, y: 5, width: KSreenWidth-50, height: 35))
paramField.placeholder = "请输入参数名称"
paramField.returnKeyType = .next
paramField.font = Font_14
paramField.textColor = HexColor("#333333")
paramField.backgroundColor = .clear
paramView.addSubview(paramField)
self.paramField = paramField
let contentSubView = UIView(frame: CGRect(x: 10, y: paramView.bottom+10, width: contentView.width-40, height: 40))
contentSubView.backgroundColor = HexColor("#F7F7F7")
contentSubView.layer.masksToBounds = true
contentSubView.layer.cornerRadius = 5
contentView.addSubview(contentSubView)
let contentField = UITextField(frame: CGRect(x: 5, y: 5, width: KSreenWidth-50, height: 30))
contentField.placeholder = "请输入参数内容"
contentField.returnKeyType = .done
contentField.font = Font_14
contentField.textColor = HexColor("#333333")
contentField.backgroundColor = .clear
contentSubView.addSubview(contentField)
self.contentField = contentField
let cancelButton = UIButton(type: .custom)
cancelButton.frame = CGRect(x: 10, y: contentSubView.bottom+10, width: (contentView.width-50)*0.5, height: 40)
cancelButton.setTitle("取消", for: .normal)
cancelButton.setTitle("取消", for: .highlighted)
cancelButton.setTitleColor(HexColor("#999999"), for: .normal)
cancelButton.setTitleColor(HexColor("#999999"), for: .highlighted)
cancelButton.layer.cornerRadius = 5
cancelButton.backgroundColor = .white
cancelButton.layer.borderColor = HexColor("#999999")!.cgColor
cancelButton.layer.borderWidth = 1
cancelButton.layer.masksToBounds = true
cancelButton.titleLabel?.font = Font_14
contentView.addSubview(cancelButton)
let confirmButton = UIButton(type: .custom)
confirmButton.frame = CGRect(x: 20+cancelButton.width, y: contentSubView.bottom+10, width: (contentView.width-50)*0.5, height: 40)
confirmButton.setTitle("确定", for: .normal)
confirmButton.setTitle("确定", for: .highlighted)
confirmButton.setTitleColor(HexColor("#FFFFFF"), for: .normal)
confirmButton.setTitleColor(HexColor("#FFFFFF"), for: .highlighted)
confirmButton.layer.cornerRadius = 5
confirmButton.layer.masksToBounds = true
confirmButton.backgroundColor = HexColor("#61C463")
confirmButton.titleLabel?.font = Font_14
contentView.addSubview(confirmButton)
let modalViewController = CNLiveModalPresentationViewController()
modalViewController.contentView = contentView
currentViewController()?.addChild(modalViewController)
modalViewController.didMove(toParent: currentViewController())
currentViewController()?.view.addSubview(modalViewController.view)
modalViewController.showingAnimationWithCompletion { finished in
}
self.modalViewController = modalViewController
cancelButton.addTarget(self, action: #selector(cancelButtonAction), for: .touchUpInside)
confirmButton.addTarget(self, action: #selector(confirmButtonAction), for: .touchUpInside)
self.completerBlock = completeBlock
self.modalViewController.confirmBlock = {
self.confirmButtonAction()
}
}
@objc func cancelButtonAction(){
self.modalViewController.hidingAnimationWithCompletion { finished in
}
}
@objc func confirmButtonAction(){
if self.paramField.text?.count ?? 0 > 0 && self.contentField.text?.count ?? 0 > 0{
self.modalViewController.hidingAnimationWithCompletion { finished in
if finished{
self.completerBlock!((self.paramField.text?.count ?? 0 > 10 ? self.paramField.text?.subString(start: 0, length: 10) : self.paramField.text) ?? "",self.contentField.text ?? "")
}
}
}
}
}