TVStationViewController.swift 13.5 KB
//
//  TVStationViewController.swift
//  YouerLiveVideo
//
//  Created by 左丞 on 2017/5/15.
//  Copyright © 2017年 左丞. All rights reserved.
//

import UIKit

class TVStationViewController: UIViewController {
    var dataSet:[AnyObject] = []
    var topTenTVStation:[TVStationInfor] = []
    var xxcellentSchool:[TVStationInfor] = []
    var excellentTVStationProgram:[TVStationSubject] = []
    @IBOutlet weak var tableView: UITableView!
    var TVStationType:[String] = ["十佳电视台","优秀电视台","优秀校园节目"]
    override func viewDidLoad() {
        super.viewDidLoad()
        self.configTheme()
        getDataList()
        self.automaticallyAdjustsScrollViewInsets = false
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(TVStationViewController.pushToSeachViewController))
        // Do any additional setup after loading the view.
    }
    
    func pushToSeachViewController(){
        let vc = Story.instantiateViewControllerWithIdentifier("SearchTVStationListViewControllerVC", storyName: "TVStation") as! SearchTVStationListViewController
        vc.title = "搜索电视台"
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    func getDataList(){
        AppDelegate.instance().httpServer.getTopTenSchool(parameters: nil) { (str, error) in
            httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
                for item in json.contentData().arrayValue{
                    self.topTenTVStation.append(TVStationInfor(json: item))
                }
                (self.tableView.cellForRow(at: IndexPath(item: 0, section: 0)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData()
            }, failHandler: { (error) in
                
            })
        }
        AppDelegate.instance().httpServer.postExcellentSchool(parameters: ["pageIndex":1 as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in
            httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
                if json.contentData().dictionaryValue["resultData"] != nil{
                    for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{
                        self.xxcellentSchool.append(TVStationInfor(json: item))
                    }
                    (self.tableView.cellForRow(at: IndexPath(item: 0, section: 1)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData()
                }
            }, failHandler: { (error) in
                
            })
        }
        AppDelegate.instance().httpServer.postExcellentProgram(parameters: ["pageIndex":1 as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in
            httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
                if json.contentData().dictionaryValue["resultData"] != nil{
                    for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{
                        self.excellentTVStationProgram.append(TVStationSubject(json: item))
                    }
                    (self.tableView.cellForRow(at: IndexPath(item: 0, section: 2)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData()
                }
            }, failHandler: { (error) in
                
            })
        }

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func moreBtnClick(sender:UIButton){
        let vc = Story.instantiateViewControllerWithIdentifier("MoreTVStationViewControllerVC", storyName: "TVStation") as! MoreTVStationViewController
        switch sender.tag {
        case 0:
            vc.topTenTVStation = topTenTVStation
        case 1:
            vc.xxcellentSchool = xxcellentSchool
        case 2:
            vc.excellentTVStationProgram = excellentTVStationProgram
        default:
            break
        }
        vc.type = sender.tag
        vc.title = TVStationType[sender.tag]
        self.navigationController?.pushViewController(vc, animated: true)
    }
    /*
    // 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.
    }
    */

}

extension TVStationViewController:UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return TVStationType.count
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view  = UIView(frame: CGRect(x: 0, y: 0, width: getScreenWidth(), height: 44))
        view.backgroundColor = tableView.backgroundColor
        let imageView = UIImageView(frame: CGRect(x: 8, y: 8, width: 28, height: 28))
         imageView.image = UIImage(named: "icon")
        let label = UILabel(frame: CGRect(x: imageView.frame.maxX+8, y: 11, width: 100, height: 21))
        label.text = TVStationType[section]
        label.textAlignment = .left
        label.sizeToFit()
        let btn = UIButton(frame: CGRect(x: getScreenWidth() - 8 - 30, y: 7, width: 30, height: 30))
        btn.setImage(UIImage(named:"moreHot"), for: .normal)
        btn.tag = section
        btn.addTarget(self, action: #selector(TVStationViewController.moreBtnClick(sender:)), for: .touchUpInside)
        view.addSubview(btn)
        view.addSubview(label)
        view.addSubview(imageView)
        return view
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 44
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TVStationViewControllerTableViewCell
        cell.collectionView.tag = indexPath.section+1
        return cell
    }
}

extension TVStationViewController:UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource{
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if collectionView.tag == 3{
            let vc = Story.instantiateViewControllerWithIdentifier("ExcellentTVViewControllerVC", storyName: "TVStation") as! ExcellentTVViewController
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! TVStationViewControllerCollectionCell
        if collectionView.tag == 1{
            cell.image.sd_setImage(with: URL(string: topTenTVStation[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon"))
            cell.tvStationName.text = topTenTVStation[indexPath.row].f_SchoolName
        }else if collectionView.tag == 2{
            cell.image.sd_setImage(with: URL(string: xxcellentSchool[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon"))
            cell.tvStationName.text = xxcellentSchool[indexPath.row].f_SchoolName
        }else if collectionView.tag == 3{
            cell.image.sd_setImage(with: URL(string: excellentTVStationProgram[indexPath.row].f_Img), placeholderImage: UIImage(named:"icon"))
            cell.tvStationName.text = excellentTVStationProgram[indexPath.row].f_Title
        }
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        switch collectionView.tag {
        case 1:
            return topTenTVStation.count
        case 2:
            return xxcellentSchool.count
        case 3:
            return excellentTVStationProgram.count
        default:
            return 0
        }
    }
    
}

class TVStationViewControllerTableViewCell:UITableViewCell{
    
    @IBOutlet weak var collectionView: UICollectionView!
}


class TVStationViewControllerCollectionCell:UICollectionViewCell{
    var index:Int!
    @IBOutlet weak var image: UIImageView!
    @IBOutlet weak var tvStationName: UILabel!
    
}

class TVStationInfor {
    var f_SchoolType:String!
    var f_Id:String! //标识字段,Guid标识 ,
    var f_DeleteMark:Bool = false //删除标识,1-已删除 ,
    var f_CreatorTime:String!//创建时间 ,
    var f_CreatorUserId:String!//创建人员ID ,
    var f_LastModifyTime:String! //最近一次编辑时间 ,
    var f_LastModifyUserId:String! //最近一次编辑人员 ,
    var f_DeleteTime:String! //删除时间 ,
    var f_DeleteUserId:String! //删除人员 ,
    var f_SchoolName:String! //学校名称 ,
    var f_SchoolTypeId:String!// 学校类型 ,
    var f_Logo:String! //校徽 ,
    var f_IsTopTen:Bool = false //是否十佳校园电视台 ,
    var f_IsExcellent:Bool = false //是否优秀校园电视台 ,
    var f_Url:String!// 机构地址
    
    init(json:JSON){
        f_SchoolType = json["f_SchoolType"].stringValue
        f_Id = json["f_Id"].stringValue
        f_DeleteMark = json["f_DeleteMark"].boolValue
        f_CreatorTime = json["f_CreatorTime"].stringValue
        f_CreatorUserId = json["f_CreatorUserId"].stringValue
        f_LastModifyTime = json["f_LastModifyTime"].stringValue
        f_LastModifyUserId = json["f_LastModifyUserId"].stringValue
        f_DeleteTime = json["f_DeleteTime"].stringValue
        f_DeleteUserId = json["f_DeleteUserId"].stringValue
        f_SchoolName = json["f_SchoolName"].stringValue
        f_SchoolTypeId = json["f_SchoolTypeId"].stringValue
        f_Logo = json["f_Logo"].stringValue
        f_IsTopTen = json["f_IsTopTen"].boolValue
        f_IsExcellent = json["f_IsExcellent"].boolValue
        f_Url = json["f_Url"].stringValue
    }
}

class TVStationSubject {
    var f_Url:String!// 机构地址
    
    var f_WaveTitle:String!
    var f_ChapterName:String!
    var f_TopicName:String!
    var f_TestName:String!
    var f_Id:String!// 标识字段,Guid标识 ,
    var f_DeleteMark:Bool = false // 删除标识,1-已删除 ,
    var f_CreatorTime:String!// 创建时间 ,
    var f_CreatorUserId:String!// 创建人员ID ,
    var f_LastModifyTime:String!// 最近一次编辑时间 ,
    var f_LastModifyUserId:String!//最近一次编辑人员 ,
    var f_DeleteTime:String!//删除时间 ,
    var f_DeleteUserId:String!// 删除人员 ,
    var f_Img :String!//课件图标/微课封面 ,
    var f_Title:String!//课件名称 ,
    var f_CreatorName:String!// 上传人员昵称 ,
    var f_Pv:Int!// 浏览量 ,
    var f_DownloadSum:Int!// 下载量 ,
    var f_LoveSum:Int!// 点赞量 ,
    var f_Price:Int!// 价格 ,
    var f_WaveId:String!// 所属教材ID ,
    var f_ChapterId:String!// 所属章节 ,
    var f_TopicId:String!//所属知识点 ,
    var f_TestId:String!//所属考点 ,
    var f_SchoolId:String!// 上传老师的学校ID ,
    var f_IsExamine:Int!// 审核状态:0-未审核,1-审核通过,2-审核不通过 ,
    var f_ExamineUserId :String!//审核人ID ,
    var f_ExamineName:String!//审核人姓名 ,
    var f_ExamineDatetime :String!// 审核日期 ,
    var f_ResourceType:Int!// 资源类型 0-微课 1-资源 2-电视台 ,
    var f_ResourceUrl:String!// 资源地址 ,
    var f_IsOpen:Bool = false // 是否公开 ,
    var f_Detail :String!// 资源简介 ,
    var f_TelevisionId :String!//电视台目录
    init(json:JSON){
        f_Url = json["f_Url"].stringValue
        f_WaveTitle = json["f_WaveTitle"].stringValue
        f_ChapterName = json["f_ChapterName"].stringValue
        f_TopicName = json["f_TopicName"].stringValue
        f_TestName = json["f_TestName"].stringValue
        f_Id = json["f_Id"].stringValue
        f_DeleteMark = json["f_DeleteMark"].boolValue
        f_CreatorTime = json["f_CreatorTime"].stringValue
        f_CreatorUserId = json["f_CreatorUserId"].stringValue
        f_LastModifyTime = json["f_LastModifyTime"].stringValue
        f_LastModifyUserId = json["f_LastModifyUserId"].stringValue
        f_DeleteTime = json["f_DeleteTime"].stringValue
        f_DeleteUserId = json["f_DeleteUserId"].stringValue
        f_Img = json["f_Img"].stringValue
        f_Title = json["f_Title"].stringValue
        f_CreatorName = json["f_CreatorName"].stringValue
        f_Pv = json["f_Pv"].intValue
        f_DownloadSum = json["f_DownloadSum"].intValue
        f_LoveSum = json["f_LoveSum"].intValue
        f_Price = json["f_Price"].intValue
        f_WaveId = json["f_WaveId"].stringValue
        f_ChapterId = json["f_ChapterId"].stringValue
        f_TopicId = json["f_TopicId"].stringValue
        f_TestId = json["f_TestId"].stringValue
        f_SchoolId = json["f_SchoolId"].stringValue
        f_IsExamine = json["f_IsExamine"].intValue
        f_ExamineUserId = json["f_ExamineUserId"].stringValue
        f_ExamineName = json["f_ExamineName"].stringValue
        f_ExamineDatetime = json["f_ExamineDatetime"].stringValue
        f_ResourceType = json["f_ResourceType"].intValue
        f_ResourceUrl = json["f_ResourceUrl"].stringValue
        f_IsOpen = json["f_IsOpen"].boolValue
        f_Detail = json["f_Detail"].stringValue
        f_TelevisionId = json["f_TelevisionId"].stringValue
        
    }
}