r
2025-09-19 8c309ff419690cc77c9b178096878e18d4849fc2
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
//
//  YardDetailVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/6/19.
//
 
import UIKit
import QMUIKit
import JQTools
import FFPage
import RxRelay
import RxSwift
import WebKit
 
 
class YardDetailDateManager {
                private static var _sharedInstance: YardDetailDateManager?
 
                class func shared() -> YardDetailDateManager {
                                guard let instance = _sharedInstance else {
                                                _sharedInstance = YardDetailDateManager()
                                                return _sharedInstance!
                                }
                                return instance
                }
 
                private init() {} // 私有化init方法
 
                var dates = BehaviorRelay<[String:[SiteDetailDateTimeModel]]>(value: [:])
 
                //销毁单例对象
                class func destroy() {
                                _sharedInstance = nil
                }
}
 
class YardDetailVC: BaseVC {
 
                @IBOutlet weak var scrollView: UIScrollView!
                @IBOutlet weak var view_banner: CommonBannerView!
                @IBOutlet weak var btn_calendar: QMUIButton!
                @IBOutlet weak var collectionView: UICollectionView!
                @IBOutlet weak var view_pages: UIView!
                @IBOutlet weak var cons_pagesHei: NSLayoutConstraint!
                @IBOutlet weak var view_coupon: UIView!
                @IBOutlet weak var label_name: UILabel!
                @IBOutlet weak var label_typeName: UILabel!
                @IBOutlet weak var label_address: UILabel!
                @IBOutlet weak var label_cashPrice: UILabel!
                @IBOutlet weak var label_coinPrice: UILabel!
                @IBOutlet weak var label_datetime: UILabel!
                @IBOutlet weak var tf_person: UITextField!
                @IBOutlet weak var tf_phone: QMUITextField!
                @IBOutlet weak var label_selectTimes: UILabel!
                @IBOutlet weak var label_totalHours: UILabel!
                @IBOutlet weak var label_price: UILabel!
                @IBOutlet weak var btn_coupon: UIButton!
                @IBOutlet weak var btn_fullYard: QMUIButton!
                @IBOutlet weak var btn_halfYard: QMUIButton!
                @IBOutlet weak var collection_halfYard: UICollectionView!
                @IBOutlet weak var collection_yardType: UICollectionView!
                @IBOutlet weak var view_yardType: UIView!
                @IBOutlet weak var cons_halfYardHei: NSLayoutConstraint!
                @IBOutlet weak var cons_yardTypeHei: NSLayoutConstraint!
                @IBOutlet weak var view_halfYard: UIView!
                @IBOutlet weak var view_selectYardType: UIView!
                @IBOutlet weak var web_introduce: WKWebView!
                @IBOutlet weak var cons_webHei: NSLayoutConstraint!
                @IBOutlet weak var btn_booking: UIButton!
                @IBOutlet weak var label_conponInfo: UILabel!
 
                private var coupons = [CouponInfoModel]()
                private var selectCouponModel:CouponInfoModel?
                private let yardCellW = (JQ_ScreenW  - 144) / 3
                private var halfIndex:Int?
                private var yardIndex:Int = 0 //场地
 
 
                lazy var pageViewController:FFPageViewController = {
                                let pageVC = FFPageViewController()
                                pageVC.view.backgroundColor = .clear
                                pageVC.scrollview.backgroundColor = .clear
                                pageVC.prePages = 2
                                pageVC.scrollview.bounces = false
                                return pageVC
                }()
 
                private var siteDetailModel:SiteDetailModel!
                private var siteDetailDateTimeModel:SiteDetailDateTimeModel!
                private let banner = CommonBannerView()
 
                private var id:Int!
                private var cellW:Double!
                private var selectIndex = 0
                private var weeklys = [Date]()
                private var currentDate:Date?{
                                didSet{
                                                if let d = currentDate{
                                                                selectIndex = currentDate?.jq_nowWeekDay(identifier: .republicOfChina).index ?? 0
                                                                weeklys = d.jq_currentWeekDates
                                                                collectionView.reloadData()
                                                }
                                }
                }
 
