CNLiveShopBodyListView.swift 14.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
//
//  CNLiveShopBodyListView.swift
//  metaCode
//
//  Created by open on 2023/10/31.
//

import Foundation
import Kingfisher
/// 订单列表尾界面
enum CNDSOrderListSectionFooterBtnClickEvent {
    case notifyOrder //通知自提
    case delivery    //发货
    case checkExpress//查快递
    case checkProgress//查进度
    case checkChat    //联系买家
    case connection   //查看详情
    case express      //快递发货
    case expDetail    //物流详情
    case none
}
typealias clickRightBtnCallBack = (_ title: String,_ event: CNDSOrderListSectionFooterBtnClickEvent,_ listModel :ShopOrderListModel) -> Void
class ShopBodyOrderFooterViewCell: UITableViewHeaderFooterView {
    
    lazy var addressLabel: UILabel = {
        let addressLabel = UILabel.init()
        addressLabel.textColor = HexColor("#727272")
        addressLabel.font = Font_14_Fit
        addressLabel.lineBreakMode = .byTruncatingTail
        addressLabel.numberOfLines = 2
        return addressLabel
    }()
    
    lazy var lineLabel: UILabel = {
        let lineLabel = UILabel.init()
        lineLabel.backgroundColor = HexColor("#EAEAEA")
        return lineLabel
    }()
    
    lazy var rightBtn: UIButton = {
        let rightBtn = UIButton.init(type: .custom)
        rightBtn.setTitleColor(HexColor("#FF3355"), for: .normal)
        rightBtn.titleLabel?.font = BoldFont_14_Fit
        rightBtn.layer.cornerRadius = 5
        rightBtn.layer.masksToBounds = true
        rightBtn.layer.borderColor = HexColor("#FF3355")?.cgColor
        rightBtn.layer.borderWidth = 1
        rightBtn.backgroundColor = .white
        rightBtn.addTarget(self, action: #selector(rightBtnClick), for: .touchUpInside)
        return rightBtn
    }()
    lazy var leftBtn: UIButton = {
        let leftBtn = UIButton.init(type: .custom)
        leftBtn.isHidden = true
        leftBtn.setTitleColor(HexColor("#FF3355"), for: .normal)
        leftBtn.titleLabel?.font = BoldFont_14_Fit
        leftBtn.layer.cornerRadius = 5
        leftBtn.layer.masksToBounds = true
        leftBtn.layer.borderColor = HexColor("#FF3355")?.cgColor
        leftBtn.layer.borderWidth = 1
        leftBtn.backgroundColor = .white
        leftBtn.addTarget(self, action: #selector(rightBtnClick), for: .touchUpInside)
        return leftBtn
    }()
    
    lazy var interView: UIView = {
        let interView = UIView.init()
        interView.backgroundColor = HexColor("#f8f8f8")
        return interView
    }()
    
    var clickRightBtnCallBack: clickRightBtnCallBack!
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .white
        
        addSubview(rightBtn)
        rightBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalToSuperview().offset(-20)
            make.width.equalTo(70)
            make.height.equalTo(30)
        }
        addSubview(leftBtn)
        leftBtn.snp.makeConstraints { make in
            make.centerY.equalTo(rightBtn)
            make.right.equalTo(rightBtn.snp.left).offset(-10)
            make.width.equalTo(70)
            make.height.equalTo(30)
        }
        
        addSubview(lineLabel)
        lineLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalTo(rightBtn.snp.top).offset(-10)
            make.height.equalTo(1)
        }
        
