younger_times
2023-04-27 117f96b4de283cd6f1896d17d8027094113435a2
BrokerDriver/Home/VC/HomeDetailContentVC.swift
@@ -11,6 +11,29 @@
    @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 cargoTableView: UIView!
    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 ?? "")"
                contentTableView.reloadData()
                cargoTableview.reloadData()
            }
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
@@ -22,12 +45,49 @@
        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
        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
        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)
    }
    required init(orderId:String,style:HomePageVC.PageStyle) {
        super.init(nibName: nil, bundle: nil)
        self.orderId = orderId
        self.style = style
    }
    override func setRx() {
    }
    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)
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
@@ -38,24 +98,49 @@
extension HomeDetailContentVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "_CargoTableHeaderView") as? CargoTableHeaderView
        return headView
        if cargoTableview == tableView{
            let headView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "_CargoTableHeaderView") as? CargoTableHeaderView
            return headView
        }
        return nil
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 45.0
        if cargoTableview == tableView{
            return 45.0
        }
        return 0.001
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
        if cargoTableview == tableView{
            return 1
        }
        return model?.list.count ?? 0
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "_CargoInfoTCell") as! CargoInfoTCell
        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 {
        return 50
        if cargoTableview == tableView{
            return 50
        }
        return UITableView.automaticDimension
    }
}