123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- //
- // YMResultViewController.swift
- // MvpGoods
- //
- // Created by 小花 on 2019/4/17.
- // Copyright © 2019 MVP. All rights reserved.
- //
- import UIKit
- import ObjectMapper
- import MJRefresh
- class YMResultViewController: YMBaseViewController {
- var KGoodsCell = "KGoodsCell"
-
- var page = 1
- var searchName: String!
-
- var collectionView: UICollectionView?
- var dataArr = [YMMainGoodModel]()
-
- var requestType: Int?
-
- override func viewDidLoad() {
- super.viewDidLoad()
- self.view.backgroundColor = UIColor.white
- self.title = searchName
- self.view.makeLoading(offY: navBarHeight)
- configCollectionView()
- loadGoodsData()
-
- }
-
- func loadGoodsData() {
-
- let url = BASE_URL + "/api/v2/goods/search"
- let para: [String: Any] = ["page":self.page,
- "keyword":self.searchName,
- "sort":1,
- "min_price":0,
- "max_price":-1,
- "stype":"0",
- "is_has_coupon":1]
-
- NetWorkTool.postRequest(url: url, param: para, success: { (json) in
- let items = json["rst"]?["data"].arrayObject
-
- for item in items ?? [] {
- let model = Mapper<YMMainGoodModel>().map(JSON: item as! [String : Any])
- self.dataArr.append(model ?? YMMainGoodModel())
- }
- self.view.addSubview(self.collectionView!)
- self.view.dismissLoading()
- self.collectionView?.reloadData()
- self.collectionView?.mj_footer.endRefreshing()
- }) { (error) in
- self.view.dismissLoading()
- }
-
- }
-
-
-
-
-
- func configCollectionView() {
- let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: SCREENW, height: SCREENH-navHeight), collectionViewLayout:UICollectionViewFlowLayout())
- collectionView.delegate = self
- collectionView.dataSource = self
- collectionView.backgroundColor = UIColor.gloadGrayColor()
- collectionView.showsVerticalScrollIndicator = false
-
- collectionView.register(YMMainGoodCollectionCell.self, forCellWithReuseIdentifier: KGoodsCell)
-
- self.collectionView = collectionView
-
- let footer = MJRefreshAutoNormalFooter()
- footer.setRefreshingTarget(self, refreshingAction: #selector(self.loadMoreData))
- collectionView.mj_footer = footer
-
- }
- @objc func loadMoreData() {
- self.page+=1
- loadGoodsData()
- }
-
-
-
- }
- extension YMResultViewController: UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return self.dataArr.count
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: KGoodsCell, for: indexPath) as! YMMainGoodCollectionCell
- cell.model = self.dataArr[indexPath.row]
-
- return cell
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width: SCREEN_WIDTH, height: fitSize(x: 135))
- }
-
- //最小 item 间距
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
-
- return 0;
- }
-
- //最小行间距
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
-
- return 5;
-
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- let detail = YMDetailViewController()
- detail.goodModel = self.dataArr[indexPath.row]
- self.navigationController?.pushViewController(detail, animated: true)
- }
-
- }
|