Commit c8fa828f authored by pete谢兆麟's avatar pete谢兆麟

bug修复

parent 58413931
...@@ -14,6 +14,10 @@ class YHMakePlanViewController: YHBaseViewController { ...@@ -14,6 +14,10 @@ class YHMakePlanViewController: YHBaseViewController {
lazy var headView: YHMakePlanHeadView = { lazy var headView: YHMakePlanHeadView = {
let view = YHMakePlanHeadView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 333.fix + 44)) let view = YHMakePlanHeadView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 333.fix + 44))
view.block = { tag in
self.tableView.scrollToRow(at: IndexPath(row: tag, section: 0), at: .top, animated: true)
self.topView.custtomView.updataData(tag)
}
return view return view
}() }()
...@@ -41,6 +45,10 @@ class YHMakePlanViewController: YHBaseViewController { ...@@ -41,6 +45,10 @@ class YHMakePlanViewController: YHBaseViewController {
lazy var topView: YHMakePlanTopView = { lazy var topView: YHMakePlanTopView = {
let view = YHMakePlanTopView() let view = YHMakePlanTopView()
view.isHidden = true view.isHidden = true
view.block = { tag in
self.tableView.scrollToRow(at: IndexPath(row: tag, section: 0), at: .top, animated: true)
self.headView.custtomView.updataData(tag)
}
return view return view
}() }()
...@@ -161,12 +169,16 @@ extension YHMakePlanViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -161,12 +169,16 @@ extension YHMakePlanViewController: UITableViewDelegate, UITableViewDataSource {
var dataSource: [YHMakePlanMainModel] = [] var dataSource: [YHMakePlanMainModel] = []
if indexPath.row == 0 { if indexPath.row == 0 {
dataSource = viewModel.makePlanModel.basic dataSource = viewModel.makePlanModel.basic
cell.titleLabel.text = "基础身份续签"
} else if indexPath.row == 1 { } else if indexPath.row == 1 {
dataSource = viewModel.makePlanModel.work dataSource = viewModel.makePlanModel.work
cell.titleLabel.text = "工作联系提升"
} else if indexPath.row == 2 { } else if indexPath.row == 2 {
dataSource = viewModel.makePlanModel.live dataSource = viewModel.makePlanModel.live
cell.titleLabel.text = "生活联系提升"
} else if indexPath.row == 3 { } else if indexPath.row == 3 {
dataSource = viewModel.makePlanModel.invest dataSource = viewModel.makePlanModel.invest
cell.titleLabel.text = "投资联系提升"
} }
cell.dataSource = dataSource cell.dataSource = dataSource
cell.actionHandler = { product in cell.actionHandler = { product in
...@@ -239,5 +251,30 @@ extension YHMakePlanViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -239,5 +251,30 @@ extension YHMakePlanViewController: UITableViewDelegate, UITableViewDataSource {
} else { } else {
topView.isHidden = true topView.isHidden = true
} }
if let topRow = tableView.topVisibleRowIndex() {
self.topView.custtomView.updataData(topRow)
self.headView.custtomView.updataData(topRow)
}
}
}
extension UITableView {
/// 获取当前显示在最顶部的行索引
func topVisibleRowIndex() -> Int? {
// 获取所有可见行的indexPath(按从上到下的顺序排列)
guard let visibleIndexPaths = self.indexPathsForVisibleRows?.sorted() else {
return nil
}
// 第一个就是最顶部的行
return visibleIndexPaths.first?.row
}
/// 获取当前显示在最顶部的单元格
func topVisibleCell() -> UITableViewCell? {
guard let topRow = topVisibleRowIndex() else {
return nil
}
return self.cellForRow(at: IndexPath(row: topRow, section: 0))
} }
} }
...@@ -76,7 +76,6 @@ class YHMakePlanCell: UITableViewCell { ...@@ -76,7 +76,6 @@ class YHMakePlanCell: UITableViewCell {
} }
func updateAllViews() { func updateAllViews() {
titleLabel.text = "基础身份续签"
mainItemView.removeSubviews() mainItemView.removeSubviews()
var y = 0 var y = 0
for i in 0 ..< (dataSource?.count ?? 0) { for i in 0 ..< (dataSource?.count ?? 0) {
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
import UIKit import UIKit
class YHMakePlanCusttomHeadView: UIView { class YHMakePlanCusttomHeadView: UIView {
typealias Block = (Int) -> Void
// Data var block: Block?
private let tabs = ["基础身份", "工作联系", "生活联系", "投资联系"] private let tabs = ["基础身份", "工作联系", "生活联系", "投资联系"]
private var buttons: [UIButton] = [] private var buttons: [UIButton] = []
private var selectedIndex: Int = 0 private var selectedIndex: Int = 0
...@@ -97,6 +97,29 @@ class YHMakePlanCusttomHeadView: UIView { ...@@ -97,6 +97,29 @@ class YHMakePlanCusttomHeadView: UIView {
self.layoutIfNeeded() self.layoutIfNeeded()
} }
selectedIndex = newIndex
self.block?(selectedIndex)
}
func updataData(_ tag: Int) {
let newIndex = tag
guard newIndex != selectedIndex else { return }
// Update colors
buttons[selectedIndex].setTitleColor(UIColor(hex: 0x6a7586), for: .normal)
buttons[newIndex].setTitleColor(UIColor.mainTextColor, for: .normal)
// Animate underline
UIView.animate(withDuration: 0.3) {
self.underlineView.snp.remakeConstraints { make in
make.top.equalTo(self.stackView.snp.bottom)
make.height.equalTo(2)
make.width.equalTo(16)
make.centerX.equalTo(self.buttons[newIndex].snp.centerX)
}
self.layoutIfNeeded()
}
selectedIndex = newIndex selectedIndex = newIndex
} }
} }
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
import UIKit import UIKit
class YHMakePlanHeadView: UIView { class YHMakePlanHeadView: UIView {
typealias Block = (Int) -> Void
var block: Block?
private lazy var centerImageView: UIImageView = { private lazy var centerImageView: UIImageView = {
let view = UIImageView() let view = UIImageView()
view.image = UIImage(named: "plan_head_bg") view.image = UIImage(named: "plan_head_bg")
...@@ -29,8 +31,11 @@ class YHMakePlanHeadView: UIView { ...@@ -29,8 +31,11 @@ class YHMakePlanHeadView: UIView {
return view return view
}() }()
private lazy var custtomView: YHMakePlanCusttomHeadView = { lazy var custtomView: YHMakePlanCusttomHeadView = {
let view = YHMakePlanCusttomHeadView() let view = YHMakePlanCusttomHeadView()
view.block = { tag in
self.block?(tag)
}
return view return view
}() }()
......
...@@ -185,12 +185,16 @@ extension YHMakePlanPriceAlertView: UITableViewDelegate, UITableViewDataSource { ...@@ -185,12 +185,16 @@ extension YHMakePlanPriceAlertView: UITableViewDelegate, UITableViewDataSource {
} }
var data: [YHMakePlanMainModel] = [] var data: [YHMakePlanMainModel] = []
if indexPath.row == 0 { if indexPath.row == 0 {
cell.titleLabel.text = "基础身份续签"
data = dataSource.basic data = dataSource.basic
} else if indexPath.row == 1 { } else if indexPath.row == 1 {
cell.titleLabel.text = "工作联系提升"
data = dataSource.work data = dataSource.work
} else if indexPath.row == 2 { } else if indexPath.row == 2 {
cell.titleLabel.text = "生活联系提升"
data = dataSource.live data = dataSource.live
} else if indexPath.row == 3 { } else if indexPath.row == 3 {
cell.titleLabel.text = "投资联系提升"
data = dataSource.invest data = dataSource.invest
} }
cell.dataSource = data cell.dataSource = data
......
...@@ -10,6 +10,8 @@ import UIKit ...@@ -10,6 +10,8 @@ import UIKit
import AttributedString import AttributedString
class YHMakePlanTopView: UIView { class YHMakePlanTopView: UIView {
typealias Block = (Int) -> Void
var block: Block?
var dataSource: YHMakePlanScoreModel? { var dataSource: YHMakePlanScoreModel? {
didSet { didSet {
let year = dataSource?.year ?? 0 let year = dataSource?.year ?? 0
...@@ -41,8 +43,11 @@ class YHMakePlanTopView: UIView { ...@@ -41,8 +43,11 @@ class YHMakePlanTopView: UIView {
return label return label
}() }()
private lazy var custtomView: YHMakePlanCusttomHeadView = { lazy var custtomView: YHMakePlanCusttomHeadView = {
let view = YHMakePlanCusttomHeadView() let view = YHMakePlanCusttomHeadView()
view.block = { tag in
self.block?(tag)
}
return view return view
}() }()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment