无故事王国
2023-10-19 eb795a6523edbc0fe3a3b1a3d3bea1063041efd5
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
//
//  ActivityDetailVC.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/13.
//
 
import UIKit
import SDWebImage
import JQTools
 
class ActivityDetailVC: BaseVC {
    private var id:Int!
 
    @IBOutlet weak var view_banner: UIView!
    @IBOutlet weak var label_storeNames: UILabel!
    @IBOutlet weak var label_title: UILabel!
    @IBOutlet weak var label_joinCondition: UILabel!
    @IBOutlet weak var label_address: UILabel!
    @IBOutlet weak var label_duetime: UILabel!
    @IBOutlet weak var label_starttime: UILabel!
    @IBOutlet weak var label_endtime: UILabel!
    @IBOutlet weak var label_ageScope: UILabel!
    @IBOutlet weak var label_city: UILabel!
    @IBOutlet weak var label_money: UILabel!
    @IBOutlet weak var label_coin: UILabel!
    @IBOutlet weak var label_courseNum: UILabel!
    @IBOutlet weak var label_introducion: UILabel!
    @IBOutlet weak var img_enrollRequired: UIImageView!
    @IBOutlet weak var cons_imgEnrollHei: NSLayoutConstraint!
    @IBOutlet weak var btn_enroll: UIButton!
    @IBOutlet weak var label_matchStore: UILabel!
    @IBOutlet weak var btn_moreMatchStore: UIButton!
 
    private lazy var bannerView:CommonBannerView = {
        let v = CommonBannerView()
        return v
    }()
 
    var activityDetailModel:ActivityDetailModel!{
        didSet{
            label_storeNames.text = activityDetailModel.storeInfos.map({$0.name}).joined(separator: ",")
            btn_moreMatchStore.isHidden = (label_storeNames.text?.count ?? 0) < 50
 
            label_title.text = activityDetailModel.name
            label_joinCondition.text = activityDetailModel.registerCondition.strTitle + "参与"
            label_address.text = activityDetailModel.address
            label_duetime.text = activityDetailModel.registerEndTime
            label_starttime.text = activityDetailModel.startTime
            label_endtime.text = activityDetailModel.endTime
            label_ageScope.text = activityDetailModel.age + "岁"
            label_introducion.text = activityDetailModel.introduction
            label_city.text = activityDetailModel.province + "|" + activityDetailModel.city
            SDWebImageDownloader.shared.downloadImage(with: URL(string: activityDetailModel.registrationNotes)!) {[weak self] image, data, error, status in
                guard let img = image else {
                    self?.cons_imgEnrollHei.constant = 0;return
                }
 
                let radio = img.size.width / img.size.height
                self?.cons_imgEnrollHei.constant = JQ_ScreenW / radio
                self?.img_enrollRequired.image = img
            }
 
            label_money.text = String(format: "%@/人", activityDetailModel.cashPrice.currency())
            label_coin.text = String(format: "%ld币/人", activityDetailModel.playPaiCoin)
            label_courseNum.text = String(format: "%ld课时/人", activityDetailModel.classPrice)
 
            let name = activityDetailModel.apply == 1 ? "已报名":"立即报名"
            let color = activityDetailModel.apply == 1 ? UIColor.gray.withAlphaComponent(0.5):Def_ThemeColor
            btn_enroll.setTitle(name, for: .normal)
            btn_enroll.backgroundColor = color
 
            bannerView.setImages(images:activityDetailModel.imgs.components(separatedBy: ","), type: .URL) { index in
 
            }
        }
    }
 
 
    required init(id:Int) {
        super.init(nibName: nil, bundle: nil)
        self.id = id
    }
 
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "活动详情"
 
        Services.queryCompetitionDetail(id: id).subscribe(onNext: {[weak self] data in
            if let data = data.data{
                self?.activityDetailModel = data
            }
        }).disposed(by: disposeBag)
    }
 
    override func setUI() {
        view_banner.addSubview(bannerView)
        bannerView.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: JQ_ScreenW * 0.56)
 
        let moreBtnAttributeding = AttributedStringbuilder.build().add(string: "查看更多", withFont: UIFont.systemFont(ofSize: 12, weight: .medium), withColor: Def_ThemeColor).underLine(color: Def_ThemeColor).mutableAttributedString
        btn_moreMatchStore.setAttributedTitle(moreBtnAttributeding, for: .normal)
    }
 
    @IBAction func matchStoreAction(_ sender: UIButton) {
        let text = activityDetailModel.storeInfos.map({$0.name}).joined(separator: ",")
        AgreentView.show(type: .matchStore, content: text)
    }
 
    @IBAction func joinAction(_ sender: UIButton) {
        guard activityDetailModel.apply == 0 else {return}
        let vc = ActivityDetailApplyVC(model: activityDetailModel)
        push(vc: vc)
    }
}