123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- //
- // CircleLeavingMessageCommentTopStepTableViewCell.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/10/16.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import RxSwift
- class CircleLeavingMessageCommentTopStepTableViewCell: UITableViewCell {
-
- let disposeBag = DisposeBag()
- class func cellWith(tableView:UITableView,indexPath:IndexPath) -> CircleLeavingMessageCommentTopStepTableViewCell {
- let ID = "CircleLeavingMessageCommentTopStepTableViewCell"
- tableView.register(CircleLeavingMessageCommentTopStepTableViewCell.self, forCellReuseIdentifier: ID)
- let cell : CircleLeavingMessageCommentTopStepTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! CircleLeavingMessageCommentTopStepTableViewCell
- cell.indexPath = indexPath
- return cell
- }
-
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- setupViews()
- setupLayouts()
- setupData()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- var indexPath: IndexPath? {
- didSet {
-
- }
- }
- //MRAK: - 设置View
- private func setupViews() {
- self.selectionStyle = .none
- addSubview(commentLabel)
- addSubview(topButton)
- addSubview(stepButton)
-
- }
-
- private func setupLayouts() {
-
- stepButton.snp.makeConstraints { (make) in
- make.centerY.equalToSuperview()
- make.right.equalTo(-14)
- make.height.equalTo(20)
- }
- stepButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 4)
-
- topButton.snp.makeConstraints { (make) in
- make.centerY.equalToSuperview()
- make.right.equalTo(stepButton.snp.left).offset(-20)
- make.height.equalTo(20)
- }
- topButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 4)
-
- commentLabel.snp.makeConstraints { (make) in
- make.centerY.equalToSuperview()
- make.left.equalTo(14)
- make.right.equalTo(topButton.snp.left).offset(12)
- make.height.equalTo(48)
- }
-
- }
-
- func setupData() {
- topButton.rx.tap.subscribe(onNext: {[weak self] in
- self?.communityCircleMessageAction(action:1)
- }).disposed(by: disposeBag)
- stepButton.rx.tap.subscribe(onNext: {[weak self] in
- self?.communityCircleMessageAction(action:-1)
- }).disposed(by: disposeBag)
- }
-
- private lazy var commentLabel: UILabel = {
- let commentLabel = UILabel()
- commentLabel.numberOfLines = 1
- commentLabel.textColor = k999999Color
- commentLabel.font = kRegularFont14
- commentLabel.textAlignment = .left
- commentLabel.text = "添加评论..."
- commentLabel.addTapGesture(1, target: self, action: #selector(commentAction))
- return commentLabel
- }()
-
- lazy var topButton: UIButton = {
- let topButton = UIButton()
- topButton.setImage(kImage(name: "question_btn_like"), for: UIControl.State.normal)
- topButton.setImage(kImage(name: "question_btn_like_pre"), for: UIControl.State.selected)
- topButton.setTitleColor(k666666Color, for: UIControl.State.normal)
- topButton.setTitle("0", for: UIControl.State.normal)
- return topButton
- }()
-
- lazy var stepButton: UIButton = {
- let stepButton = UIButton()
- stepButton.setImage(kImage(name: "question_btn_dislike"), for: UIControl.State.normal)
- stepButton.setImage(kImage(name: "question_btn_dislike_pre"), for: UIControl.State.selected)
- stepButton.setTitleColor(k666666Color, for: UIControl.State.normal)
- stepButton.setTitle("0", for: UIControl.State.normal)
- return stepButton
- }()
-
- var communityCircleMessageModel: CommunityCircleMessageModel? {
- didSet {
- action()
- }
- }
-
- func action() {
- if communityCircleMessageModel?.action ?? 0 == 0 {
- topButton.isUserInteractionEnabled = true
- stepButton.isUserInteractionEnabled = true
- topButton.isSelected = false
- stepButton.isSelected = false
- }else if communityCircleMessageModel?.action ?? 0 == 1 {
- topButton.isUserInteractionEnabled = false
- stepButton.isUserInteractionEnabled = false
- topButton.isSelected = true
- stepButton.isSelected = false
- }else if communityCircleMessageModel?.action ?? 0 == -1 {
- topButton.isUserInteractionEnabled = false
- stepButton.isUserInteractionEnabled = false
- topButton.isSelected = false
- stepButton.isSelected = true
- }
- topButton.setTitle("\(communityCircleMessageModel?.good ?? 0)", for: UIControl.State.normal)
- topButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 4)
- stepButton.setTitle("\(communityCircleMessageModel?.bad ?? 0)", for: UIControl.State.normal)
- stepButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 4)
- }
-
-
- /// 评论回调
- typealias CommentCloSure = () -> Void
- var commentCloSure : CommentCloSure?
-
- // 评论
- @objc func commentAction() {
- showKeyBoardCommentView()
- }
-
- /// 显示键盘
- func showKeyBoardCommentView() {
-
- KeyBoardInputView.show(inputViewResultClosure: { [weak self] (content) in
- self?.communityCircleCommentPostApi(content: content)
- }) {
- }
- }
-
- /// 评论
- ///
- /// - Parameter content: 评论内容
- func communityCircleCommentPostApi(content:String?) {
- SwiftMoyaNetWorkServiceCommunity.shared().communityCircleCommentPostApi(circleId: communityCircleMessageModel?.circleId ?? 0, msgId: communityCircleMessageModel?.id ?? 0, content: content ?? "") { [weak self] (communityCircleCommentModel) -> (Void) in
- let communityCircleCommentModel = communityCircleCommentModel as? CommunityCircleCommentModel
- let communityCircleMessageCommentModel = CommunityCircleMessageCommentModel()
- communityCircleMessageCommentModel.id = communityCircleCommentModel?.id
- communityCircleMessageCommentModel.uid = UserModel.shared().getModel()?.uid
- communityCircleMessageCommentModel.username = UserModel.shared().getModel()?.username
- communityCircleMessageCommentModel.content = content
- communityCircleMessageCommentModel.isDelete = 0
- communityCircleMessageCommentModel.replyCount = 0
- self?.communityCircleMessageModel?.commentCount = (self?.communityCircleMessageModel?.commentCount ?? 0) + 1
- self?.communityCircleMessageModel?.comment?.insert(communityCircleMessageCommentModel, at: 0)
- if let commentCloSure = self?.commentCloSure {
- commentCloSure()
- }
- }
- }
-
-
- /// 提问顶踩
- ///
- /// - Parameter action: 0/1/-1
- func communityCircleMessageAction(action:Int) {
- SwiftMoyaNetWorkServiceCommunity.shared().communityCircleMessageActionApi(msgId: communityCircleMessageModel?.id ?? 0, action: action) { [weak self] (_) -> (Void) in
- self?.communityCircleMessageModel?.action = action
- if action == -1 {
- self?.communityCircleMessageModel?.bad = (self?.communityCircleMessageModel?.bad ?? 0) + 1
- }else if action == 1 {
- self?.communityCircleMessageModel?.good = (self?.communityCircleMessageModel?.good ?? 0) + 1
- }
- self?.action()
- }
- }
-
-
- }
|