| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- //
- // MyGoodsViewController.swift
- // MTP2_iOS
- //
- // Created by Handy_Cao on 2020/11/12.
- // Copyright © 2020 Muchinfo. All rights reserved.
- //
- import UIKit
- import WHToast
- import GTMRefresh
- /// 我的商品视图容器控制类
- class MyGoodsViewController: BaseViewController {
-
- // MARK: - 属性列表
- /// 我的商品
- @IBOutlet weak var tableView: UITableView!
- /// MyOrdersCellIdentifier
- let MyOrdersCellIdentifier = "MyOrders_Cell"
- /// 我的商品数据信息
- var myGoods: [MoHsbyMyGoods] = [] {
- didSet {
- /// 刷新列表数据
- tableView.reloadData()
- /// 隐藏按钮
- self.noDataButton.isHidden = !(myGoods.count == 0)
- }
- }
- /// 执行回调块
- var block: ((_ model: MoHsbyMyGoods?) -> Void)?
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
-
- /// UI界面初始化
- self.buildView()
- /// 数据初始化
- self.initData()
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- /// 隐藏导航栏
- self.navigationController?.setNavigationBarHidden(false, animated: true)
- }
-
- // MARK: - 初始化
- /// UI界面初始化
- fileprivate func buildView() {
- /// addLoadingView
- self.addLoadingView()
-
- /// 添加下拉刷新控件
- self.tableView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
- /// 查询我的商品数据请求
- self.requestQueryMyGoods()
- }
- }
-
- /// 数据初始化
- fileprivate func initData() {
- /// 查询我的商品数据请求
- self.tableView.triggerRefreshing()
- }
-
- // MARK: - 接口请求
- /// 查询我的商品数据请求
- func requestQueryMyGoods() {
- /// 异常
- guard let orderManager = MTP2BusinessCore.shared.orderManager else {
- return
- }
- /// startAnimating
- self._anim?.startAnimating()
- /// 发送请求
- orderManager.requestQueryHsbyMyGoods { (isComplete, error, goods) in
- DispatchQueue.main.async {
- /// stopAnimating
- self._anim?.stopAnimating()
- /// endRefreshing
- self.tableView.endRefreshing(isSuccess: true)
- /// 数据赋值
- if isComplete {
- self.myGoods = goods ?? []
- } else {
- self.myGoods = []
- WHToast.showError(withMessage: "数据查询失败,原因:\(error?.retMsg ?? "未知错误")", duration: 1.5, finishHandler: {})
- }
- }
- }
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
- // MARK: - 初始化相关
- extension MyGoodsViewController: UITableViewDelegate, UITableViewDataSource {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return myGoods.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: MyOrdersCellIdentifier, for: indexPath) as! MyOrdersCell
- cell.model = myGoods[indexPath.row]
- return cell
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 115.0
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- /// 执行回调
- if let _ = block {
- block!(myGoods[indexPath.row])
- /// 返回上层视图
- self.navigationController?.popViewController(animated: true)
- } else {
- /// 商品详情
- guard let goods = MTP2BusinessCore.shared.goodsManager?.goodsInfos.first(where: {$0.goodsid == myGoods[indexPath.row].goodsid}) else { return }
- let goodsDetailController = UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "GoodsDetail") as! GoodsDetailViewController
- goodsDetailController.model = goods
- self.navigationController?.pushViewController(goodsDetailController, animated: true)
- }
- }
- }
|