无故事王国
2023-06-28 a56ff03fc62bb894160f9b71fc54f66e77e48712
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
//
//  CourseInfoVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/6/21.
//
 
import UIKit
import JQTools
import SPPageMenu
import FFPage
import QMUIKit
 
class CourseInfoVC: BaseVC {
 
    private struct MentalInfo {
        var img:UIImage!
        var t1:String!
        var t2:String!
    }
 
    @IBOutlet weak var scrollView: CourseInfoScrollView!
    @IBOutlet weak var view_container: UIView!
    @IBOutlet weak var img_header: UIImageView!
    @IBOutlet weak var label_stu_hei: UILabel!
    @IBOutlet weak var label_stu_wei: UILabel!
    @IBOutlet weak var label_stu_BMI: UILabel!
    @IBOutlet weak var view_menu: UIView!
    @IBOutlet weak var btn_record: UIButton!
    @IBOutlet weak var view_schedule: UIView!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var mentalCollectionView: UICollectionView!
    @IBOutlet weak var cons_mentalViewHei: NSLayoutConstraint!
    @IBOutlet weak var exerciseCollectionView: UICollectionView!
 
    private var mentals = [MentalInfo]()
 
    private var pageMenu:SPPageMenu = {
        let pageMenu = SPPageMenu(frame: .zero, trackerStyle: .line)
        // 追踪线
        pageMenu.trackerWidth = 56
        pageMenu.setTrackerHeight(3, cornerRadius: 1.5)
        pageMenu.tracker.backgroundColor = .clear
        pageMenu.trackerFollowingMode = .always
        pageMenu.contentInset = UIEdgeInsets(top: 0, left: 19, bottom: 0, right: 19)
 
        // 分割线
        pageMenu.dividingLine.backgroundColor = .clear
        pageMenu.dividingLineHeight = 1
 
        // item
        pageMenu.spacing = 27.0
        pageMenu.permutationWay = .scrollAdaptContent
        pageMenu.setItems(["荷兰足球队","全科体育课"], selectedItemIndex: 0)
 
        // 字体
        pageMenu.selectedItemTitleFont = UIFont.systemFont(ofSize: 18, weight: .medium)
        pageMenu.unSelectedItemTitleFont = UIFont.systemFont(ofSize: 18,weight: .medium)
        // 颜色
        pageMenu.selectedItemTitleColor = UIColor(hexStr: "#6CC366")
        pageMenu.unSelectedItemTitleColor = UIColor(hexStr: "#A4A4A4")
 
        return pageMenu
    }()
 
