Commit 48e8d997 authored by Steven杜宇's avatar Steven杜宇

// 人脉

parent 2acd8a02
......@@ -11,15 +11,24 @@ import UIKit
class YHConnectListViewController: YHBaseViewController {
let viewModel = YHContactViewModel()
let matchViewModel = YHMatchUserViewModel()
var arr: [YHContact] = []
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.showsVerticalScrollIndicator = false
tableView.contentInsetAdjustmentBehavior = .never
tableView.estimatedSectionHeaderHeight = 1.0
tableView.estimatedSectionFooterHeight = 1.0
tableView.separatorStyle = .none
tableView.delegate = self
tableView.dataSource = self
tableView.backgroundColor = UIColor.white
tableView.register(YHConnectListCell.self, forCellReuseIdentifier: YHConnectListCell.cellReuseIdentifier)
tableView.es.addYHPullToRefresh {
self.reguestData(true)
}
tableView.es.addInfiniteScrolling {
self.reguestData(false)
}
......@@ -57,7 +66,7 @@ class YHConnectListViewController: YHBaseViewController {
self.arr.append(contentsOf: (self.viewModel.contacts))
self.tableView.reloadData()
self.tableView.es.stopLoadingMore()
self.tableView.es.stopPullToRefresh()
if !self.viewModel.hasMore {
self.tableView.es.noticeNoMoreData()
}
......@@ -75,9 +84,36 @@ extension YHConnectListViewController: UITableViewDelegate, UITableViewDataSourc
if 0 <= indexPath.row, indexPath.row < arr.count {
let model = arr[indexPath.row]
cell.updateModel(model)
cell.addFriendBlock = {[weak self] text in
guard let self = self else { return }
YHHUD.show(.progress(message: "加载中..."))
self.matchViewModel.addFriendWithText(text!, yhId: model.yh_id) {
success, error in
YHHUD.hide()
if success {
model.type = YHContactRelation.unvalidate.rawValue
self.tableView.reloadData()
} else {
var msg = "申请失败"
if let errMsg = error?.errorMsg, !errMsg.isEmpty {
msg = errMsg
}
YHHUD.flash(message: msg)
}
}
}
}
return cell
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 1.0
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 1.0
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
......
......@@ -19,9 +19,9 @@ class YHContactListModel: SmartCodable {
}
enum YHContactRelation: Int {
case stranger = 1
case unvalidate = 3
case friend = 5
case stranger = 1 // 陌生人
case unvalidate = 3 // 待验证
case friend = 5 // 好友
}
// 联系人数据模型
......
......@@ -12,6 +12,9 @@ class YHConnectListCell: UITableViewCell {
static let cellReuseIdentifier = "YHConnectListCell"
var addFriendBlock: ((String?) -> Void) = { (_: String?) in }
var contact: YHContact = YHContact()
private lazy var avatarImageView: UIImageView = {
let imageView = UIImageView()
imageView.layer.cornerRadius = 22
......@@ -50,6 +53,7 @@ class YHConnectListCell: UITableViewCell {
button.setTitleColor(UIColor.brandGrayColor8, for: .normal)
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.brandGrayColor5.cgColor
button.addTarget(self, action: #selector(didAddFriendBtnClicked), for: .touchUpInside)
return button
}()
......@@ -75,6 +79,18 @@ class YHConnectListCell: UITableViewCell {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupUI()
}
@objc func didAddFriendBtnClicked() {
let view = YHFriendRequestView.createView()
view.userModel = self.contact
view.sendBlock = {
[weak self] text in
guard let self = self else { return }
self.addFriendBlock(text)
}
view.show()
}
private func setupUI() {
selectionStyle = .none
......@@ -118,12 +134,14 @@ class YHConnectListCell: UITableViewCell {
make.left.equalTo(avatarImageView.snp.right).offset(10)
make.top.equalTo(nameLabel.snp.bottom).offset(3)
make.right.equalToSuperview().offset(-20)
make.height.equalTo(18)
}
signatureLabel.snp.makeConstraints { make in
make.left.equalTo(avatarImageView.snp.right).offset(10)
make.top.equalTo(titleLabel.snp.bottom).offset(4)
make.right.equalToSuperview().offset(-20)
make.height.equalTo(15)
make.bottom.equalTo(-20)
}
......@@ -136,12 +154,24 @@ class YHConnectListCell: UITableViewCell {
}
func updateModel(_ contact: YHContact) {
self.contact = contact
avatarImageView.sd_setImage(with: URL(string: contact.avatar), placeholderImage: UIImage(named: ""))
nameLabel.text = contact.username
titleLabel.text = "\(contact.position)\(contact.industry)"
signatureLabel.text = contact.signature
var text1 = ""
var text1Arr: [String] = []
if !self.contact.position.isEmpty {
text1Arr.append(self.contact.position)
}
if !self.contact.industry.isEmpty {
text1Arr.append(self.contact.industry)
}
if text1Arr.count > 0 {
text1 = text1Arr.joined(separator: " | ")
}
titleLabel.text = text1
if contact.type == YHContactRelation.stranger.rawValue {
addFriendButton.isHidden = false
statusLabel.isHidden = true
......@@ -159,6 +189,5 @@ class YHConnectListCell: UITableViewCell {
statusLabel.text = ""
}
}
}
}
......@@ -47,7 +47,7 @@ class YHAddFriendCardCell: UITableViewCell {
}
self.nameLabel.text = self.friendModel.username
self.msgLabel.text = self.friendModel.verifyInfo
self.signImgV.isHidden = !self.friendModel.isSign
// self.signImgV.isHidden = !self.friendModel.isSign
var text1 = ""
var text1Arr: [String] = []
......@@ -80,6 +80,7 @@ class YHAddFriendCardCell: UITableViewCell {
lazy var bgImageView: UIImageView = {
let bgImgView = UIImageView(image: UIImage(named: "people_add_friend_bg"))
bgImgView.isHidden = true
return bgImgView
}()
......@@ -102,6 +103,7 @@ class YHAddFriendCardCell: UITableViewCell {
lazy var signImgV: UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "people_sign")
view.isHidden = true
return view
}()
......
......@@ -14,7 +14,7 @@ class YHFriendRequestView: UIView {
static let cardHeight = 313.0
let textMaxCount = 200
let defaultStr = "在银河相遇,期待与你共话未来,互学互鉴,盼成为好友,谢谢~"
var userModel: YHMatchUserInfo = YHMatchUserInfo() {
var userModel: YHContact = YHContact() {
didSet {
if let url = URL(string: self.userModel.avatar) {
self.headImgV.kf.setImage(with: url, placeholder: UIImage(named: "people_head_default"))
......@@ -22,7 +22,7 @@ class YHFriendRequestView: UIView {
self.headImgV.image = UIImage(named: "people_head_default")
}
self.nameLabel.text = self.userModel.username
self.signImgV.isHidden = !self.userModel.isSign
// self.signImgV.isHidden = !self.userModel.isSign
var text1 = ""
var text1Arr: [String] = []
......@@ -75,6 +75,7 @@ class YHFriendRequestView: UIView {
lazy var signImgV: UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "people_sign")
view.isHidden = true
return view
}()
......
......@@ -166,7 +166,7 @@ class YHNameCardInfoView: DragCardView {
@objc func didBottomBtnClicked() {
let view = YHFriendRequestView.createView()
view.userModel = self.userModel
// view.userModel = self.userModel
view.sendBlock = {
[weak self] text in
guard let self = self else { return }
......
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