| | |
| | | import HandyJSON |
| | | |
| | | class StudentViewModel:RefreshModel<CourseDetailStudentModel>{ |
| | | override func api() -> (Observable<BaseResponse<[CourseDetailStudentModel]>>)? { |
| | | return Services.queryStudentList() |
| | | } |
| | | override func api() -> (Observable<BaseResponse<[CourseDetailStudentModel]>>)? { |
| | | return Services.queryStudentList() |
| | | } |
| | | } |
| | | |
| | | class ActivityViewModel:RefreshModel<ActivityDetailPartModel>{ |
| | | var isAuth = BehaviorRelay<Int?>.init(value: nil) |
| | | override func api() -> (Observable<BaseResponse<[ActivityDetailPartModel]>>)? { |
| | | return Services.queryParticipantList(isAuth: isAuth.value) |
| | | } |
| | | |
| | | var isAuth = BehaviorRelay<Int?>.init(value: nil) |
| | | override func api() -> (Observable<BaseResponse<[ActivityDetailPartModel]>>)? { |
| | | return Services.queryParticipantList(isAuth: isAuth.value) |
| | | } |
| | | |
| | | } |
| | | |
| | | class StudentChooseView: UIView,JQNibView{ |
| | | |
| | | @IBOutlet weak var tableView: UITableView! |
| | | @IBOutlet weak var view_container: UIView! |
| | | @IBOutlet weak var cons_bottom: NSLayoutConstraint! |
| | | @IBOutlet weak var btn_add: QMUIButton! |
| | | @IBOutlet weak var cons_tableHei: NSLayoutConstraint! |
| | | @IBOutlet weak var cons_tableLeading: NSLayoutConstraint! |
| | | @IBOutlet weak var cons_tableTrailing: NSLayoutConstraint! |
| | | |
| | | private var clickClouse:(([Any])->Void)! |
| | | private var needAddClouse:(()->Void)! |
| | | private var itemType:ItemType! |
| | | private var selectStudents = [Any]() |
| | | private var disposeBag = DisposeBag() |
| | | |
| | | |
| | | private lazy var stuViewModel:StudentViewModel = { |
| | | return StudentViewModel() |
| | | }() |
| | | |
| | | private lazy var actViewModel:ActivityViewModel = { |
| | | return ActivityViewModel() |
| | | }() |
| | | |
| | | override func awakeFromNib() { |
| | | super.awakeFromNib() |
| | | btn_add.imagePosition = .right |
| | | btn_add.spacingBetweenImageAndTitle = 5 |
| | | cons_bottom.constant = -(JQ_ScreenW * 1.1) |
| | | tableView.delegate = self |
| | | tableView.dataSource = self |
| | | tableView.separatorStyle = .none |
| | | alpha = 0 |
| | | layoutIfNeeded() |
| | | setRx() |
| | | } |
| | | |
| | | static func show(itemType:ItemType,defaultStu:[Any]? = nil,isAuth:Int? = nil,clickClouse:@escaping ([Any])->Void,needAddClouse:@escaping ()->Void){ |
| | | let studentChooseView = StudentChooseView.jq_loadNibView() |
| | | if defaultStu != nil{ |
| | | studentChooseView.selectStudents = defaultStu! |
| | | } |
| | | if itemType == .course{ |
| | | studentChooseView.tableView.register(UINib(nibName: "StudentInfoTCell", bundle: nil), forCellReuseIdentifier: "_StudentInfoTCell") |
| | | studentChooseView.btn_add.setTitle("添加运动营成员", for: .normal) |
| | | }else if itemType == .activity{ |
| | | studentChooseView.tableView.register(UINib(nibName: "StudentInfo_2_TCell", bundle: nil), forCellReuseIdentifier: "_StudentInfo_2_TCell") |
| | | studentChooseView.btn_add.setTitle("添加人员", for: .normal) |
| | | } |
| | | |
| | | studentChooseView.frame = sceneDelegate?.window?.frame ?? .zero |
| | | studentChooseView.itemType = itemType |
| | | studentChooseView.clickClouse = clickClouse |
| | | studentChooseView.needAddClouse = needAddClouse |
| | | sceneDelegate?.window?.addSubview(studentChooseView) |
| | | studentChooseView.cons_bottom.constant = 0 |
| | | |
| | | if itemType == .course{ |
| | | studentChooseView.stuViewModel.configure(studentChooseView.tableView,needMore: false) |
| | | studentChooseView.stuViewModel.beginRefresh() |
| | | }else{ |
| | | studentChooseView.actViewModel.configure(studentChooseView.tableView,needMore: false) |
| | | studentChooseView.actViewModel.isAuth.accept(isAuth) |
| | | studentChooseView.actViewModel.beginRefresh() |
| | | studentChooseView.cons_tableLeading.constant = 0 |
| | | studentChooseView.cons_tableTrailing.constant = 0 |
| | | } |
| | | |
| | | UIView.animate(withDuration: 0.4) { |
| | | studentChooseView.alpha = 1 |
| | | studentChooseView.layoutIfNeeded() |
| | | studentChooseView.tableView.reloadData() |
| | | } |
| | | } |
| | | |
| | | private func setRx(){ |
| | | stuViewModel.dataSource.subscribe(onNext: {[weak self] data in |
| | | |
| | | let hei = min(360,Double(data.count) * 90.0) |
| | | self?.cons_tableHei.constant = hei |
| | | UIView.animate(withDuration: 0.4) { |
| | | self?.layoutIfNeeded() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | actViewModel.dataSource.subscribe(onNext: {[weak self] data in |
| | | let hei = min(360,Double(data.count) * 90.0) |
| | | self?.cons_tableHei.constant = hei |
| | | UIView.animate(withDuration: 0.4) { |
| | | self?.layoutIfNeeded() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | @IBAction func closeAction(_ sender: UIButton) { |
| | | closeAction() |
| | | } |
| | | |
| | | @IBAction func addNewStudentAction(_ sender: QMUIButton) { |
| | | needAddClouse!() |
| | | closeAction() |
| | | } |
| | | |
| | | |
| | | override func layoutSubviews() { |
| | | super.layoutSubviews() |
| | | DispatchQueue.main.asyncAfter(wallDeadline: .now()+0.1) { |
| | | self.view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 20) |
| | | } |
| | | } |
| | | |
| | | 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() |
| | | } |
| | | } |
| | | |
| | | @IBAction func completeAction(_ sender: UIButton) { |
| | | clickClouse!(selectStudents) |
| | | closeAction() |
| | | } |
| | | |
| | | @IBOutlet weak var tableView: UITableView! |
| | | @IBOutlet weak var view_container: UIView! |
| | | @IBOutlet weak var cons_bottom: NSLayoutConstraint! |
| | | @IBOutlet weak var btn_add: QMUIButton! |
| | | @IBOutlet weak var cons_tableHei: NSLayoutConstraint! |
| | | @IBOutlet weak var cons_tableLeading: NSLayoutConstraint! |
| | | @IBOutlet weak var cons_tableTrailing: NSLayoutConstraint! |
| | | |
| | | private var clickClouse:(([Any])->Void)! |
| | | private var needAddClouse:(()->Void)! |
| | | private var itemType:ItemType! |
| | | private var selectStudents = [Any]() |
| | | private var disposeBag = DisposeBag() |
| | | |
| | | |
| | | private lazy var stuViewModel:StudentViewModel = { |
| | | return StudentViewModel() |
| | | }() |
| | | |
| | | private lazy var actViewModel:ActivityViewModel = { |
| | | return ActivityViewModel() |
| | | }() |
| | | |
| | | override func awakeFromNib() { |
| | | super.awakeFromNib() |
| | | btn_add.imagePosition = .right |
| | | btn_add.spacingBetweenImageAndTitle = 5 |
| | | cons_bottom.constant = -(JQ_ScreenW * 1.1) |
| | | tableView.delegate = self |
| | | tableView.dataSource = self |
| | | tableView.separatorStyle = .none |
| | | alpha = 0 |
| | | layoutIfNeeded() |
| | | setRx() |
| | | } |
| | | |
| | | static func show(itemType:ItemType,defaultStu:[Any]? = nil,isAuth:Int? = nil,clickClouse:@escaping ([Any])->Void,needAddClouse:@escaping ()->Void){ |
| | | let studentChooseView = StudentChooseView.jq_loadNibView() |
| | | if defaultStu != nil{ |
| | | studentChooseView.selectStudents = defaultStu! |
| | | } |
| | | if itemType == .course{ |
| | | studentChooseView.tableView.register(UINib(nibName: "StudentInfoTCell", bundle: nil), forCellReuseIdentifier: "_StudentInfoTCell") |
| | | studentChooseView.btn_add.setTitle("添加运动营成员", for: .normal) |
| | | }else if itemType == .activity{ |
| | | studentChooseView.tableView.register(UINib(nibName: "StudentInfo_2_TCell", bundle: nil), forCellReuseIdentifier: "_StudentInfo_2_TCell") |
| | | studentChooseView.btn_add.setTitle("添加人员", for: .normal) |
| | | } |
| | | |
| | | studentChooseView.frame = sceneDelegate?.window?.frame ?? .zero |
| | | studentChooseView.itemType = itemType |
| | | studentChooseView.clickClouse = clickClouse |
| | | studentChooseView.needAddClouse = needAddClouse |
| | | sceneDelegate?.window?.addSubview(studentChooseView) |
| | | studentChooseView.cons_bottom.constant = 0 |
| | | |
| | | if itemType == .course{ |
| | | studentChooseView.stuViewModel.configure(studentChooseView.tableView,needMore: false) |
| | | studentChooseView.stuViewModel.beginRefresh() |
| | | }else{ |
| | | studentChooseView.actViewModel.configure(studentChooseView.tableView,needMore: false) |
| | | studentChooseView.actViewModel.isAuth.accept(isAuth) |
| | | studentChooseView.actViewModel.beginRefresh() |
| | | studentChooseView.cons_tableLeading.constant = 0 |
| | | studentChooseView.cons_tableTrailing.constant = 0 |
| | | } |
| | | |
| | | UIView.animate(withDuration: 0.4) { |
| | | studentChooseView.alpha = 1 |
| | | studentChooseView.layoutIfNeeded() |
| | | studentChooseView.tableView.reloadData() |
| | | } |
| | | } |
| | | |
| | | private func setRx(){ |
| | | stuViewModel.dataSource.subscribe(onNext: {[weak self] data in |
| | | |
| | | let hei = min(360,Double(data.count) * 90.0) |
| | | self?.cons_tableHei.constant = hei |
| | | UIView.animate(withDuration: 0.4) { |
| | | self?.layoutIfNeeded() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | actViewModel.dataSource.subscribe(onNext: {[weak self] data in |
| | | let hei = min(360,Double(data.count) * 90.0) |
| | | self?.cons_tableHei.constant = hei |
| | | UIView.animate(withDuration: 0.4) { |
| | | self?.layoutIfNeeded() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | @IBAction func closeAction(_ sender: UIButton) { |
| | | closeAction() |
| | | } |
| | | |
| | | @IBAction func addNewStudentAction(_ sender: QMUIButton) { |
| | | needAddClouse!() |
| | | closeAction() |
| | | } |
| | | |
| | | |
| | | override func layoutSubviews() { |
| | | super.layoutSubviews() |
| | | DispatchQueue.main.asyncAfter(wallDeadline: .now()+0.1) { |
| | | self.view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 20) |
| | | } |
| | | } |
| | | |
| | | 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() |
| | | } |
| | | } |
| | | |
| | | @IBAction func completeAction(_ sender: UIButton) { |
| | | clickClouse!(selectStudents) |
| | | closeAction() |
| | | } |
| | | } |
| | | |
| | | extension StudentChooseView:UITableViewDelegate{ |
| | | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
| | | |
| | | if itemType == .course{ |
| | | let item = stuViewModel.dataSource.value[indexPath.row] |
| | | if self.selectStudents.contains(where: {($0 as! CourseDetailStudentModel).id == item.id}){ |
| | | if self.selectStudents.count == 1{ |
| | | alert(msg: "至少选择一位运动营成员");return |
| | | } |
| | | if let index = self.selectStudents.firstIndex(where: {($0 as! CourseDetailStudentModel).id == item.id}){ |
| | | self.selectStudents.remove(at: index) |
| | | } |
| | | }else{ |
| | | self.selectStudents.append(item) |
| | | } |
| | | }else{ |
| | | let item = actViewModel.dataSource.value[indexPath.row] |
| | | if self.selectStudents.contains(where: {($0 as! ActivityDetailPartModel).id == item.id}){ |
| | | if self.selectStudents.count == 1{ |
| | | alert(msg: "至少选择一位运动营成员");return |
| | | } |
| | | if let index = self.selectStudents.firstIndex(where: {($0 as! ActivityDetailPartModel).id == item.id}){ |
| | | self.selectStudents.remove(at: index) |
| | | } |
| | | }else{ |
| | | self.selectStudents.append(item) |
| | | } |
| | | } |
| | | tableView.reloadData() |
| | | } |
| | | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
| | | |
| | | if itemType == .course{ |
| | | let item = stuViewModel.dataSource.value[indexPath.row] |
| | | if self.selectStudents.contains(where: {($0 as! CourseDetailStudentModel).id == item.id}){ |
| | | if self.selectStudents.count == 1{ |
| | | alert(msg: "至少选择一位运动营成员");return |
| | | } |
| | | if let index = self.selectStudents.firstIndex(where: {($0 as! CourseDetailStudentModel).id == item.id}){ |
| | | self.selectStudents.remove(at: index) |
| | | } |
| | | }else{ |
| | | self.selectStudents.append(item) |
| | | } |
| | | }else{ |
| | | let item = actViewModel.dataSource.value[indexPath.row] |
| | | if self.selectStudents.contains(where: {($0 as! ActivityDetailPartModel).id == item.id}){ |
| | | if self.selectStudents.count == 1{ |
| | | alert(msg: "至少选择一位运动营成员");return |
| | | } |
| | | if let index = self.selectStudents.firstIndex(where: {($0 as! ActivityDetailPartModel).id == item.id}){ |
| | | self.selectStudents.remove(at: index) |
| | | } |
| | | }else{ |
| | | self.selectStudents.append(item) |
| | | } |
| | | } |
| | | tableView.reloadData() |
| | | } |
| | | } |
| | | |
| | | extension StudentChooseView:UITableViewDataSource{ |
| | | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| | | if itemType == .course{ |
| | | return stuViewModel.dataSource.value.count |
| | | }else{ |
| | | return actViewModel.dataSource.value.count |
| | | } |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | |
| | | if itemType == .course{ |
| | | let item = stuViewModel.dataSource.value[indexPath.row] |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfoTCell") as! StudentInfoTCell |
| | | cell.cons_handleCenterY.constant = -7 |
| | | if self.selectStudents.contains(where: {($0 as! CourseDetailStudentModel).id == item.id}){ |
| | | cell.btn_handle.setImage(UIImage(named: "btn_choose_s"), for: .normal) |
| | | cell.view_container.borderColor = UIColor(hexStr: "#FD7902").withAlphaComponent(0.28) |
| | | }else{ |
| | | cell.btn_handle.setImage(nil, for: .normal) |
| | | cell.view_container.borderColor = UIColor(hexStr: "#ADADAD").withAlphaComponent(0.28) |
| | | } |
| | | cell.studentModel = item |
| | | return cell |
| | | }else if itemType == .activity{ |
| | | let item = actViewModel.dataSource.value[indexPath.row] |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfo_2_TCell") as! StudentInfo_2_TCell |
| | | cell.btn_delete.isHidden = true |
| | | cell.btn_edit.isHidden = true |
| | | cell.activityDetailPartModel = item |
| | | if self.selectStudents.contains(where: {($0 as! ActivityDetailPartModel).id == item.id}){ |
| | | cell.img_radio.image = UIImage(named: "btn_choose_s") |
| | | cell.view_container.borderColor = UIColor(hexStr: "#FD7902").withAlphaComponent(0.28) |
| | | }else{ |
| | | cell.img_radio.image = UIImage(named: "") |
| | | cell.view_container.borderColor = UIColor(hexStr: "#ADADAD").withAlphaComponent(0.28) |
| | | } |
| | | return cell |
| | | } |
| | | |
| | | |
| | | return UITableViewCell() |
| | | } |
| | | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| | | if itemType == .course{ |
| | | return stuViewModel.dataSource.value.count |
| | | }else{ |
| | | return actViewModel.dataSource.value.count |
| | | } |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | |
| | | if itemType == .course{ |
| | | let item = stuViewModel.dataSource.value[indexPath.row] |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfoTCell") as! StudentInfoTCell |
| | | cell.cons_handleCenterY.constant = -7 |
| | | if self.selectStudents.contains(where: {($0 as! CourseDetailStudentModel).id == item.id}){ |
| | | cell.btn_handle.setImage(UIImage(named: "btn_choose_s"), for: .normal) |
| | | cell.view_container.borderColor = UIColor(hexStr: "#FD7902").withAlphaComponent(0.28) |
| | | }else{ |
| | | cell.btn_handle.setImage(nil, for: .normal) |
| | | cell.view_container.borderColor = UIColor(hexStr: "#ADADAD").withAlphaComponent(0.28) |
| | | } |
| | | cell.studentModel = item |
| | | return cell |
| | | }else if itemType == .activity{ |
| | | let item = actViewModel.dataSource.value[indexPath.row] |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfo_2_TCell") as! StudentInfo_2_TCell |
| | | cell.btn_delete.isHidden = true |
| | | cell.btn_edit.isHidden = true |
| | | cell.activityDetailPartModel = item |
| | | if self.selectStudents.contains(where: {($0 as! ActivityDetailPartModel).id == item.id}){ |
| | | cell.img_radio.image = UIImage(named: "btn_choose_s") |
| | | cell.view_container.borderColor = UIColor(hexStr: "#FD7902").withAlphaComponent(0.28) |
| | | }else{ |
| | | cell.img_radio.image = UIImage(named: "") |
| | | cell.view_container.borderColor = UIColor(hexStr: "#ADADAD").withAlphaComponent(0.28) |
| | | } |
| | | return cell |
| | | } |
| | | |
| | | |
| | | return UITableViewCell() |
| | | } |
| | | } |
| | | |
| | | |