| | |
| | | @IBOutlet weak var view_container: UIView! |
| | | @IBOutlet weak var view_bottomContainer: NSLayoutConstraint! |
| | | @IBOutlet weak var tableView: UITableView! |
| | | private var clouse:(()->Void)! |
| | | private var clouse:((StoreSimpleModel)->Void)! |
| | | private var models = [StoreSimpleModel]() |
| | | private var selectIndex = 0 |
| | | private var defaultModel:StoreSimpleModel? |
| | | |
| | | override func awakeFromNib() { |
| | | super.awakeFromNib() |
| | |
| | | layoutIfNeeded() |
| | | } |
| | | |
| | | static func show(_ clouse:@escaping ()->Void){ |
| | | static func show(models:[StoreSimpleModel],defaultModel:StoreSimpleModel? = nil, clouse:@escaping (StoreSimpleModel)->Void){ |
| | | let chooseStoreView = ChooseStoreView.jq_loadNibView() |
| | | chooseStoreView.frame = screnDelegate?.window?.frame ?? .zero |
| | | screnDelegate?.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() |
| | |
| | | self.layoutIfNeeded() |
| | | } completion: { _ in |
| | | self.removeFromSuperview() |
| | | self.clouse!() |
| | | let model = self.models[self.selectIndex] |
| | | self.clouse!(model) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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, numberOfRowsInSection section: Int) -> Int { |
| | | return 5 |
| | | return models.count |
| | | } |
| | | } |