优惠券swift版马甲包

YMResultViewController.swift 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // YMResultViewController.swift
  3. // MvpGoods
  4. //
  5. // Created by 小花 on 2019/4/17.
  6. // Copyright © 2019 MVP. All rights reserved.
  7. //
  8. import UIKit
  9. import ObjectMapper
  10. import MJRefresh
  11. class YMResultViewController: YMBaseViewController {
  12. var KGoodsCell = "KGoodsCell"
  13. var page = 1
  14. var searchName: String!
  15. var collectionView: UICollectionView?
  16. var dataArr = [YMMainGoodModel]()
  17. var requestType: Int?
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. self.view.backgroundColor = UIColor.white
  21. self.title = searchName
  22. self.view.makeLoading(offY: navBarHeight)
  23. configCollectionView()
  24. loadGoodsData()
  25. }
  26. func loadGoodsData() {
  27. let url = BASE_URL + "/api/v2/goods/search"
  28. let para: [String: Any] = ["page":self.page,
  29. "keyword":self.searchName,
  30. "sort":1,
  31. "min_price":0,
  32. "max_price":-1,
  33. "stype":"0",
  34. "is_has_coupon":1]
  35. NetWorkTool.postRequest(url: url, param: para, success: { (json) in
  36. let items = json["rst"]?["data"].arrayObject
  37. for item in items ?? [] {
  38. let model = Mapper<YMMainGoodModel>().map(JSON: item as! [String : Any])
  39. self.dataArr.append(model ?? YMMainGoodModel())
  40. }
  41. self.view.addSubview(self.collectionView!)
  42. self.view.dismissLoading()
  43. self.collectionView?.reloadData()
  44. self.collectionView?.mj_footer.endRefreshing()
  45. }) { (error) in
  46. self.view.dismissLoading()
  47. }
  48. }
  49. func configCollectionView() {
  50. let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: SCREENW, height: SCREENH-navHeight), collectionViewLayout:UICollectionViewFlowLayout())
  51. collectionView.delegate = self
  52. collectionView.dataSource = self
  53. collectionView.backgroundColor = UIColor.gloadGrayColor()
  54. collectionView.showsVerticalScrollIndicator = false
  55. collectionView.register(YMMainGoodCollectionCell.self, forCellWithReuseIdentifier: KGoodsCell)
  56. self.collectionView = collectionView
  57. let footer = MJRefreshAutoNormalFooter()
  58. footer.setRefreshingTarget(self, refreshingAction: #selector(self.loadMoreData))
  59. collectionView.mj_footer = footer
  60. }
  61. @objc func loadMoreData() {
  62. self.page+=1
  63. loadGoodsData()
  64. }
  65. }
  66. extension YMResultViewController: UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
  67. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  68. return self.dataArr.count
  69. }
  70. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  71. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: KGoodsCell, for: indexPath) as! YMMainGoodCollectionCell
  72. cell.model = self.dataArr[indexPath.row]
  73. return cell
  74. }
  75. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  76. return CGSize(width: SCREEN_WIDTH, height: fitSize(x: 135))
  77. }
  78. //最小 item 间距
  79. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  80. return 0;
  81. }
  82. //最小行间距
  83. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  84. return 5;
  85. }
  86. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  87. let detail = YMDetailViewController()
  88. detail.goodModel = self.dataArr[indexPath.row]
  89. self.navigationController?.pushViewController(detail, animated: true)
  90. }
  91. }