//
//  HomeMoreViewController+initCollectionView.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/3/21.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

extension HomeMoreViewController {

    func initCollectionView(){
        cellNum = 4
        btnViewWidth = (SCREEN_WHIDTH()-10)/CGFloat(cellNum)
        btnViewHeight = btnViewWidth*0.8
        //btnViewWidth = 85*WHIDTH_RATIO()
        //btnViewHeight = 70*WHIDTH_RATIO()
        self.dataSource = NSMutableArray()
        //self.dataSource = xinfo.detaileArray
        //initData()
        delegate.dataSource = self.dataSource
        self.view.addSubview(collectionView)
        collectionView.snp.makeConstraints { (make) in
            make.width.height.equalToSuperview()
            make.center.equalToSuperview()
        }
        collectionView.delegate = self.delegate
        collectionView.dataSource = self.delegate
    }

}
class HomeMoreViewControllerDelegate: NSObject ,UICollectionViewDelegate,UICollectionViewDataSource{
    var dataSource:NSMutableArray!
    var updateBlock:passParameterBlock!
    //MARK: - 代理方法
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        
        return self.dataSource.count
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        let arr:NSMutableArray = self.dataSource[section] as! NSMutableArray
        return arr.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomeMoreCollectionViewCell", for: indexPath) as! HomeMoreCollectionViewCell
        let arr:NSMutableArray = self.dataSource[indexPath.section] as! NSMutableArray
        let info:BaseCollectionViewCellModel = arr[indexPath.row] as! BaseCollectionViewCellModel
        cell.configurateTheCell(info: info)
        //print(cell.modelHttp.titleValue,cell.indexPath.section,cell.indexPath.row)
        //info.indexPath = indexPath
        return cell
    }
    
    //是否可以移动
    func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
        return true
    }
}
