| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- //
- // NewQuoteViewController.swift
- // MTP2_iOS
- //
- // Created by Handy_Cao on 2020/10/30.
- // Copyright © 2020 Muchinfo. All rights reserved.
- //
- import UIKit
- import WHToast
- import SDWebImage
- import SwiftDate
- import SwiftyAttributes
- import GTMRefresh
- /// 新品上市视图容器控制类
- class NewQuoteViewController: BaseViewController {
- // MARK: - 属性列表
- /// 商品展示列表
- @IBOutlet weak var tableView: UITableView!
- /// 位置按钮
- @IBOutlet weak var location: UIButton!
-
- /// CellIdentifier
- let CellIdentifier = "Goods_Cell"
- /// 省份信息
- var geographics: [MoGeographicPosition] = []
- /// 市区信息
- var city: MoGeographic? {
- didSet {
- self.location.setTitle(city?.pathname ?? "全部", for: .normal)
- /// 查询商品
- self.requestQueryHotGoods(self.city)
- }
- }
- /// 商品数据
- var preGoods: [MoGoodsInfo] = [] {
- didSet {
- /// 刷新数据
- tableView.reloadData()
- /// 是否隐藏按钮
- self.noDataButton.isHidden = preGoods.count != 0
- }
- }
-
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- /// UI界面初始化
- buildView()
- }
-
- override func didMove(toParent parent: UIViewController?) {
- super.didMove(toParent: parent)
-
- if let _ = parent {
- /// 数据初始化
- initData()
- } else {
- noDataButton.isHidden = true
- }
- }
-
- // MARK: - 数据初始化
- /// 数据初始化
- fileprivate func initData() {
- /// 查询热门商品信息
- requestQueryHotGoods(self.city)
- }
-
- /// UI界面初始化
- fileprivate func buildView() {
- /// 异常
- guard let accountManager = MTP2BusinessCore.shared.accountManager else {
- return
- }
- /// loding......
- addLoadingView()
- /// 赋值省市区信息
- self.geographics = accountManager.geographics ?? []
- /// 添加下拉刷新控件
- self.tableView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
- /// 重置请求条件
- self.initData()
- }
- }
-
- // MARK: - 接口请求
- /// 获取热门商品数据信息
- fileprivate func requestQueryHotGoods(_ city: MoGeographic?) {
-
- /// 异常
- guard let goodsManager = MTP2BusinessCore.shared.goodsManager else {
- return
- }
- /// 目标省份
- let descProvinceID = (city == nil || city?.divisionlevel != "province") ? nil : city?.autoid
- /// 目标城市
- let descCityID = (city == nil || city?.divisionlevel != "city") ? nil : city?.autoid
- /// startAnimating
- self._anim?.startAnimating()
- /// 发送请求
- goodsManager.requestQueryHsbyPreGoodses(goodsManager.getMarketIDs(.TRADEMODE_TRADEMODE_CPTRADE_LS), descProvinceID, descCityID) { (isComplete, error, preGoods) in
- DispatchQueue.main.async {
- /// stopAnimating
- self._anim?.stopAnimating()
- /// endRefreshing
- self.tableView.endRefreshing()
- if isComplete {
- /// 数据获取成功
- self.preGoods = preGoods ?? []
- } else {
- self.preGoods = []
- /// toast
- WHToast.showError(withMessage: "数据获取失败,原因:\(error?.retMsg ?? "未知错误")", duration: 1.0, finishHandler: {})
- }
- }
- }
- }
-
- // MARK: - 交互相关
- /// onButtonPressed
- /// - Parameter sender: sender
- @IBAction fileprivate func onButtonPressed(_ sender: UIButton) {
- switch sender {
- case location: /// 位置
- let geographicPickView = GeographicPickView(nibName: "GeographicPickView", bundle: nil)
- geographicPickView.modalTransitionStyle = .coverVertical
- geographicPickView.modalPresentationStyle = .overFullScreen
- geographicPickView.callback = { (_ takeInfo: MoGeographic?, _ isSure: Bool) in
- self.city = takeInfo
- }
- self.present(geographicPickView, animated: true, completion: {})
- default:
- break
- }
- }
-
- // 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.
- if segue.identifier == "ShowGoodsDetail" {
- /// 商品详情
- (segue.destination as? GoodsDetailViewController)?.model = (sender as? QuoteCell)?.model
- }
- }
- }
- // MARK: - UITableViewDelegate, UITableViewDataSource
- extension NewQuoteViewController: UITableViewDelegate, UITableViewDataSource {
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return preGoods.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! QuoteCell
- cell.model = preGoods[indexPath.row]
- return cell
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 210.0
- }
- }
- // MARK: - QuoteCell
- class QuoteCell: BaseTableViewCell<MoGoodsInfo> {
-
- /// 商品状态
- @IBOutlet weak var status: UILabel!
- /// 商品状态
- @IBOutlet weak var statusImage: UIImageView!
- /// 倒计时
- @IBOutlet weak var timeDown: UILabel!
- /// 抢购价
- @IBOutlet weak var price: UILabel!
- /// 商品名称
- @IBOutlet weak var goodsName: UILabel!
- /// 商品图片
- @IBOutlet weak var goodsImage: UIImageView!
- /// stackView
- @IBOutlet weak var stackView: UIStackView! {
- didSet {
- stackView.layer.masksToBounds = true
- stackView.layer.cornerRadius = 7.5
- }
- }
- @IBOutlet weak var priceView: UIImageView!
-
- /// 商品数据
- override var model: MoGoodsInfo? {
- didSet {
- guard let obj = model else { return }
- /// 商品状态- 1:待审核 2:未上市 3:上市 4:已注销 5:审核拒绝 6:退市 7:待退市
- status.text = obj.goodsstatus == 3 ? "抢购中" : "预告"
- /// statusImage
- statusImage.image = UIImage(named: obj.goodsstatus == 3 ? "goods_detail_red" : "goods_detail_blue")
- /// 价格视图
- priceView.image = UIImage(named: obj.goodsstatus == 3 ? "image_blued_grident" : "image_read_grident")
- if obj.goodsstatus == 3 {
- /// 倒计时
- timeDown.attributedText = " \(DateUtils.getTDateString(obj.lasttradedate)) 结束".withTextColor(.white)
- } else {
- /// 倒计时
- timeDown.text = "\(DateUtils.getTDateString(obj.listingdate)) 上市"
- }
- /// 商品名称
- goodsName.text = obj.goodsname
- /// 抢购价
- price.text = "抢购价:\(obj.currencysign)"+obj.refprice.description
- /// 商品图片
- guard let url = StringUtils.getImageUrl(obj.picurls) else { return }
- goodsImage.sd_setImage(with: url, placeholderImage: UIImage(named: "placeholder_image"), options: .queryDiskDataSync, context: nil)
- }
- }
- }
|