| | |
| | | import RxCocoa |
| | | |
| | | class SignUpCourseViewModel:RefreshModel<SignUpCourseItemModel>{ |
| | | |
| | | var packageTypeData = BehaviorRelay<[NormalSimpleModel]?>(value: nil) |
| | | var selectPackeType = BehaviorRelay<NormalSimpleModel?>(value: nil) |
| | | var courseType = BehaviorRelay<NormalSimpleModel?>(value: nil) |
| | | var search = BehaviorRelay<String?>(value: nil) |
| | | |
| | | override func api() -> (Observable<BaseResponse<[SignUpCourseItemModel]>>)? { |
| | | return Services.registeredCourse(courseTypeId: courseType.value?.id, search: search.value) |
| | | } |
| | | |
| | | func getDefaultData(){ |
| | | Services.coursePackageType().subscribe(onNext: {[weak self] data in |
| | | if var datas = data.data{ |
| | | datas.insert(NormalSimpleModel(id: -1, name: "全部"), at: 0) |
| | | self?.packageTypeData.accept(datas) |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | |
| | | var packageTypeData = BehaviorRelay<[NormalSimpleModel]?>(value: nil) |
| | | var selectPackeType = BehaviorRelay<NormalSimpleModel?>(value: nil) |
| | | var courseType = BehaviorRelay<NormalSimpleModel?>(value: nil) |
| | | var search = BehaviorRelay<String?>(value: nil) |
| | | |
| | | override func api() -> (Observable<BaseResponse<[SignUpCourseItemModel]>>)? { |
| | | return Services.registeredCourse(courseTypeId: courseType.value?.id, search: search.value) |
| | | } |
| | | |
| | | func getDefaultData(){ |
| | | Services.coursePackageType().subscribe(onNext: {[weak self] data in |
| | | if var datas = data.data{ |
| | | datas.insert(NormalSimpleModel(id: -1, name: "全部"), at: 0) |
| | | self?.packageTypeData.accept(datas) |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | } |
| | | |
| | | class SignUpCourseVC: BaseVC { |
| | | |
| | | @IBOutlet weak var view_topView: UIView! |
| | | @IBOutlet weak var tf_search: QMUITextField! |
| | | @IBOutlet weak var tableView: BaseTableView! |
| | | @IBOutlet weak var btn_courseType: QMUIButton! |
| | | |
| | | private var showSubTypeView:CourseSubTypeView? |
| | | private let viewModel = SignUpCourseViewModel() |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "已报名运动营" |
| | | viewModel.getDefaultData() |
| | | viewModel.beginRefresh() |
| | | } |
| | | |
| | | override func setUI() { |
| | | btn_courseType.imagePosition = .right |
| | | btn_courseType.spacingBetweenImageAndTitle = 5 |
| | | |
| | | tableView.delegate = self |
| | | tableView.dataSource = self |
| | | tableView.register(UINib(nibName: "CourseSignUpTCell", bundle: nil), forCellReuseIdentifier: "_CourseSignUpTCell") |
| | | tableView.separatorStyle = .none |
| | | tf_search.delegate = self |
| | | viewModel.configure(tableView,needMore: false) |
| | | // tableView.jq_setEmptyView() |
| | | } |
| | | |
| | | override func setRx() { |
| | | tf_search.rx.controlEvent(.editingDidEnd).subscribe(onNext: { [weak self] in |
| | | if self?.tf_search.text?.isEmpty ?? true{ |
| | | self?.viewModel.search.accept(nil) |
| | | }else{ |
| | | self?.viewModel.search.accept(self?.tf_search.text!) |
| | | } |
| | | self?.viewModel.beginRefresh() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | private func cleanOther(){ |
| | | btn_courseType.isSelected = false |
| | | } |
| | | |
| | | @IBAction func crouseTypeAction(_ sender: UIButton) { |
| | | |
| | | guard !sender.isSelected else {return} |
| | | cleanOther() |
| | | sender.isSelected = true |
| | | showSubTypeView = CourseSubTypeView.show(inView: self.view, afterView: view_topView, items: viewModel.packageTypeData.value!,selectModel: viewModel.courseType.value) { [weak self] m in |
| | | if m.name != "全部"{ |
| | | sender.setTitle(m.name, for: .normal) |
| | | self?.viewModel.courseType.accept(m) |
| | | }else{ |
| | | sender.setTitle("运动营类型", for: .normal) |
| | | self?.viewModel.courseType.accept(nil) |
| | | } |
| | | sender.isSelected = false |
| | | self?.viewModel.beginRefresh() |
| | | } closeClouse: { |
| | | sender.isSelected = false |
| | | } |
| | | } |
| | | |
| | | @IBAction func searchAction(_ sender: UIButton) { |
| | | view.endEditing(true) |
| | | viewModel.beginRefresh() |
| | | } |
| | | |
| | | @IBOutlet weak var view_topView: UIView! |
| | | @IBOutlet weak var tf_search: QMUITextField! |
| | | @IBOutlet weak var tableView: BaseTableView! |
| | | @IBOutlet weak var btn_courseType: QMUIButton! |
| | | |
| | | private var showSubTypeView:CourseSubTypeView? |
| | | private let viewModel = SignUpCourseViewModel() |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "已报名运动营" |
| | | viewModel.getDefaultData() |
| | | viewModel.beginRefresh() |
| | | } |
| | | |
| | | override func setUI() { |
| | | btn_courseType.imagePosition = .right |
| | | btn_courseType.spacingBetweenImageAndTitle = 5 |
| | | |
| | | tableView.delegate = self |
| | | tableView.dataSource = self |
| | | tableView.register(UINib(nibName: "CourseSignUpTCell", bundle: nil), forCellReuseIdentifier: "_CourseSignUpTCell") |
| | | tableView.separatorStyle = .none |
| | | tf_search.delegate = self |
| | | viewModel.configure(tableView,needMore: false) |
| | | // tableView.jq_setEmptyView() |
| | | } |
| | | |
| | | override func setRx() { |
| | | tf_search.rx.controlEvent(.editingDidEnd).subscribe(onNext: { [weak self] in |
| | | if self?.tf_search.text?.isEmpty ?? true{ |
| | | self?.viewModel.search.accept(nil) |
| | | }else{ |
| | | self?.viewModel.search.accept(self?.tf_search.text!) |
| | | } |
| | | self?.viewModel.beginRefresh() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | private func cleanOther(){ |
| | | btn_courseType.isSelected = false |
| | | } |
| | | |
| | | @IBAction func crouseTypeAction(_ sender: UIButton) { |
| | | |
| | | guard !sender.isSelected else {return} |
| | | cleanOther() |
| | | sender.isSelected = true |
| | | showSubTypeView = CourseSubTypeView.show(inView: self.view, afterView: view_topView, items: viewModel.packageTypeData.value!,selectModel: viewModel.courseType.value) { [weak self] m in |
| | | if m.name != "全部"{ |
| | | sender.setTitle(m.name, for: .normal) |
| | | self?.viewModel.courseType.accept(m) |
| | | }else{ |
| | | sender.setTitle("运动营类型", for: .normal) |
| | | self?.viewModel.courseType.accept(nil) |
| | | } |
| | | sender.isSelected = false |
| | | self?.viewModel.beginRefresh() |
| | | } closeClouse: { |
| | | sender.isSelected = false |
| | | } |
| | | } |
| | | |
| | | @IBAction func searchAction(_ sender: UIButton) { |
| | | view.endEditing(true) |
| | | viewModel.beginRefresh() |
| | | } |
| | | } |
| | | |
| | | extension SignUpCourseVC:UITableViewDelegate{ |
| | | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
| | | let item = viewModel.dataSource.value[indexPath.row] |
| | | Services.registeredData(coursePayId: item.coursePayId,orderId: item.orderId).subscribe(onNext: {data in |
| | | if let m1 = data.data{ |
| | | if m1.payStatus == .unPayment{ |
| | | Services.queryCourseInfo(id: item.coursePackageId,payId: item.coursePayId).subscribe(onNext: { data in |
| | | if let m2 = data.data{ |
| | | let vc = CourseDetailApplyVC(detailModel: m2,signUpModel: m1) |
| | | self.push(vc: vc) |
| | | } |
| | | }).disposed(by: self.disposeBag) |
| | | }else{ |
| | | let vc = CourseDetailVC(id: item.coursePackageId, signUpCourseModel: m1) |
| | | self.push(vc: vc) |
| | | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
| | | let item = viewModel.dataSource.value[indexPath.row] |
| | | Services.registeredData(coursePayId: item.coursePayId,orderId: item.orderId).subscribe(onNext: {data in |
| | | if let m1 = data.data{ |
| | | if m1.payStatus == .unPayment{ |
| | | Services.queryCourseInfo(id:item.coursePackageId,payId: item.coursePayId).subscribe(onNext: { data in |
| | | if let m2 = data.data{ |
| | | let vc = CourseDetailApplyVC(detailModel: m2,signUpModel: m1) |
| | | self.push(vc: vc) |
| | | } |
| | | }).disposed(by: self.disposeBag) |
| | | }else{ |
| | | let vc = CourseDetailVC(id: item.coursePackageId, signUpCourseModel: m1) |
| | | self.push(vc: vc) |
| | | } |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | } |
| | | |
| | | extension SignUpCourseVC:UITableViewDataSource{ |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseSignUpTCell") as! CourseSignUpTCell |
| | | cell.signUpCourseItemModel = viewModel.dataSource.value[indexPath.row] |
| | | return cell |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| | | return viewModel.dataSource.value.count |
| | | } |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseSignUpTCell") as! CourseSignUpTCell |
| | | cell.signUpCourseItemModel = viewModel.dataSource.value[indexPath.row] |
| | | return cell |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| | | return viewModel.dataSource.value.count |
| | | } |
| | | } |
| | | |
| | | extension SignUpCourseVC:QMUITextFieldDelegate{ |
| | | func textFieldShouldReturn(_ textField: UITextField) -> Bool { |
| | | textField.resignFirstResponder() |
| | | viewModel.beginRefresh() |
| | | return true |
| | | } |
| | | func textFieldShouldReturn(_ textField: UITextField) -> Bool { |
| | | textField.resignFirstResponder() |
| | | viewModel.beginRefresh() |
| | | return true |
| | | } |
| | | } |
| | | |