//
|
// MineWalletVC.swift
|
// OKProject
|
//
|
// Created by alvin_y on 2020/6/16.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
/// 我的钱包
|
class MineWalletVC: YYViewController {
|
|
/// 充值
|
@IBOutlet weak var button_topUp: YYButton!
|
|
/// UITableView
|
@IBOutlet weak var tableView: UITableView!
|
|
/// 余额
|
@IBOutlet weak var label_balance: UILabel!
|
|
/// 授信余额
|
@IBOutlet weak var label_credit_balance: UILabel!
|
|
//提现
|
@IBOutlet weak var btn_withfraw: UIButton!
|
|
//申请
|
@IBOutlet weak var btn_apply: UIButton!
|
|
/// 余额描述
|
// @IBOutlet weak var label_balanceDesc: UILabel!
|
|
/// 数据源
|
private let dataSource = ["消费记录","打车红包","企业额度"]
|
private var viewModel = EnterpriseViewModel()
|
private var model:EnterpriseInfoModel?{
|
didSet{
|
tableView.reloadData()
|
}
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
let attribute1 = NSAttributedString(string: "提现", attributes: [NSAttributedString.Key.underlineStyle:1])
|
btn_withfraw.setAttributedTitle(attribute1, for: .normal)
|
|
let attribute2 = NSAttributedString(string: "申请", attributes: [NSAttributedString.Key.underlineStyle:1])
|
btn_apply.setAttributedTitle(attribute2, for: .normal)
|
getData()
|
}
|
|
override func viewWillAppear(_ animated: Bool) {
|
super.viewWillAppear(animated)
|
label_balance.text = "\(app.userInfo.balance.remain2Digits())"
|
label_credit_balance.text = "\(app.userInfo.balanceQuota.remain2Digits())"
|
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.color(light: UIColor.color(hexString: "#000000"), dark: UIColor.color(hexString: "#FFFFFF")),NSAttributedString.Key.font: UIFont.init(name: Medium, size: 18) ?? UIFont.systemFont(ofSize: 18)]
|
self.navigationController?.navigationBar.barTintColor = UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#191919"))
|
self.navigationController?.navigationBar.barTintColor = ThemeColor
|
}
|
|
override func viewWillDisappear(_ animated: Bool) {
|
super.viewWillDisappear(animated)
|
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.color(light: UIColor.color(hexString: "#000000"), dark: UIColor.color(hexString: "#FFFFFF")),NSAttributedString.Key.font: UIFont.init(name: Medium, size: 18) ?? UIFont.systemFont(ofSize: 18)]
|
self.navigationController?.navigationBar.barTintColor = UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#191919"))
|
}
|
|
override func viewDidAppear(_ animated: Bool) {
|
super.viewDidAppear(animated)
|
label_balance.text = app.userInfo.balance.remain2Digits()
|
label_credit_balance.text = app.userInfo.balanceQuota.remain2Digits()
|
}
|
|
//MARK: - UI
|
override func setupViews() {
|
super.setupViews()
|
navigationItem.title = "钱包"
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.tableFooterView = UIView()
|
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "item")
|
tableView.separatorColor = UIColor.color(light: UIColor.color(hexString: "#F6F6F6"), dark: UIColor.color(hexString: "#F6F6F6"))
|
}
|
|
private func getData(){
|
viewModel.queryEnterpriseInfo { status in
|
switch status{
|
case .success(let m):
|
self.model = m
|
|
case .error(let error):break
|
}
|
}
|
}
|
|
//MARK: - Rx
|
override func bindRx() {
|
super.bindRx()
|
button_topUp.rx.tap.subscribe(onNext: {[unowned self] (_) in
|
let vc = MineTopUpVC()
|
self.yy_push(vc: vc)
|
}).disposed(by: disposeBag)
|
}
|
|
@IBAction func withdrawAction(_ sender: Any) {
|
let vc = MineWithdrawalVC()
|
self.yy_push(vc: vc)
|
}
|
|
@IBAction func applyAction(_ sender: Any) {
|
guard let m = model else {
|
alert(text: "数据获取失败,请稍候")
|
getData()
|
return
|
}
|
|
switch m.authStatus{
|
case .Pass:
|
let vc = MineCreditApplyVC()
|
self.yy_push(vc: vc)
|
case .Pending:
|
alert(popup: .single, title: "提示", text: "请先进行企业认证", submitTitle: "确定",cancelTitle: nil) {
|
|
} cancelClick: {
|
|
}
|
case .Reject:
|
alert(popup: .single, title: "提示", text: "企业认证审核失败,请重新提交", submitTitle: "确定",cancelTitle: nil) {
|
|
} cancelClick: {
|
|
}
|
case .none:break
|
case .Review:
|
alert(popup: .single, title: "提示", text: "请耐心等待,审核通过后会通过短信的形式通知", submitTitle: "确定",cancelTitle: nil) {
|
|
} cancelClick: {
|
|
}
|
}
|
|
}
|
}
|
|
// MARK: - UITableViewDelegate
|
extension MineWalletVC:UITableViewDelegate{
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 50
|
}
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
tableView.deselectRow(at: indexPath, animated: true)
|
switch dataSource[indexPath.row] {
|
case "消费记录":
|
let vc = MineExpenseRecordVC()
|
self.yy_push(vc: vc)
|
break
|
case "打车红包":
|
let vc = MineTripRedEnvelopeVC()
|
self.yy_push(vc: vc)
|
break
|
case "企业额度":
|
let vc = MineBusinessCreditVC()
|
self.yy_push(vc: vc)
|
default:
|
break
|
}
|
}
|
}
|
|
// MARK: - UITableViewDelegate
|
extension MineWalletVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
if model == nil{
|
return 2
|
}
|
return dataSource.count
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "item", for: indexPath)
|
cell.textLabel?.text = dataSource[indexPath.row]
|
cell.textLabel?.font = Medium(font: 14)
|
cell.textLabel?.textColor = UIColor.color(light: UIColor.color(hexString: "#333333"), dark: UIColor.color(hexString: "#333333"))
|
cell.separatorInset = UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14)
|
cell.accessoryType = .disclosureIndicator
|
return cell
|
}
|
}
|