                required init(id:Int){
                                super.init(nibName: nil, bundle: nil)
                                self.id = id
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
                override func viewDidLoad() {
                                super.viewDidLoad()
                                title = "预约场地"
                                Services.querySiteDetail(id: id).subscribe(onNext: {[weak self] data in
                                                guard let weakSelf = self else { return }
                                                if let model = data.data{
                                                                weakSelf.siteDetailModel = model
                                                                weakSelf.label_name.text = model.name
                                                                weakSelf.label_typeName.text = model.siteTypeName
                                                                weakSelf.label_address.text = String(format: "%@(%@)",model.storeName, model.storeAddress)
                                                                weakSelf.changePrice(cashPrice: model.cashPrice, coin: model.playPaiCoin, typeName: model.typeName)
                                                                weakSelf.view_yardType.isHidden = model.nextName.count == 0
                                                                weakSelf.view_selectYardType.isHidden = model.ishalf == 2
 
                                                                let c:Double = Double(model.halfName.count)
                                                                let h:Double = weakSelf.yardCellW * 0.439
                                                                weakSelf.cons_halfYardHei.constant = ceil(c / 3.0) * h + floor(c / 3.0) * 21
 
                                                                let c1:Double = Double(model.nextName.count)
                                                                weakSelf.cons_yardTypeHei.constant = ceil(c1 / 3.0) * h + floor(c1 / 3.0) * 21
 
                                                                weakSelf.collection_halfYard.reloadData()
                                                                weakSelf.collection_yardType.reloadData()
 
                                                                weakSelf.web_introduce.loadHTMLString(model.introduce.jq_wrapHtml(), baseURL: nil)
                                                                weakSelf.view_banner.frame = CGRect(origin: .zero, size: CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.56))
 
                                                                let imgs = model.imgs.components(separatedBy: ",")
                                                                var items = [CommonBannerModel]()
                                                                for (index,img) in imgs.enumerated(){
                                                                                items.append(CommonBannerModel(index: index,resource: img,mediaType: .imageUrl))
                                                                }
                                                                weakSelf.view_banner.setItems(items: items)
 
                                                                weakSelf.view_yardType.isHidden = model.nextName.filter({!$0.isEmpty}).count == 0
                                                                DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
                                                                                weakSelf.pageViewController.reloadData()
                                                                                if let currentVC = weakSelf.pageViewController.currentController as? YardDetailDateTimeVC{
                                                                                                currentVC.querySiteTimes(halfName: nil, siteName: nil)
                                                                                }
                                                                }
                                                }
                                }).disposed(by: disposeBag)
                }
 
                override func setRx() {
                                YardDetailDateManager.shared().dates.subscribe(onNext: { [weak self] dict in
                                                guard let weakSelf = self else { return }
                                                guard weakSelf.siteDetailModel != nil else {return}
 
                                                if let a = dict.values.first,a.count > 0{
                                                                var cashPrice:Double = 0
                                                                var coinPrice:Int = 0
 
                                                                if weakSelf.btn_halfYard.isSelected{
                                                                                cashPrice = weakSelf.siteDetailModel.cashPriceOne
                                                                                coinPrice = weakSelf.siteDetailModel.playPaiCoinOne
                                                                }else{
                                                                                cashPrice = weakSelf.siteDetailModel.cashPrice
                                                                                coinPrice = weakSelf.siteDetailModel.playPaiCoin
                                                                }
 
                                                                let key = dict.keys.first!
                                                                weakSelf.label_price.text = String(format: "%@/%ld币", (Double(a.count) * cashPrice - (weakSelf.selectCouponModel?.favorable ?? 0)).currency(),a.count * coinPrice)
                                                                let prefix = a.first?.time.components(separatedBy: "-").first
                                                                let suffix = a.last?.time.components(separatedBy: "-").last
                                                                weakSelf.label_selectTimes.text = String(format: "%@ %@-%@",key,prefix ?? "",suffix ?? "")
                                                                weakSelf.label_totalHours.text = String(format: "(合计%.1lf小时)", Double(a.count) * 0.5)
                                                                weakSelf.queryCoupon(price: (Double(a.count) * cashPrice))
                                                }else{
                                                                weakSelf.label_selectTimes.text = "未选择"
                                                                weakSelf.label_totalHours.text = "(合计0小时)"
                                                                weakSelf.label_price.text = "¥-/-币"
                                                }
                                }).disposed(by: disposeBag)
 
                                web_introduce.scrollView.rx.observe(CGSize.self, "contentSize").map { (size) -> CGFloat? in
                                                if let size = size{
                                                                return size.height
                                                }
                                                return nil
                                }.subscribe(onNext: { [unowned self](height) in
                                                if let height = height{
                                                                self.cons_webHei.constant = height
                                                }
                                }).disposed(by: disposeBag)
                }
 
                override func setUI() {
                                view_coupon.isHidden = true
                                cellW = (JQ_ScreenW - 68.0) / 7.0
                                btn_calendar.imagePosition = .top
                                btn_calendar.spacingBetweenImageAndTitle = 3
                                cons_pagesHei.constant = 150
 
                                collectionView.register(UINib(nibName: "CalendarItemCCell", bundle: nil), forCellWithReuseIdentifier: "_CalendarItemCCell")
                                collectionView.delegate = self
                                collectionView.dataSource = self
 
                                addChild(pageViewController)
                                view_pages.insertSubview(pageViewController.view, at: 0)
                                pageViewController.didMove(toParent: self)
 
                                pageViewController.view.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
                                pageViewController.delegate = self
 
                                btn_fullYard.spacingBetweenImageAndTitle = 13
                                btn_halfYard.spacingBetweenImageAndTitle = 13
 
                                collection_halfYard.delegate = self
                                collection_halfYard.dataSource = self
                                collection_halfYard.register(UINib(nibName: "Common_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_1_CCell")
 
                                collection_yardType.delegate = self
                                collection_yardType.dataSource = self
                                collection_yardType.register(UINib(nibName: "Common_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_1_CCell")
 
                                view_halfYard.isHidden = true
                                view_yardType.isHidden = true
                                view_selectYardType.isHidden = true
 
                                scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 75, right: 0)
 
                                tf_person.text = UserInfoModel.get()?.userName ?? ""
                                tf_phone.text = UserInfoModel.get()?.userPhone ?? ""
                }
 
                /// 查询优惠券
                private func queryCoupon(price:Double){
                                Services.querySiteCouponList(price: price, siteId: siteDetailModel.id).subscribe(onNext: {[weak self] data in
                                                if let models = data.data{
                                                                self?.view_coupon.isHidden = models.count == 0
                                                                self?.coupons = models
                                                                self?.label_conponInfo.isHidden = models.count == 0
                                                                self?.label_conponInfo.text = String(format: "(%ld张可用)",models.count)
                                                }
                                }).disposed(by: disposeBag)
                }
 
                private func changePrice(cashPrice:Double,coin:Int,typeName:String){
                                let att = AttributedStringbuilder.build()
                                att.add(string: "\(cashPrice.currency())/", withFont: UIFont.systemFont(ofSize: 18, weight: .medium), withColor: UIColor(hexStr: "#EC0808"))
                                if  typeName == "智慧场地"{
                                                att.add(string: "15分钟", withFont: UIFont.systemFont(ofSize: 14, weight: .medium), withColor: UIColor(hexStr: "#535353"))
                                }else{
                                                att.add(string: "半小时", withFont: UIFont.systemFont(ofSize: 14, weight: .medium), withColor: UIColor(hexStr: "#535353"))
                                }
                                label_cashPrice.attributedText = att.mutableAttributedString
 
                                let att1 = AttributedStringbuilder.build()
                                att1.add(string: "\(coin)币/", withFont: UIFont.systemFont(ofSize: 18, weight: .medium), withColor: UIColor(hexStr: "#EC0808"))
                                if  typeName == "智慧场地"{
                                                att1.add(string: "15分钟", withFont: UIFont.systemFont(ofSize: 14, weight: .medium), withColor: UIColor(hexStr: "#535353"))
                                }else{
                                                att1.add(string: "半小时", withFont: UIFont.systemFont(ofSize: 14, weight: .medium), withColor: UIColor(hexStr: "#535353"))
                                }
                                label_coinPrice.attributedText = att1.mutableAttributedString
                }
 
                @IBAction func halfYardTypeAction(_ sender: QMUIButton) {
                                btn_fullYard.isSelected = sender.tag == 200
                                btn_halfYard.isSelected = sender.tag == 201
                                selectCouponModel = nil
                                btn_coupon.setTitle("去选择", for: .normal)
                                if btn_fullYard.isSelected{
                                                halfIndex = nil
                                }else{
                                                halfIndex = 0
                                }
 
                                collection_halfYard.reloadData()
 
                                UIView.animate(withDuration: 0.5) {
                                                self.view_halfYard.isHidden = self.btn_fullYard.isSelected
                                                self.view_halfYard.alpha = (self.view_halfYard.isHidden ? 0:1)
                                }
 
                                if btn_halfYard.isSelected{
                                                changePrice(cashPrice: siteDetailModel.cashPriceOne, coin: siteDetailModel.playPaiCoinOne, typeName: siteDetailModel.typeName)
                                }else{
                                                changePrice(cashPrice: siteDetailModel.cashPrice, coin: siteDetailModel.playPaiCoin, typeName: siteDetailModel.typeName)
                                }
 
                                //为了计算价格 【半场/全场】切换
                                var val = YardDetailDateManager.shared().dates.value
                                val.removeAll()
                                YardDetailDateManager.shared().dates.accept(val)
                                clearAll()
                }
 
                private func clearAll(){
                                if let currentVC = pageViewController.currentController as? YardDetailDateTimeVC{
                                                currentVC.clearALL()
                                                var halfName:String?
                                                var nextName:String?
 
                                                if halfIndex != nil{
                                                                halfName = siteDetailModel.halfName[halfIndex!]
                                                }
 
                                                if siteDetailModel.nextName.count > 0{
                                                                nextName = siteDetailModel.nextName[yardIndex]
                                                }
                                                currentVC.querySiteTimes(halfName: halfName, siteName: nextName)
                                }
                }
 
 
                @IBAction func callPhoneAction(_ sender: UIButton) {
                                UIApplication.shared.open(URL(string: "tel://\(siteDetailModel.storePhone)")!)
                }
 
                @IBAction func couponAction(_ sender: UIButton) {
                                CouponChooseView.show(coupons, defaultModel: selectCouponModel) { [weak self] m in
                                                self?.selectCouponModel = m
                                                let string = m == nil ? "去选择":"-\(m!.favorable.currency())"
                                                self?.btn_coupon.setTitle(string, for: .normal)
                                                let temp = YardDetailDateManager.shared().dates.value
                                                YardDetailDateManager.shared().dates.accept(temp)
                                }
                }
 
                @IBAction func calendarAction(_ sender: QMUIButton) {
                                CalendarPickerView.show(selectDate: currentDate) { [weak self] date in
                                                let offsetDay = Date.jq_CalByDays(startDate: Date().jq_clearTimes(), endDate: date)
                                                self?.pageViewController.scroll(toPage: offsetDay, animation: true)
                                                self?.collectionView.reloadData()
                                }
                }
 
                @IBAction func bookingAction(_ sender: UIButton) {
 
                                guard !YardDetailDateManager.shared().dates.value.isEmpty else {alertError(msg: "请选择预约时间");return}
                                guard YardDetailDateManager.shared().dates.value.values.first!.count != 0 else {alertError(msg: "请选择预约时间");return}
                                guard !tf_person.isEmpty else {alertError(msg: "请输入预约人");tf_person.becomeFirstResponder();return}
                                guard !tf_phone.isEmpty else {alertError(msg: "请输入联系方式");tf_phone.becomeFirstResponder();return}
                                guard tf_phone.text!.jq_isPhone else {alertError(msg: "请输入正确的联系方式");return}
                                if btn_halfYard.isSelected && halfIndex == nil{
                                                alert(msg: "请选择半场");return
                                }
 
                                var halfName:String?
                                var isHalf:Int = 2
                                var nextName:String?
 
                                if halfIndex != nil{
                                                halfName = siteDetailModel.halfName[halfIndex!]
                                }
 
                                if siteDetailModel.ishalf == 1 && btn_halfYard.isSelected{
                                                isHalf = 1
                                }
 
                                if siteDetailModel.nextName.count > 0{
                                                nextName = siteDetailModel.nextName[yardIndex]
                                }
 
 
                                StoresInfoView.show(siteDetailModel) { [weak self] status in
                                                guard let weakSelf = self else { return }
                                                if status{
                                                                let a = YardDetailDateManager.shared().dates.value.values.first!
                                                                let cashPrice = weakSelf.btn_halfYard.isSelected ? weakSelf.siteDetailModel.cashPriceOne:weakSelf.siteDetailModel.cashPrice
                                                                let coinPrice = weakSelf.btn_halfYard.isSelected ? weakSelf.siteDetailModel.playPaiCoinOne : weakSelf.siteDetailModel.playPaiCoin
                                                                let price = Double(a.count) * cashPrice - (weakSelf.selectCouponModel?.favorable ?? 0)
                                                                let coin = a.count * coinPrice
 
                                                                var datetimes = [String]()
                                                                let key = YardDetailDateManager.shared().dates.value.keys.first!
                                                                for value in YardDetailDateManager.shared().dates.value.values.first!{
                                                                                datetimes.append(String(format: "%@ %@", key,value.time))
                                                                }
 
 
                                                                PaymentView.show(enumType: .yard, money: (ali:price,wx:price,coin:coin,course:nil,integral:nil)) { [weak self] type in
                                                                                guard let weakSelf = self else { return }
                                                                                Services.reservationSite(booker: weakSelf.tf_person.text!, couponId: weakSelf.selectCouponModel?.id, id: weakSelf.siteDetailModel.id, payType: type, phone: weakSelf.tf_phone.text!, times: datetimes.joined(separator: ";"),halfName:halfName,isHalf:isHalf,nextName:nextName).subscribe(onNext: { data in
                                                                                                if let m = data.data{
                                                                                                                weakSelf.selectCouponModel = nil
                                                                                                                weakSelf.btn_coupon.setTitle("去选择", for: .normal)
                                                                                                                weakSelf.queryCoupon(price: Double(a.count) * cashPrice)
                                                                                                                switch type {
                                                                                                                                case .aliPay:
                                                                                                                                                YYPaymentManager.shared.sendPaymentRequest(YYAlipayRequest(orderString: m.orderString)) { result in
                                                                                                                                                                switch result {
                                                                                                                                                                                case .success:
                                                                                                                                                                                                NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                                                                let vc = YardBookingDetailVC(siteBookingId: m.siteBooking)
                                                                                                                                                                                                weakSelf.push(vc: vc)
                                                                                                                                                                                case .cancel:
                                                                                                                                                                                                alert(msg: "交易取消")
                                                                                                                                                                                                let vc = YardBookingListVC(page: 5)
                                                                                                                                                                                                weakSelf.push(vc: vc)
                                                                                                                                                                                                NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                                                case .failure(_):
                                                                                                                                                                                                NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                                                                let vc = PaymentResultVC(result: .fail("交易失败",0), objType: .yard,handleVC: nil)
                                                                                                                                                                                                weakSelf.push(vc: vc)
                                                                                                                                                                }
                                                                                                                                                }
 
                                                                                                                                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:
                                                                                                                                                                                                NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                                                                let vc = YardBookingDetailVC(siteBookingId: m.siteBooking)
                                                                                                                                                                                                weakSelf.push(vc: vc)
                                                                                                                                                                                case .cancel:
                                                                                                                                                                                                alert(msg: "交易取消")
                                                                                                                                                                                                let vc = YardBookingListVC(page: 5)
                                                                                                                                                                                                weakSelf.push(vc: vc)
                                                                                                                                                                                                NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                                                case .failure(_):
                                                                                                                                                                                                NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                                                                let vc = PaymentResultVC(result: .fail("交易失败",0), objType: .yard,handleVC: nil)
                                                                                                                                                                                                weakSelf.push(vc: vc)
                                                                                                                                                                }
                                                                                                                                                }
 
                                                                                                                                case .integral:break
                                                                                                                                case .coin,.free:
                                                                                                                                                NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                let vc = YardBookingDetailVC(siteBookingId: m.siteBooking)
                                                                                                                                                weakSelf.push(vc: vc)
                                                                                                                                case .courseNum:break
                                                                                                                }
                                                                                                }
                                                                                },onError: { error in
                                                                                                if let er = error as? NetworkRequest.NetRequestError{
                                                                                                                switch er {
                                                                                                                                case .Other(let code,let string):
                                                                                                                                                //                                    NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                let vc = PaymentResultVC(result: .fail(string,code), objType: .yard){[weak self] in
                                                                                                                                                                let vc1 = YardBookingListVC(page: 5)
                                                                                                                                                                self?.push(vc: vc1)
                                                                                                                                                }
                                                                                                                                                self?.push(vc: vc)
                                                                                                                                default:
                                                                                                                                                //                                    NotificationCenter.default.post(name: UpdateDetailDate_Noti, object: nil)
                                                                                                                                                let vc = PaymentResultVC(result: .fail("支付失败",0), objType: .yard){[weak self] in
                                                                                                                                                                let vc1 = YardBookingListVC(page: 5)
                                                                                                                                                                self?.push(vc: vc1)
                                                                                                                                                }
                                                                                                                                                self?.push(vc: vc)
                                                                                                                }
                                                                                                }
                                                                                }).disposed(by: weakSelf.disposeBag)
                                                                }
                                                }else{
                                                                weakSelf.navigationController?.popToRootViewController(animated: true)
                                                                NotificationCenter.default.post(name: ChooseHomeStore_Noti, object: nil)
                                                }
                                }
                }
                
 
                private func showPaymentView(){
 
                }
 
                deinit{
                                YardDetailDateManager.destroy()
                }
}
 
