CNLiveHelpFeedBackViewController.swift 3.2 KB
//
//  CNLiveHelpFeedBackViewController.swift
//  metaCode
//
//  Created by open on 2023/6/7.
//

import Foundation


class CNLiveHelpFeedBackViewController : CNLiveBaseViewController, UICollectionViewDelegate, UICollectionViewDataSource {
    
    let kCNLiveHelpFeedBackViewCellKey = "kCNLiveHelpFeedBackViewCellKey"
    
    lazy var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout.init()
        layout.itemSize = CGSize(width: (KSreenWidth - 45)/2, height: 60)
        layout.sectionInset = .init(top: 5, left: 15, bottom: 5, right: 15)
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = .clear
        collectionView.register(MineFeedBackListCollectViewCell.self, forCellWithReuseIdentifier: kCNLiveHelpFeedBackViewCellKey)
        return collectionView
    }()
    
    lazy var dataArray: NSMutableArray = {
        let dataArray = NSMutableArray()
        dataArray.add(["image":"mine_add_feed_back_list","name":"反馈"])
        dataArray.add(["image":"mine_add_custom_service_list","name":"客服"])
        return dataArray
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        navigationBarHidden = false
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        titleName = "帮助与反馈"
        
        view.addSubview(collectionView)
        collectionView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(KNavigationHeight)
            make.left.bottom.right.equalToSuperview()
        }
    }
}

extension CNLiveHelpFeedBackViewController {
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataArray.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let item = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveHelpFeedBackViewCellKey, for: indexPath) as! MineFeedBackListCollectViewCell
        let dict = dataArray[indexPath.row] as! Dictionary<String, Any>
        item.setupWithDataSource(dict: dict)
        return item
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        return CGSize.init(width: KSreenWidth, height: 20)
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if indexPath.row == 0 {
            self.navigationController?.pushViewController(CNLiveTypeFeedBackViewController.init(show_type: .feedback), animated: true)
        }
        if indexPath.row == 1 {
            AlertTool.systemActionSheet(title: nil, message: nil, actionTitles: ["呼叫 010-65832485"]) { index in
                if index == 1 {
                    let url: NSURL = NSURL(string: "TEL://010-65832485")!
                    UIApplication.shared.open(url as URL)
                }
            }
        }
    }
    
}