//
|
// ChooseStoreView.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2023/6/29.
|
//
|
|
import UIKit
|
import JQTools
|
|
class ChooseStoreView: UIView,JQNibView{
|
|
@IBOutlet weak var view_container: UIView!
|
@IBOutlet weak var view_bottomContainer: NSLayoutConstraint!
|
@IBOutlet weak var tableView: UITableView!
|
private var clouse:((StoreSimpleModel)->Void)!
|
private var models = [StoreSimpleModel]()
|
private var selectIndex:Int?
|
private var defaultModel:StoreSimpleModel?
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
tableView.register(UINib(nibName: "CommonSingleTCell", bundle: nil), forCellReuseIdentifier: "_CommonSingleTCell")
|
view_bottomContainer.constant = -(JQ_ScreenW * 0.8153)
|
alpha = 0
|
layoutIfNeeded()
|
}
|
|
static func show(models:[StoreSimpleModel],defaultModel:StoreSimpleModel? = nil, clouse:@escaping (StoreSimpleModel)->Void){
|
let chooseStoreView = ChooseStoreView.jq_loadNibView()
|
chooseStoreView.frame = sceneDelegate?.window?.frame ?? .zero
|
sceneDelegate?.window?.addSubview(chooseStoreView)
|
chooseStoreView.view_bottomContainer.constant = 0
|
chooseStoreView.defaultModel = defaultModel
|
chooseStoreView.clouse = clouse
|
chooseStoreView.models = models
|
|
for (index,m) in models.enumerated(){
|
if m.storeId == defaultModel?.storeId{
|
chooseStoreView.selectIndex = index;break
|
}
|
}
|
|
chooseStoreView.tableView.reloadData()
|
UIView.animate(withDuration: 0.4) {
|
chooseStoreView.alpha = 1
|
chooseStoreView.layoutIfNeeded()
|
}
|
}
|
|
@IBAction func closeAction(_ sender: Any) {
|
view_bottomContainer.constant = -(JQ_ScreenW * 0.8153)
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.layoutIfNeeded()
|
} completion: { _ in
|
self.removeFromSuperview()
|
}
|
}
|
|
@IBAction func completeAction(_ sender: UIButton) {
|
view_bottomContainer.constant = -(JQ_ScreenW * 0.8153)
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.layoutIfNeeded()
|
} completion: { _ in
|
self.removeFromSuperview()
|
if let s = self.selectIndex{
|
let model = self.models[s]
|
self.clouse!(model)
|
}
|
}
|
}
|
|
override func layoutSubviews() {
|
super.layoutSubviews()
|
view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 20)
|
}
|
}
|
|
extension ChooseStoreView:UITableViewDelegate{
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
selectIndex = indexPath.row
|
tableView.reloadData()
|
}
|
|
}
|
|
extension ChooseStoreView:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let model = models[indexPath.row]
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_CommonSingleTCell") as! CommonSingleTCell
|
cell.label_title.text = model.storeName
|
cell.img_select.image = indexPath.row == selectIndex ? UIImage(named: "btn_choose_s") : UIImage(named: "btn_choose")
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 68
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return models.count
|
}
|
}
|