杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
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
    //
    //  SearchStoreDetailVC.swift
    //  WanPai
    //
    //  Created by 无故事王国 on 2023/6/30.
    //
 
import UIKit
import JQTools
import QMUIKit
 
class SearchStoreDetailVC: BaseVC {
    private var id:Int!
    private var searchStoreDetailModel:SearchStoreDetailModel?{
        didSet{
            if let m = searchStoreDetailModel{
                headView.searchStoreDetailModel = m
 
                DispatchQueue.main.async {
                    self.headView.cons_labelHeiCons.constant = String.jq_getHeight(text: m.storeInfo, width: self.view.width - 100, font: 14)
                    self.headView.layoutIfNeeded()
                    self.headView.layoutSubviews()
                    self.tableView.reloadData()
                    let height = self.headView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
                    self.headView.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: height)
                    self.tableView.tableHeaderView = self.headView
                }
            }
        }
    }
 
    lazy private var tableView:UITableView = {
        let table = UITableView(frame: .zero, style: .grouped)
        table.separatorStyle = .none
        table.delegate = self
        table.dataSource = self
        table.register(UINib(nibName: "YardTCell", bundle: nil), forCellReuseIdentifier: "_YardTCell")
        table.register(UINib(nibName: "SearchStoreDetail_1_TCell", bundle: nil), forCellReuseIdentifier: "_SearchStoreDetail_1_TCell")
        return table
    }()
 
    private let headView = SearchStoreDetailHeadView.jq_loadNibView()
 
    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.exploreStoreDetail(storeId: id).subscribe(onNext: {[weak self] data in
            if let model = data.data{
                self?.searchStoreDetailModel = model
            }
        }).disposed(by: disposeBag)
 
    }
 
    override func setUI() {
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
 
        tableView.layoutIfNeeded()
//        tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: UIDevice.jq_safeEdges.bottom, right: 0)
        tableView.tableHeaderView = headView
    }
 
    @objc func moreAction(btn:UIButton){
        let selectStore = NormalSimpleModel(id: searchStoreDetailModel!.storeId, name: searchStoreDetailModel!.storeName)
        if btn.tag == 10{
            let vc = YardListVC(selectStore: selectStore)
            push(vc: vc)
        }else{
            let vc = CourseListVC(selectStore: selectStore)
            push(vc: vc)
        }
    }
}
 
extension SearchStoreDetailVC:UITableViewDelegate{
 
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == 0{
            let model = searchStoreDetailModel!.venueList[indexPath.row]
            let vc = YardDetailVC(id: model.siteId)
            push(vc: vc)
        }else{
            let model = searchStoreDetailModel!.courseVoList[indexPath.row]
            let vc = CourseDetailVC(id: model.courseId)
            push(vc: vc)
        }
    }
 
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 40
    }
 
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        var headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header")
        if headerView == nil{
            headerView = UITableViewHeaderFooterView()
            headerView!.contentView.backgroundColor = .white
            headerView!.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: 40)
            let label = UILabel()
            label.textColor = .black.withAlphaComponent(0.8)
            label.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
            label.tag = 1000
            headerView!.contentView.addSubview(label)
            label.snp.makeConstraints { make in
                make.left.equalTo(8)
                make.centerY.equalToSuperview()
            }
        }
 
        if let label = headerView!.viewWithTag(1000) as? UILabel{
            if section == 0{
                label.text = "场地列表"
            }else{
                label.text = "运动营列表"
            }
        }
        return headerView
    }
 
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 40
    }
 
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        var footView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "footer")
        if footView == nil{
            footView = UITableViewHeaderFooterView()
            footView!.contentView.backgroundColor = .white
            footView!.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: 40)
 
            let morebtn = QMUIButton(type: .custom)
            morebtn.setTitle("查看更多", for: .normal)
            morebtn.tag = 10+section
            morebtn.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .semibold)
            morebtn.setTitleColor(UIColor(hexStr: "#0048FF"), for: .normal)
            morebtn.setImage(UIImage(named: "btn_more"), for: .normal)
            morebtn.imagePosition = .right
            morebtn.spacingBetweenImageAndTitle = 3
            morebtn.addTarget(self, action: #selector(moreAction), for: .touchUpInside)
 
            footView?.contentView.addSubview(morebtn)
            morebtn.snp.makeConstraints { make in
                make.center.equalToSuperview()
            }
        }
        return footView
    }
}
 
extension SearchStoreDetailVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0{
            return min(searchStoreDetailModel?.venueList.count ?? 0,3)
        }else{
            return searchStoreDetailModel?.courseVoList.count ?? 0
        }
    }
 
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 0{
            let cell = tableView.dequeueReusableCell(withIdentifier: "_YardTCell") as! YardTCell
            let model = searchStoreDetailModel!.venueList[indexPath.row]
            cell.venueModel = model
            cell.label_distance.isHidden = true
            return cell
        }else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "_SearchStoreDetail_1_TCell") as! SearchStoreDetail_1_TCell
            let model = searchStoreDetailModel!.courseVoList[indexPath.row]
            cell.detailCourseModel = model
            return cell
        }
    }
 
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0{
                return 80
        }else{
            return 180
        }
    }
}