Commit e71127e31c916c1dd12cf64295c79cae3c6b8253

Authored by 张旭
1 parent ed3612fd

没有商品时显示empty

metaCode/Classes/Main/HomePage/Controller/GoodsManager/CNLiveShopProductManagerController.swift
... ... @@ -41,6 +41,17 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa
41 41 tableView.register(CNLiveShopGoodsListCell.self, forCellReuseIdentifier: kCNLiveShopGoodsListCellIdentifier)
42 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 56 override func viewDidLoad() {
46 57 super.viewDidLoad()
... ... @@ -53,6 +64,8 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa
53 64 // rightNavBtns = [self.addBtn]
54 65 self.view.addSubview(self.classifyView)
55 66 self.view.addSubview(tableView)
  67 + self.view.addSubview(self.emptyLabel)
  68 + self.emptyLabel.isHidden = true
56 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 108 CNLiveShopGoodListViewModel.requestGoodsList(shopId: DSUserInfoManager.shared.dsUserInfo.id, sortType: "1", page: page) { result, status in
96 109 hiddenLoading()
97 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 132 }else if (status == .failed){
110 133 // self.NetApiStatus = .apiError
111 134 }else if (status == .noNetwork){
... ...
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopGoodsListClassifyView.swift
... ... @@ -34,6 +34,7 @@ class CNLiveShopGoodsListClassifyView: UIView {
34 34 priceBtn.addTarget(self, action: #selector(priceBtnAction), for: .touchUpInside)
35 35 return priceBtn
36 36 }()
  37 +
37 38  
38 39 override init(frame: CGRect) {
39 40 super.init(frame: frame)
... ... @@ -50,6 +51,12 @@ class CNLiveShopGoodsListClassifyView: UIView {
50 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 60 @objc func priceBtnAction(){
54 61 self.priceBtn.isSelected = true
55 62 self.lastestBtn.isSelected = false
... ...