CNLiveShopBodyExpressView.swift 7.51 KB
//
//  CNLiveShopBodyExpressView.swift
//  metaCode
//
//  Created by open on 2023/11/8.
//

import Foundation

class ShopBodyOrderExpressListTableViewCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate{
    
    lazy var logoImageView: UIImageView = {
        let logoImageView = UIImageView.init()
        logoImageView.backgroundColor = .white
        return logoImageView
    }()
    
    lazy var expressName: UILabel = {
        let expressName = UILabel.init()
        expressName.textColor = HexColor("#333333")
        expressName.font = medium_font(pointSize: 14)
        return expressName
    }()
    
    lazy var expressNo: UILabel = {
        let expressNo = UILabel.init()
        expressNo.textColor = HexColor("#b4b4b4")
        expressNo.font = regular_font(pointSize: 12)
        return expressNo
    }()
    
    lazy var expressCopy: UIButton = {
        let expressCopy = UIButton.init(type: .custom)
        expressCopy.backgroundColor = .white
        expressCopy.setTitle("复制单号", for: .normal)
        expressCopy.layer.cornerRadius = 4
        expressCopy.titleLabel?.font = medium_font(pointSize: 14)
        expressCopy.setTitleColor(HexColor("#28c1c6"), for: .normal)
        expressCopy.contentHorizontalAlignment = .center
        expressCopy.layer.borderWidth = 1
        expressCopy.layer.borderColor = HexColor("#28c1c6")?.cgColor
        expressCopy.addTarget(self, action: #selector(actionClick), for: .touchUpInside)
        return expressCopy
    }()
    
    lazy var expressTime: UILabel = {
        let expressTime = UILabel.init()
        expressTime.font = regular_font(pointSize: 12)
        expressTime.textColor = HexColor("#333333")
        return expressTime
    }()
    
    lazy var expressAddress: UILabel = {
        let expressAddress = UILabel.init()
        expressAddress.font = regular_font(pointSize: 12)
        expressAddress.textColor = HexColor("#333333")
        expressAddress.numberOfLines = 0
        return expressAddress
    }()
    
    let kShopBodyOrderExpressListCollectionViewCellIdentifier = "kShopBodyOrderExpressListCollectionViewCellIdentifier"
    lazy var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout.init()
        layout.itemSize = CGSizeMake(adapt_length(length: 65), adapt_length(length: 65))
        layout.minimumLineSpacing = adapt_length(length: 5)
        layout.scrollDirection = .horizontal
        let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
        collectionView.dataSource = self
        collectionView.delegate = self
        collectionView.backgroundColor = .white
        collectionView.register(ShopBodyOrderExpressListCollectionViewCell.self, forCellWithReuseIdentifier: kShopBodyOrderExpressListCollectionViewCellIdentifier)
        return collectionView
    }()
    
    lazy var totleExpress: UILabel = {
        let totleExpress = UILabel.init()
        totleExpress.textColor = HexColor("#9b9b9b")
        totleExpress.font = regular_adapt_font(pointSize: 12)
        return totleExpress
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .clear
        selectionStyle = .none
        
        addSubview(logoImageView)
        logoImageView.snp.makeConstraints { make in
            make.left.top.equalToSuperview().offset(adapt_length(length: 15))
            make.size.equalTo(adapt_length(length: 39.68))
        }
        addSubview(expressName)
        expressName.snp.makeConstraints { make in
            make.top.equalTo(logoImageView.snp.top).offset(adapt_length(length: 0.5))
            make.left.equalTo(logoImageView.snp.right).offset(adapt_length(length: 15))
        }
        addSubview(expressCopy)
        expressCopy.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(adapt_length(length: 20))
            make.right.equalToSuperview().offset(-adapt_length(length: 20))
            make.width.equalTo(adapt_length(length: 77))
            make.height.equalTo(adapt_length(length: 30))
        }
        addSubview(expressNo)
        expressNo.snp.makeConstraints { make in
            make.top.equalTo(expressName.snp.bottom).offset(adapt_length(length: 2.5))
            make.left.equalTo(expressName.snp.left)
            make.right.equalTo(expressCopy.snp.left).offset(adapt_length(length: 5))
        }
        addSubview(expressTime)
        expressTime.snp.makeConstraints { make in
            make.top.equalTo(logoImageView.snp.bottom).offset(adapt_length(length: 5))
            make.left.equalTo(logoImageView.snp.left)
        }
        addSubview(expressAddress)
        expressAddress.snp.makeConstraints { make in
            make.top.equalTo(expressTime.snp.bottom).offset(adapt_length(length: 2))
            make.left.equalTo(expressTime.snp.left)
            make.right.equalToSuperview().offset(-adapt_length(length: 15))
        }
        addSubview(collectionView)
        collectionView.snp.makeConstraints { make in
            make.top.equalTo(expressAddress.snp.bottom).offset(adapt_length(length: 15))
            make.left.equalToSuperview().offset(adapt_length(length: 15))
            make.right.equalToSuperview().offset(-adapt_length(length: 15))
            make.height.equalTo(adapt_length(length: 65))
        }
        addSubview(totleExpress)
        totleExpress.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(adapt_length(length: 15))
            make.bottom.equalToSuperview().offset(-adapt_length(length: 15))
        }
    }
    
    
    var _listModel: ShopOrderExpressListModel!
    func setupDataSource(listModel: ShopOrderExpressListModel) {
        _listModel = listModel
        
    }
    
    @objc func actionClick(sender: UIButton) {
        if !_listModel.express_num!.isNotBlank() {
            return
        }
        
        let pasteboard = UIPasteboard.general
        pasteboard.string = _listModel.express_num
        showMessage(message: "复制成功")
    }
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return _listModel.detail_goods.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        return UICollectionViewCell.init()
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

class ShopBodyOrderExpressListCollectionViewCell: UICollectionViewCell {
    
    lazy var goodsImage: UIImageView = {
        let goodsImage = UIImageView.init()
        goodsImage.contentMode = .scaleAspectFill
        goodsImage.layer.cornerRadius = 6
        return goodsImage
    }()
    
    lazy var expressNum: UILabel = {
        let expressNum = UILabel.init()
        expressNum.font = regular_adapt_font(pointSize: 9)
        expressNum.textColor = HexColor("#ffffff")
        expressNum.backgroundColor = HexColor("#000000")
        expressNum.textAlignment  
        return expressNum
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.backgroundColor = .white
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}