// // UnderLineTrainViewController.swift // xingchuangke // // Created by Virgil on 2019/5/13. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class UnderLineTrainViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var tableView: UITableView! @IBOutlet weak var viewMenu: UIView! var currentType = 0 override func viewDidLoad() { super.viewDidLoad() self.title = "线下培训" initNavLeftBackButton() tableView.register(UINib(nibName: "UnderLineTrainTableViewCell", bundle: nil), forCellReuseIdentifier: "UnderLineTrainTableViewCell") tableView.delegate = self tableView.dataSource = self tableView.separatorStyle = .none tableView.showsVerticalScrollIndicator = false tableView.estimatedRowHeight = 100 tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in self!.currentPage = 1 self!.loadData() }) tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell" tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in self!.currentPage += 1 self!.loadData() }) } let arrType = NSMutableArray() func loadType() { if arrType.count > 0 { returnData(tag: 1001) return } let url = RequestURL.studyTypeList let params = NSMutableDictionary() params.setValue(1, forKey: "type") loadDataList(url: url, params: params, tag: 1001, array: arrType) } func loadData() { let url = RequestURL.trainingList let params = NSMutableDictionary() params.setValue(arrType.getString(index: currentType, key: "id"), forKey: "typeId") loadDataList(url: url, params: params, tableView: tableView, tag: 1002) } override func returnData(tag: Int) { if tag == 1001 { if arrType.count < 1 { SVProgressHUD.showError(withStatus: "培训分类获取失败,请联系客服!") return } var arrTitle = [String]() for dic in self.arrType { arrTitle.append((dic as! NSDictionary).getString(key: "name")) } let segment = Virgil_SegmentView(frame: CGRect(x: 0, y: 3, width: ScreenWidth, height: 45), titles: arrTitle, defaultColor: CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0), currentColor: CommonUntils.getUIColorFromRGB(rgbValue: 0x2094f5, alpha: 1.0), lineHeight: 2, lineIsBottom: true) { [weak self](index) in self!.currentType = index self!.tableView.mj_header?.beginRefreshing() } self.viewMenu.removeAll() self.viewMenu.addSubview(segment) self.tableView.mj_header?.beginRefreshing() } else if tag == 1002 { tableView.reloadData() } } override func returnError(tag: Int, type: String) { } // MARK: TABLEVLEW 实现 // MARK: TABLEVLEW 实现 func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.arrData.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "UnderLineTrainTableViewCell", for: indexPath as IndexPath) as! UnderLineTrainTableViewCell cell.initCell(dic: self.arrData[indexPath.row] as! NSDictionary) return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row >= arrData.count { return } let vc = CommonWebViewViewController() vc.strTitle = "培训详情" vc.url = getString(current: indexPath.row, key: "webUrl") toViewController(viewController: vc) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) loadType() } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "UnderLineTrainViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }