CNLiveShopDetailBtnsCell.swift 2.76 KB
//
//  CNLiveShopDetailBtnsCell.swift
//  metaCode
//
//  Created by zx on 2023/11/3.
//

import Foundation

class CNLiveShopDetailBtnsCell: UICollectionViewCell {
    
    //shopDetailModel
    var _shopDetailModel : CNLiveShopDetailModel?
    var shopDetailModel : CNLiveShopDetailModel? {
        get{
            _shopDetailModel
        }
        set{
            _shopDetailModel = newValue!
               
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
        self.setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI(){
        self.backgroundColor = .white
        var titlesArr:Array<String> = []
        if DSUserInfoManager.shared.dsUserInfo.type != "3" {
            titlesArr = ["发布动态", "商品管理", "订单管理", "交易记录"]
        }else{
            //健康餐桌 不处理
        }
        //替换icon
        let icons = ["ds_Up_Btn", "ds_Up_Btn", "ds_Up_Btn", "ds_Up_Btn"]
        if titlesArr.count > 0 {
            for i in 0..<titlesArr.count {
                let titleStr = titlesArr[i]
                let iconStr = icons[i]
                //icon
                let imgWH = 45
                let imgGap = (Int(KSreenWidth)-4*imgWH)/5
                
                let iconBtn = UIButton(type: .custom)
                iconBtn.frame = CGRect(x: imgGap*(i+1)+imgWH*i, y: 10, width: imgWH, height: imgWH)
                iconBtn.setBackgroundImage(UIImage(named: iconStr), for: .normal)
                iconBtn.addTarget(self, action: #selector(iconBtnAction(_:)), for: .touchUpInside)
                iconBtn.tag = i+100
                iconBtn.layer.cornerRadius = 11.5
                self.contentView.addSubview(iconBtn)
                
                let titleLbl = UILabel(frame: CGRect(x: iconBtn.left-5, y: iconBtn.bottom+5, width: iconBtn.width+10, height: 17))
                titleLbl.text = titleStr
                titleLbl.textAlignment = .center
                titleLbl.font = Font_12
                titleLbl.textColor = HexColor("#4A4A4A")
                self.contentView.addSubview(titleLbl)
            }
        }
    }
    
    @objc func iconBtnAction(_ sender: UIButton){
        let tag = sender.tag
        ///push VC
        if tag == 100 {
            //发布动态
        }else if tag == 101 {
            //商品管理
            let webVC = CNWebViewController()
            webVC.url = URL(string:"https://www.baidu.com")
            currentViewController()?.navigationController?.pushViewController(webVC, animated: true)

        }else if tag == 102 {
            //订单管理
        }else if tag == 103 {
            //交易记录
        }
        
    }
}