    private lazy var leftBtn:QMUIButton = {
        let btn = QMUIButton(type: .custom)
        btn.setTitle("添加学员", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        btn.setTitleColor(.white, for: .normal)
        btn.setImage(UIImage(named: "btn_add_shadow"), for: .normal)
        btn.imagePosition = .left
        btn.spacingBetweenImageAndTitle = 0
        btn.imageEdgeInsets = UIEdgeInsets(top: 2, left: 0, bottom: 0, right: 0)
        btn.addTarget(self, action: #selector(addStudentAction), for: .touchUpInside)
        return btn
    }()
 
    lazy var pageViewController:FFPageViewController = {
        let pageVC = FFPageViewController()
        pageVC.view.backgroundColor = .clear
        pageVC.scrollview.backgroundColor = .clear
 
        pageVC.scrollview.bounces = false
        return pageVC
    }()
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        label_stu_hei.attributedText = setAttribute(t1: "0", t2: "cm")
        label_stu_wei.attributedText = setAttribute(t1: "0", t2: "kg")
        label_stu_BMI.attributedText = setAttribute(t1: "0.0", t2: "正常")
    }
 
 
    override func setUI() {
        scrollView.contentInset = UIEdgeInsets( top: JQ_ScreenW * 0.6794 - JQ_NavBarHeight, left: 0, bottom: 0, right: 0)
        scrollView.delegate = self
        scrollView.bringSubviewToFront(img_header)
 
        pageMenu.frame = CGRect(origin: .zero, size: CGSize(width: JQ_ScreenW, height: 25))
        pageMenu.delegate = self
        view_menu.addSubview(pageMenu)
        scrollView.bounces = false
        scrollView.contentInsetAdjustmentBehavior = .never
 
        let attribute = AttributedStringbuilder()
        attribute.add(string: "预约记录", withFont: UIFont.systemFont(ofSize: 14), withColor: Def_ThemeColor)
        attribute.underLine(color: Def_ThemeColor)
        btn_record.titleLabel?.attributedText = attribute.mutableAttributedString
 
 
        view_schedule.addSubview(pageViewController.view)
        addChild(pageViewController)
        pageViewController.delegate = self
        view_schedule.insertSubview(pageViewController.view, at: 0)
        pageViewController.didMove(toParent: self)
        pageViewController.view.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: 50)
 
        tableView.delegate = self
        tableView.dataSource = self
        tableView.isScrollEnabled = false
        tableView.separatorStyle = .none
        tableView.register(UINib(nibName: "CourseBookingTCell", bundle: nil), forCellReuseIdentifier: "_CourseBookingTCell")
 
        mentalCollectionView.delegate = self
        mentalCollectionView.dataSource = self
        mentalCollectionView.contentInset = UIEdgeInsets(top: 0, left: 58, bottom: 0, right: 58)
        mentalCollectionView.tag = 1000
        mentalCollectionView.isScrollEnabled = false
        mentalCollectionView.register(UINib(nibName: "StudentMedalCCell", bundle: nil), forCellWithReuseIdentifier: "_StudentMedalCCell")
 
        exerciseCollectionView.delegate = self
        exerciseCollectionView.dataSource = self
        exerciseCollectionView.tag = 1001
        exerciseCollectionView.register(UINib(nibName: "StudentVideoCCell", bundle: nil), forCellWithReuseIdentifier: "_StudentVideoCCell")
 
 
        mentals.append(MentalInfo(img: UIImage(named: "icon_coupon_1"), t1: "COURSE", t2: "俱乐部之星"))
        mentals.append(MentalInfo(img: UIImage(named: "icon_coupon_2"), t1: "EVENTS", t2: "运动大人"))
        mentals.append(MentalInfo(img: UIImage(named: "icon_coupon_3"), t1: "ON_LINE", t2: "社区之王"))
        mentals.append(MentalInfo(img: UIImage(named: "icon_coupon_4"), t1: "APPOINTMENT", t2: "深度玩家"))
        mentals.append(MentalInfo(img: UIImage(named: "icon_coupon_5"), t1: "EVENTS", t2: "月度冠军"))
        mentals.append(MentalInfo(img: UIImage(named: "icon_coupon_6"), t1: "MORE", t2: "更多"))
 
        cons_mentalViewHei.constant = ceil(Double(mentals.count) / 3) * 91 + floor(Double(mentals.count) / 3) * 30
 
        navigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftBtn)
 
    }
 
    private func setAttribute(t1:String,t2:String)->NSMutableAttributedString{
        let color:UIColor = UIColor(hexStr: "#2F5264")
        let a1 = AttributedStringbuilder()
        a1.add(string: t1, withFont: UIFont.systemFont(ofSize: 26), withColor: color)
            .add(string: t2, withFont: UIFont.systemFont(ofSize: 16), withColor: color)
        return a1.mutableAttributedString
    }
 
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 42)
    }
 
    @objc func addStudentAction() {
        let vc = AddStudentVC()
        push(vc: vc)
    }
 
    @IBAction func exchangeAction(_ sender: UIButton) {
        let vc = StudentExchangeVC()
        push(vc: vc)
    }
 
    @IBAction func reportAction(_ sender: UIButton) {
        let vc = StudentReportVC()
        push(vc: vc)
    }
 
 
    @IBAction func detailAction(_ sender: UIButton) {
        let vc = StudentCourseDetailVC()
        push(vc: vc)
    }
 
    @IBAction func bookingRecordAction(_ sender: UIButton) {
        let vc = CourseBookingListVC()
        push(vc: vc)
    }
 
 
    @IBAction func remarkAction(_ sender: UIButton) {
        let vc = StudentRemarkListVC()
        push(vc: vc)
    }
 
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .darkContent
    }
 
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let offsetX = min(1,max(0,-(scrollView.contentOffset.y / 177.0)))
        leftBtn.alpha = offsetX
    }
}
 
extension CourseInfoVC:UITableViewDelegate{
 
}
 
extension CourseInfoVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseBookingTCell") as! CourseBookingTCell
 
        return cell
    }
 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
 
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 70
    }
}
 
 
extension CourseInfoVC:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
 
        if collectionView.tag == 1000{
            let vc = StudentMentalListVC()
            push(vc: vc)
        }else{
            let vc = CourseVideoDetailVC()
            vc.title = "课后练习"
            push(vc: vc)
        }
    }
}
 
extension CourseInfoVC:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return mentals.count
    }
 
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        if collectionView.tag == 1000{
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_StudentMedalCCell", for: indexPath) as! StudentMedalCCell
            cell.img.image = mentals[indexPath.row].img
            cell.t1.text = mentals[indexPath.row].t1
            cell.t2.text = mentals[indexPath.row].t2
            return cell
        } else{
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_StudentVideoCCell", for: indexPath) as! StudentVideoCCell
            return cell
        }
    }
}
 
extension CourseInfoVC:UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        if collectionView.tag == 1000{
            return 30
        }else {
            return 12
        }
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        if collectionView.tag == 1000{
            return 30
        }else {
            return 0
        }
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        if collectionView.tag == 1000{
            let CellW = (JQ_ScreenW - 116 - 62 * 2) / 3
            return CGSize(width: CellW, height: 91)
        }else {
            let CellW = (JQ_ScreenW - 44 - 13) / 2
            return CGSize(width: CellW, height: 166)
        }
    }
}
 
extension CourseInfoVC:SPPageMenuDelegate{
    func pageMenu(_ pageMenu: SPPageMenu, itemSelectedAt index: Int) {
        
    }
}
 
 
extension CourseInfoVC:FFPageViewControllerDelegate{
 
    func pageViewController(_ pageViewController: FFPageViewController, currentPageChanged currentPage: Int) {
 
    }
 
    func totalPagesOfpageViewController(_ pageViewConteoller: FFPageViewController) -> UInt {
        return 10
    }
 
    func pageViewController(_ pageViewConteoller: FFPageViewController, controllerForPage page: Int) -> UIViewController {
 
        return CourseInfoScheduleVC()
    }
}
 
public class CourseInfoScrollView:UIScrollView{
    public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        for subView in subviews{
            let p = subView.convert(point, to: self)
            let hitTestView = subView.hitTest(p, with: event)
            return hitTestView
        }
        return nil
    }
}