ProgramViewController.swift 5.26 KB
//
//  ProgramViewController.swift
//  ParentAssistant
//
//  Created by Cao yang on 2018/4/10.
//  Copyright © 2018年 HANGZHOUTEAM. All rights reserved.
//

import UIKit

class ProgramViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

    lazy var tableView = {()->UITableView in
        let table = UITableView.init()
        table.backgroundColor = UIColor.white
        table.delegate = self
        table.dataSource = self
        table.tableFooterView = UIView.init()
        return table
    }()
    
    lazy var empty = {()->UIView in
        
        let emptyView = UIView.init(frame: self.view.bounds)
        emptyView.backgroundColor = backGroundColor
        
        let label1 = UILabel.init(frame: CGRect.init(x: 0, y: 50, width: screenWidth, height: 30))
        label1.text = "如需使用该模块,请前往"
        label1.textAlignment = .center
        
        let label2 = UILabel.init(frame: CGRect.init(x: 0, y: 80, width: screenWidth, height: 30))
        label2.text = "个人中心-我的孩子"
        label2.textAlignment = .center
        label2.textColor = UIColor.blue
        
        let tapGest = UITapGestureRecognizer.init(target: self, action: #selector(gotoChildView))
        label2.isUserInteractionEnabled = true
        label2.addGestureRecognizer(tapGest)
        
        let label3 = UILabel.init(frame: CGRect.init(x: 0, y: 110, width: screenWidth, height: 30))
        label3.textAlignment = .center
        label3.text = "绑定孩子账号"
        
        emptyView.addSubview(label1)
        emptyView.addSubview(label2)
        emptyView.addSubview(label3)
        
        return emptyView
    }()
    
    //Data
    var tableData = Array<String>()
    
    var titleImage = Array<String>()
    
    override func viewWillAppear(_ animated: Bool) {
        
        let array = AccountManager.shared.getChildClassInfo()
        if array.isEmpty {
            self.view.addSubview(self.empty)
            self.tableView.isHidden = true
        }else{
            self.empty.removeFromSuperview()
            self.tableView.isHidden = false
        }
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = backGroundColor
        self.view.addSubview(self.tableView)
       
        tableView.snp.makeConstraints { (maker) in
            maker.width.height.equalToSuperview()
            maker.center.equalToSuperview()
        }
        self.tableData = ["考勤","补卡","请假"]
        self.titleImage = ["program_check","program_card","program_leave"]
        // Do any additional setup after loading the view.
    }

    @objc func gotoChildView () {
        let vc = Story.instantiateViewControllerWithIdentifier("MyChildrenViewController", storyName: "My") as! MyChildrenViewController
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    
    //MARK: - UITableView Delegate & DataSource
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.tableData.count
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 40
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let title = UILabel.init(frame: CGRect.init(x: 0, y: 0, width: tableView.bounds.size.width, height: 40))
        title.textAlignment = .center
        title.text = "智能校卫"
        title.backgroundColor = UIColor.white
        return title
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell.init()
        cell.selectionStyle = .none
        cell.textLabel?.text = self.tableData[indexPath.row]
        cell.imageView?.image = UIImage.init(named: self.titleImage[indexPath.row])
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        switch indexPath.row {
        case 0:
            let vc  = ProgramCheckViewController()
            vc.title = "考勤"
            self.navigationController?.pushViewController(vc, animated: true)
        case 1:
            let vc = ProgramCardViewController()
            vc.title = "补卡"
            self.navigationController?.pushViewController(vc, animated: true)
        case 2:
            let vc = ProgramVacateViewController()
            vc.title = "请假"
            self.navigationController?.pushViewController(vc, animated: true)
        default:
            break
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}