Commit 1e74b607 authored by David黄金龙's avatar David黄金龙

首页 model

parent 93c7ec4d
...@@ -11,7 +11,10 @@ import ESPullToRefresh ...@@ -11,7 +11,10 @@ import ESPullToRefresh
import GKNavigationBarSwift import GKNavigationBarSwift
class YHHomePageViewController: YHBaseViewController { class YHHomePageViewController: YHBaseViewController {
var viewModel: YHHomePageViewModel! lazy var viewModel : YHHomePageViewModel = {
let viewModel = YHHomePageViewModel()
return viewModel
}()
lazy var items = { lazy var items = {
return [AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配,专属方案获批率更高", url: "")] return [AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配,专属方案获批率更高", url: "")]
...@@ -37,7 +40,6 @@ class YHHomePageViewController: YHBaseViewController { ...@@ -37,7 +40,6 @@ class YHHomePageViewController: YHBaseViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
viewModel = YHHomePageViewModel()
setupUI() setupUI()
getData() getData()
} }
......
...@@ -12,6 +12,13 @@ import Kingfisher ...@@ -12,6 +12,13 @@ import Kingfisher
class YHHomeCollectionViewCell: UICollectionViewCell { class YHHomeCollectionViewCell: UICollectionViewCell {
static let cellReuseIdentifier = "YHHomeCollectionViewCell" static let cellReuseIdentifier = "YHHomeCollectionViewCell"
lazy var viewModel: YHHomeWebViewModel = {
let viewModel = YHHomeWebViewModel()
return viewModel
}()
var listModel: YHHomeListModel? { var listModel: YHHomeListModel? {
didSet { didSet {
updataSubViews() updataSubViews()
...@@ -48,6 +55,14 @@ class YHHomeCollectionViewCell: UICollectionViewCell { ...@@ -48,6 +55,14 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
return imageV return imageV
}() }()
lazy var heartImageViewBtn : UIButton = {
let btn : UIButton = UIButton(type: .custom)
btn.setImage(UIImage(named: "home_grey_heart"), for: .normal)
btn.setImage(UIImage(named: "home_red_heart"), for: .selected)
return btn
}()
lazy var numLable:UILabel = { lazy var numLable:UILabel = {
let label = UILabel() let label = UILabel()
label.text = "" label.text = ""
...@@ -98,12 +113,15 @@ class YHHomeCollectionViewCell: UICollectionViewCell { ...@@ -98,12 +113,15 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
make.height.equalTo(16) make.height.equalTo(16)
} }
subHoldView.addSubview(heartImageView) subHoldView.addSubview(heartImageViewBtn)
heartImageView.snp.makeConstraints { make in heartImageViewBtn.snp.makeConstraints { make in
make.right.equalTo(numLable.snp.left).offset(-2) make.right.equalTo(numLable.snp.left).offset(-2)
make.height.width.equalTo(16) make.height.width.equalTo(16)
make.centerY.equalTo(numLable) make.centerY.equalTo(numLable)
} }
heartImageViewBtn.addTarget(self, action: #selector(clickHeart), for: .touchUpInside)
heartImageViewBtn.YH_clickEdgeInsets = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
} }
func updataSubViews() { func updataSubViews() {
...@@ -126,10 +144,43 @@ class YHHomeCollectionViewCell: UICollectionViewCell { ...@@ -126,10 +144,43 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
} }
numLable.text = listModel.collect_count.string numLable.text = listModel.collect_count.string
if listModel.is_like { // if listModel.is_like {
headImageView.image = UIImage(named: "home_red_heart") // headImageView.image = UIImage(named: "home_red_heart")
// } else {
// headImageView.image = UIImage(named: "home_grey_heart")
// }
heartImageViewBtn.isSelected = listModel.is_like
}
@objc func clickHeart() {
guard let listModel = listModel else { return }
if YHLoginManager.shared.isLogin() {
if listModel.is_like == false {
viewModel.getLike(listModel.id, 1) {[weak self] success, error in
guard let self = self else { return }
if success {
YHHUD.flash(message: "已点赞")
listModel.is_like = true
updataSubViews()
}
}
} else {
viewModel.getLike(listModel.id, 0) {[weak self] success, error in
guard let self = self else { return }
if success {
YHHUD.flash(message: "已取消点赞")
listModel.is_like = false
updataSubViews()
}
}
}
} else { } else {
headImageView.image = UIImage(named: "home_grey_heart") let vc = UINavigationController(rootVC: YHPhoneLoginViewController())
vc.modalPresentationStyle = .custom
self.parentViewController?.navigationController?.present(vc, animated: true)
} }
} }
} }
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