extension YardDetailVC:FFPageViewControllerDelegate{
 
                func pageViewController(_ pageViewController: FFPageViewController, currentPageChanged currentPage: Int) {
                                if let vc = pageViewController.currentController as? YardDetailDateTimeVC{
                                                currentDate = vc.date
                                                label_datetime.text = vc.date.jq_format("yyyy年MM月dd日")
                                                cons_pagesHei.constant = vc.innerHeight
                                                UIView.animate(withDuration: 0.5) {
                                                                self.view.layoutIfNeeded()
                                                }
 
                                                var halfName:String?
                                                var nextName:String?
                                                if halfIndex != nil{
                                                                halfName = siteDetailModel.halfName[halfIndex!]
                                                }
 
                                                if siteDetailModel.nextName.count > 0{
                                                                nextName = siteDetailModel.nextName[yardIndex]
                                                }
                                                vc.querySiteTimes(halfName: halfName, siteName: nextName)
                                }
                }
 
                func totalPagesOfpageViewController(_ pageViewConteoller: FFPageViewController) -> UInt {
                                guard siteDetailModel != nil else {return 0}
                                return 11
                }
 
                func pageViewController(_ pageViewConteoller: FFPageViewController, controllerForPage page: Int) -> UIViewController {
                                let date = Date().jq_add(day: page)
                                var halfName:String?
                                var nextName:String?
 
                                if halfIndex != nil{
                                                halfName = siteDetailModel.halfName[halfIndex!]
                                }
 
                                if (siteDetailModel?.nextName.count ?? 0) > 0{
                                                nextName = siteDetailModel.nextName[yardIndex]
                                }
 
                                let vc = YardDetailDateTimeVC(id:id,date: date!,currentPage: page,halfName: halfName,siteName: nextName)
                                vc.updateInnerHeight { [weak self] (height, currentPage) in
                                                if currentPage == self?.pageViewController.currentPage{
                                                                self?.cons_pagesHei.constant = height
                                                                UIView.animate(withDuration: 0.3) {
                                                                                self?.view.layoutIfNeeded()
                                                                }
                                                }
                                }
                                return vc
                }
}
 
 
extension YardDetailVC:UICollectionViewDataSource{
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
 
