无故事王国
2023-11-01 b3269976c84d03208f633cd0136a6f78e8dd53f7
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
//  StudentExchangeVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/6/26.
//
 
import UIKit
import RxSwift
import QMUIKit
 
class StudentExchangeViewModel:RefreshModel<StudentProfile1Model>{
    override func api() -> (Observable<BaseResponse<[StudentProfile1Model]>>)? {
        return Services.startCourceStudentList()
    }
}
 
class StudentExchangeVC: BaseVC {
 
    @IBOutlet weak var tableView: BaseTableView!
    @IBOutlet weak var btn_add: QMUIButton!
    private var selectIndex:Int?
    private let viewModel = StudentExchangeViewModel()
 
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "切换运动营成员"
        selectIndex = 0
        viewModel.configure(tableView,needMore: false)
        viewModel.beginRefresh()
        btn_add.imagePosition = .right
        btn_add.spacingBetweenImageAndTitle = 5
    }
 
    override func setUI() {
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        tableView.register(UINib(nibName: "StudentInfo_3_TCell", bundle: nil), forCellReuseIdentifier: "_StudentInfo_3_TCell")
//        tableView.jq_setEmptyView()
    }
 
    override func setRx() {
        NotificationCenter.default.rx.notification(StudentUpdate_Nofi).take(until: self.rx.deallocated).subscribe(onNext: {noti in
            self.viewModel.beginRefresh()
        }).disposed(by: disposeBag)
    }
 
    @IBAction func addStudentAction(_ sender: UIButton) {
        let studentVC = AddStudentVC(type: .course)
        push(vc: studentVC)
    }
 
    @IBAction func changeAction(_ sender: UIButton) {
        if let s = selectIndex{
            let id = viewModel.dataSource.value[s].stuId
            Services.startCourseSwitch(id: id).subscribe(onNext: { data in
                NotificationCenter.default.post(name: StudentUpdate_Nofi, object: nil)
                self.navigationController?.popViewController()
            }).disposed(by: disposeBag)
        }
    }
}
 
extension StudentExchangeVC:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        selectIndex = indexPath.row
        tableView.reloadData()
    }
}
 
extension StudentExchangeVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let model = viewModel.dataSource.value[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfo_3_TCell") as! StudentInfo_3_TCell
        cell.studentProfile1Model = model
        cell.viewModel = viewModel
 
        if selectIndex != nil{
            if indexPath.row == selectIndex{
                cell.view_container.jq_borderColor = UIColor(hexStr: "#FD7902").withAlphaComponent(0.28)
            }else{
                cell.view_container.jq_borderColor = UIColor(hexStr: "#818080").withAlphaComponent(0.28)
            }
        }else{
            if model.isNot == 1{
                cell.view_container.jq_borderColor = UIColor(hexStr: "#FD7902").withAlphaComponent(0.28)
            }else{
                cell.view_container.jq_borderColor = UIColor(hexStr: "#818080").withAlphaComponent(0.28)
            }
        }
        return cell
    }
 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel.dataSource.value.count
    }
}