123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- //
- // RedemptionAreaViewController.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/7/16.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import SwiftyMediator
- import Kingfisher
- class RedemptionAreaViewController: BaseViewController {
-
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- //KingfisherManager.shared.cache.clearDiskCache()
- KingfisherManager.shared.cache.clearMemoryCache()
- }
-
- deinit {
- NXLLog("deinit")
- if observe != nil {
- NotificationCenter.default.removeObserver(observe!)
- }
- }
- weak var observe : NSObjectProtocol?
- var cmsRedemptionAreaModel : CMSRedemptionAreaModel?
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setupViews()
- setupLayouts()
- setupData()
- }
-
- override func setupViews() {
- navigationBar.title = "积分商城"
- view.addSubview(tableView)
- view.insertSubview(navigationBar, aboveSubview: tableView)
- }
-
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect(x: 0, y: kNavBarTotalHeight, width: kScreenWidth, height: kScreenHeight - kNavBarTotalHeight), style: UITableView.Style.grouped)
- tableView.separatorStyle = .none
- tableView.backgroundColor = UIColor.white
- tableView.dataSource = self
- tableView.delegate = self
- return tableView
- }()
-
-
- override func setupData() {
- tableView.addHeader(withBeginRefresh: true, animation: true) {
- [weak self] (page) in
- self?.cmsTemplateExchangeApi()
- }
- navigationBar.onClickRightButton = {
- Mediator.push(H5RouterModuleType.pushCategory)
- }
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("RedemptionAreaModuleTop"), object: nil, queue: OperationQueue.main, using: {
- [weak self] (notification) in
- if self?.tableView.contentOffset == CGPoint(x: 0, y: 0) {
- self?.tableView.mj_header.beginRefreshing()
- }else {
- self?.tableView.scrollToTop()
- }
- })
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("login"), object: nil, queue: OperationQueue.main, using: {
- [weak self] (notification) in
- self?.tableView.mj_header.beginRefreshing()
- })
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("loginOut"), object: nil, queue: OperationQueue.main, using: {
- [weak self] (notification) in
- self?.tableView.mj_header.beginRefreshing()
- })
-
- }
-
- }
- extension RedemptionAreaViewController {
-
- /// 加载cms
- func cmsTemplateExchangeApi() {
- SwiftMoyaNetWorkServiceCMS.shared().cmsTemplateExchangeApi(completion: {
- [weak self] (cmsRedemptionAreaModel) -> (Void) in
- DIYEmptyView.emptyNoDataTableView(tableView: self?.tableView)
- self?.cmsRedemptionAreaModel = cmsRedemptionAreaModel as? CMSRedemptionAreaModel
- self?.navigationBar.wr_setRightButton(image: kImage(name: "navbar_class_black")!)
- self?.navigationBar.rightButton.isHidden = false
- self?.navigationBar.title = self?.cmsRedemptionAreaModel?.title
- self?.tableView.reloadData()
- MJRefreshManager.mjRefreshManager(tableView: self?.tableView)
- }) {
- [weak self] loadingStatus in
- MJRefreshManager.mjRefreshManagerLoadingStatus(tableView: self?.tableView,loadingStatus: loadingStatus)
-
- }
- }
-
- }
- extension RedemptionAreaViewController : UITableViewDelegate, UITableViewDataSource {
- func numberOfSections(in tableView: UITableView) -> Int {
- return self.cmsRedemptionAreaModel?.content?.isEmpty ?? true ? 0 : (self.cmsRedemptionAreaModel?.content?.count)!
- }
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.cmsRedemptionAreaModel?.content?[section].rule?.isEmpty ?? true ? 0 : 1
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-
- let cmsRedemptionAreaContent = self.cmsRedemptionAreaModel?.content?[indexPath.section]
-
- switch cmsRedemptionAreaContent?.cmsRedemptionAreaContentType {
- case .banner?:
- let cell = RedemptionAreaBannerTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.cmsRedemptionAreaContent = cmsRedemptionAreaContent
- return cell
- case .specialOne?:
- let cell = RedemptionAreaSpecialOneTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.cmsRedemptionAreaContent = cmsRedemptionAreaContent
- return cell
- case .specialTwo?:
- let cell = RedemptionAreaSpecialTwoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.cmsRedemptionAreaContent = cmsRedemptionAreaContent
- return cell
- case .floor?:
- let cell = RedemptionAreaFloorTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.cmsRedemptionAreaContent = cmsRedemptionAreaContent
- return cell
- default:
- return UITableViewCell()
- }
-
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- let cmsRedemptionAreaContent = self.cmsRedemptionAreaModel?.content?[indexPath.section]
- switch cmsRedemptionAreaContent?.cmsRedemptionAreaContentType {
- case .banner?:
- if UserModel.isTokenNil() {
- return (150 * kScaleWidth)
- }else {
- if cmsRedemptionAreaContent?.rule?.isEmpty ?? true {
- return 105
- }else {
- return (150 * kScaleWidth) + 105
- }
- }
- case .specialOne?:
- if cmsRedemptionAreaContent?.rule?.isEmpty ?? true {
- return 0
- }else {
- return (193 * kScaleWidth) + 30
- }
- case .specialTwo?:
- if cmsRedemptionAreaContent?.rule?.isEmpty ?? true {
- return 0
- }else {
- return (275 * kScaleWidth) + 30
- }
- case .floor?:
- if cmsRedemptionAreaContent?.rule?.isEmpty ?? true {
- return 0
- }else {
- let count = Int((cmsRedemptionAreaContent?.rule?.count ?? 0) / 2)
- if ((cmsRedemptionAreaContent?.rule?.count ?? 0) % 2) == 0 {
- return CGFloat(CGFloat(count) * ((kScreenWidth-15)/2 + 116.0)) + CGFloat(5 * CGFloat(count))
- }else {
- return CGFloat(CGFloat(count) * ((kScreenWidth-15)/2 + 116.0)) + CGFloat((kScreenWidth-15)/2 + 116.0) + CGFloat(5 * (CGFloat(count) + 1))
- }
- }
- default:
- return 0
- }
-
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- let cmsRedemptionAreaContent = self.cmsRedemptionAreaModel?.content?[section]
- switch cmsRedemptionAreaContent?.cmsRedemptionAreaContentType {
- case .banner?:
- return 0.000001
- default:
- if cmsRedemptionAreaContent?.floorImg != nil && cmsRedemptionAreaContent?.floorImg != "" {
- return 88*kScaleWidth
- }else {
- return 0.000001
- }
- }
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- let cmsRedemptionAreaContent = self.cmsRedemptionAreaModel?.content?[section]
- switch cmsRedemptionAreaContent?.cmsRedemptionAreaContentType {
- case .banner?:
- return nil
- default:
- if cmsRedemptionAreaContent?.floorImg != nil && cmsRedemptionAreaContent?.floorImg != "" {
- let headerView = FloorHeaderViewFloorHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 88*kScaleWidth))
- headerView.cmsRedemptionAreaContent = cmsRedemptionAreaContent
- return headerView
- }else {
- return nil
- }
-
- }
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- if self.cmsRedemptionAreaModel?.content?.isEmpty ?? true {
- return 0.000001
- }else {
- return 10
- }
- }
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
-
- if self.cmsRedemptionAreaModel?.content?.isEmpty ?? true {
- return nil
- }else {
- if section == (self.cmsRedemptionAreaModel?.content?.count ?? 1) - 1 {
- return nil
- }else {
- let view = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 10))
- view.backgroundColor = kf7f8faColor
- return view
- }
- }
-
- }
-
- }
|