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

import UIKit

class MineHeadTableViewCell: BaseTableViewCell {

    var nameLabel:UILabel!
    var companyLabel:UILabel!
    var xinfo:MineHeadTableViewCellModel!
    var block:selectBlock!
    
    lazy var headImageView: UIImageView = {
        let headImageView = UIImageView.init(frame: CGRect(x:15*WHIDTH_RATIO(), y:69*HEIGHT_RATIO()+STATUBAR_HEIGHT()-20, width:58*HEIGHT_RATIO() , height:58*HEIGHT_RATIO() ))
        headImageView.image = UIImage.init(named: "touxiang_image")
        //设置遮罩
        headImageView.layer.masksToBounds = true
        //设置圆角半径(宽度的一半)，显示成圆形。
        headImageView.layer.cornerRadius = headImageView.width/2
        self .addSubview(headImageView)
        return headImageView
    }()
    lazy var mineCellImageView: UIImageView = {
        let mineCellImageView = UIImageView.init()
        mineCellImageView.image = UIImage.init(named: "mine_cell")
        mineCellImageView.contentMode = .scaleAspectFit
//        mineCellImageView.backgroundColor = UIColor.yellow
        self .addSubview(mineCellImageView)
        return mineCellImageView
    }()
    lazy var bottomOcclusionImageView: UIImageView = {
        let bottomOcclusionImageView = UIImageView.init()
        bottomOcclusionImageView.image = UIImage.init(named: "bottomOcclusion_image")
        bottomOcclusionImageView.contentMode = .scaleToFill
        self .addSubview(bottomOcclusionImageView)
        return bottomOcclusionImageView
    }()
//    lazy var ribbonView:UIImageView = {
//        let ribbonView = UIImageView.init()
//        ribbonView.image = UIImage.init(named: "ribbon_image")
//        ribbonView.contentMode = .scaleToFill
//        ribbonView.isUserInteractionEnabled = true
//        self .addSubview(ribbonView)
//        return ribbonView
//    }()
    lazy var ribbonView:RibbonView = {
        let ribbonView = RibbonView.init(frame: CGRect(x:0, y:self.height-117, width:SCREEN_WHIDTH() , height:117))
        ribbonView.isUserInteractionEnabled = true
        self .addSubview(ribbonView)
        return ribbonView
    }()
    lazy var actionBtn : UIButton = {
        let actionBtn = UIButton.init(type: .custom)
        actionBtn.addTarget(self, action: #selector(actionBtnAction), for: .touchUpInside)
//        actionBtn.backgroundColor = UIColor.red
        self.addSubview(actionBtn)
        return actionBtn
    }()
    func initNameLabel() {

//        headImageView.frame = CGRect(x:15*WHIDTH_RATIO(), y:(self.height-117)-80, width:58*HEIGHT_RATIO() , height:58*HEIGHT_RATIO() )
        nameLabel.frame = CGRect(x:headImageView.originX+headImageView.width+15*WHIDTH_RATIO(), y:headImageView.originY+2, width:SCREEN_WHIDTH()-headImageView.originX+headImageView.width+20*WHIDTH_RATIO() , height:16 )
//        let departementLabelH = getTextHeigh(textStr: xinfo.departementStr!, font: UIFont.test_systemFont(ofSize: 13.33), width: SCREEN_WHIDTH()-headImageView.originX-headImageView.width-50*WHIDTH_RATIO())
        
        departementLabel.frame = CGRect(x:nameLabel.originX, y:nameLabel.originY+nameLabel.height+5, width:SCREEN_WHIDTH()-headImageView.originX-headImageView.width-50*WHIDTH_RATIO() , height:15)
        
        let companyLabellH = getTextHeigh(textStr: xinfo.companyStr!, font: UIFont.test_systemFont(ofSize: 13.33), width: SCREEN_WHIDTH()-headImageView.originX+headImageView.width+20*WHIDTH_RATIO())
        
        companyLabel.frame = CGRect(x:departementLabel.originX, y:departementLabel.originY+departementLabel.height+5, width:SCREEN_WHIDTH()-headImageView.originX+headImageView.width+20*WHIDTH_RATIO() , height:companyLabellH )
        
        mineCellImageView.frame = CGRect(x:SCREEN_WHIDTH()-30*WHIDTH_RATIO(), y:departementLabel.originY+5*WHIDTH_RATIO()+nameLabel.height, width:10*WHIDTH_RATIO() , height:15*HEIGHT_RATIO() )
        mineCellImageView.centerY = headImageView.centerY
        
        bottomOcclusionImageView.frame = CGRect(x:0, y:self.height-61.66, width:SCREEN_WHIDTH() , height:61.66)
//        ribbonView.frame = CGRect(x:0, y:self.height-117, width:SCREEN_WHIDTH() , height:117)
        
        
        actionBtn.frame = CGRect(x:0, y:0, width:SCREEN_WHIDTH() , height:ribbonView.originY)
    }
    
    func getUILabel() -> UILabel {
        let label = UILabel.init()
//        label.font = UIFont.systemFont(ofSize: 16)
        label.textAlignment = .left
        label.font = UIFont.test_systemFont(ofSize: 13.33)
        label.numberOfLines = 0
        label.backgroundColor = UIColor.clear
        label.lineBreakMode = .byCharWrapping
        label.textColor = UIColor.white
        self .addSubview(label)
        return label
    }
    lazy var departementLabel: UILabel = {
        let departementLabel = UILabel.init()
        departementLabel.textAlignment = .left
        departementLabel.font = UIFont.test_systemFont(ofSize: 13.33)
        departementLabel.numberOfLines = 0
//        departementLabel.backgroundColor = UIColor.clear
//        departementLabel.lineBreakMode = .byCharWrapping
        departementLabel.textColor = UIColor.white
//        departementLabel.backgroundColor = UIColor.red
        return departementLabel
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
        self.backgroundColor = UIColor.clear
        self.selectionStyle = .none
        nameLabel = self.getUILabel()
        //departementLabel = self.getUILabel()
        self.addSubview(departementLabel)
        companyLabel = self.getUILabel()
    }
    override func configurateTheCell(_ info: BaseCellModel) {
        xinfo = info as? MineHeadTableViewCellModel
        self.block = xinfo.block
        initNameLabel()
        nameLabel.text = xinfo.nameStr
        companyLabel.text = xinfo.companyStr!
        departementLabel.text = xinfo.departementStr!
        if AccountInfo.sharedInstance().weChatInfo_headimgurl == nil || AccountInfo.sharedInstance().weChatInfo_headimgurl == "" {
            headImageView.image = UIImage.init(named: "touxiang_image")
        } else {
            headImageView.sd_setImage(with: URL.init(string: AccountInfo.sharedInstance().weChatInfo_headimgurl!), placeholderImage: UIImage.init(named: "touxiang_image"))
        }
        addRibbonItemView()
    }
//    override func setSelected(_ selected: Bool, animated: Bool) {
//        super.setSelected(selected, animated: animated)
//        if selected {
////            self.block()
//        }
//    }
    @objc func actionBtnAction(){
        if (self.block != nil) {
            self.block()
        }
    }

}
class MineHeadTableViewCellModel: BaseCellModel {
    var nameStr:String?
    var companyStr:String?
    var departementStr:String?
    var headImageUrl:String?
    var block:selectBlock!
    var ribbonItemModelArry = NSMutableArray()
    
}
class MineHeadTableViewCellRibbonModel: BaseCellModel {
    var titleStr:String?
    var imageName:String?
    var biaojiNum:String?
    var quickApplicationType:QuickApplicationType = .AddressBook
    var block:selectBlock!
}
