杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
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
//
//  WorldCupContentApplyInputVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2024/2/28.
//
 
import UIKit
import JQTools
import QMUIKit
import HandyJSON
 
struct WorldCupStudentSimpleInfoModel:HandyJSON{
                var id = 0
                var isStudent = 0
}
 
class WorldCupContentApplyInputVC: BaseVC {
 
                @IBOutlet weak var view_banner: UIView!
                @IBOutlet weak var label_title: UILabel!
                @IBOutlet weak var label_hot: UILabel!
                @IBOutlet weak var label_duetime: UILabel!
                @IBOutlet weak var label_starttime: UILabel!
                @IBOutlet weak var label_endtime: UILabel!
                @IBOutlet weak var label_ageScope: UILabel!
                @IBOutlet weak var label_genderCond: UILabel!
                @IBOutlet weak var label_city: UILabel!
                @IBOutlet weak var label_address: UILabel!
                @IBOutlet weak var label_matchPoint: UILabel!
                @IBOutlet weak var label_pay_money: UILabel!
                @IBOutlet weak var label_pay_coin: UILabel!
                @IBOutlet weak var label_pay_course: UILabel!
                @IBOutlet weak var btn_moreStore: UIButton!
                @IBOutlet weak var tableView: UITableView!
                @IBOutlet weak var btn_agreement: UIButton!
                @IBOutlet weak var cons_tableHei: NSLayoutConstraint!
                @IBOutlet weak var btn_addStudent: QMUIButton!
                @IBOutlet weak var btn_enroll: UIButton!
 
                @IBOutlet weak var view_cash: UIView!
                @IBOutlet weak var view_payCoin: UIView!
                @IBOutlet weak var view_course: UIView!
 
                private var students = [ActivityDetailPartModel]()
                private var detailModel:WorldCupDetailModel!
 
                private lazy var bannerView:CommonBannerView = {
                                let v = CommonBannerView()
                                return v
                }()
 
                init(_ model:WorldCupDetailModel) {
                                super.init(nibName: nil, bundle: nil)
                                self.detailModel = model
                }
 
