//
|
// HomeDetailContentVC.swift
|
// BrokerDriver
|
//
|
// Created by 无故事王国 on 2023/4/25.
|
//
|
|
import UIKit
|
import FFPage
|
|
class HomeDetailContentVC: BaseViewController {
|
|
@IBOutlet weak var scrollView: UIScrollView!
|
@IBOutlet weak var cargoTableview: UITableView!
|
@IBOutlet weak var cargoTableHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var label_type: UILabel!
|
@IBOutlet weak var label_id: UILabel!
|
@IBOutlet weak var icon_id: UIImageView!
|
@IBOutlet weak var contentTableView: UITableView!
|
@IBOutlet weak var contentTableHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var label_BLN: UILabel!
|
@IBOutlet weak var label_status: UILabel!
|
@IBOutlet weak var view_btn: UIView!
|
|
var adapterViewController:FFAdapterViewController!
|
|
private(set) var orderId:String!
|
private(set) var style:HomePageVC.PageStyle!
|
private var model:OrderDetailModel?{
|
didSet{
|
if let m = model{
|
label_type.text = m.orderType
|
label_id.text = m.orderId
|
icon_id.image = m.status.transImage
|
label_BLN.text = "B/L OR AWB NO.:\(m.tGoods?.containerNumber ?? "")"
|
label_status.text = m.nextStatus.transStr
|
contentTableView.reloadData()
|
cargoTableview.reloadData()
|
view_btn.isHidden = m.status == .Complete
|
|
|
var startCoordinate:CLLocationCoordinate2D?
|
var endCoordinate:CLLocationCoordinate2D?
|
|
if m.lat != 0 && m.lon != 0 {
|
startCoordinate = CLLocationCoordinate2D(latitude: m.lat, longitude: m.lon)
|
}
|
|
if m.eLat != 0 && m.eLon != 0{
|
endCoordinate = CLLocationCoordinate2D(latitude: m.eLat, longitude: m.eLon)
|
}
|
|
let tuple = (startCoordinate,endCoordinate)
|
NotificationCenter.default.post(name: UpdateMap_Noti, object: tuple)
|
}
|
}
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
view.backgroundColor = .color("#F9FAFF")
|
}
|
|
override func setUI() {
|
super.setUI()
|
cargoTableview.delegate = self
|
cargoTableview.dataSource = self
|
contentTableView.delegate = self
|
contentTableView.dataSource = self
|
cargoTableview.isScrollEnabled = false
|
contentTableView.isScrollEnabled = false
|
cargoTableview.separatorStyle = .none
|
contentTableView.separatorStyle = .none
|
scrollView.delegate = self
|
|
contentTableView.register(UINib(nibName: "HomeDetailContentTCell", bundle: nil), forCellReuseIdentifier: "_HomeDetailContentTCell")
|
cargoTableview.register(UINib(nibName: "CargoInfoTCell", bundle: nil), forCellReuseIdentifier: "_CargoInfoTCell")
|
cargoTableview.register(UINib(nibName: "CargoTableHeaderView", bundle: nil), forHeaderFooterViewReuseIdentifier: "_CargoTableHeaderView")
|
cargoTableHeiCons.constant = 55 * 5.0 + 45.0
|
|
// footviewHeiCons.constant = UIDevice.jq_safeEdges.bottom + 44.0
|
|
getData()
|
}
|
|
required init(orderId:String,style:HomePageVC.PageStyle) {
|
super.init(nibName: nil, bundle: nil)
|
self.orderId = orderId
|
self.style = style
|
}
|
|
override func setRx() {
|
|
}
|
|
private func getData(){
|
Services.orderInfo(id: orderId, type:style).subscribe(onNext: { [weak self] data in
|
if let model = data.data{
|
self?.model = model
|
}
|
}) { error in
|
|
}.disposed(by: disposeBag)
|
}
|
|
|
override func viewDidLayoutSubviews() {
|
super.viewDidLayoutSubviews()
|
contentTableView.rx.observe(CGSize.self,"contentSize").subscribe(onNext: {[weak self] contentSize in
|
self?.contentTableHeiCons.constant = contentSize?.height ?? 0
|
}).disposed(by: disposeBag)
|
}
|
|
@IBAction func tapAction(_ sender: UIButton) {
|
//到达码头:提示上传
|
//运输中:上传POD
|
//运回码头:提示上传
|
guard let m = model else { return }
|
if m.nextStatus == .ArrivedPort{
|
CommonAlertView.show(title: "Prompt!", content: "You need to upload gate out ticket", bt1: "Not upload yet", bt2: "To upload") { [weak self] in
|
AttachTypeView.show(orderId: m.orderId) {
|
self?.changeStatus(orderId: m.orderId)
|
}
|
}
|
} else if m.nextStatus == .Transiting{
|
CommonAlertView.show(title: "Prompt!", content: "You need to upload POD", bt1: "Not upload yet", bt2: "To upload") { [weak self] in
|
AttachTypeView.show(orderId: m.orderId) {
|
self?.changeStatus(orderId: m.orderId)
|
}
|
}
|
}else if m.nextStatus == .BackYard{
|
CommonAlertView.show(title: "Prompt!", content: "You need to upload gate in ticket", bt1: "Not upload yet", bt2: "To upload") { [weak self] in
|
AttachTypeView.show(orderId: m.orderId) {
|
self?.changeStatus(orderId: m.orderId)
|
}
|
}
|
}else{
|
changeStatus(orderId: orderId)
|
}
|
}
|
|
private func changeStatus(orderId:String){
|
Services.nextStatus(id: orderId).subscribe(onNext: { data in
|
if data.code == 200{
|
self.getData()
|
//Update Home data status.
|
NotificationCenter.default.post(name: RefreshHomePage_Noti, object: true)
|
}else{
|
alert(msg: data.msg)
|
}
|
}) { error in
|
alert(msg: error.localizedDescription)
|
}.disposed(by: disposeBag)
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
}
|
|
extension HomeDetailContentVC:UIScrollViewDelegate{
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
|
let totalHeight = adapterViewController.headHeight
|
let offset = totalHeight - scrollView.contentOffset.y
|
let isTop = (offset - topSafeHeight) < 0
|
|
if scrollView.contentOffset.y > 0 && !isTop{
|
adapterViewController.scrollview.contentOffset = scrollView.contentOffset
|
}
|
}
|
}
|
|
extension HomeDetailContentVC:UITableViewDelegate{
|
|
}
|
|
extension HomeDetailContentVC:UITableViewDataSource{
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
if cargoTableview == tableView{
|
let headView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "_CargoTableHeaderView") as? CargoTableHeaderView
|
return headView
|
}
|
return nil
|
}
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
if cargoTableview == tableView{
|
return 45.0
|
}
|
return 0.001
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
if cargoTableview == tableView{
|
return 1
|
}
|
return model?.list.count ?? 0
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
if cargoTableview == tableView{
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_CargoInfoTCell") as! CargoInfoTCell
|
cell.l1.text = model?.tGoods?.containerNumber ?? ""
|
cell.l2.text = "\(model?.tGoods?.weight ?? 0)"
|
cell.l3.text = model?.tGoods?.size ?? ""
|
cell.l4.text = String(format: "%@\n%@", model?.tGoods?.type ?? "" ,model?.tGoods?.typeClass ?? "")
|
return cell
|
}
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_HomeDetailContentTCell") as! HomeDetailContentTCell
|
if let dict = model?.list[indexPath.row]{
|
cell.dicts = dict
|
}
|
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
if cargoTableview == tableView{
|
return 50
|
}
|
return UITableView.automaticDimension
|
}
|
}
|