CNLiveShopOrderSendViewController.swift
7.8 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
//
// CNLiveShopOrderSendViewController.swift
// metaCode
//
// Created by open on 2023/11/7.
//
import Foundation
import EmptyDataSet_Swift
enum CNLiveShopOrderSpliteSendViewType {
case splite //发货界面
case select //拆单界面
}
class CNLiveShopOrderSendViewController: CNLiveBaseViewController, UITableViewDelegate, UITableViewDataSource, EmptyDataSetSource, EmptyDataSetDelegate {
let kShopBodyOrderSelectTableViewCellIdentifier = "kShopBodyOrderSelectTableViewCellIdentifier"
let kShopBodyOrderSpliteTableViewCellIdentifier = "kShopBodyOrderSpliteTableViewCellIdentifier"
lazy var tableView: UITableView = {
let tableView = UITableView.init(frame: CGRect.zero, style: .plain)
tableView.dataSource = self
tableView.delegate = self
tableView.emptyDataSetSource = self
tableView.emptyDataSetDelegate = self
tableView.backgroundColor = .clear
tableView.tableFooterView = UIView.init()
tableView.separatorStyle = .none
tableView.register(ShopBodyOrderSelectTableViewCell.self, forCellReuseIdentifier: kShopBodyOrderSelectTableViewCellIdentifier)
tableView.register(ShopBodyOrderSpliteTableViewCell.self, forCellReuseIdentifier: kShopBodyOrderSpliteTableViewCellIdentifier)
return tableView
}()
lazy var saveButton: UIButton = {
let saveButton = UIButton.init(type: .custom)
saveButton.frame = CGRect(x: KSreenWidth - 70, y: (get_system_nav_height() - (get_system_statusBar_height() + 25))/2 + get_system_statusBar_height(), width: 60, height: 25)
saveButton.setTitle("拆单", for: .normal)
saveButton.titleLabel?.font = medium_adapt_font(pointSize: 12)
saveButton.setTitleColor(HexColor("#F5A623"), for: .normal)
saveButton.backgroundColor = .white
saveButton.layer.masksToBounds = true
saveButton.layer.cornerRadius = 5
saveButton.addTarget(self, action: #selector(spliteBtnClick), for: .touchUpInside)
return saveButton
}()
lazy var dataArray: NSMutableArray = {
let dataArray = NSMutableArray.init()
return dataArray
}()
var _orderId: NSString
var network_type: CNLiveMineResponseType!
var _show_type: CNLiveShopOrderSpliteSendViewType!
init(orderId: NSString, show_type:CNLiveShopOrderSpliteSendViewType) {
_orderId = orderId
_show_type = show_type
super.init(nibName:nil, bundle:nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
navigationBarHidden = false
titleName = "选择发货商品"
if _show_type == .splite {
topNavView.addSubview(saveButton)
}
loadDataSourceAction()
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.top.equalTo(KNavigationHeight)
make.left.right.equalToSuperview()
make.bottom.equalToSuperview().offset(-get_system_tabbar_height())
}
}
func loadDataSourceAction() {
CNLiveShopViewModel.requestOrderDetail(orderId: _orderId as String, isOrderDetai: true, isRefund: false) { [weak self] result, respStatue in
if respStatue == .success {
let detailModel = result as! ShopOrderDetailModel
if self!._show_type == .splite {
for goodsModel in detailModel.order_detail {
if (detailModel.state == "2" && (goodsModel.num! - goodsModel.refund_num!) > 0) || (goodsModel.send_num! != 0 && (goodsModel.send_num! - goodsModel.refund_num!) > 0) {
self!.dataArray.add(goodsModel)
}
}
} else {
for goodsModel in detailModel.order_detail {
goodsModel.select = false
goodsModel.selectNum = 1
if (detailModel.state == "2" && (goodsModel.num! - goodsModel.refund_num!) > 0 ) || (goodsModel.send_num! != 0 && (goodsModel.send_num! - goodsModel.refund_num!) > 0 ) {
self!.dataArray.add(goodsModel)
}
}
}
self?.tableView.reloadData()
}else if (respStatue == .noNetwork) {
self!.network_type = .noNetwork
self!.tableView.reloadEmptyDataSet()
} else {
self!.network_type = .failed
self!.tableView.reloadEmptyDataSet()
}
}
}
@objc func spliteBtnClick() {
}
}
extension CNLiveShopOrderSendViewController {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if _show_type == .select {
guard let cell = tableView.dequeueReusableCell(withIdentifier: kShopBodyOrderSelectTableViewCellIdentifier) as? ShopBodyOrderSelectTableViewCell else {
return ShopBodyOrderSelectTableViewCell()
}
return cell
} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: kShopBodyOrderSpliteTableViewCellIdentifier) as? ShopBodyOrderSpliteTableViewCell else {
return ShopBodyOrderSpliteTableViewCell()
}
cell.setupDataSource(goodsModel: self.dataArray[indexPath.row] as! ShopOrderListGoodsModel)
return cell
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return adapt_length(length: 130)
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
}
extension CNLiveShopOrderSendViewController {
func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
if network_type == .failed || network_type == .unkonw {
return UIImage(named: "mine_list_source_unusual_failed")
}
if dataArray.count == 0 {
return UIImage(named: "mine_list_source_unusual_empty")
}
if network_type == .noNetwork {
return UIImage(named: "mine_list_source_unusual_noNet")
}
return UIImage(named: "mine_list_source_unusual_empty")
}
func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
var defult_string = ""
if network_type == .failed || network_type == .unkonw {
defult_string = "接口请求错误,刷新试试~"
}
if network_type == .noNetwork {
defult_string = "网络开小差了,刷新试试~"
}
if dataArray.count == 0 {
defult_string = "暂时没有数据~"
}
return NSAttributedString(string: defult_string, attributes: [.font: Font_17,.foregroundColor: HexColor("#666666")!])
}
func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? {
if network_type == .failed || network_type == .noNetwork {
let attributes = [NSAttributedString.Key.font:Font_16_Fit,
NSAttributedString.Key.foregroundColor: HexColor("#609BFF")]
return NSAttributedString(string: "刷一刷", attributes: attributes as [NSAttributedString.Key : Any])
}
return nil
}
func emptyDataSet(_ scrollView: UIScrollView, didTapView view: UIView) {
if network_type == .failed || network_type == .noNetwork {
loadDataSourceAction()
}
}
}