//
|
// MerchantListVC.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2022/2/14.
|
// Copyright © 2022 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import RxSwift
|
|
|
class MerchantListVC: YYTableViewController {
|
|
let viewModel = MerchantViewModel()
|
let customerViewModel = MineContactCustomerServiceViewModel()
|
var type:ActiveStatus = .ongoing
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
view.backgroundColor = UIColor(hexString: "#F3F4F5")
|
viewModel.orderType.accept(type)
|
customerViewModel.queryCustomerPhone()
|
}
|
|
override func viewDidAppear(_ animated: Bool) {
|
super.viewDidAppear(animated)
|
tableView.beginRefreshing()
|
}
|
|
//MARK: - UI
|
override func setupViews() {
|
super.setupViews()
|
tableView.separatorStyle = .none
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.register(cellName: "MerchantCouponTCell", identifier: "_MerchantCouponTCell")
|
viewModel.configure(tableView: tableView)
|
// tableView.beginRefreshing()
|
emptyImage = UIImage(named: "empty_data")
|
emptyTitleColor = UIColor.black
|
emptyTitle = "您还没有优惠券信息\n您可以和平台联系,建立合作哦~\n平台电话:"
|
}
|
|
|
//MARK: - Layouts
|
override func defineLayouts() {
|
super.defineLayouts()
|
tableView.snp.remakeConstraints { (make) in
|
make.edges.equalToSuperview()
|
}
|
}
|
|
//MARK: - Rx
|
override func bindRx() {
|
super.bindRx()
|
|
customerViewModel.requestSubject
|
.subscribe(onNext: {[unowned self] (status) in
|
switch status{
|
case .loading:break
|
case .success(_):
|
self.emptyTitle = "您还没有优惠券信息\n您可以和平台联系,建立合作哦~\n平台电话:\(customerViewModel.platform.value)"
|
self.tableView.reloadData()
|
break
|
case .error(_):
|
break
|
}
|
}).disposed(by: rx.disposeBag)
|
}
|
|
@objc func recordAction(_ btn:UIButton){
|
let m = viewModel.dataSource.value[btn.tag - 10]
|
let vc = MerchantCouponRecordVC()
|
vc.id = m.id
|
vc.activityId = m.activityId
|
yy_push(vc: vc)
|
}
|
}
|
|
|
// MARK: - UITableViewDelegate
|
extension MerchantListVC:UITableViewDelegate{
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return UITableView.automaticDimension
|
}
|
}
|
|
// MARK: - UITableViewDelegate
|
extension MerchantListVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return viewModel.dataSource.value.count
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let m = viewModel.dataSource.value[indexPath.row]
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_MerchantCouponTCell", for: indexPath) as! MerchantCouponTCell
|
cell.selectionStyle = .none
|
cell.contentView.backgroundColor = .clear
|
cell.backgroundColor = .clear
|
cell.type = type
|
cell.merchantCouponModel = m
|
cell.recordBtn.tag = 10 + indexPath.row
|
cell.checkImg.isHidden = true
|
cell.invaildImg.isHidden = true
|
cell.recordBtn.addTarget(self, action: #selector(recordAction(_:)), for: .touchUpInside)
|
return cell
|
}
|
}
|