ReportViewController.swift
7.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//
// ReportViewController.swift
// ParentAssistant
//
// Created by 葛建军 on 2018/3/5.
// Copyright © 2018年 HANGZHOUTEAM. All rights reserved.
//
import UIKit
class ReportViewController: UIViewController {
var titleView:ReportHeaderView!//navigationBar自定义view
@IBOutlet weak var reportTable: UITableView!
@IBOutlet var dateViewHeight: NSLayoutConstraint!//顶部固定日期的高度
@IBOutlet var calendarView: UIView!
@IBOutlet weak var EmptyView: UIView!
var dateView:LXCalendarView!
var dateAry:(weeks:[String],days:[String]) = ([],[])
override func viewDidLoad() {
super.viewDidLoad()
//MARK: - 空白页面
self.EmptyView.isHidden = true
if !self.EmptyView.isHidden {
//设置顶部按钮
setupNavigationBar()
//设置日期页面
setupDateView()
}
}
// MARK: - 设置顶部按钮
func setupNavigationBar(){
self.navigationController?.navigationBar.barStyle = UIBarStyle.default// UIColorFromRGB(0xC5DAFF)
let backImage = UIImage(named: "navigationBar_backgrounImage")
self.navigationController?.navigationBar.setBackgroundImage(backImage, for: UIBarMetrics.default)
self.configTheme()
self.navigationItem.title = "报告"
setuptitleView()
}
func setuptitleView(){
// MARK: - 设置顶部的titleView
titleView = Bundle.main.loadNibNamed("ReportHeaderView", owner: nil, options: nil)![0] as! ReportHeaderView
titleView.delegate = self
titleView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: 44)
self.navigationItem.titleView = titleView
titleView.layoutSubviews()
//navigation左上角显示名称 家长未绑定孩子
if AccountManager.shared.isOnline() {
if AccountManager.shared.rawUserInfo!.contentData()["studentClass"].arrayValue.count == 0 {
titleView.nameButton.setTitle("未绑定", for: UIControlState.normal)
}else{
titleView.nameButton.setTitle(AccountManager.shared.rawUserInfo!.contentData()["studentClass"][0]["studentName"].stringValue, for: UIControlState.normal)
}
}else{
titleView.nameButton.setTitle("未登录", for: UIControlState.normal)
}
}
// MARK: - 设置日期页面
func setupDateView(){
titleView.dateButton.setTitle("\(getCurrentDate())", for: UIControlState.normal)
dateViewHeight.constant = getScreenWidth()/7
//添加顶部固定一周日期
dateAry = getCurrentWeeks()
//添加日历
dateView = LXCalendarView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenWidth/2))
dateView.isHaveAnimation = true
dateView.isCanScroll = true
dateView.isShowLastAndNextBtn = false
dateView.isShowLastAndNextDate = true
dateView.todayTitleColor = UIColor.red
dateView.selectBackColor = UIColorFromRGB(0xC5DAFF)
dateView.dealData()
dateView.backgroundColor = UIColor.white
calendarView.addSubview(dateView)
dateView.selectBlock = { (year:NSInteger,month:NSInteger,day:NSInteger) -> () in
self.calendarView.isHidden = true
self.titleView.dateButton.setTitle("\(month)月\(day)日", for: UIControlState.normal)
//选择日期后应隐藏日历并刷新界面
appDelegate.window!.makeToast("\(year)年\(month)月\(day)日", duration: 2, position: CSToastPositionCenter)
}
}
// MARK: - 页面将要显示时替换navigation的titleView
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.calendarView.isHidden = true
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if titleView != nil {
titleView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: 44)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
// MARK: - 点击顶部titleView按钮的代理方法
extension ReportViewController: ReportHeaderViewDelegate{
//点击孩子姓名
func selectStudentButton() {
appDelegate.window!.makeToast("该功能暂不开放", duration: 1, position: CSToastPositionCenter)
return
//如果家长未绑定孩子
if AccountManager.shared.isOnline() {
if AccountManager.shared.rawUserInfo!.contentData()["studentClass"].arrayValue.count == 0 {
appDelegate.window!.makeToast("请先绑定孩子", duration: 1, position: CSToastPositionCenter)
}else{
//切换孩子
let alert = UIAlertController(title: "切换孩子", message: "", preferredStyle: UIAlertControllerStyle.actionSheet)
for item in AccountManager.shared.rawUserInfo!.contentData()["studentClass"].arrayValue {
let action = UIAlertAction(title: item["studentName"].stringValue, style: UIAlertActionStyle.default, handler: { (action) in
//选择完孩子切换数据
})
alert.addAction(action)
}
self.present(alert, animated: true, completion: nil)
}
}else{
appDelegate.window!.makeToast("请先登录", duration: 1, position: CSToastPositionCenter)
}
}
//点击日期
func selectDateButton() {
appDelegate.window!.makeToast("该功能暂不开放", duration: 1, position: CSToastPositionCenter)
return
let isHidden = calendarView.isHidden
if isHidden {
calendarView.isHidden = false
}else{
calendarView.isHidden = true
}
}
//点击筛选
func selectTypeButton() {
appDelegate.window!.makeToast("该功能暂不开放", duration: 1, position: CSToastPositionCenter)
return
}
}
// MARK: - 顶部展示日期
extension ReportViewController: UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: getScreenWidth()/7, height: getScreenWidth()/7)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ReportDateCollectionViewCell", for: indexPath) as! ReportDateCollectionViewCell
cell.setupWithDate(week: dateAry.weeks[indexPath.row], date: dateAry.days[indexPath.row])
return cell
}
}
// MARK: - 作业报告列表
extension ReportViewController: UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "MoralTableViewCell", for: indexPath) as! MoralTableViewCell
return cell
}else{
let cell = tableView.dequeueReusableCell(withIdentifier: "TaskPresentationTableViewCell", for: indexPath) as! TaskPresentationTableViewCell
return cell
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 280
}
}