//
//  UpcomingCollectionViewCell.swift
//  MobilePortal
//
//  Created by caiyang on 2020/4/22.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

class UpcomingCollectionViewCell: BaseCollectionViewCell {
    var block:passParameterBlock!
    var modelHttp = UpcomingCollectionViewCellModel()
    var text :String!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        //        self.backgroundColor = UIColor.yellow
//        self .addSubview(bagView)
        self .addSubview(titleImage)
        self .addSubview(titleLable)
        self .addSubview(bagBtn)
        self .addSubview(baojiBtn)
    }
    lazy var bagView: UIImageView = {
        let bagView = UIImageView.init()
        //        bagView.backgroundColor = moreClassColor
        //        bagView.backgroundColor = UIColor.red
        bagView.isHidden = true
        return bagView
    }()
    override func configurateTheCell(info:BaseCollectionViewCellModel){
        
        self.modelHttp = info as! UpcomingCollectionViewCellModel
        self.block = self.modelHttp.block
        bagBtn.frame = CGRect(x:0, y: 0, width:self.width , height:self.height)
        //        let titleImageW = self.width-73*WHIDTH_RATIO()
        let titleImageW = 33.33*WHIDTH_RATIO()
        titleImage.frame = CGRect(x:(self.width-titleImageW)/2, y: 10*WHIDTH_RATIO(), width:titleImageW , height:titleImageW )
        
        let titleLableH = getTextHeigh(textStr: judgmentStrNil(str: modelHttp.titleValue!), font: UIFont.test_systemFont(ofSize: 12), width: self.width-10*WHIDTH_RATIO())
        titleLable.frame = CGRect(x:5*WHIDTH_RATIO(), y: titleImage.originY+titleImage.height+5*HEIGHT_RATIO(), width:self.width-10*WHIDTH_RATIO() , height:titleLableH )
        
        if modelHttp.imageName == "more_image" {
            titleImage.image = UIImage.init(named: "more_image")
        }else{
            titleImage.sd_setImage(with: URL.init(string: modelHttp.imageName!), placeholderImage: UIImage.init(named: "center_image"))
        }
        titleLable.text = modelHttp.titleValue
        let baojiBtnWidth:CGFloat = 21*WHIDTH_RATIO()
        baojiBtn.frame = CGRect(x:self.titleImage.originX+self.titleImage.width-10, y: self.titleImage.originY/2, width:baojiBtnWidth , height:baojiBtnWidth)
        if self.modelHttp.biaojiNum == nil || self.modelHttp.biaojiNum?.count == 0 || self.modelHttp.biaojiNum == "0"{
            baojiBtn.isHidden = true
        }else{
            baojiBtn.isHidden = false
            baojiBtn.setTitle(self.modelHttp.biaojiNum, for: .normal)
        }
    }
    
    lazy var titleImage: UIImageView = {
        let titleImage = UIImageView.init()
        titleImage.contentMode = .scaleAspectFit
        //titleImage.clipsToBounds = true
        return titleImage
    }()
    
    lazy var titleLable: UILabel = {
        let titleLable = UILabel.init()
        titleLable.textAlignment = .center
        titleLable.font = UIFont.test_systemFont(ofSize: 11.33)
        titleLable.numberOfLines = 0
//        titleLable.backgroundColor = UIColor.yellow
        titleLable.lineBreakMode = .byCharWrapping
        titleLable.textColor = UIColorFromRGB(rgbValue: 0x23262A)
        return titleLable
    }()
    
    lazy var bagBtn: UIButton = {
        let bagBtn = UIButton.init(type: .custom)
        bagBtn.alpha = 0.1
        bagBtn.backgroundColor = UIColor.clear
        bagBtn.addTarget(self, action: #selector(actions), for: .touchUpInside)
        return bagBtn
    }()
    lazy var baojiBtn: UIButton = {
        let baojiBtn = UIButton.init(type: .custom)
        baojiBtn.setTitleColor(UIColor.white, for: .normal)
        baojiBtn.titleLabel?.font = UIFont.test_systemFont(ofSize: 10)
        baojiBtn.setBackgroundImage(UIImage.init(named: "biaoji_image"), for: .normal)
        baojiBtn.isHidden = true
        return baojiBtn
    }()
    @objc func actions() {
        //if self.modelHttp.url != nil && self.modelHttp.url?.characters.count != 0 {
        self.block(self.modelHttp.comments as AnyObject)
        //}
    }
}
class UpcomingCollectionViewCellModel: BaseCollectionViewCellModel {
    var titleValue:String?
    var imageName:String?
    var block:passParameterBlock!
    var biaojiNum:String?
    //var url:String?
    var comments:String?
    var openUrl:String?
    var key:String?
    var type:String?
    
}
