//
//  ServiceCollectionViewCell.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/3/20.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

class ServiceCollectionViewCell: BaseCollectionViewCell {
    var block:passParameterBlock!
    var modelHttp = ServiceCollectionViewCellModel()
    var text :String!
    var indexPath: IndexPath!
    
    
    lazy var titleImage: UIImageView = {
        let titleImage = UIImageView.init()
        titleImage.contentMode = .scaleAspectFill
        titleImage.backgroundColor = UIColor.clear
        return titleImage
    }()
    
    
    lazy var titleLable: UILabel = {
        let titleLable = UILabel.init()
        titleLable.textAlignment = .center
        titleLable.font = UIFont.systemFont(ofSize: 17*WHIDTH_RATIO())
        titleLable.numberOfLines = 0
        //titleLable.backgroundColor = UIColor.red
        //titleLable.lineBreakMode = .byCharWrapping
        titleLable.textColor = UIColor.white
        return titleLable
    }()
    lazy var bagView: UIImageView = {
        let bagView = UIImageView.init()
        bagView.backgroundColor = moreClassColor
        bagView.contentMode = .scaleAspectFill
        bagView.backgroundColor = UIColor.clear
        return bagView
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
        self.backgroundColor = UIColor.white
        self .addSubview(bagView)
        //self .addSubview(titleImage)
        self .addSubview(titleLable)
        //self .addSubview(operatingView)
    }
    override func configurateTheCell(info:BaseCollectionViewCellModel){
        
        self.modelHttp = info as! ServiceCollectionViewCellModel
        self.block = self.modelHttp.block
        bagView.frame = CGRect(x:0, y: 0, width:self.width , height:self.width )
        titleLable.frame = CGRect(x:0, y: self.height-40*HEIGHT_RATIO(), width:self.width , height:getTextHeigh(textStr: modelHttp.titleValue!, font: UIFont.systemFont(ofSize: 14), width: self.width) )
        titleLable.text = modelHttp.titleValue
        // bagView.addTarget(self, action: #selector(btnAction), for: .touchUpInside)
        bagView.sd_setImage(with: URL(string: modelHttp.imageName!), placeholderImage: UIImage.init(named: "center_image"), completed: { (image, error, SDImageCacheTypeNone, url) in
            if error != nil {
                print(error ?? Error.self)
            }
        })
        
    }
    func operatingAction(){
        //self.block(self)
    }
    func btnAction() {
        if self.modelHttp.url != nil && self.modelHttp.url?.count != 0 {
            self.block(self.modelHttp.titleValue as AnyObject)
        }
    }
}
class ServiceCollectionViewCellModel: BaseCollectionViewCellModel {
    var titleValue:String?
    var imageName:String?
    var block:passParameterBlock!
    var url:String?
    var id:String?
    var value1:String?
}