        addSubview(addressLabel)
        addressLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalTo(lineLabel.snp.top).offset(-10)
        }
        
        addSubview(interView)
        interView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview()
            make.height.equalTo(10)
        }
    }
    
    @objc func rightBtnClick(button: UIButton) {
        
        var clickEvent: CNDSOrderListSectionFooterBtnClickEvent! = CNDSOrderListSectionFooterBtnClickEvent.none

        if button.titleLabel?.text == "快递发货" {
            if _listModel.state == "2" {
                if _listModel.order_detail.count > 1 {
                    clickEvent = .expDetail
                } else {
                    let goodsModel = _listModel.order_detail.first!
                    if goodsModel.num! > 1 {
                        clickEvent = .expDetail
                    } else {
                        clickEvent = .delivery
                    }
                }
            } else {
                if _listModel.is_send == "0" {
                    clickEvent = .expDetail
                } else {
                    clickEvent = .delivery
                }
            }
        }
        if button.titleLabel?.text == "通知自提" {
            clickEvent = .notifyOrder
        }
        if button.titleLabel?.text == "查看物流" {
            clickEvent = .checkExpress
        }
        if button.titleLabel?.text == "查看进度" {
            clickEvent = .checkProgress
        }
        if button.titleLabel?.text == "查看详情" {
            clickEvent = .connection
        }
        if button.titleLabel?.text == "物流详情" {
            clickEvent = .express
        }
        if clickEvent == CNDSOrderListSectionFooterBtnClickEvent.none {
            return
        }
        
        if (_listModel != nil) && (clickRightBtnCallBack != nil) {
            self.clickRightBtnCallBack((button.titleLabel?.text)!, clickEvent, _listModel)
        }
    }
    
    
    var _listModel: ShopOrderListModel!
    func setupDataSource(listModel: ShopOrderListModel) {
        _listModel = listModel
        
        if listModel.isRefund == "1" {
            addressLabel.isHidden = true
            lineLabel.isHidden = true
        } else {
            addressLabel.isHidden = false
            lineLabel.isHidden = false
            
            addressLabel.text = "\(listModel.address_name ?? "") \(listModel.address_phone ?? "") \(listModel.address_address ?? "")"
        }
        
        rightBtn.isHidden = false
        leftBtn.isHidden = true
        
        if listModel.isRefund == "1" {
            rightBtn.setTitle("查看详情", for: .normal)
            return
        }
        
        switch listModel.state {
        case "2":
            if listModel.is_send == "0" {
                leftBtn.isHidden = false
                rightBtn.setTitle("快递发货", for: .normal)
                leftBtn.setTitle("物流详情", for: .normal)
            } else {
                if listModel.delivery == "2" {
                    rightBtn.setTitle("通知自提", for: .normal)
                } else {
                    rightBtn.setTitle("快递发货", for: .normal)
                }
            }
        case "3":
            if listModel.is_send == "0" {
                leftBtn.isHidden = false
                rightBtn.setTitle("快递发货", for: .normal)
                leftBtn.setTitle("物流详情", for: .normal)
            } else {
                if listModel.delivery == "2" {
                    rightBtn.setTitle("查看进度", for: .normal)
                } else {
                    rightBtn.setTitle("查看物流", for: .normal)
                }
            }
        case "4":
            if listModel.delivery == "2" {
                rightBtn.setTitle("查看进度", for: .normal)
            } else {
                rightBtn.setTitle("查看物流", for: .normal)
            }
        case "6":
            rightBtn.setTitle("查看详情", for: .normal)
        default:
            rightBtn.setTitle("", for: .normal)
            rightBtn.isHidden = true
            break
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

/// 订单列表首界面
class ShopBodyOrderHeaderViewCell: UITableViewHeaderFooterView {
    
    lazy var orderLabel: UILabel = {
        let orderLabel = UILabel.init()
        orderLabel.textColor = HexColor("#3D3D3D")
        orderLabel.font = Font_13_Fit
        return orderLabel
    }()
    
    lazy var statueLabel: UILabel = {
        let statueLabel  = UILabel.init()
        statueLabel.textColor = HexColor("#FF3050")
        statueLabel.font = BoldFont_14_Fit
        statueLabel.textAlignment = .right
        return statueLabel
    }()
    
    lazy var lineLabel: UILabel = {
        let lineLabel = UILabel.init()
        lineLabel.backgroundColor = HexColor("#EAEAEA")
        return lineLabel
    }()
    

    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .white
        
        addSubview(orderLabel)
        orderLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(15)
        }
        addSubview(statueLabel)
        statueLabel.snp.makeConstraints { make in
            make.centerY.equalTo(orderLabel)
            make.right.equalToSuperview().offset(-15)
        }
        addSubview(lineLabel)
        lineLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(1)
            make.bottom.equalToSuperview().offset(-1)
        }
    }
    
    func setupDataSource(listModel: ShopOrderListModel) {
        
        if listModel.isRefund == "1" {
            orderLabel.text = "退款单号:\(listModel.id ?? "")"
        } else {
            orderLabel.text = "订单号:\(listModel.id ?? "")"
        }
        if listModel.isRefund == "1" {//退款
            switch listModel.state {
            case "1":
                statueLabel.text = "申请中"
            case "2":
                if listModel.state == "2" {
                    statueLabel.text = "同意退款"
                } else {
                    statueLabel.text = "等待邮寄"
                }
            case "3":
                statueLabel.text = "已拒绝"
            case "5":
                statueLabel.text = "已撤销"
            default:
                break
            }
        } else {
            switch listModel.state {
            case "1":
                statueLabel.text = "待付款"
            case "2":
                if listModel.is_send == "0" {
                    statueLabel.text = "部分发货"
                }  else {
                    if listModel.delivery == "2" {
                        statueLabel.text = "备货中"
                    } else {
                        statueLabel.text = "待发货"
                    }
                }
            case "3":
                if listModel.is_send == "0" {
                    statueLabel.text = "部分发货"
                } else {
                    if listModel.delivery == "2" {
                        statueLabel.text = "备货完毕"
                    } else {
                        statueLabel.text = "已发货"
                    }
                }
            case "4":
                statueLabel.text = "已完成"
            case "5":
                statueLabel.text = "已取消"
            case "6":
                statueLabel.text = "已退款"
            default:
                break
            }
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

/// 订单列表界面显示
class ShopBodyOrderListViewCell: UITableViewCell {
    
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.font = BoldFont_16_Fit
        titleLabel.numberOfLines = 2
        titleLabel.lineBreakMode = .byTruncatingTail
        return titleLabel
    }()
    
    lazy var timeLabel: UILabel = {
        let timeLabel = UILabel.init(frame: CGRect.zero)
        timeLabel.font = Font_12_Fit
        timeLabel.textColor = HexColor("#999999")
        return timeLabel
    }()
    
    lazy var iconView: UIImageView = {
        let iconView = UIImageView.init()
        iconView.backgroundColor = .white
        iconView.layer.cornerRadius = 5
        iconView.layer.masksToBounds = true
        iconView.contentMode = .scaleAspectFit
        iconView.image = UIImage.imageWithColor(color: HexColor("#f9f9f9")!, size: CGSize(width: 90, height: 90))
        return iconView
    }()
    
    lazy var lineLabel: UILabel = {
        let lineLabel = UILabel.init()
        lineLabel.backgroundColor = HexColor("#EAEAEA")
        return lineLabel
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .clear
        selectionStyle = .none
        
        addSubview(titleLabel)
        addSubview(timeLabel)
        addSubview(iconView)
        addSubview(lineLabel)
        
        setConstrainta()
    }
    
    func setupDataSource(goodsModel: ShopOrderListGoodsModel, addTime: String) {
        titleLabel.text = goodsModel.title
        timeLabel.text = addTime
        iconView.kf.setImage(with: URL(string: goodsModel.simg!), placeholder: UIImage.imageWithColor(color: HexColor("#f9f9f9")!, size: CGSize(width: 90, height: 90)))
    }
    
    func setConstrainta() {
        iconView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(10)
            make.bottom.equalToSuperview().offset(-10)
            make.width.equalTo(90)
        }
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(iconView.snp.right).offset(10)
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(iconView.snp.top).offset(5)
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(iconView.snp.right).offset(10)
            make.bottom.equalTo(iconView.snp.bottom).offset(-5)
        }
        lineLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalToSuperview().offset(-1)
            make.height.equalTo(1)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}