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

import UIKit

class DialogueRightTableViewCell: BaseTableViewCell {

    var xinfo = DialogueRightTableViewCellModel()
    
    lazy var headImageView: UIImageView = {
        let headImageView = UIImageView.init()
        //subImageView.contentMode = .scaleToFill
        headImageView.contentMode = .scaleAspectFill
        //        subImageView.backgroundColor = UIColor.yellow
        headImageView.image = UIImage.init(named: "touxiang_image")
        
        return headImageView
    }()
    lazy var webLabel: UILabel = {
        let webLabel = UILabel.init()
        webLabel.textAlignment = .right
        webLabel.numberOfLines = 0
        webLabel.font = UIFont.test_systemFont(ofSize: 13.33)
        webLabel.textColor = UIColorFromRGB(rgbValue: 0x3D444F)
//        webLabel.backgroundColor = UIColor.yellow
        return webLabel
    }()
    lazy var bagImageView: UIImageView = {
        let bagImageView = UIImageView.init()
//        bagImageView.backgroundColor = UIColor.red
        return bagImageView
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
        self.separatorInset=UIEdgeInsetsMake(0, SCREEN_WHIDTH(), 0, 0)
        let insets = UIEdgeInsets.init(top: 12, left: 12, bottom: 10, right: 10)
        var aaimage = UIImage.init(named: "rightBag_image")
        aaimage = aaimage?.resizableImage(withCapInsets: insets, resizingMode: UIImageResizingMode.stretch)
        bagImageView.image = aaimage
        self.backgroundColor = UIColorFromRGB(rgbValue: 0xE9F2F8)
        self.addSubview(headImageView)
        self.addSubview(bagImageView)
        self.addSubview(webLabel)
        // Initialization code
    }
    override func configurateTheCell(_ info: BaseCellModel) {
        xinfo = info as! DialogueRightTableViewCellModel
        headImageView.frame = CGRect(x:SCREEN_WHIDTH()-71, y: 20.67, width:57.33 , height:57.33 )
        let webLabelW = SCREEN_WHIDTH()-(headImageView.width+13.67+67+24.67)
        let webLabelH = getTextHeigh(textStr: self.xinfo.titleStr!, font: UIFont.test_systemFont(ofSize: 13.33), width: webLabelW)
        
        webLabel.frame = CGRect(x:67, y: headImageView.originY+24, width:webLabelW , height:webLabelH )
        webLabel.text = xinfo.titleStr
        
        var bagImageViewW = getTexWidth(textStr: xinfo.titleStr!, font: UIFont.test_systemFont(ofSize: 14), height: webLabel.height)+26
        if (bagImageViewW >= webLabelW) {
            bagImageViewW = webLabelW+26
        }
        bagImageView.frame = CGRect(x:SCREEN_WHIDTH()-bagImageViewW-headImageView.width-27, y: webLabel.originY-13, width: bagImageViewW, height:webLabel.height+26 )
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }

}
class DialogueRightTableViewCellModel: BaseCellModel {
    var titleStr:String?
    var content:String?
    var cellH:CGFloat?
    var block:selectBlock!
}
