//
|
// YYSpecialCarCanceledViewController.swift
|
// OKProject
|
//
|
// Created by alvin_y on 2020/9/17.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
class YYSpecialCarCanceledViewController: YYTableViewController {
|
|
let viewModel: YYSpecialCarViewModel
|
|
/// 金额
|
let cell_amount = YYAmountCell.makeByXIB()
|
|
/// 司机和行程信息栏
|
let view_travel = YYTravelInfosView.makeByXIB()
|
|
let didPressRefresh = Delegate<Void, Void>()
|
|
|
init(viewModel: YYSpecialCarViewModel) {
|
self.viewModel = viewModel
|
super.init(nibName: nil, bundle: nil)
|
}
|
|
required init?(coder aDecoder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
// Do any additional setup after loading the view.
|
}
|
|
//MARK: - UI
|
override func setupViews() {
|
super.setupViews()
|
view.backgroundColor = #colorLiteral(red: 0.9529411765, green: 0.9568627451, blue: 0.9607843137, alpha: 1)
|
tableView.backgroundColor = #colorLiteral(red: 0.9529411765, green: 0.9568627451, blue: 0.9607843137, alpha: 1)
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
view.addSubview(view_travel)
|
}
|
|
//MARK: - Layouts
|
override func defineLayouts() {
|
super.defineLayouts()
|
|
view_travel.snp.makeConstraints { (make) in
|
make.top.equalTo(topLayoutGuide.snp.bottom)
|
make.left.right.equalTo(view)
|
}
|
var height = 42 * 3
|
if viewModel.orderType.value.rawValue == 3 {
|
height = 42 * 4
|
if viewModel.dataSource.value?.remark.count ?? 0 > 0 {
|
height = 42 * 5
|
}
|
}
|
tableView.snp.remakeConstraints { (make) in
|
if #available(iOS 11.0, *) {
|
make.top.equalTo(self.view.safeAreaLayoutGuide).offset(height)
|
} else {
|
make.top.equalTo(self.view).offset(height)
|
// Fallback on earlier versions
|
}
|
make.left.equalToSuperview()
|
make.right.equalToSuperview()
|
make.bottom.equalToSuperview()
|
}
|
}
|
|
//MARK: - Rx
|
override func bindRx() {
|
super.bindRx()
|
|
viewModel.dataSource.map{value in
|
let attributedString = AttributedStringbuilder.build()
|
.add(string: "查看收费明细", withFont: UIFont.systemFont(ofSize: 12, weight: .medium), withColor: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.6)).underLine()
|
.mutableAttributedString
|
|
var cancelAttributedString = AttributedStringbuilder.build()
|
|
if value?.driverCancle == 1{
|
cancelAttributedString = cancelAttributedString.add(string: "司机取消订单", withFont: UIFont.systemFont(ofSize: 12, weight: .medium), withColor: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.6))
|
}else{
|
cancelAttributedString = cancelAttributedString.add(string: "注:司机已接单后用户取消订单费用", withFont: UIFont.systemFont(ofSize: 12, weight: .medium), withColor: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.6))
|
}
|
|
self.cell_amount.button_costRule.isHidden = value?.state == 10
|
if value?.state == 12 || value?.state == 10{
|
self.cell_amount.buttonDetailCons.constant = 0
|
}
|
return value?.state == 10 ? cancelAttributedString.mutableAttributedString : attributedString
|
|
}.bind(to: cell_amount.button_detail.rx.attributedTitle())
|
.disposed(by: disposeBag)
|
|
|
viewModel.dataSource.map{value in
|
return value?.state == 10 ? false : true
|
}.bind(to: cell_amount.button_detail.rx.isUserInteractionEnabled)
|
.disposed(by: disposeBag)
|
|
/// 司机信息
|
viewModel.dataSource
|
.subscribe(onNext: { [unowned self] (dataSource) in
|
self.view_travel.configure(for: dataSource)
|
guard let data = dataSource else {return}
|
if data.state == 9 || data.state == 8{
|
self.cell_amount.label_payDescribe.isHidden = false
|
self.cell_amount.label_amount.text = "¥\(data.payMoney.remain2Digits())"
|
self.cell_amount.label_amount.isHidden = data.payMoney == 0
|
}
|
else if data.state == 10{
|
self.cell_amount.label_payDescribe.isHidden = true
|
self.cell_amount.label_amount.text = "¥\(data.cancelPayMoney.remain2Digits())"
|
self.cell_amount.label_amount.isHidden = data.cancelPayMoney == 0
|
}
|
else{
|
self.cell_amount.label_payDescribe.isHidden = false
|
self.cell_amount.label_amount.text = "¥\(data.orderMoney.remain2Digits())"
|
self.cell_amount.label_amount.isHidden = data.orderMoney == 0
|
}
|
})
|
.disposed(by: disposeBag)
|
|
|
/// 订单详情
|
cell_amount.button_detail.rx.tap
|
.subscribe(onNext: {[unowned self] (_) in
|
let vc = YYCostDetailViewController.init(orderId: self.viewModel.orderId.value, orderType: self.viewModel.orderType.value)
|
self.yy_push(vc: vc)
|
})
|
.disposed(by: disposeBag)
|
|
cell_amount.button_costRule.rx.tap.subscribe(onNext: { [unowned self] (_) in
|
guard let model = self.viewModel.dataSource.value else { return }
|
let vc = ValuationRuleVC()
|
vc.model = model
|
switch model.rideType {
|
case 1:vc.type = 11
|
case 2:vc.type = 12
|
case 3:vc.type = 10
|
default:vc.type = 10
|
}
|
self.yy_push(vc: vc)
|
}) { error in
|
|
}.disposed(by: disposeBag)
|
|
|
view_travel.button_call
|
.rx.tap
|
.subscribe(onNext: {[unowned self] (_) in
|
guard let phone = self.viewModel.dataSource.value?.driverPhone else {return}
|
call(number: phone)
|
})
|
.disposed(by: disposeBag)
|
|
view_travel.button_avatar.rx.tap
|
.subscribe(onNext: {[unowned self] (_) in
|
guard let driverId = self.viewModel.dataSource.value?.driverId else{return}
|
let vc = DriverInfoVC(driverId: driverId)
|
self.yy_push(vc: vc)
|
})
|
.disposed(by: disposeBag)
|
}
|
|
|
}
|
extension YYSpecialCarCanceledViewController: UITableViewDataSource {
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
return 1
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return 1
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
return cell_amount
|
}
|
}
|
|
extension YYSpecialCarCanceledViewController: UITableViewDelegate {
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return UITableView.automaticDimension
|
}
|
}
|