//
|
// 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
|
}
|
}
|
}
|