                override func setUI() {
                                btn_addStudent.imagePosition = .right
                                btn_addStudent.spacingBetweenImageAndTitle = 4
                                view_banner.addSubview(bannerView)
                                bannerView.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: JQ_ScreenW * 0.56)
                                tableView.delegate = self
                                tableView.dataSource = self
                                tableView.separatorStyle = .none
                                tableView.register(UINib(nibName: "StudentInfo_2_TCell", bundle: nil), forCellReuseIdentifier: "_StudentInfo_2_TCell")
                }
 
                override func viewDidLoad() {
                                super.viewDidLoad()
                                title = "社区世界杯"
                                let imgs = detailModel.infoImg.components(separatedBy: ",")
                                var items = [CommonBannerModel]()
                                for (index,img) in imgs.enumerated(){
                                                items.append(CommonBannerModel(index: index,resource: img,mediaType: .imageUrl))
                                }
                                bannerView.setItems(items: items)
 
                                if let endDate = detailModel.registrationClosingTime{
                                                let endDateTimeInterval = Date.jq_StringToTimeInterval(endDate, "yyyy-MM-dd HH:mm")
                                                if endDateTimeInterval < Date().timeIntervalSince1970{
                                                                btn_enroll.setTitle("报名已截止", for: .normal)
                                                                btn_enroll.backgroundColor = .gray.withAlphaComponent(0.5)
                                                                btn_enroll.isEnabled = false
                                                }
                                }
 
 
                                btn_moreStore.isHidden = detailModel.storeInfos.count == 1
 
                                label_title.text = detailModel.name
                                label_hot.text = "\(detailModel.heat)"
 
                                if detailModel.registrationClosingTime != nil{
                                                label_duetime.text = detailModel.registrationClosingTime
                                }else{
                                                label_duetime.text = detailModel.endTime
                                }
 
 
                                label_starttime.text = detailModel.startTime
                                label_endtime.text = detailModel.endTime
                                label_ageScope.text = detailModel.age + "岁"
                                switch detailModel.gender{
                                                case 1:label_genderCond.text = "男"
                                                case 2:label_genderCond.text = "女"
                                                default:label_genderCond.text = "全部"
                                }
                                label_city.text = [detailModel.province,detailModel.city].joined(separator: "|")
                                label_address.text = detailModel.address
                                label_matchPoint.text = detailModel.storeInfos.map({$0.name}).joined(separator: "、")
 
                                view_cash.isHidden = detailModel.cash == nil
                                view_payCoin.isHidden = detailModel.paiCoin == nil
                                view_course.isHidden = detailModel.classHour == nil
 
                                if let cash = detailModel.cash{
                                                label_pay_money.text = cash == 0 ? "免费":"¥\(cash)/人"
                                }
 
                                if let paiCoin = detailModel.paiCoin{
                                                label_pay_coin.text = paiCoin == 0 ? "免费":"\(paiCoin)币/人"
                                }
 
                                if let classHour = detailModel.classHour{
                                                label_pay_course.text  = classHour == 0 ? "免费":"\(classHour)课时/人"
                                }
                }
 
                override func setRx() {
                                tableView.rx.observe(CGSize.self, "contentSize").subscribe(onNext: {[weak self] size in
                                                self?.cons_tableHei.constant = size?.height ?? 0
                                }).disposed(by: disposeBag)
                }
 
                @IBAction func addStudentAction(_ sender: QMUIButton) {
                                let minAge = detailModel.age.components(separatedBy: "-").first?.int ?? 0
                                let maxAge = detailModel.age.components(separatedBy: "-").last?.int ?? 1000
                                StudentChooseView.show(itemType: .worldCup, defaultStu: students,isAuth: 1,authGender: detailModel.gender,authAgeRange: (minAge,maxAge)) { [weak self] studs in
                                                self?.students = studs as! [ActivityDetailPartModel]
                                                self?.cons_tableHei.constant = Double(self?.students.count ?? 0) * 100
                                                self?.tableView.reloadData()
                                } needAddClouse: {[weak self] () in
                                                let vc = AddStudentVC(type: .worldCup,activityDetailPartModel: nil,identity: true,identityPhone: true)
                                                self?.push(vc: vc)
                                }
                }
 
                @IBAction func matchStoreAction(_ sender: UIButton) {
                                guard let detailModel = detailModel else{return}
                                AgreentView.show(type: .matchPoint, content: detailModel.storeInfos.map({$0.name}).joined(separator: "、"))
                }
 
 
                @IBAction func agreementAction(_ sender: UIButton) {
                                sender.isSelected = !sender.isSelected
 
                }
 
                @IBAction func webAction(_ sender: Any) {
                                let webVC = CommonWebVC(type: .matchStore,customTitle: "社区世界杯报名协议")
                                push(vc: webVC)
                }
 
 
                @IBAction func applyAction(_ sender: Any) {
                                guard btn_agreement.isSelected else {
                                                alert(msg: "请先阅读并同意协议");return
                                }
 
                                guard students.count > 0 else {
                                                alert(msg: "请选择参赛人员");return
                                }
 
                                if detailModel.storeInfos.count == 1{
                                                StoresInfoView.show(detailModel.storeInfos.first ?? ActivityDetailStoreModel(),type: .worldCup) {[weak self] status in
                                                                if status{
                                                                                self?.showPaymentView()
                                                                }else{
                                                                                self?.navigationController?.popToRootViewController(animated: true)
                                                                                NotificationCenter.default.post(name: ChooseHomeStore_Noti, object: nil)
                                                                }
                                                }
                                }else{
                                                let stores = detailModel.storeInfos.map({$0.name})
                                                StoresInfo_2_View.show(stores) {[weak self] status in
                                                                if status{
                                                                                self?.showPaymentView()
                                                                }
                                                }
                                }
                }
 
                private func showPaymentView(){
                                var result = [Dictionary<String,Int>]()
                                for v in students{
                                                result.append(["id":v.id,"isStudent":v.isStudent])
                                }
 
                                var money:Double?
                                var paiCoin:Int?
                                var classHour:Int?
 
                                //选中有非学员,显示课时支付灰色
                                let hasNotStudent = students.filter({$0.isStudent == 0}).count > 0
 
                                if detailModel.cash != nil{
                                                money = detailModel.cash! * Double(students.count)
                                }
 
                                if detailModel.paiCoin != nil{
                                                paiCoin = detailModel.paiCoin! * students.count
                                }
 
                                if detailModel.classHour != nil{
                                                classHour = detailModel.classHour! * students.count
                                }
 
                                if money == 0 && paiCoin == 0 && classHour == 0{
                                                payment(payType: .free, result: result)
                                }else{
                                                PaymentView.show(enumType: .worldCup, money: (ali: money, wx: money, coin: paiCoin, course:classHour, integral: nil),hasNotStudent: hasNotStudent) {[weak self] payType in
                                                                guard let weakSelf = self else { return }
                                                                weakSelf.payment(payType: payType, result: result)
                                                }
                                }
                }
 
                private func payment(payType:PayType,result:[Dictionary<String,Int>]){
                                Services.worldCupPayment(id: detailModel.id, ids: result.jq_toJson1(), payType: payType, uid: nil).subscribe(onNext: {[weak self]data in
                                                if let m = data.data{
                                                                switch payType {
                                                                                case .wechat:
                                                                                                YYPaymentManager.shared.sendPaymentRequest(YYWeChatPayRequest(partnerId: m.partnerid, prepayId: m.prepayid, package: m.package, nonceStr: m.noncestr, timeStamp: m.timestamp, sign: m.sign)) { result in
                                                                                                                switch result {
                                                                                                                                case .success:
                                                                                                                                                let vc = PaymentResultVC(result: .success, objType: .worldCup)
                                                                                                                                                self?.push(vc: vc)
                                                                                                                                case .cancel:
                                                                                                                                                alert(msg: "交易取消")
                                                                                                                                case .failure(_):
                                                                                                                                                let vc = PaymentResultVC(result: .fail("支付失败",0), objType: .worldCup){[weak self] () in
                                                                                                                                                                self?.showPaymentView()
                                                                                                                                                }
                                                                                                                                                self?.push(vc: vc)
                                                                                                                }
                                                                                                }
 
                                                                                case .aliPay:
                                                                                                YYPaymentManager.shared.sendPaymentRequest(YYAlipayRequest(orderString: m.orderString)) { result in
                                                                                                                switch result {
                                                                                                                                case .success:
                                                                                                                                                let vc = PaymentResultVC(result: .success, objType: .worldCup)
                                                                                                                                                self?.push(vc: vc)
                                                                                                                                case .cancel:
                                                                                                                                                alert(msg: "交易取消")
                                                                                                                                case .failure(_):
                                                                                                                                                let vc = PaymentResultVC(result: .fail("支付失败",0), objType: .worldCup){[weak self] () in
                                                                                                                                                                self?.showPaymentView()
                                                                                                                                                }
                                                                                                                                                self?.push(vc: vc)
                                                                                                                }
                                                                                                }
                                                                                case .coin,.free:
                                                                                                let vc = PaymentResultVC(result: .success, objType: .worldCup)
                                                                                                self?.push(vc: vc)
                                                                                case .courseNum:
                                                                                                let vc = PaymentResultVC(result: .success, objType: .worldCup)
                                                                                                self?.push(vc: vc)
                                                                                default:break
                                                                }
                                                }
                                },onError: { error in
                                                if let er = error as? NetworkRequest.NetRequestError{
                                                                switch er {
                                                                                case .Other(let code,let string):
                                                                                                let vc = PaymentResultVC(result: .fail(string,code), objType: .worldCup) {[weak self] () in
                                                                                                                self?.showPaymentView()
                                                                                                }
                                                                                                JQ_currentViewController().jq_push(vc: vc)
                                                                                default:
                                                                                                let vc = PaymentResultVC(result: .fail("支付失败",0), objType: .worldCup){[weak self] () in
                                                                                                                self?.showPaymentView()
                                                                                                }
                                                                                                JQ_currentViewController().jq_push(vc: vc)
                                                                }
                                                }
                                }).disposed(by: disposeBag)
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
}
 
extension WorldCupContentApplyInputVC:UITableViewDelegate{
 
}
 
 
extension WorldCupContentApplyInputVC:UITableViewDataSource{
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                                let student = students[indexPath.row]
                                let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfo_2_TCell") as! StudentInfo_2_TCell
                                cell.indexPath = indexPath
                                cell.activityDetailPartModel = student
                                cell.btn_edit.isHidden = true
                                cell.img_radio.isHidden = true
                                cell.delClouse = {[weak self] index in
                                                tableView.beginUpdates()
                                                self?.students.remove(at: index.row)
                                                tableView.deleteItemsAtIndexPaths([index], animationStyle: .automatic)
                                                tableView.endUpdates()
                                                tableView.reloadData()
                                }
                                return cell
                }
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                return students.count
                }
}