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

首页 model

parent 93c7ec4d
......@@ -11,7 +11,10 @@ import ESPullToRefresh
import GKNavigationBarSwift
class YHHomePageViewController: YHBaseViewController {
var viewModel: YHHomePageViewModel!
lazy var viewModel : YHHomePageViewModel = {
let viewModel = YHHomePageViewModel()
return viewModel
}()
lazy var items = {
return [AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配,专属方案获批率更高", url: "")]
......@@ -37,7 +40,6 @@ class YHHomePageViewController: YHBaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
viewModel = YHHomePageViewModel()
setupUI()
getData()
}
......
......@@ -12,6 +12,13 @@ import Kingfisher
class YHHomeCollectionViewCell: UICollectionViewCell {
static let cellReuseIdentifier = "YHHomeCollectionViewCell"
lazy var viewModel: YHHomeWebViewModel = {
let viewModel = YHHomeWebViewModel()
return viewModel
}()
var listModel: YHHomeListModel? {
didSet {
updataSubViews()
......@@ -48,6 +55,14 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
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 = {
let label = UILabel()
label.text = ""
......@@ -98,12 +113,15 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
make.height.equalTo(16)
}
subHoldView.addSubview(heartImageView)
heartImageView.snp.makeConstraints { make in
subHoldView.addSubview(heartImageViewBtn)
heartImageViewBtn.snp.makeConstraints { make in
make.right.equalTo(numLable.snp.left).offset(-2)
make.height.width.equalTo(16)
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() {
......@@ -126,10 +144,43 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
}
numLable.text = listModel.collect_count.string
if listModel.is_like {
headImageView.image = UIImage(named: "home_red_heart")
// if listModel.is_like {
// 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 {
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