                                if self.collectionView == collectionView{
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CalendarItemCCell", for: indexPath) as! CalendarItemCCell
                                                let date = weeklys[indexPath.row]
                                                cell.label_weekly.text = weeklys[indexPath.row].jq_nowWeekDay(identifier: .republicOfChina).weekName
                                                cell.label_date.text = weeklys[indexPath.row].jq_format("MM.dd")
 
                                                if date.jq_nowDay() == currentDate?.jq_nowDay(){
                                                                cell.label_weekly.textColor = .white
                                                                cell.label_date.textColor = .white
                                                                cell.view_bg.backgroundColor = Def_ThemeColor
                                                }else{
                                                                cell.label_weekly.textColor = .black.withAlphaComponent(0.6)
                                                                cell.label_date.textColor = .black.withAlphaComponent(0.6)
                                                                cell.view_bg.backgroundColor = .clear
                                                }
                                                return cell
                                }
 
                                if collection_yardType == collectionView{
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_1_CCell", for: indexPath) as! Common_1_CCell
                                                cell.label_content.text = siteDetailModel.nextName[indexPath.row]
                                                cell.label_content.backgroundColor = yardIndex == indexPath.row ? Def_ThemeColor : .white
                                                cell.label_content.textColor = yardIndex == indexPath.row ? .white : UIColor(hexStr: "#898989")
                                                cell.label_content.jq_borderWidth = yardIndex == indexPath.row ? 0:1
                                                return cell
                                }
 
