fix
无故事王国
2024-03-04 54c6ef0be42d9f2e49a344fd69f231cb6df43797
WanPai/Root/Course/VC/StudentExchangeVC.swift
@@ -10,91 +10,91 @@
import QMUIKit
class StudentExchangeViewModel:RefreshModel<StudentProfile1Model>{
    override func api() -> (Observable<BaseResponse<[StudentProfile1Model]>>)? {
        return Services.startCourceStudentList()
    }
            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()
            @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 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 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)
    }
            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 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
         UserDefaults.standard.setValue(id, forKey: "currentStuId")
         UserDefaults.standard.synchronize()
         Services.startCourseSwitch(id: id).subscribe(onNext: { data in
            NotificationCenter.default.post(name: StudentRefresh_Nofi, object: nil)
            self.navigationController?.popViewController()
         }).disposed(by: disposeBag)
      }
   }
            @IBAction func changeAction(_ sender: UIButton) {
                        if let s = selectIndex{
                                    let id = viewModel.dataSource.value[s].stuId
                                    UserDefaults.standard.setValue(id, forKey: "currentStuId")
                                    UserDefaults.standard.synchronize()
                                    Services.startCourseSwitch(id: id).subscribe(onNext: { data in
                                                NotificationCenter.default.post(name: StudentRefresh_Nofi, object: nil)
                                                self.navigationController?.popViewController()
                                    }).disposed(by: disposeBag)
                        }
            }
}
extension StudentExchangeVC:UITableViewDelegate{
   func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      selectIndex = indexPath.row
      tableView.reloadData()
   }
            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
            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
    }
                        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
    }
            func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                        return viewModel.dataSource.value.count
            }
}