| | |
| | | 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{ |
| | | |
| | |
| | | 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() |
| | |
| | | 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{ |
| | |
| | | } |
| | | } |
| | | |
| | | @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() |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @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 |