|
@@ -0,0 +1,256 @@
|
|
|
+//
|
|
|
+// CircleHeaderView.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by 南鑫林 on 2019/10/15.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import SwiftyMediator
|
|
|
+
|
|
|
+class CircleHeaderView: BaseView {
|
|
|
+
|
|
|
+ var imageViewFrame = CGRect(x: 0, y: 0, width: kScreenWidth, height: 114 + kNavBarTotalHeight + 8)
|
|
|
+
|
|
|
+ override func setupViews() {
|
|
|
+ addSubview(bgImageView)
|
|
|
+ addSubview(bgView)
|
|
|
+ bgView.addSubview(titleLabel)
|
|
|
+ addSubview(midBgView)
|
|
|
+ addSubview(avatarImageView)
|
|
|
+ midBgView.addSubview(circleButton)
|
|
|
+ midBgView.addSubview(chatRootButton)
|
|
|
+ midBgView.addSubview(memberNameLabel)
|
|
|
+ midBgView.addSubview(memberNumberLabel)
|
|
|
+ midBgView.addSubview(albumNameLabel)
|
|
|
+ midBgView.addSubview(albumNumberLabel)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupLayouts() {
|
|
|
+ titleLabel.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.equalTo(-50)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ }
|
|
|
+ avatarImageView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(midBgView).offset(-30)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.size.equalTo(80)
|
|
|
+ }
|
|
|
+ circleButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(20)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ make.width.equalTo(110)
|
|
|
+ make.height.equalTo(30)
|
|
|
+ }
|
|
|
+ chatRootButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(20)
|
|
|
+ make.right.equalTo(circleButton.snp.left).offset(-10)
|
|
|
+ make.width.equalTo(64)
|
|
|
+ make.height.equalTo(30)
|
|
|
+ }
|
|
|
+
|
|
|
+ memberNameLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(avatarImageView.snp.bottom).offset(22)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ }
|
|
|
+
|
|
|
+ memberNumberLabel.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalTo(memberNameLabel)
|
|
|
+ make.left.equalTo(memberNameLabel.snp.right).offset(8)
|
|
|
+ }
|
|
|
+
|
|
|
+ albumNameLabel.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalTo(memberNameLabel)
|
|
|
+ make.left.equalTo(memberNumberLabel.snp.right).offset(30)
|
|
|
+ }
|
|
|
+
|
|
|
+ albumNumberLabel.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalTo(memberNameLabel)
|
|
|
+ make.left.equalTo(albumNameLabel.snp.right).offset(8)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupData() {
|
|
|
+ chatRootButton.rx.tap.subscribe(onNext: { [weak self] (_) in
|
|
|
+ if self?.communityCircleModel?.chatroom?.isOpen == 1 {
|
|
|
+ self?.userChatroomValidRoomApi()
|
|
|
+ }else {
|
|
|
+ SwiftProgressHUD.shared().showText("这个圈子没有聊天室哦~")
|
|
|
+ }
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+
|
|
|
+ circleButton.rx.tap.subscribe(onNext: { [weak self] (_) in
|
|
|
+ if self?.circleButton.isSelected ?? false { //退出圈子
|
|
|
+ self?.communityCircleJoinDeleteApi()
|
|
|
+ }else { //加入圈子
|
|
|
+ // 是否答题
|
|
|
+ if self?.communityCircleModel?.joinLimit == 0 { //不需要
|
|
|
+ self?.communityCircleJoinPostApi()
|
|
|
+ } else if self?.communityCircleModel?.joinLimit == 1 { //需要
|
|
|
+ let vc = CircleQuestionsAnswersViewController()
|
|
|
+ vc.circleId = self?.communityCircleModel?.id ?? 0
|
|
|
+ UIViewController.topMost?.navigationController?.pushViewController(vc, animated: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private lazy var bgImageView: UIImageView = {
|
|
|
+ let bgImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 114 + kNavBarTotalHeight + 8))
|
|
|
+ bgImageView.image = kImage(name: "default_pic")
|
|
|
+ bgImageView.contentMode = .scaleAspectFill
|
|
|
+ bgImageView.layer.masksToBounds = true
|
|
|
+ return bgImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var bgView: UIView = {
|
|
|
+ let bgView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 114 + kNavBarTotalHeight + 8))
|
|
|
+ bgView.backgroundColor = UIColor(hexString: "000000", alpha: 0.5)
|
|
|
+ return bgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var titleLabel: UILabel = {
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.text = "昵称"
|
|
|
+ titleLabel.textColor = .white
|
|
|
+ titleLabel.font = kMediumFont23
|
|
|
+ return titleLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var midBgView: UIView = {
|
|
|
+ let midBgView = UIView(frame: CGRect(x: 0, y: 114 + kNavBarTotalHeight, width: kScreenWidth, height: 104))
|
|
|
+ midBgView.backgroundColor = .white
|
|
|
+ midBgView.configRectCorner(corner: [.topRight,.topLeft], radii: CGSize(width: 8, height: 8))
|
|
|
+ return midBgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var avatarImageView: UIImageView = {
|
|
|
+ let avatarImageView = UIImageView()
|
|
|
+ avatarImageView.image = kImage(name: "default_avatar")
|
|
|
+ avatarImageView.cornerRadius = 40
|
|
|
+ avatarImageView.masksToBounds = true
|
|
|
+ return avatarImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var circleButton: UIButton = {
|
|
|
+ let circleButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ circleButton.setBackgroundImage(UIImage.imageWithColor(color: kThemeColor), for: UIControl.State.normal)
|
|
|
+ circleButton.setBackgroundImage(UIImage.imageWithColor(color: .white), for: UIControl.State.selected)
|
|
|
+ circleButton.setTitle("加入圈子", for: UIControl.State.normal)
|
|
|
+ circleButton.setTitle("退出圈子", for: UIControl.State.selected)
|
|
|
+ circleButton.setTitleColor(.white, for: UIControl.State.normal)
|
|
|
+ circleButton.setTitleColor(kThemeColor, for: UIControl.State.selected)
|
|
|
+ circleButton.titleLabel?.font = kRegularFont14
|
|
|
+ circleButton.layer.borderColor = kThemeColor.cgColor
|
|
|
+ circleButton.layer.borderWidth = 1
|
|
|
+ circleButton.cornerRadius = 15
|
|
|
+ circleButton.masksToBounds = true
|
|
|
+ return circleButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var chatRootButton: UIButton = {
|
|
|
+ let chatRootButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ chatRootButton.setBackgroundImage(UIImage.imageWithColor(color: .white), for: UIControl.State.normal)
|
|
|
+ chatRootButton.setTitle("聊天室", for: UIControl.State.normal)
|
|
|
+ chatRootButton.setTitleColor(k584F60Color, for: UIControl.State.normal)
|
|
|
+ chatRootButton.titleLabel?.font = kRegularFont14
|
|
|
+ chatRootButton.layer.borderColor = k584F60Color.cgColor
|
|
|
+ chatRootButton.layer.borderWidth = 1
|
|
|
+ chatRootButton.cornerRadius = 15
|
|
|
+ chatRootButton.masksToBounds = true
|
|
|
+ return chatRootButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var memberNameLabel: UILabel = {
|
|
|
+ let memberNameLabel = UILabel()
|
|
|
+ memberNameLabel.text = "成员"
|
|
|
+ memberNameLabel.textColor = .black
|
|
|
+ memberNameLabel.font = kRegularFont14
|
|
|
+ return memberNameLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var memberNumberLabel: UILabel = {
|
|
|
+ let memberNumberLabel = UILabel()
|
|
|
+ memberNumberLabel.text = "0"
|
|
|
+ memberNumberLabel.textColor = .black
|
|
|
+ memberNumberLabel.font = kMediumFont16
|
|
|
+ return memberNumberLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var albumNameLabel: UILabel = {
|
|
|
+ let albumNameLabel = UILabel()
|
|
|
+ albumNameLabel.text = "相册"
|
|
|
+ albumNameLabel.textColor = .black
|
|
|
+ albumNameLabel.font = kRegularFont14
|
|
|
+ return albumNameLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var albumNumberLabel: UILabel = {
|
|
|
+ let albumNumberLabel = UILabel()
|
|
|
+ albumNumberLabel.text = "0"
|
|
|
+ albumNumberLabel.textColor = .black
|
|
|
+ albumNumberLabel.font = kMediumFont16
|
|
|
+ return albumNumberLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ var communityCircleModel :CommunityCircleModel? {
|
|
|
+ didSet {
|
|
|
+ bgImageView.kf.setImage(with: kURLImage(name: communityCircleModel?.image ?? "default_pic"), placeholder: kImage(name: "default_pic"))
|
|
|
+ titleLabel.text = communityCircleModel?.name
|
|
|
+ avatarImageView.kf.setImage(with: kURLImage(name: communityCircleModel?.image ?? "default_avatar"), placeholder: kImage(name: "default_avatar"))
|
|
|
+ memberNumberLabel.text = communityCircleModel?.members?.extra
|
|
|
+ albumNumberLabel.text = communityCircleModel?.pictures?.extra
|
|
|
+
|
|
|
+ if communityCircleModel?.isJoin == 0 {
|
|
|
+ circleButton.isSelected = false
|
|
|
+ }else if communityCircleModel?.isJoin == 1 {
|
|
|
+ circleButton.isSelected = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// 验证聊天室是否开启了
|
|
|
+ func userChatroomValidRoomApi() {
|
|
|
+ SwiftMoyaNetWorkServiceUser.shared().userChatroomValidRoomApi(ChatroomId: communityCircleModel?.chatroom?.extra ?? "0") { [weak self] data in
|
|
|
+ Mediator.push(RongCloudIMRouterModuleType.IMChatRoom(targetId: self?.communityCircleModel?.chatroom?.extra ?? "0", messageCount: 50, roomName: self?.communityCircleModel?.name ?? ""))
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 加入圈子
|
|
|
+ func communityCircleJoinPostApi() {
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityCircleJoinPostApi(circleId: communityCircleModel?.id ?? 0) {[weak self] (_) -> (Void) in
|
|
|
+ self?.circleButton.isSelected = true
|
|
|
+ self?.communityCircleModel?.isJoin = 1
|
|
|
+ SwiftProgressHUD.shared().showText("加入圈子成功")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// 退出圈子
|
|
|
+ func communityCircleJoinDeleteApi() {
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityCircleJoinDeleteApi(circleId: communityCircleModel?.id ?? 0) {[weak self] (_) -> (Void) in
|
|
|
+ self?.circleButton.isSelected = false
|
|
|
+ self?.communityCircleModel?.isJoin = 0
|
|
|
+ SwiftProgressHUD.shared().showText("退出圈子成功")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func scrollViewDidScroll(contentOffsetY: CGFloat) {
|
|
|
+ if contentOffsetY < 0 {
|
|
|
+ var frame = imageViewFrame
|
|
|
+ frame.size.height -= contentOffsetY
|
|
|
+ frame.origin.y = contentOffsetY
|
|
|
+ bgImageView.frame = frame
|
|
|
+ bgView.frame = frame
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|