Commit e71127e31c916c1dd12cf64295c79cae3c6b8253
1 parent
ed3612fd
没有商品时显示empty
Showing
2 changed files
with
39 additions
and
9 deletions
metaCode/Classes/Main/HomePage/Controller/GoodsManager/CNLiveShopProductManagerController.swift
| @@ -41,6 +41,17 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa | @@ -41,6 +41,17 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa | ||
| 41 | tableView.register(CNLiveShopGoodsListCell.self, forCellReuseIdentifier: kCNLiveShopGoodsListCellIdentifier) | 41 | tableView.register(CNLiveShopGoodsListCell.self, forCellReuseIdentifier: kCNLiveShopGoodsListCellIdentifier) |
| 42 | return tableView | 42 | return tableView |
| 43 | }() | 43 | }() |
| 44 | + | ||
| 45 | + lazy var emptyLabel: UILabel = { | ||
| 46 | + let emptyLabel = UILabel.init(frame: CGRectMake(0, 0, 100, 35)) | ||
| 47 | + emptyLabel.center = self.view.center | ||
| 48 | + emptyLabel.textColor = .black | ||
| 49 | + emptyLabel.textAlignment = .center | ||
| 50 | + emptyLabel.text = "暂无商品" | ||
| 51 | + emptyLabel.font = Font_21 | ||
| 52 | + emptyLabel.adjustsFontSizeToFitWidth=true | ||
| 53 | + return emptyLabel | ||
| 54 | + }() | ||
| 44 | 55 | ||
| 45 | override func viewDidLoad() { | 56 | override func viewDidLoad() { |
| 46 | super.viewDidLoad() | 57 | super.viewDidLoad() |
| @@ -53,6 +64,8 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa | @@ -53,6 +64,8 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa | ||
| 53 | // rightNavBtns = [self.addBtn] | 64 | // rightNavBtns = [self.addBtn] |
| 54 | self.view.addSubview(self.classifyView) | 65 | self.view.addSubview(self.classifyView) |
| 55 | self.view.addSubview(tableView) | 66 | self.view.addSubview(tableView) |
| 67 | + self.view.addSubview(self.emptyLabel) | ||
| 68 | + self.emptyLabel.isHidden = true | ||
| 56 | tableView.frame = CGRect(x: 0, y:self.classifyView.bottom , width: KSreenWidth, height: KSreenHeight - self.classifyView.bottom) | 69 | tableView.frame = CGRect(x: 0, y:self.classifyView.bottom , width: KSreenWidth, height: KSreenHeight - self.classifyView.bottom) |
| 57 | } | 70 | } |
| 58 | 71 | ||
| @@ -95,17 +108,27 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa | @@ -95,17 +108,27 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa | ||
| 95 | CNLiveShopGoodListViewModel.requestGoodsList(shopId: DSUserInfoManager.shared.dsUserInfo.id, sortType: "1", page: page) { result, status in | 108 | CNLiveShopGoodListViewModel.requestGoodsList(shopId: DSUserInfoManager.shared.dsUserInfo.id, sortType: "1", page: page) { result, status in |
| 96 | hiddenLoading() | 109 | hiddenLoading() |
| 97 | if status == .success{ | 110 | if status == .success{ |
| 98 | - self.dataArray.addObjects(from: result as! [CNLiveShopGoodsListModel]) | ||
| 99 | - let newDataArray = NSMutableArray() | ||
| 100 | - for goodsModel in self.dataArray { | ||
| 101 | - if let model = goodsModel as? CNLiveShopGoodsListModel{ | ||
| 102 | - newDataArray.add(model) | 111 | + let arr = result as! [CNLiveShopGoodsListModel] |
| 112 | + if arr.count > 0 | ||
| 113 | + { | ||
| 114 | + self.dataArray.addObjects(from: result as! [CNLiveShopGoodsListModel]) | ||
| 115 | + let newDataArray = NSMutableArray() | ||
| 116 | + for goodsModel in self.dataArray { | ||
| 117 | + if let model = goodsModel as? CNLiveShopGoodsListModel{ | ||
| 118 | + newDataArray.add(model) | ||
| 119 | + } | ||
| 103 | } | 120 | } |
| 121 | + self.dataArray.removeAllObjects() | ||
| 122 | + self.dataArray.addObjects(from: newDataArray as! [Any]) | ||
| 123 | + | ||
| 124 | + self.tableView.reloadData() | ||
| 125 | + self.emptyLabel.isHidden = true | ||
| 126 | + self.classifyView.emptyView(isEmpty: false) | ||
| 127 | + }else if arr.count == 0{ | ||
| 128 | + //展示emptyView | ||
| 129 | + self.classifyView.emptyView(isEmpty: true) | ||
| 130 | + self.emptyLabel.isHidden = false | ||
| 104 | } | 131 | } |
| 105 | - self.dataArray.removeAllObjects() | ||
| 106 | - self.dataArray.addObjects(from: newDataArray as! [Any]) | ||
| 107 | - | ||
| 108 | - self.tableView.reloadData() | ||
| 109 | }else if (status == .failed){ | 132 | }else if (status == .failed){ |
| 110 | // self.NetApiStatus = .apiError | 133 | // self.NetApiStatus = .apiError |
| 111 | }else if (status == .noNetwork){ | 134 | }else if (status == .noNetwork){ |
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopGoodsListClassifyView.swift
| @@ -34,6 +34,7 @@ class CNLiveShopGoodsListClassifyView: UIView { | @@ -34,6 +34,7 @@ class CNLiveShopGoodsListClassifyView: UIView { | ||
| 34 | priceBtn.addTarget(self, action: #selector(priceBtnAction), for: .touchUpInside) | 34 | priceBtn.addTarget(self, action: #selector(priceBtnAction), for: .touchUpInside) |
| 35 | return priceBtn | 35 | return priceBtn |
| 36 | }() | 36 | }() |
| 37 | + | ||
| 37 | 38 | ||
| 38 | override init(frame: CGRect) { | 39 | override init(frame: CGRect) { |
| 39 | super.init(frame: frame) | 40 | super.init(frame: frame) |
| @@ -50,6 +51,12 @@ class CNLiveShopGoodsListClassifyView: UIView { | @@ -50,6 +51,12 @@ class CNLiveShopGoodsListClassifyView: UIView { | ||
| 50 | fatalError("init(coder:) has not been implemented") | 51 | fatalError("init(coder:) has not been implemented") |
| 51 | } | 52 | } |
| 52 | 53 | ||
| 54 | + public func emptyView(isEmpty:Bool){ | ||
| 55 | + //后面替换成其他 | ||
| 56 | + self.lastestBtn.isHidden = isHidden | ||
| 57 | + | ||
| 58 | + } | ||
| 59 | + | ||
| 53 | @objc func priceBtnAction(){ | 60 | @objc func priceBtnAction(){ |
| 54 | self.priceBtn.isSelected = true | 61 | self.priceBtn.isSelected = true |
| 55 | self.lastestBtn.isSelected = false | 62 | self.lastestBtn.isSelected = false |