CNLiveShopBodyExpressView.swift
17.3 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
//
// CNLiveShopBodyExpressView.swift
// metaCode
//
// Created by open on 2023/11/8.
//
import Foundation
import EmptyDataSet_Swift
class ShopBodyOrderExpressListTableViewCell: UITableViewCell, UICollectionViewDataSource {
lazy var logoImageView: UIImageView = {
let logoImageView = UIImageView.init()
logoImageView.backgroundColor = .white
logoImageView.layer.cornerRadius = 4
logoImageView.layer.masksToBounds = true
return logoImageView
}()
lazy var expressName: UILabel = {
let expressName = UILabel.init()
expressName.textColor = HexColor("#333333")
expressName.font = medium_font(pointSize: 14)
return expressName
}()
lazy var expressNo: UILabel = {
let expressNo = UILabel.init()
expressNo.textColor = HexColor("#b4b4b4")
expressNo.font = regular_font(pointSize: 12)
return expressNo
}()
lazy var expressCopy: UIButton = {
let expressCopy = UIButton.init(type: .custom)
expressCopy.backgroundColor = .white
expressCopy.setTitle("复制单号", for: .normal)
expressCopy.layer.cornerRadius = 4
expressCopy.titleLabel?.font = medium_font(pointSize: 14)
expressCopy.setTitleColor(HexColor("#28c1c6"), for: .normal)
expressCopy.contentHorizontalAlignment = .center
expressCopy.layer.borderWidth = 1
expressCopy.layer.borderColor = HexColor("#28c1c6")?.cgColor
expressCopy.addTarget(self, action: #selector(actionClick), for: .touchUpInside)
return expressCopy
}()
lazy var expressTime: UILabel = {
let expressTime = UILabel.init()
expressTime.font = regular_font(pointSize: 12)
expressTime.textColor = HexColor("#333333")
return expressTime
}()
lazy var expressAddress: UILabel = {
let expressAddress = UILabel.init()
expressAddress.font = regular_font(pointSize: 12)
expressAddress.textColor = HexColor("#333333")
expressAddress.numberOfLines = 0
return expressAddress
}()
let kShopBodyOrderExpressListCollectionViewCellIdentifier = "kShopBodyOrderExpressListCollectionViewCellIdentifier"
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout.init()
layout.itemSize = CGSizeMake(adapt_length(length: 65), adapt_length(length: 65))
layout.minimumLineSpacing = adapt_length(length: 5)
layout.scrollDirection = .horizontal
let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.backgroundColor = .white
collectionView.register(ShopBodyOrderExpressListCollectionViewCell.self, forCellWithReuseIdentifier: kShopBodyOrderExpressListCollectionViewCellIdentifier)
let tap = UITapGestureRecognizer.init(target: self, action: #selector(pushExpressDetail))
collectionView.addGestureRecognizer(tap)
return collectionView
}()
lazy var totleExpress: UILabel = {
let totleExpress = UILabel.init()
totleExpress.textColor = HexColor("#9b9b9b")
totleExpress.font = regular_adapt_font(pointSize: 12)
return totleExpress
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.backgroundColor = .clear
selectionStyle = .none
addSubview(logoImageView)
logoImageView.snp.makeConstraints { make in
make.left.top.equalToSuperview().offset(adapt_length(length: 15))
make.size.equalTo(adapt_length(length: 39.68))
}
addSubview(expressName)
expressName.snp.makeConstraints { make in
make.top.equalTo(logoImageView.snp.top).offset(adapt_length(length: 0.5))
make.left.equalTo(logoImageView.snp.right).offset(adapt_length(length: 15))
}
addSubview(expressCopy)
expressCopy.snp.makeConstraints { make in
make.top.equalToSuperview().offset(adapt_length(length: 20))
make.right.equalToSuperview().offset(-adapt_length(length: 20))
make.width.equalTo(adapt_length(length: 77))
make.height.equalTo(adapt_length(length: 30))
}
addSubview(expressNo)
expressNo.snp.makeConstraints { make in
make.top.equalTo(expressName.snp.bottom).offset(adapt_length(length: 2.5))
make.left.equalTo(expressName.snp.left)
make.right.equalTo(expressCopy.snp.left).offset(adapt_length(length: 5))
}
addSubview(expressTime)
expressTime.snp.makeConstraints { make in
make.top.equalTo(logoImageView.snp.bottom).offset(adapt_length(length: 5))
make.left.equalTo(logoImageView.snp.left)
}
addSubview(expressAddress)
expressAddress.snp.makeConstraints { make in
make.top.equalTo(expressTime.snp.bottom).offset(adapt_length(length: 2))
make.left.equalTo(expressTime.snp.left)
make.right.equalToSuperview().offset(-adapt_length(length: 15))
}
addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.top.equalTo(expressAddress.snp.bottom).offset(adapt_length(length: 15))
make.left.equalToSuperview().offset(adapt_length(length: 15))
make.right.equalToSuperview().offset(-adapt_length(length: 15))
make.height.equalTo(adapt_length(length: 65))
}
addSubview(totleExpress)
totleExpress.snp.makeConstraints { make in
make.left.equalToSuperview().offset(adapt_length(length: 15))
make.bottom.equalToSuperview().offset(-adapt_length(length: 15))
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
var _listModel: ShopOrderExpressListModel!
func setupDataSource(listModel: ShopOrderExpressListModel) {
_listModel = listModel
logoImageView.kf.setImage(with: URL(string: listModel.simg!))
expressName.text = listModel.express
expressName.sizeToFit()
expressNo.text = "快递编号:\(listModel.express_num ?? "0")"
totleExpress.text = "共\(listModel.detail_goods.count)件商品"
totleExpress.sizeToFit()
expressTime.text = listModel.expressNew.AcceptTime
expressTime.sizeToFit()
var address : String = ""
if listModel.expressNew.AcceptStation!.isNotBlank() {
address = listModel.expressNew.AcceptStation!
} else {
address = "包裹正在等待揽收"
}
expressAddress.text = address
expressAddress.sizeToFit()
collectionView.reloadData()
setNeedsLayout()
}
@objc func pushExpressDetail() {
currentViewController()?.navigationController?.pushViewController(CNLiveShopOrderExpressDetailViewController.init(orderId: _listModel.id! as NSString, expId: _listModel.express_num! as NSString, show_type: .orderExpress, progress: .Zero), animated: true)
}
@objc func actionClick(sender: UIButton) {
if !_listModel.express_num!.isNotBlank() {
return
}
let pasteboard = UIPasteboard.general
pasteboard.string = _listModel.express_num
showMessage(message: "复制成功")
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return _listModel.detail_goods.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kShopBodyOrderExpressListCollectionViewCellIdentifier, for: indexPath) as? ShopBodyOrderExpressListCollectionViewCell else {
return ShopBodyOrderExpressListCollectionViewCell()
}
let goodsModel = _listModel.detail_goods[indexPath.row]
cell.goodsImage.kf.setImage(with: URL(string: goodsModel.simg!))
cell.expressNum.text = "\(goodsModel.num ?? 0)件"
return cell
}
}
class ShopBodyOrderExpressListCollectionViewCell: UICollectionViewCell {
lazy var goodsImage: UIImageView = {
let goodsImage = UIImageView.init()
goodsImage.contentMode = .scaleAspectFill
goodsImage.layer.cornerRadius = 6
goodsImage.layer.masksToBounds = true
return goodsImage
}()
lazy var expressNum: UILabel = {
let expressNum = UILabel.init()
expressNum.font = regular_adapt_font(pointSize: 9)
expressNum.textColor = HexColor("#ffffff")
expressNum.backgroundColor = HexColor("#000000")
expressNum.textAlignment = .center
expressNum.alpha = 0.5
expressNum.layer.cornerRadius = 6
return expressNum
}()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.backgroundColor = .white
contentView.addSubview(goodsImage)
goodsImage.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
contentView.addSubview(expressNum)
expressNum.snp.makeConstraints { make in
make.left.bottom.right.equalToSuperview()
make.height.equalTo(adapt_length(length: 15))
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ShopBodyOrderExpressDetailHeaderView: UIView {
var _showType: CNLiveShopOrderExpressDetailShowType!
init(frame: CGRect, showType: CNLiveShopOrderExpressDetailShowType) {
super.init(frame: frame)
_showType = showType
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ShopBodyOrderExpressDetailTableView: UITableViewCell, UITextViewDelegate {
lazy var lineLabel: UILabel = {
let lineLabel = UILabel.init()
lineLabel.backgroundColor = HexColor("#EAEAEA")
return lineLabel
}()
lazy var pointImageView: UIImageView = {
let pointImageView = UIImageView.init()
return pointImageView
}()
lazy var titleTextView: UITextView = {
let titleTextView = UITextView.init(frame: CGRect(x: 0, y: 0, width: KSreenWidth - adapt_length(length: 48) - adapt_length(length: 20), height: 0))
titleTextView.isEditable = false
titleTextView.isScrollEnabled = false
titleTextView.delegate = self
titleTextView.linkTextAttributes = [.foregroundColor:HexColor("#28c1c6")!]
return titleTextView
}()
lazy var timeLabel: UILabel = {
let timeLabel = UILabel.init()
timeLabel.textColor = HexColor("#b4b4b4")
timeLabel.font = regular_adapt_font(pointSize: 12)
return timeLabel
}()
lazy var bottomLine: UIImageView = {
let bottomLine = UIImageView.init()
bottomLine.backgroundColor = HexColor("#e4e4e4")
return bottomLine
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.backgroundColor = .white
selectionStyle = .none
addSubview(lineLabel)
addSubview(pointImageView)
addSubview(titleTextView)
addSubview(timeLabel)
addSubview(bottomLine)
}
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if URL.absoluteString == "tel://" {
let phone = URL.absoluteString.components(separatedBy: "tel://").last
ConfigAlertManager.shared.presentAlert(title: phone!, message: "", actionTitles: ["取消","呼叫"]) { index in
if index == 1 {
UIApplication.shared.open(NSURL(string: phone!)! as URL)
}
}
} else {
let webVC = CNWebViewController.init()
webVC.url = URL
currentViewController()?.navigationController?.pushViewController(webVC, animated: true)
}
return false
}
var _dataModel: ShopOrderExpressDetailDateModel!
var _row: NSInteger!
var _isLastRow: Bool!
var _type: CNLiveShopOrderExpressDetailShowType!
var _address: NSString!
var _express_state: NSString!
func setupDataSource(dataModel: ShopOrderExpressDetailDateModel, row: NSInteger, isLastRow: Bool, type: CNLiveShopOrderExpressDetailShowType, address: NSString, express_state: NSString) {
_dataModel = dataModel
_row = row
_isLastRow = isLastRow
_type = type
_address = address
_express_state = express_state
if _type == .orderExpress || _type == .refundExpress {
let para = NSMutableParagraphStyle()
para.lineSpacing = adapt_length(length: 3)
if row == 0 {
let title = NSMutableAttributedString.init(string: "[收货地址]\(address)", attributes: [.font:medium_adapt_font(pointSize: 14),.foregroundColor:HexColor("#999999")!,.paragraphStyle:para.copy()])
titleTextView.attributedText = setHyperlinksAttrStr(attrStr: title)
timeLabel.text = ""
pointImageView.image = nil
pointImageView.backgroundColor = HexColor("#d2d2d2")
pointImageView.size = CGSizeMake(adapt_length(length: 5), adapt_length(length: 5))
pointImageView.layer.cornerRadius = pointImageView.height/2
pointImageView.layer.masksToBounds = true
} else if (_row == 1) {
let state = _express_state == "3" ? "已签收" : "运输中"
let title = NSMutableAttributedString.init(string: "\(state)\n\(dataModel.AcceptStation!)", attributes: [.font:medium_adapt_font(pointSize: 12),.foregroundColor:HexColor("#b4b4b4")!,.paragraphStyle:para.copy()])
para.lineSpacing = adapt_length(length: 5)
title.addAttributes([.font:medium_adapt_font(pointSize: 14),.foregroundColor:HexColor("#28c1c6")!,.paragraphStyle:para.copy()], range: NSMakeRange(0, state.count+1))
titleTextView.attributedText = setHyperlinksAttrStr(attrStr: title)
timeLabel.text = dataModel.AcceptTime
pointImageView.image = UIImage(named: "DS_express_current")
pointImageView.backgroundColor = .clear
pointImageView.size = CGSizeMake(adapt_length(length: 15), adapt_length(length: 15))
pointImageView.layer.cornerRadius = 0
pointImageView.layer.masksToBounds = false
}
} else {
titleTextView.font = medium_adapt_font(pointSize: 14)
if _row == 0 {
titleTextView.textColor = HexColor("#28c1c6")
pointImageView.image = UIImage(named: "DS_express_current")
pointImageView.backgroundColor = .clear
pointImageView.size = CGSizeMake(adapt_length(length: 15), adapt_length(length: 15))
pointImageView.layer.cornerRadius = 0
pointImageView.layer.masksToBounds = false
} else {
titleTextView.textColor = HexColor("#999999")
pointImageView.image = UIImage(named: "DS_express_current")
pointImageView.backgroundColor = .clear
pointImageView.size = CGSizeMake(adapt_length(length: 15), adapt_length(length: 15))
pointImageView.layer.cornerRadius = pointImageView.height/2
pointImageView.layer.masksToBounds = true
pointImageView.layer.borderColor = HexColor("#d2d2d2")?.cgColor
pointImageView.layer.borderWidth = adapt_length(length: 1)
}
titleTextView.text = dataModel.AcceptStation
timeLabel.text = dataModel.AcceptTime
}
titleTextView.sizeToFit()
}
func setHyperlinksAttrStr(attrStr: NSMutableAttributedString) -> NSAttributedString {
do {
let dataDetector = try NSDataDetector(types: NSTextCheckingTypes(NSTextCheckingResult.CheckingType.link.rawValue) | NSTextCheckingTypes(NSTextCheckingResult.CheckingType.phoneNumber.rawValue))
let res = dataDetector.matches(in: attrStr.string, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, attrStr.string.count))
for checkingRes in res {
if (checkingRes.phoneNumber != nil) {
attrStr.addAttribute(.link, value: "tel://\(checkingRes.phoneNumber!)", range: checkingRes.range)
} else {
attrStr.addAttribute(.link, value: checkingRes.url!, range: checkingRes.range)
}
}
return attrStr.copy() as! NSAttributedString
} catch {
print(error)
}
return attrStr.copy() as! NSAttributedString
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}