CNLiveShopBodyCustomView.swift
11.1 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
//
// CNLiveShopBodyCustomView.swift
// metaCode
//
// Created by open on 2023/11/6.
//
import Foundation
import SnapKit
import Kingfisher
typealias clickAgreeCallBack = (_ refundView: ShopBodyOrderRefundView,_ desc: String) -> Void
class ShopBodyOrderRefundView: UIView, UITextViewDelegate {
var clickBlock: clickAgreeCallBack!
lazy var shadowView: UIView = {
let shadowView = UIView.init()
shadowView.backgroundColor = UIColor(white: 0, alpha: 0.38)
return shadowView
}()
lazy var alertView: UIView = {
let alertView = UIView.init()
alertView.backgroundColor = .white
alertView.layer.cornerRadius = adapt_length(length: 4)
alertView.layer.masksToBounds = true
return alertView
}()
lazy var titleLab: UILabel = {
let titleLab = UILabel.init()
titleLab.font = medium_adapt_font(pointSize: 17)
titleLab.textColor = HexColor("#444444")
titleLab.textAlignment = .center
titleLab.text = "拒绝原因"
return titleLab
}()
lazy var contentBgView: UIView = {
let contentBgView = UIView.init()
contentBgView.backgroundColor = HexColor("#F5F6F8")
contentBgView.layer.cornerRadius = adapt_length(length: 4)
contentBgView.layer.masksToBounds = true
return contentBgView
}()
lazy var contentTextView: UITextView = {
let contentTextView = UITextView.init(frame: CGRect.zero)
contentTextView.text = "拒单原因,最多不超过100字…"
contentTextView.backgroundColor = HexColor("#F5F6F8")
contentTextView.textColor = UIColor.lightGray
contentTextView.font = regular_adapt_font(pointSize: 14)
contentTextView.delegate = self
contentTextView.returnKeyType = .done
contentTextView.showsVerticalScrollIndicator = false
return contentTextView
}()
lazy var cancelBtn: UIButton = {
let cancelBtn = UIButton.init(type: .custom)
cancelBtn.setTitle("取消", for: .normal)
cancelBtn.setTitleColor(HexColor("#ffffff"), for: .normal)
cancelBtn.titleLabel?.font = medium_adapt_font(pointSize: 14)
cancelBtn.layer.cornerRadius = adapt_length(length: 4)
cancelBtn.layer.masksToBounds = true
cancelBtn.backgroundColor = HexColor("#F5A623")
cancelBtn.addTarget(self, action: #selector(cancelBtnClick), for: .touchUpInside)
return cancelBtn
}()
lazy var agreeBtn: UIButton = {
let agreeBtn = UIButton.init(type: .custom)
agreeBtn.setTitle("确认拒绝", for: .normal)
agreeBtn.setTitleColor(HexColor("#ffffff"), for: .normal)
agreeBtn.titleLabel?.font = medium_adapt_font(pointSize: 14)
agreeBtn.layer.cornerRadius = adapt_length(length: 4)
agreeBtn.layer.masksToBounds = true
agreeBtn.backgroundColor = HexColor("#28C1C6")
agreeBtn.addTarget(self, action: #selector(agreeBtnClick), for: .touchUpInside)
return agreeBtn
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(shadowView)
shadowView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
addSubview(alertView)
alertView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(adapt_length(length: 30))
make.right.equalToSuperview().offset(-adapt_length(length: 30))
make.center.equalToSuperview()
make.height.equalTo(KSreenWidth-adapt_length(length: 60))
}
alertView.addSubview(titleLab)
titleLab.snp.makeConstraints { make in
make.left.equalToSuperview().offset(adapt_length(length: 20))
make.top.equalToSuperview().offset(adapt_length(length: 20))
make.right.equalToSuperview().offset(-adapt_length(length: 20))
}
alertView.addSubview(contentBgView)
contentBgView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(adapt_length(length: 25))
make.top.equalTo(titleLab.snp.bottom).offset(adapt_length(length: 15))
make.right.equalToSuperview().offset(-adapt_length(length: 25))
make.bottom.equalToSuperview().offset(-adapt_length(length: 60))
}
contentBgView.addSubview(contentTextView)
contentTextView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(adapt_length(length: 15))
make.top.equalToSuperview().offset(adapt_length(length: 12))
make.right.equalToSuperview().offset(-adapt_length(length: 15))
make.bottom.equalToSuperview().offset(-adapt_length(length: 12))
}
alertView.addSubview(cancelBtn)
cancelBtn.snp.makeConstraints { make in
make.left.equalToSuperview().offset((KSreenWidth-adapt_length(length: 228))/3)
make.bottom.equalToSuperview().offset(-adapt_length(length: 15))
make.width.equalTo(adapt_length(length: 84))
make.height.equalTo(adapt_length(length: 30))
}
alertView.addSubview(agreeBtn)
agreeBtn.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-((KSreenWidth-adapt_length(length: 228))/3))
make.bottom.equalToSuperview().offset(-adapt_length(length: 15))
make.width.equalTo(adapt_length(length: 84))
make.height.equalTo(adapt_length(length: 30))
}
}
@objc func agreeBtnClick() {
if (clickBlock != nil) {
self.clickBlock(self, self.contentTextView.text)
}
}
func textViewDidBeginEditing(_ textView: UITextView) {
if textView.textColor == UIColor.lightGray {
textView.text = nil
textView.textColor = HexColor("#444444")
}
}
func textViewShouldEndEditing(_ textView: UITextView) -> Bool {
if textView.text.isEmpty {
textView.text = "拒单原因,最多不超过100字…"
textView.textColor = UIColor.lightGray
}
return true
}
func textViewDidChange(_ textView: UITextView) {
if self.contentTextView == textView && self.contentTextView.text.count > 100 {
showMessage(message: "最多不超过100字!!!")
}
}
func textViewDidEndEditing(_ textView: UITextView) {
if self.contentTextView == textView && self.contentTextView.text.count > 100 {
self.contentTextView.text = self.contentTextView.text.prefix(100).lowercased()
}
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if text == "\n" {
self.endEditing(true)
return false
}
return true
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
guard let contentTextViewRect = self.contentTextView.superview?.convert(self.contentTextView.frame, to: self) else { return self.contentTextView }
if !CGRectContainsPoint(contentTextViewRect, point) {
self.endEditing(true)
}
return super.hitTest(point, with: event)
}
@objc func cancelBtnClick() {
removeFromSuperview()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ShopBodyOrderSpliteTableViewCell: UITableViewCell {
lazy var goodsImageView: UIImageView = {
let goodsImageView = UIImageView.init()
goodsImageView.backgroundColor = .white
goodsImageView.contentMode = .scaleAspectFill
goodsImageView.layer.masksToBounds = true
return goodsImageView
}()
lazy var goodsTitle: UILabel = {
let goodsTitle = UILabel.init()
goodsTitle.lineBreakMode = .byClipping
goodsTitle.numberOfLines = 2
goodsTitle.textColor = HexColor("#333333")
goodsTitle.font = regular_adapt_font(pointSize: 14)
return goodsTitle
}()
lazy var priceLabel: UILabel = {
let priceLabel = UILabel.init()
priceLabel.textColor = HexColor("#FC1541")
priceLabel.font = medium_adapt_font(pointSize: 21)
return priceLabel
}()
lazy var numberLabel: UILabel = {
let numberLabel = UILabel.init()
numberLabel.textAlignment = .right
numberLabel.textColor = HexColor("#222833")
numberLabel.font = regular_adapt_font(pointSize: 15)
return numberLabel
}()
lazy var lineLabel: UILabel = {
let lineLabel = UILabel.init()
lineLabel.backgroundColor = HexColor("#EAEAEA")
return lineLabel
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.backgroundColor = .clear
selectionStyle = .none
addSubview(goodsImageView)
goodsImageView.snp.makeConstraints { make in
make.left.top.equalToSuperview().offset(adapt_length(length: 15))
make.size.equalTo(adapt_length(length: 100))
}
addSubview(goodsTitle)
goodsTitle.snp.makeConstraints { make in
make.top.equalTo(goodsImageView)
make.left.equalTo(goodsImageView.snp.right).offset(adapt_length(length: 15))
make.right.equalToSuperview().offset(-adapt_length(length: 15))
}
addSubview(priceLabel)
priceLabel.snp.makeConstraints { make in
make.left.equalTo(goodsTitle)
make.bottom.equalTo(goodsImageView)
}
addSubview(numberLabel)
numberLabel.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-adapt_length(length: 10))
make.bottom.equalTo(goodsImageView)
}
addSubview(lineLabel)
lineLabel.snp.makeConstraints { make in
make.left.equalTo(goodsImageView)
make.right.equalTo(numberLabel)
make.bottom.equalToSuperview().offset(-adapt_length(length: 0.5))
make.height.equalTo(adapt_length(length: 0.5))
}
}
func setupDataSource(goodsModel: ShopOrderListGoodsModel) {
goodsImageView.kf.setImage(with: URL(string: goodsModel.simg!), placeholder: UIImage.imageWithColor(color: HexColor("#F8F8F8")!, size: CGSize(width: adapt_length(length: 100), height: adapt_length(length: 100))))
goodsTitle.text = goodsModel.title
priceLabel.text = "¥ \(goodsModel.price ?? 0.00)"
priceLabel.sizeToFit()
numberLabel.text = "x \(goodsModel.num ?? 0)"
numberLabel.sizeToFit()
setNeedsLayout()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ShopBodyOrderSelectTableViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}