CNLiveShopClassilyManageTableViewCell.swift 3.25 KB
//
//  CNLiveShopClassilyManageTableViewCell.swift
//  metaCode
//
//  Created by zx on 2023/12/12.
// 二级分类cell

import Foundation

class CNLiveShopClassilyManageTableViewCell:UITableViewCell{
    
    ///点击编辑事件回调
    var editBtnBlock:editBtnActionBlock?
    /// 分类model
    var _classifyModel:CNLiveShopClassifyModel?
    var classifyModel:CNLiveShopClassifyModel?{
        get{
            _classifyModel
        }
        set{
            _classifyModel = newValue
            self.classifyNameBtn.setTitle(_classifyModel!.title, for: .normal)
            self.sortLab.text = _classifyModel!.ord
            if Int(_classifyModel!.state ?? "") == 2{
                self.showSwitch.isOn = true
            }else{
                self.showSwitch.isOn = false
            }
        }
    }
    ///分类名称
    lazy var classifyNameBtn: UIButton = {
        let  classifyNameBtn = UIButton(type: .custom)
        classifyNameBtn.frame = CGRect(x: 0, y: 0, width: KSreenWidth*0.3, height: 50)
        classifyNameBtn.setTitleColor(HexColor("#333333"), for: .normal)
        classifyNameBtn.titleLabel?.font = Font_14
        return classifyNameBtn
    }()
    ///排序名称
    lazy var sortLab: UILabel = {
        let sortLab = UILabel.init(frame: CGRectMake(self.classifyNameBtn.right, 0, KSreenWidth*0.2, 50))
        sortLab.text = "排序"
        sortLab.textColor = HexColor("#333333")
        sortLab.textAlignment = .center
        sortLab.font = Font_14
        sortLab.adjustsFontSizeToFitWidth=true
        return sortLab
    }()
    ///是否显示
    lazy var showSwitch :UISwitch = {
        let showSwitch = UISwitch(frame: CGRect(x: self.sortLab.right+10, y: 10, width: KSreenWidth*0.2, height: 50))
        showSwitch.isEnabled = false
        return showSwitch
    }()
    ///编辑
    lazy var editBtn: UIButton = {
        let  editBtn = UIButton(type: .custom)
        editBtn.frame = CGRect(x: self.showSwitch.right, y: 0, width: KSreenWidth*0.3, height: 50)
        editBtn.setTitle("编辑", for: .normal)
        editBtn.setTitleColor(HexColor("#0091FF"), for: .normal)
        editBtn.titleLabel?.font = Font_14
        editBtn.addTarget(self, action: #selector(editBtnAction), for: .touchUpInside)
        return editBtn
    }()
    /// 底部线
    lazy var bottomLine: UILabel = {
        let bottomLine = UILabel.init(frame: CGRectMake(0, 49, KSreenWidth, 1))
        bottomLine.backgroundColor = HexColor("#E4E4E4")
        return bottomLine
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - 初始化UI
    func initUI(){
        self.contentView.backgroundColor = HexColor("#F6F6F6")
        self.contentView.addSubview(self.classifyNameBtn)
        self.contentView.addSubview(self.sortLab)
        self.contentView.addSubview(self.showSwitch)
        self.contentView.addSubview(self.editBtn)
        self.contentView.addSubview(self.bottomLine)
    }
    
    // MARK: - response method
    /// 编辑
    @objc func editBtnAction(){
        self.editBtnBlock!(self.classifyModel!)
    }    
}