|
@@ -8,9 +8,16 @@
|
8
|
8
|
|
9
|
9
|
import UIKit
|
10
|
10
|
|
11
|
|
-class KXSFMineOrderViewController: KXBaseViewController ,UITableViewDelegate,UITableViewDataSource {
|
12
|
|
-
|
|
11
|
+protocol KXSFFlowerFooterViewDelegate: NSObjectProtocol {
|
|
12
|
+ func kxsf_FlowerFooterViewAction(section: Int)
|
|
13
|
+}
|
|
14
|
+
|
|
15
|
+class KXSFMineOrderViewController: KXBaseViewController,UITableViewDelegate,UITableViewDataSource,KXSFFlowerFooterViewDelegate {
|
|
16
|
+
|
13
|
17
|
let tabCellID = "tableCellID"
|
|
18
|
+ var dataSource: NSMutableArray = NSMutableArray.init()
|
|
19
|
+ var page = 1
|
|
20
|
+ var status = 1
|
14
|
21
|
|
15
|
22
|
override func viewDidLoad() {
|
16
|
23
|
super.viewDidLoad()
|
|
@@ -26,9 +33,46 @@ class KXSFMineOrderViewController: KXBaseViewController ,UITableViewDelegate,UIT
|
26
|
33
|
view.addSubview(tableView)
|
27
|
34
|
}
|
28
|
35
|
|
29
|
|
- lazy var headerLineView : KXHeaderLineView = {
|
30
|
|
- var headerView : KXHeaderLineView = KXHeaderLineView.init(items: ["代发货","待收货","已完成"])!
|
31
|
|
- headerView.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 50)
|
|
36
|
+ fileprivate func requestConfirmOrder(id: String) {
|
|
37
|
+ let urlString: String = KXURL + "/trial/confirmFlowerBill"
|
|
38
|
+ KXHTTP.post(urlString, params: ["id": id], success: { (json) in
|
|
39
|
+ self.tableView.mj_header.beginRefreshing()
|
|
40
|
+ }) { (error) in
|
|
41
|
+
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ fileprivate func requestDataSourceWithPage(Page: Int) {
|
|
47
|
+ let urlString: String = KXURL + "/trial/myFlowerBillList"
|
|
48
|
+ KXHTTP.post(urlString, params: ["page": Page, "status": status], success: { (json) in
|
|
49
|
+ let responseJson: NSDictionary = json as! NSDictionary
|
|
50
|
+ let array = responseJson["data"] as! [NSDictionary]
|
|
51
|
+
|
|
52
|
+ let dataArr = NSArray.yy_modelArray(with: KXSFMineFlowerOrderModel.self, json: array) as! [KXSFMineFlowerOrderModel]
|
|
53
|
+ if Page == 1 {
|
|
54
|
+ self.dataSource.removeAllObjects()
|
|
55
|
+ self.dataSource.addObjects(from: dataArr)
|
|
56
|
+ self.tableView.mj_header.endRefreshing()
|
|
57
|
+ self.tableView.mj_footer.endRefreshing()
|
|
58
|
+ self.tableView.reloadData()
|
|
59
|
+ } else {
|
|
60
|
+ self.dataSource.addObjects(from: dataArr)
|
|
61
|
+ self.tableView.mj_header.endRefreshing()
|
|
62
|
+ self.tableView.mj_footer.endRefreshing()
|
|
63
|
+ self.tableView.reloadData()
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ }) { (error) in
|
|
67
|
+ self.tableView.mj_header.endRefreshing()
|
|
68
|
+ self.tableView.mj_footer.endRefreshing()
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ lazy var headerLineView: KXHeaderLineView = {
|
|
74
|
+ var headerView: KXHeaderLineView = KXHeaderLineView.init(items: ["待发货","待收货","已完成"])!
|
|
75
|
+ headerView.frame = CGRect(x: 10, y: 14, width: SCREEN_WIDTH-20, height: 38)
|
32
|
76
|
headerView.selectedIndex = 1
|
33
|
77
|
headerView.lineColor = UIColor.base()
|
34
|
78
|
headerView.buttonNormalColor = UIColor.detailTitle()
|
|
@@ -38,34 +82,60 @@ class KXSFMineOrderViewController: KXBaseViewController ,UITableViewDelegate,UIT
|
38
|
82
|
return headerView
|
39
|
83
|
}()
|
40
|
84
|
|
41
|
|
- lazy var tableView : UITableView = {
|
42
|
|
- var table = UITableView.init(frame: CGRect.init(x: 0, y: 50, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-NavHeight - 50), style: .plain)
|
|
85
|
+ lazy var tableView: UITableView = {
|
|
86
|
+ var table = UITableView.init(frame: CGRect.init(x: 10, y: 52, width: SCREEN_WIDTH-20, height: SCREEN_HEIGHT-NavHeight - 52), style: .grouped)
|
43
|
87
|
table.delegate = self
|
44
|
88
|
table.dataSource = self
|
45
|
89
|
table.separatorStyle = .none
|
46
|
|
- table.tableFooterView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 0.1))
|
47
|
|
- table.tableHeaderView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 0.1))
|
48
|
|
- table.rowHeight = 190
|
49
|
|
- table.register(UINib.init(nibName: "KXSFMineOrderTableViewCell", bundle: Bundle.main), forCellReuseIdentifier: tabCellID)
|
|
90
|
+ table.tableFooterView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH-20, height: 0.1))
|
|
91
|
+ table.tableHeaderView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH-20, height: 0.1))
|
|
92
|
+ table.rowHeight = 150
|
|
93
|
+ table.register(KXSFBuySubmitOrderTableCell.classForCoder(), forCellReuseIdentifier: tabCellID)
|
|
94
|
+ let header = MJRefreshNormalHeader.init()
|
|
95
|
+ header.setRefreshingTarget(self, refreshingAction: #selector(refreshWithHeader(header:)))
|
|
96
|
+ table.mj_header = header
|
|
97
|
+
|
|
98
|
+ let footer : MJRefreshBackNormalFooter = MJRefreshBackNormalFooter.init()
|
|
99
|
+ footer.setRefreshingTarget(self, refreshingAction: #selector(refreshFooter(footer:)))
|
|
100
|
+ table.mj_footer = footer
|
|
101
|
+
|
|
102
|
+ header.stateLabel.font = FontSize(14)
|
|
103
|
+ header.stateLabel.textColor = UIColor.detailTitle()
|
|
104
|
+ header.lastUpdatedTimeLabel.font = FontSize(14)
|
|
105
|
+ header.lastUpdatedTimeLabel.textColor = UIColor.detailTitle()
|
|
106
|
+ footer.stateLabel.textColor = UIColor.detailTitle()
|
|
107
|
+ header.beginRefreshing()
|
50
|
108
|
return table
|
51
|
109
|
}()
|
52
|
110
|
|
|
111
|
+ @objc fileprivate func refreshWithHeader(header : MJRefreshHeader) {
|
|
112
|
+ page = 1
|
|
113
|
+ requestDataSourceWithPage(Page: page)
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ @objc fileprivate func refreshFooter (footer : MJRefreshAutoFooter) {
|
|
117
|
+ page += 1
|
|
118
|
+ requestDataSourceWithPage(Page: page)
|
|
119
|
+ }
|
53
|
120
|
|
54
|
121
|
@objc func headerViewClick(button : UIButton) {
|
55
|
|
- switch button.tag - 2000 {
|
|
122
|
+ switch button.tag - 1000 {
|
56
|
123
|
case 0:
|
57
|
124
|
do{
|
58
|
|
-
|
|
125
|
+ status = 1
|
|
126
|
+ tableView.mj_header.beginRefreshing()
|
59
|
127
|
}
|
60
|
128
|
break
|
61
|
129
|
case 1:
|
62
|
130
|
do{
|
63
|
|
-
|
|
131
|
+ status = 2
|
|
132
|
+ tableView.mj_header.beginRefreshing()
|
64
|
133
|
}
|
65
|
134
|
break
|
66
|
135
|
case 2:
|
67
|
136
|
do{
|
68
|
|
-
|
|
137
|
+ status = 3
|
|
138
|
+ tableView.mj_header.beginRefreshing()
|
69
|
139
|
}
|
70
|
140
|
break
|
71
|
141
|
default:
|
|
@@ -76,15 +146,120 @@ class KXSFMineOrderViewController: KXBaseViewController ,UITableViewDelegate,UIT
|
76
|
146
|
}
|
77
|
147
|
|
78
|
148
|
extension KXSFMineOrderViewController{
|
|
149
|
+
|
|
150
|
+ func kxsf_FlowerFooterViewAction(section: Int) {
|
|
151
|
+ let mo: KXSFMineFlowerOrderModel = dataSource[section] as! KXSFMineFlowerOrderModel
|
|
152
|
+ requestConfirmOrder(id: mo.id!)
|
|
153
|
+ }
|
|
154
|
+
|
|
155
|
+ func numberOfSections(in tableView: UITableView) -> Int {
|
|
156
|
+ return dataSource.count
|
|
157
|
+ }
|
|
158
|
+
|
79
|
159
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
80
|
|
- return 10
|
|
160
|
+ let mo: KXSFMineFlowerOrderModel = dataSource[section] as! KXSFMineFlowerOrderModel
|
|
161
|
+ return mo.product?.count ?? 0
|
81
|
162
|
}
|
82
|
163
|
|
83
|
164
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
84
|
|
- let cell : KXSFMineOrderTableViewCell = tableView.dequeueReusableCell(withIdentifier: tabCellID)! as! KXSFMineOrderTableViewCell
|
|
165
|
+ let cell : KXSFBuySubmitOrderTableCell = tableView.dequeueReusableCell(withIdentifier: tabCellID)! as! KXSFBuySubmitOrderTableCell
|
|
166
|
+ let mo: KXSFMineFlowerOrderModel = dataSource[indexPath.section] as! KXSFMineFlowerOrderModel
|
|
167
|
+ let subMo: KXSFMListModel = mo.product?[indexPath.row] as! KXSFMListModel
|
|
168
|
+ cell.configTableViewCell(model: subMo, indexPath: indexPath as NSIndexPath)
|
|
169
|
+ cell.selectionStyle = .none
|
85
|
170
|
return cell
|
86
|
171
|
}
|
87
|
|
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
88
|
|
-
|
|
172
|
+
|
|
173
|
+ func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
174
|
+ return 6
|
|
175
|
+ }
|
|
176
|
+
|
|
177
|
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
178
|
+ return UIView()
|
|
179
|
+ }
|
|
180
|
+
|
|
181
|
+ func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
|
182
|
+ return 66
|
|
183
|
+ }
|
|
184
|
+
|
|
185
|
+ func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
|
186
|
+ let view : KXSFFlowerFooterView = KXSFFlowerFooterView.init(frame: CGRect(x: 0, y: 0, width: tableView.width, height: 66))
|
|
187
|
+ let mo: KXSFMineFlowerOrderModel = dataSource[section] as! KXSFMineFlowerOrderModel
|
|
188
|
+ var isHidden: Bool = true
|
|
189
|
+ if status == 2 {
|
|
190
|
+ isHidden = false
|
|
191
|
+ }
|
|
192
|
+ view.configFooterView(model: mo, section: section, hidden: isHidden)
|
|
193
|
+ return view
|
|
194
|
+ }
|
|
195
|
+}
|
|
196
|
+
|
|
197
|
+class KXSFFlowerFooterView: UIView {
|
|
198
|
+
|
|
199
|
+ weak var delegate: KXSFFlowerFooterViewDelegate?
|
|
200
|
+
|
|
201
|
+ override init(frame: CGRect) {
|
|
202
|
+ super.init(frame: frame)
|
|
203
|
+ backgroundColor = UIColor.white
|
|
204
|
+ addSubview(countLabel)
|
|
205
|
+ addSubview(accountLabel)
|
|
206
|
+ addSubview(nextButton)
|
|
207
|
+ countLabel.mas_makeConstraints { (make) in
|
|
208
|
+ make?.left.equalTo()(self)?.offset()(18)
|
|
209
|
+ make?.centerY.equalTo()(self)
|
|
210
|
+ }
|
|
211
|
+ accountLabel.mas_makeConstraints { (make) in
|
|
212
|
+ make?.left.equalTo()(countLabel.mas_right)?.offset()(20)
|
|
213
|
+ make?.centerY.equalTo()(countLabel)
|
|
214
|
+ }
|
|
215
|
+ nextButton.mas_makeConstraints { (make) in
|
|
216
|
+ make?.right.equalTo()(self)?.offset()(-18)
|
|
217
|
+ make?.centerY.equalTo()(self)
|
|
218
|
+ make?.size.equalTo()(CGSize(width: 99, height: 32))
|
|
219
|
+ }
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ required init?(coder aDecoder: NSCoder) {
|
|
223
|
+ fatalError("init(coder:) has not been implemented")
|
|
224
|
+ }
|
|
225
|
+
|
|
226
|
+ func configFooterView(model: AnyObject, section: Int, hidden: Bool) {
|
|
227
|
+ let mo: KXSFMineFlowerOrderModel = model as! KXSFMineFlowerOrderModel
|
|
228
|
+ countLabel.text = String.init(format: "共%@件商品", mo.total_num ?? 0)
|
|
229
|
+ let atts: NSMutableAttributedString = NSMutableAttributedString()
|
|
230
|
+ atts.append(NSAttributedString.ppInit(title: "合计:", foregroundColor: UIColor.kxColor(withHex: 0x63D273), font: UIFont.init(name: "PingFangSC-Regular", size: 14)))
|
|
231
|
+ atts.append(NSAttributedString.ppInit(title: String(format: "¥%@", mo.total_price ?? 0), foregroundColor: UIColor.kxColor(withHex: 0x208C2B), font: UIFont.init(name: "PingFangSC-Semibold", size: 14)))
|
|
232
|
+ accountLabel.attributedText = atts
|
|
233
|
+ nextButton.isHidden = hidden
|
|
234
|
+ if hidden == false {
|
|
235
|
+ nextButton.tag = section
|
|
236
|
+ nextButton.addTarget(self, action: #selector(submitAction(button:)), for: UIControl.Event.touchUpInside)
|
|
237
|
+ }
|
|
238
|
+ }
|
|
239
|
+
|
|
240
|
+ lazy var countLabel: UILabel = {
|
|
241
|
+ var countLabel: UILabel = UILabel.init()
|
|
242
|
+ countLabel.font = UIFont.init(name: "PingFangSC-Regular", size: 15)
|
|
243
|
+ countLabel.textColor = UIColor.title()
|
|
244
|
+ return countLabel
|
|
245
|
+ }()
|
|
246
|
+
|
|
247
|
+ lazy var accountLabel: UILabel = {
|
|
248
|
+ var accountLabel: UILabel = UILabel.init()
|
|
249
|
+ return accountLabel
|
|
250
|
+ }()
|
|
251
|
+
|
|
252
|
+ lazy var nextButton: UIButton = {
|
|
253
|
+ var nextButton: UIButton = UIButton.init(type: UIButton.ButtonType.custom)
|
|
254
|
+ nextButton.layer.cornerRadius = 16
|
|
255
|
+ nextButton.layer.masksToBounds = true
|
|
256
|
+ let normalAtt = NSAttributedString.ppInit(title: "确认订单", foregroundColor: UIColor.white, font: FontSize(14))
|
|
257
|
+ nextButton.backgroundColor = UIColor.base()
|
|
258
|
+ nextButton.setAttributedTitle(normalAtt, for: UIControl.State.normal)
|
|
259
|
+ return nextButton
|
|
260
|
+ }()
|
|
261
|
+
|
|
262
|
+ @objc func submitAction(button: UIButton) {
|
|
263
|
+ delegate?.kxsf_FlowerFooterViewAction(section: button.tag)
|
89
|
264
|
}
|
90
|
265
|
}
|