From c5579d0cb660bc6490fc932ad8e86248f57899d2 Mon Sep 17 00:00:00 2001
From: younger_times <841720330@qq.com>
Date: 星期四, 13 七月 2023 18:21:59 +0800
Subject: [PATCH] 新增

---
 WanPai/Root/Other/View/StudentChooseView.swift |   69 ++++++++++++++++++++++++++--------
 1 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/WanPai/Root/Other/View/StudentChooseView.swift b/WanPai/Root/Other/View/StudentChooseView.swift
index 62751ff..05b2370 100644
--- a/WanPai/Root/Other/View/StudentChooseView.swift
+++ b/WanPai/Root/Other/View/StudentChooseView.swift
@@ -8,6 +8,14 @@
 import UIKit
 import JQTools
 import QMUIKit
+import RxSwift
+import RxCocoa
+
+class StudentViewModel:RefreshModel<CourseDetailStudentModel>{
+    override func api() -> (Observable<BaseResponse<[CourseDetailStudentModel]>>)? {
+        return Services.queryStudentList()
+    }
+}
 
 class StudentChooseView: UIView,JQNibView{
 
@@ -19,6 +27,8 @@
     private var clickClouse:(()->Void)!
     private var needAddClouse:(()->Void)!
     private var itemType:ItemType!
+    private var selectStudents = [CourseDetailStudentModel]()
+    private var viewModel = StudentViewModel()
     
     override func awakeFromNib() {
         super.awakeFromNib()
@@ -30,10 +40,17 @@
         tableView.separatorStyle = .none
         alpha = 0
         layoutIfNeeded()
+
+        viewModel.configure(tableView,needMore: false)
+        viewModel.beginRefresh()
+
     }
     
-    static func show(itemType:ItemType,clickClouse:@escaping ()->Void,needAddClouse:@escaping ()->Void){
+    static func show(itemType:ItemType,defaultStu:CourseDetailStudentModel? = nil,clickClouse:@escaping ()->Void,needAddClouse:@escaping ()->Void){
         let studentChooseView = StudentChooseView.jq_loadNibView()
+        if defaultStu != nil{
+            studentChooseView.selectStudents.append(defaultStu!)
+        }
         if itemType == .course{
             studentChooseView.tableView.register(UINib(nibName: "StudentInfoTCell", bundle: nil), forCellReuseIdentifier: "_StudentInfoTCell")
         }else if itemType == .activity{
@@ -55,15 +72,13 @@
         }
     }
     
-    
+    @IBAction func closeAction(_ sender: UIButton) {
+        closeAction()
+    }
+
     @IBAction func addNewStudentAction(_ sender: QMUIButton) {
-        self.cons_bottom.constant = -(JQ_ScreenW * 1.1)
-        UIView.animate(withDuration: 0.4) {
-            self.alpha = 0
-        } completion: { _ in
-            self.removeFromSuperview()
-            self.needAddClouse!()
-        }
+        needAddClouse!()
+        closeAction()
     }
     
     
@@ -73,33 +88,55 @@
             self.view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 20)
         }
     }
-    
-    @IBAction func completeAction(_ sender: UIButton) {
-        
-    
+
+    private func closeAction(){
         self.cons_bottom.constant = -(JQ_ScreenW * 1.1)
         UIView.animate(withDuration: 0.4) {
             self.alpha = 0
+            self.layoutIfNeeded()
         } completion: { _ in
             self.removeFromSuperview()
-            self.clickClouse!()
         }
+    }
+    
+    @IBAction func completeAction(_ sender: UIButton) {
+        clickClouse!()
+        closeAction()
     }
 }
 
 extension StudentChooseView:UITableViewDelegate{
-    
+    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+
+         let item = viewModel.dataSource.value[indexPath.row]
+        if self.selectStudents.contains(where: {$0.id == item.id}){
+            if self.selectStudents.count == 1{
+                alert(msg: "至少选择一位学员");return
+            }
+            self.selectStudents.remove(at: indexPath.row)
+        }else{
+            self.selectStudents.append(item)
+        }
+        tableView.reloadData()
+    }
 }
 
 extension StudentChooseView:UITableViewDataSource{
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return 5
+        return viewModel.dataSource.value.count
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         
         if itemType == .course{
+            let item = viewModel.dataSource.value[indexPath.row]
             let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfoTCell") as! StudentInfoTCell
+            if selectStudents.contains(where: {$0.id == item.id}){
+                cell.btn_handle.setImage(UIImage(named: "btn_choose_s"), for: .normal)
+            }else{
+                cell.btn_handle.setImage(nil, for: .normal)
+            }
+            cell.studentModel = item
             return cell
         }else if itemType == .activity{
             let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfo_2_TCell") as! StudentInfo_2_TCell

--
Gitblit v1.7.1