CNLiveInputFeedBackViewController.swift
10.2 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
//
// CNLiveInputFeedBackViewController.swift
// metaCode
//
// Created by open on 2023/6/7.
//
import Foundation
import HXPHPicker
import APButton
enum InputFeedBackType {
case problem
case product
}
let textView_placeholder = "请尽可能详细地输入您遇到的问题,包括时间、问题发生的页面、进行什么样的操作、出现的具体问题和细节,以便我们更快地处理您的问题 (至少5个字)"
class CNLiveInputFeedBackViewController: CNLiveBaseViewController, UITextViewDelegate {
var _show_type:InputFeedBackType!
init(show_type:InputFeedBackType) {
super.init(nibName:nil, bundle:nil)
_show_type = show_type
}
lazy var iView: UIView = {
let iView = UIView.init()
iView.backgroundColor = .white
iView.layer.cornerRadius = 10
iView.layer.masksToBounds = true
return iView
}()
lazy var p_textView : UITextView = {
let p_textView = UITextView.init()
p_textView.backgroundColor = .white
p_textView.font = BoldFont_16
p_textView.text = textView_placeholder
p_textView.textColor = HexColor("#C8C8C8")
p_textView.delegate = self
return p_textView
}()
lazy var numberLabel : UILabel = {
let numberLabel = UILabel.init()
numberLabel.text = "0/200"
numberLabel.textColor = .black
numberLabel.font = Font_14
numberLabel.textAlignment = .right
return numberLabel
}()
lazy var photoLabel : UILabel = {
let photoLabel = UILabel.init()
let mString = NSMutableAttributedString(string: "上传截图 (选填 0/3)")
mString.addAttributes([.foregroundColor: UIColor.black,.font: BoldFont_18], range: NSRange(location: 0, length: 4))
mString.addAttributes([.foregroundColor: HexColor("#B4B4B4")!,.font: Font_14], range: NSRange(location: 4, length: 9))
photoLabel.attributedText = mString
return photoLabel
}()
lazy var photoView: MinePhotoUploadView = {
let pView = MinePhotoUploadView.init(frame: .zero, resutBlock: { [weak self] index, imageUrl in
let mString = NSMutableAttributedString(string: "上传截图 (选填 \(index)/3)")
mString.addAttributes([.foregroundColor: UIColor.black,.font: BoldFont_18], range: NSRange(location: 0, length: 4))
mString.addAttributes([.foregroundColor: HexColor("#B4B4B4")!,.font: Font_14], range: NSRange(location: 4, length: 9))
self!.photoLabel.attributedText = mString
self!.imageUrlArray.replaceObject(at: Int(index)! - 1, with: imageUrl)
})
pView.backgroundColor = .clear
return pView
}()
lazy var mobileLabel : UILabel = {
let mobileLabel = UILabel.init()
let mString = NSMutableAttributedString(string: "联系电话 (选填)")
mString.addAttributes([.foregroundColor: UIColor.black,.font: BoldFont_18], range: NSRange(location: 0, length: 4))
mString.addAttributes([.foregroundColor: HexColor("#B4B4B4")!,.font: Font_14], range: NSRange(location: 4, length: 5))
mobileLabel.attributedText = mString
return mobileLabel
}()
lazy var mobileView: UIView = {
let mobileView = UIView.init()
mobileView.backgroundColor = .white
mobileView.layer.cornerRadius = 10
mobileView.layer.masksToBounds = true
return mobileView
}()
lazy var mobileField: UITextField = {
let mobileField = UITextField.init()
mobileField.backgroundColor = .white
mobileField.placeholder = "便于我们与您联系"
mobileField.font = BoldFont_16_Fit
mobileField.keyboardType = .numberPad
mobileField.clearButtonMode = .whileEditing
mobileField.layer.cornerRadius = 10
mobileField.layer.masksToBounds = true
return mobileField
}()
lazy var sendButton: APButton = {
let sendButton = APButton()
sendButton.setTitle("提 交", for: .normal)
sendButton.setTitleColor(.white, for: .normal)
sendButton.titleLabel?.font = BoldFont_16_Fit
sendButton.layer.cornerRadius = 20
sendButton.layer.masksToBounds = true
sendButton.activityIndicator.color = .white
sendButton.addTarget(self, action: #selector(sendInfoActionMothod), for: .touchUpInside)
return sendButton
}()
lazy var imageUrlArray: NSMutableArray = ["","",""]
required init?(coder aDecoder:NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewWillAppear(_ animated: Bool) {
}
override func viewDidLoad() {
super.viewDidLoad()
navigationBarHidden = false
switch _show_type {
case .problem:
titleName = "问题反馈"
case .product:
titleName = "产品建议"
case .none:
break
}
view.addSubview(iView)
iView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(get_system_nav_height()+10)
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.height.equalTo(200)
}
iView.addSubview(p_textView)
p_textView.snp.makeConstraints { make in
make.top.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.bottom.equalToSuperview().offset(-30)
}
iView.addSubview(numberLabel)
numberLabel.snp.makeConstraints { make in
make.left.bottom.equalToSuperview()
make.right.equalToSuperview().offset(-20)
make.height.equalTo(30)
}
view.addSubview(photoLabel)
photoLabel.snp.makeConstraints { make in
make.top.equalTo(iView.snp.bottom).offset(15)
make.left.equalToSuperview().offset(10)
}
view.addSubview(photoView)
photoView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(photoLabel.snp.bottom).offset(10)
make.height.equalTo((KSreenWidth - 40)/3)
}
view.addSubview(mobileLabel)
mobileLabel.snp.makeConstraints { make in
make.top.equalTo(photoView.snp.bottom).offset(15)
make.left.equalToSuperview().offset(10)
}
view.addSubview(mobileView)
mobileView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.top.equalTo(mobileLabel.snp.bottom).offset(10)
make.height.equalTo(50)
}
mobileView.addSubview(mobileField)
mobileField.snp.makeConstraints { make in
make.top.bottom.equalToSuperview()
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
}
view.addSubview(sendButton)
sendButton.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-get_system_tabbar_ui_offsetHeight() - 20)
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.height.equalTo(40)
}
setupWithSendBtnStatue(statue: false)
}
private func setupWithSendBtnStatue(statue: Bool) {
var alpha = 0.3
if statue {
alpha = 1
}
sendButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: alpha),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: alpha)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
sendButton.isUserInteractionEnabled = statue
}
@objc func sendInfoActionMothod() {
sendButton.startAnimating()
CNLiveMineViewModel.requestFeedBack(text: p_textView.text ?? "", contactWay: UserInfoManager.shared.userInfo.mobile, images: imageUrlArray) { [self] type, result in
sendButton.stopAnimating()
if result {
showMessage(message: "内容提交成功")
self.navigationController?.popViewController(animated: true)
}
}
}
}
extension CNLiveInputFeedBackViewController {
func textViewDidEndEditing(_ textView: UITextView) {
if textView.text.lengthOfBytes(using: .utf8) < 1 {
textView.text = textView_placeholder
textView.textColor = HexColor("#C8C8C8")
setupWithSendBtnStatue(statue: false)
}
}
func textViewDidBeginEditing(_ textView: UITextView) {
if textView.text == textView_placeholder {
textView.text = ""
textView.textColor = .black
setupWithSendBtnStatue(statue: true)
}
}
func textViewDidChange(_ textView: UITextView) {
if textView.text.count > 200 {
let selectRang = textView.markedTextRange
if let selectRang = selectRang {
let position = textView.position(from: (selectRang.start), offset: 0)
if position != nil {
return
}
}
let textContent = textView.text ?? ""
let textNum = textContent.count
if textNum > 200 {
textView.text = string_prefix(index: 200, text: textContent)
}
}
numberLabel.text = "\(textView.text.count)/200"
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if textView.returnKeyType == .done {
if text == "\n" {
textView.resignFirstResponder()
}
return true
}
return true
}
private func string_prefix(index: Int, text: String) -> String {
if text.count <= index {
return text
} else {
let index = text.index(text.startIndex, offsetBy: index)
let str = text.prefix(upTo: index)
return String(str)
}
}
}