//
|
// TaxiOrderDetailsVC.swift
|
// OKProject
|
//
|
// Created by alvin_y on 2020/6/13.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import RxSwift
|
import RxCocoa
|
/// 出租车订单详情
|
class TaxiOrderDetailsVC: YYViewController {
|
|
/// 地图
|
private let mapView = MAMapView()
|
|
/// viewModel
|
let viewModel = TravelServiceViewModel()
|
|
/// 用户点数据
|
private var pointArray: [PointAnnotation] = []
|
|
/// 折线数据
|
private var lineCoordinates: [CLLocationCoordinate2D] = []
|
|
/// 评价信息
|
private let view_info = TaxiOrderDetailsView.instance()
|
|
init(orderId: Int,orderType: OrderType) {
|
super.init(nibName: nil, bundle: nil)
|
viewModel.orderId.accept(orderId)
|
viewModel.orderType.accept(orderType)
|
|
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
// Do any additional setup after loading the view.
|
viewModel.queryTrack()
|
viewModel.queryOrderInfo()
|
}
|
|
//MARK: - UI
|
override func setupViews() {
|
super.setupViews()
|
navigationItem.title = "订单详情"
|
navigationItem.rightBarButtonItem = UIBarButtonItem.yy_creat(title: "开发票", target: self, action: #selector(invoice)).item
|
mapView.showsUserLocation = false // YES 为打开定位,NO为关闭定位
|
mapView.isRotateEnabled = false
|
mapView.isRotateCameraEnabled = false
|
mapView.showsCompass = false
|
mapView.showsScale = false
|
mapView.delegate = self
|
mapView.zoomLevel = 17
|
mapView.mapType = .standard
|
view.addSubview(mapView)
|
view.addSubview(view_info)
|
|
}
|
|
//MARK: - Layouts
|
override func defineLayouts() {
|
super.defineLayouts()
|
mapView.snp.makeConstraints { (make) in
|
make.edges.equalToSuperview()
|
}
|
view_info.snp.makeConstraints { (make) in
|
make.left.right.bottom.equalToSuperview()
|
}
|
}
|
|
/// 开发票
|
@objc func invoice()
|
{
|
// let vc = InvoiceApplyViewController(orderId: viewModel.orderId.value)
|
let vc = InvoiceViewController()
|
yy_push(vc: vc)
|
}
|
|
//MARK: - Rx
|
override func bindRx() {
|
super.bindRx()
|
|
view_info.didPressEvaluation.delegate(on: self) { (self, arge) in
|
let (score,tags) = arge
|
self.viewModel.fraction.accept(Int(score))
|
self.viewModel.content.accept(tags)
|
self.viewModel.orderEvaluate()
|
}
|
|
view_info.didPressMore.delegate(on: self) { (self, _) in
|
let vc = YYCostDetailViewController.init(orderId: self.viewModel.orderId.value, orderType: self.viewModel.orderType.value)
|
self.yy_push(vc: vc)
|
}
|
|
// 评价订单
|
viewModel.evaluateSubject
|
.subscribeOn(MainScheduler.instance)
|
.subscribe(onNext: { [unowned self](status) in
|
switch status{
|
case .loading:
|
self.show()
|
break
|
case .success(_ ):
|
self.hide()
|
alert(text: "评价成功")
|
NotificationCenter.default.post(name: NSNotification.Name.init(YYOrderListRefresh), object: nil)
|
self.viewModel.queryOrderInfo()
|
// 查询是否有红包
|
self.viewModel.queryRedMoney()
|
break
|
case .error(let error):
|
self.hide()
|
alert(text: error.localizedDescription)
|
break
|
}
|
}).disposed(by: disposeBag)
|
|
// 查询是否有红包
|
viewModel.queryRedMoneySubject
|
.subscribeOn(MainScheduler.instance)
|
.subscribe(onNext: { [unowned self](status) in
|
switch status{
|
case .loading:
|
self.show()
|
break
|
case .success(let model):
|
self.hide()
|
if let data = model as? CancleAmountModel{
|
if data.amount != 0{
|
alert(popup: .double, title: "提示", text: "分享APP给好友可以获得\(data.amount)元打车红包", submitTitle: "去分享", cancelTitle: "不分享", submitClick: {[unowned self] in
|
// 弹出分享框
|
ShareView.share(controller: self, title: nil, content: "新版“宽窄优行”隆重上线,下载注册即送打车券。", url: "\(share_url)/share/shareIndex.html?uid=\(app.userInfo.id)&type=1",hiddenMessage: true).show(success: {
|
self.viewModel.shareRedEnvelope()
|
})
|
}) {}
|
}
|
}
|
break
|
case .error(let error):
|
self.hide()
|
alert(text: error.localizedDescription)
|
break
|
}
|
}).disposed(by: disposeBag)
|
|
|
viewModel.track
|
.observeOn(MainScheduler.instance)
|
.subscribe(onNext: { (data) in
|
for item in data{
|
let point = CLLocationCoordinate2D.init(latitude: item.lat, longitude: item.lon)
|
self.lineCoordinates.append(point)
|
}
|
if self.lineCoordinates.count > 0{
|
let polyline = MAPolyline(coordinates: &self.lineCoordinates, count: UInt(self.lineCoordinates.count))!
|
self.mapView.add(polyline)
|
self.mapView.showOverlays([polyline], animated: true)
|
}
|
}).disposed(by: disposeBag)
|
|
|
/// 更新行程信息
|
viewModel.data
|
.subscribeOn(MainScheduler.instance)
|
.subscribe(onNext: {[unowned self] (r) in
|
guard let model = r else {return}
|
self.view_info.configure(data: model)
|
/// 加入起点
|
let startPointAnnotation = PointAnnotation()
|
startPointAnnotation.coordinate = CLLocationCoordinate2DMake(model.startLat, model.startLon)
|
startPointAnnotation.title = nil
|
startPointAnnotation.type = 3
|
self.pointArray.append(startPointAnnotation)
|
|
/// 加入终点
|
let destinationAnnotation = PointAnnotation()
|
destinationAnnotation.coordinate = CLLocationCoordinate2DMake(model.endLat, model.endLon)
|
destinationAnnotation.title = nil
|
destinationAnnotation.type = 4
|
self.pointArray.append(destinationAnnotation)
|
self.mapView.addAnnotations(self.pointArray)
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
self.mapView.showAnnotations(self.pointArray, edgePadding: UIEdgeInsets(top: navH + 20, left: 10, bottom: 350, right: 10), animated: true)
|
}
|
}).disposed(by: disposeBag)
|
}
|
}
|
//MARK: - MAMapViewDelegate
|
extension TaxiOrderDetailsVC: MAMapViewDelegate
|
{
|
func mapView(_ mapView: MAMapView!, regionDidChangeAnimated animated: Bool) {
|
|
}
|
|
func mapView(_ mapView: MAMapView!, mapDidMoveByUser wasUserAction: Bool) {
|
|
}
|
|
func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
|
if annotation.isKind(of: PointAnnotation.classForCoder()) {
|
let annotation = annotation as! PointAnnotation
|
var imageName: String = ""
|
let identifier = "annotation"
|
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? UserAnnotationView
|
if annotationView == nil{
|
annotationView = UserAnnotationView(annotation: annotation, reuseIdentifier: identifier)
|
}
|
switch annotation.type {
|
// 开始位置
|
case 1:
|
imageName = "icon_location"
|
annotationView?.yy_tintColor = UIColor.color(hexString: "#E30B0B")
|
annotationView?.yy_isTintColor = true
|
annotationView?.yy_font = UIFont.init(name: Medium, size: 14)!
|
case 2:// 车辆位置
|
imageName = "car"
|
case 3:// 起点位置
|
imageName = "starting_point"
|
case 4:// 终点位置
|
imageName = "end_point"
|
case 5: // 修改起点位置
|
imageName = "starting_point"
|
annotationView?.yy_font = UIFont.init(name: Medium, size: 14)!
|
case 6://司机位置
|
imageName = "bus_location"
|
default:
|
return nil
|
}
|
let image = UIImage(named: imageName)
|
annotationView?.image = image
|
if annotation.title != nil{
|
annotationView?.title = annotation.title
|
}
|
return annotationView
|
|
}
|
return nil
|
}
|
|
func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! {
|
let renderer: MAPolylineRenderer = MAPolylineRenderer(overlay: overlay)
|
renderer.lineWidth = 6.0
|
renderer.strokeColor = UIColor.color(hexString: "#00C47A")
|
return renderer
|
}
|
|
|
}
|