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