//
|
// HomeDetailAttachVC.swift
|
// BrokerDriver
|
//
|
// Created by 无故事王国 on 2023/4/25.
|
//
|
|
import UIKit
|
import RxSwift
|
import RxRelay
|
import JQTools
|
import FFPage
|
|
let RefresgDetailAttach_Noti = Notification.Name.init("RefresgDetailAttach_Noti")
|
|
class HomeDetailAttachVC: BaseViewController,Refreshable {
|
|
@IBOutlet weak var attachTableView: BaseTableView!
|
private(set) var orderId:String!
|
public let refreshStatus = BehaviorSubject(value: RefreshStatus.others)
|
private var page = 1
|
private var datas = [AttachmentRecordModel]()
|
var adapterViewController:FFAdapterViewController!
|
|
struct AttachmentType:HandyJSON {
|
var orderId = ""
|
var file = ""
|
var name = ""
|
var category:RecordEnum = .none
|
}
|
|
required init(orderId:String) {
|
super.init(nibName: nil, bundle: nil)
|
self.orderId = orderId
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
view.jq_height = 1000
|
view.backgroundColor = UIColor(hexStr: "#F9FAFF")
|
attachTableView.delegate = self
|
attachTableView.dataSource = self
|
attachTableView.separatorStyle = .none
|
attachTableView.register(UINib(nibName: "AttachHeadView", bundle: nil), forHeaderFooterViewReuseIdentifier: "_AttachHeadView")
|
attachTableView.register(UINib(nibName: "AttachTCell", bundle: nil), forCellReuseIdentifier: "_AttachTCell")
|
|
self.refreshStatusBind(to: attachTableView, header: { [weak self] () in
|
self?.getData()
|
}, footer: { [weak self] () in
|
self?.getData(false)
|
}).disposed(by: disposeBag)
|
|
attachTableView.jq_setEmptyView("Not data", image: UIImage(named: "empty"), foregroundColor: .gray, clouse: nil)
|
|
DispatchQueue.main.asyncAfter(deadline: .now()+0.2) {
|
self.refreshStatus.onNext(.beingHeaderRefresh)
|
}
|
}
|
|
override func setRx() {
|
NotificationCenter.default.rx.notification(RefresgDetailAttach_Noti, object: nil).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in
|
self?.refreshStatus.onNext(.beingHeaderRefresh)
|
}) { error in
|
|
}.disposed(by: disposeBag)
|
}
|
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
let totalHeight = adapterViewController?.headHeight ?? 0
|
let offset = totalHeight - scrollView.contentOffset.y
|
let isTop = (offset - topSafeHeight) < 0
|
if scrollView.contentOffset.y >= 0 {
|
if isTop{
|
print("-->1")
|
adapterViewController?.scrollview.contentOffset = CGPoint(x: 0, y: totalHeight - topSafeHeight)
|
}else if scrollView.contentOffset.y <= 0{
|
print("-->2")
|
adapterViewController?.scrollview.setContentOffset(.zero, animated: true)
|
}else{
|
print("-->3")
|
adapterViewController?.scrollview.contentOffset = scrollView.contentOffset
|
}
|
}
|
}
|
|
private func getData(_ isHeader:Bool = true){
|
|
if isHeader{
|
page = 1
|
}else{
|
page += 1
|
}
|
|
Services.orderAttachment(id: orderId, page: page).subscribe(onNext: { data in
|
if let model = data.data{
|
if isHeader{
|
self.datas.removeAll()
|
self.refreshStatus.onNext(.endHeaderRefresh)
|
self.refreshStatus.onNext(.resetNoMoreData)
|
}else{
|
if model.records.count == 0{
|
self.refreshStatus.onNext(.noMoreData)
|
}else{
|
self.refreshStatus.onNext(.endFooterRefresh)
|
}
|
}
|
self.datas.append(contentsOf: model.records)
|
self.attachTableView.reloadData()
|
}
|
}) { error in
|
alert(msg: error.localizedDescription)
|
self.refreshStatus.onNext(.endFooterRefresh)
|
self.refreshStatus.onNext(.endHeaderRefresh)
|
}.disposed(by: disposeBag)
|
}
|
|
@IBAction func addAttachmentAction(_ sender: UIButton) {
|
AttachTypeView.show(orderId: orderId) {[weak self] ()in
|
self?.refreshStatus.onNext(.beingHeaderRefresh)
|
}
|
}
|
}
|
|
|
extension HomeDetailAttachVC:UITableViewDelegate{
|
|
}
|
|
extension HomeDetailAttachVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return datas.count
|
}
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
let headView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "_AttachHeadView") as? AttachHeadView
|
return headView
|
}
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
return 46
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let data = datas[indexPath.row]
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_AttachTCell") as! AttachTCell
|
cell.recordModel = data
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 46
|
}
|
}
|