宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
//  MineFeedbackVC.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/17.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
 
/// 意见反馈
class MineFeedbackVC: YYViewController {
    
    /// 字符
    @IBOutlet weak var label_character: UILabel!
    
    /// 输入框
    @IBOutlet weak var textView: YYTextView!
    
    let viewModel = MineFeedbackViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
    }
    
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        navigationItem.title = "意见反馈"
        view.backgroundColor = UIColor.color(light: UIColor.color(hexString: "#F3F4F5"), dark: UIColor.color(hexString: "#F3F4F5"))
        navigationItem.rightBarButtonItem = UIBarButtonItem.yy_creat(title: "提交", UIFont.systemFont(ofSize: 14), UIColor.color(light: UIColor.color(hexString: "#666666"), dark: UIColor.color(hexString: "#666666")), target: self, action: #selector(submit)).item
    }
    
    //MARK: - Rx
    override func bindRx() {
        super.bindRx()
        
        textView.rx.text.orEmpty.bind(to: viewModel.content).disposed(by: disposeBag)
        
        textView.rx.text.subscribe(onNext: {[unowned self] (_) in
            let leng = self.textView.text.length
            self.label_character.text = "还可以输入\(200 - leng)字"
        }).disposed(by: disposeBag)
        
        
        /// 反馈
        viewModel.requestSubject
            .subscribe(onNext: {[unowned self] (status) in
                switch status{
                case .loading:
                    self.show()
                    break
                case .success(_):
                    self.hide()
                    alert(text: "提交成功!我们将尽快处理")
                    self.yy_pop()
                    break
                case .error(let error):
                    self.hide()
                    alert(text: error.localizedDescription)
                    break
                }
            }).disposed(by: rx.disposeBag)
    }
    
    /// 提交
    @objc func submit()
    {
        if textView.text.isEmpty{
            alert(text: "请输入反馈内容")
            return
        }
        self.viewModel.feedback()
    }
}