                                //选择半场:
                                if collection_halfYard == collectionView{
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_1_CCell", for: indexPath) as! Common_1_CCell
                                                cell.label_content.text = siteDetailModel.halfName[indexPath.row]
                                                cell.label_content.backgroundColor = halfIndex == indexPath.row ? Def_ThemeColor : .white
                                                cell.label_content.textColor = halfIndex == indexPath.row ? .white : UIColor(hexStr: "#898989")
                                                cell.label_content.jq_borderWidth = halfIndex == indexPath.row ? 0:1
                                                return cell
                                }
                                return UICollectionViewCell()
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
 
                                if self.collectionView == collectionView{
                                                return weeklys.count
                                }
 
                                guard siteDetailModel != nil else {
                                                return 0
                                }
 
                                if collection_yardType == collectionView{
                                                return siteDetailModel.nextName.count
                                }
 
                                if collection_halfYard == collectionView{
                                                return siteDetailModel.halfName.count
                                }
 
                                return 0
                }
}
 
extension YardDetailVC:UICollectionViewDelegate{
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
 
                                if self.collectionView == collectionView{
                                                let date = weeklys[indexPath.row]
                                                let offsetDay = Date.jq_CalByDays(startDate: Date().jq_clearTimes(), endDate: date)
                                                if (date.jq_isToday() || date.isInFuture) && offsetDay <= 10{
                                                                currentDate = weeklys[indexPath.row]
                                                                collectionView.reloadData()
                                                                pageViewController.scroll(toPage: offsetDay, animation: true)
                                                }
                                }
 
                                if self.collection_yardType == collectionView{
                                                yardIndex = indexPath.row
                                                collectionView.reloadData()
                                                clearAll()
                                }
 
                                if self.collection_halfYard == collectionView{
                                                halfIndex = indexPath.row
                                                collectionView.reloadData()
                                                clearAll()
                                }
                }
}
 
extension YardDetailVC:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
 
                                if self.collectionView == collectionView{
                                                return CGSize(width: cellW, height: 50)
                                }
 
                                return CGSize(width: yardCellW, height: yardCellW * 0.439)
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                if self.collectionView == collectionView{
                                                return 0
                                }
                                return 21
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                if self.collectionView == collectionView{
                                                return 0
                                }
                                return 21
                }
}