宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-06-01 60a5e5d29ea3a7c63bc5acc9052a656821127ab9
OKProject/Class/Home/View/OrderReviewTCell.swift
@@ -9,6 +9,68 @@
import UIKit
class OrderReviewTCell: UITableViewCell {
    @IBOutlet weak var label_datetime: UILabel!
    @IBOutlet weak var label_state: UILabel!
    @IBOutlet weak var label_useTime: UILabel!
    @IBOutlet weak var label_useDatetime: UILabel!
    @IBOutlet weak var btn_detail: UIButton!
    @IBOutlet weak var label_useRequire: UILabel!
    var viewModel:TravelServiceViewModel?
    var orderReviewModel:OrderReviewModel!{
        didSet{
            label_useRequire.text = "用车要求:" + orderReviewModel.serverCardName
            label_datetime.text = orderReviewModel.insertTime
            label_state.text = orderReviewModel.auditStatus.rawStr
            switch orderReviewModel.auditStatus{
            case .review:
                label_state.text = "待处理"
                label_state.textColor = UIColor(hexString: "#45B494")
            case .reject:
                label_state.text = "已拒绝"
                label_state.textColor = UIColor.red
            case .pass:
                label_state.text = "已处理"
                label_state.textColor = UIColor(hexString: "#626262")
            default:break
            }
            label_useTime.isHidden  = (orderReviewModel.useDay == 0 && orderReviewModel.useHour == 0)
            label_useDatetime.text = "用车时间:" + orderReviewModel.useTime
            label_useTime.text = String(format: "用车时长:%ld天%ld时", orderReviewModel.useDay,orderReviewModel.useHour)
        }
    }
    var taxiOrderModel:TaxiOrderModel!{
        didSet{
            label_useRequire.text = "用车要求:" + taxiOrderModel.serverCarModel
            label_datetime.text = taxiOrderModel.orderTime
            label_state.text = taxiOrderModel.auditStatus.rawStr
            switch taxiOrderModel.auditStatus{
            case .review:
                label_state.text = "待处理"
                label_state.textColor = UIColor(hexString: "#45B494")
                btn_detail.setTitle("取消订单", for: .normal)
            case .reject:
                label_state.text = "已拒绝"
                label_state.textColor = UIColor.red
                btn_detail.setTitle("详情", for: .normal)
            case .pass:
                label_state.text = "已处理"
                label_state.textColor = UIColor(hexString: "#626262")
                btn_detail.setTitle("详情", for: .normal)
            default:break
            }
            label_useTime.isHidden  = (taxiOrderModel.useDay == 0 && taxiOrderModel.useHour == 0)
            label_useDatetime.text = "用车时间:" + taxiOrderModel.useTime
            label_useTime.text = String(format: "用车时长:%ld天%ld时", taxiOrderModel.useDay,taxiOrderModel.useHour)
        }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
@@ -16,7 +78,59 @@
    }
    @IBAction func detailAction(_ sender: UIButton) {
        let detailVC = OrderReviewDetailVC()
        if sender.titleLabel?.text == "取消订单"{
            alert(popup: .double, title: "提示", text: "您确定要取消该订单吗?", submitTitle: "确定取消", cancelTitle: "不取消", submitClick: { [weak self]  in
                guard let self = self else{return}
                self.viewModel = TravelServiceViewModel()
                self.viewModel?.cancleOrderTaxiSubject.subscribe(onNext: { status in
                    switch status{
                    case .success(_):
                        NotificationCenter.default.post(name: OrderReviewRefresh_Noti, object: nil)
                    case .error(let error):
                        alert(text: error.localizedDescription)
                    case .loading:break
                    }
                }, onError: { error in
                    alert(text: error.localizedDescription)
                }).disposed(by: self.rx.disposeBag)
                self.viewModel?.addCancleSubject.subscribe(onNext: { status in
                    switch status{
                    case .success(_):self.viewModel!.cancleOrderTaxi()
                    case .error(let error):
                        alert(text: error.localizedDescription)
                    case .loading:break
                    }
                }, onError: { error in
                    alert(text: error.localizedDescription)
                }).disposed(by: self.rx.disposeBag)
                self.viewModel!.orderId.accept(self.taxiOrderModel.orderId)
                self.viewModel!.orderType.accept(OrderType(rawValue: self.taxiOrderModel.orderType)!)
                self.viewModel!.addCancle()
            }){}
            return
        }
        var id:Int!
        if taxiOrderModel != nil {
            id = taxiOrderModel.orderId
        }
        if orderReviewModel != nil{
            id = orderReviewModel.id
        }
        let detailVC = OrderReviewDetailVC(id:id)
        LD_currentNavigationController().pushViewController(detailVC)
    }
}