| | |
| | | // |
| | | // StudentCourseDetailVC.swift |
| | | // WanPai |
| | | // |
| | | // Created by 无故事王国 on 2023/6/27. |
| | | // |
| | | // |
| | | // StudentCourseDetailVC.swift |
| | | // WanPai |
| | | // |
| | | // Created by 无故事王国 on 2023/6/27. |
| | | // |
| | | |
| | | import UIKit |
| | | import JQTools |
| | |
| | | |
| | | class StudentCourseViewModel:RefreshModel<CourseRecordModel>{ |
| | | |
| | | let stuId = BehaviorRelay<Int>(value: 0) |
| | | let lessionId = BehaviorRelay<Int>(value: 0) |
| | | let startTime = BehaviorRelay<Date?>(value: nil) |
| | | let type = BehaviorRelay<Int?>(value: nil) |
| | | let stuId = BehaviorRelay<Int>(value: 0) |
| | | let lessionId = BehaviorRelay<Int>(value: 0) |
| | | let startTime = BehaviorRelay<Date?>(value: nil) |
| | | let type = BehaviorRelay<Int?>(value: nil) |
| | | |
| | | override func api() -> (Observable<BaseResponse<[CourseRecordModel]>>)? { |
| | | return Services.recordDetails(stuId: stuId.value, lessionId: lessionId.value, startTime: startTime.value?.jq_format("yyyy-MM"), type: type.value) |
| | | } |
| | | override func api() -> (Observable<BaseResponse<[CourseRecordModel]>>)? { |
| | | return Services.recordDetails(stuId: stuId.value, lessionId: lessionId.value, startTime: startTime.value?.jq_format("yyyy-MM"), type: type.value) |
| | | } |
| | | } |
| | | |
| | | |
| | | class StudentCourseDetailVC: BaseVC { |
| | | |
| | | private var models = [StartClouseListModel]() |
| | | private var studentModel:StudentSimpleProfileModel! |
| | | private var defaultIndex = 0 |
| | | private var models = [StartClouseListModel]() |
| | | private var studentModel:StudentSimpleProfileModel! |
| | | private var defaultIndex = 0 |
| | | |
| | | private lazy var tableView:BaseTableView = { |
| | | let table = BaseTableView(frame: .zero, style: .plain) |
| | | table.separatorStyle = .none |
| | | table.delegate = self |
| | | table.dataSource = self |
| | | if #available(iOS 15.0, *) { |
| | | table.sectionHeaderTopPadding = 0 |
| | | } |
| | | table.register(UINib(nibName: "CourseChargeTCell", bundle: nil), forCellReuseIdentifier: "_CourseChargeTCell") |
| | | return table |
| | | }() |
| | | private lazy var tableView:BaseTableView = { |
| | | let table = BaseTableView(frame: .zero, style: .plain) |
| | | table.separatorStyle = .none |
| | | table.delegate = self |
| | | table.dataSource = self |
| | | if #available(iOS 15.0, *) { |
| | | table.sectionHeaderTopPadding = 0 |
| | | } |
| | | table.register(UINib(nibName: "CourseChargeTCell", bundle: nil), forCellReuseIdentifier: "_CourseChargeTCell") |
| | | return table |
| | | }() |
| | | |
| | | private var headView:StudentCourseDetailHeadView = { |
| | | return StudentCourseDetailHeadView.jq_loadNibView() |
| | | }() |
| | | private let viewModel = StudentCourseViewModel() |
| | | private var headView:StudentCourseDetailHeadView = { |
| | | return StudentCourseDetailHeadView.jq_loadNibView() |
| | | }() |
| | | private let viewModel = StudentCourseViewModel() |
| | | |
| | | private lazy var sectionView:HeaderInSectionView = { |
| | | let v = HeaderInSectionView() |
| | | v.btn_filter.addTarget(self, action: #selector(fliterAction), for: .touchUpInside) |
| | | v.btn_datetime.addTarget(self, action: #selector(datetimePickerAction), for: .touchUpInside) |
| | | return v |
| | | }() |
| | | private lazy var sectionView:HeaderInSectionView = { |
| | | let v = HeaderInSectionView() |
| | | v.btn_filter.addTarget(self, action: #selector(fliterAction), for: .touchUpInside) |
| | | v.btn_datetime.addTarget(self, action: #selector(datetimePickerAction), for: .touchUpInside) |
| | | return v |
| | | }() |
| | | |
| | | |
| | | required init(models:[StartClouseListModel],defaultIndex:Int,studentModel:StudentSimpleProfileModel) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.models = models |
| | | self.defaultIndex = defaultIndex |
| | | self.studentModel = studentModel |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "课时详情" |
| | | |
| | | headView.renewalClouse = { [weak self] () in |
| | | guard let weakSelf = self else { return } |
| | | let model = weakSelf.models[weakSelf.headView.pageMenu.selectedItemIndex] |
| | | |
| | | Services.registeredData(coursePayId: model.id,orderId: model.orderId).subscribe(onNext: {[weak self]data in |
| | | if let m1 = data.data{ |
| | | let vc = CourseDetailVC(id: model.courseId, signUpCourseModel: m1) |
| | | self?.push(vc: vc) |
| | | required init(models:[StartClouseListModel],defaultIndex:Int,studentModel:StudentSimpleProfileModel) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.models = models |
| | | self.defaultIndex = defaultIndex |
| | | self.studentModel = studentModel |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | /** |
| | | Services.queryCourseInfo(id: model.courseId).subscribe(onNext: {[weak self] data in |
| | | guard let weakSelf = self else { return } |
| | | if let m = data.data{ |
| | | Services.registeredData(coursePayId: model.coursePayId ?? 0,orderId: model.orderId).subscribe(onNext: {data in |
| | | if let m1 = data.data{ |
| | | let vc = CourseDetailVC(id: model.courseId, signUpCourseModel: m1) |
| | | weakSelf.push(vc: vc) |
| | | } |
| | | }) { error in |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | } |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "课时详情" |
| | | |
| | | **/ |
| | | } |
| | | headView.renewalClouse = { [weak self] () in |
| | | guard let weakSelf = self else { return } |
| | | let model = weakSelf.models[weakSelf.headView.pageMenu.selectedItemIndex] |
| | | |
| | | viewModel.startTime.accept(Date()) |
| | | viewModel.lessionId.accept(models[defaultIndex].courseId) |
| | | viewModel.stuId.accept(studentModel.stuId) |
| | | Services.registeredData(coursePayId: model.id,orderId: model.orderId).subscribe(onNext: {[weak self]data in |
| | | if let m1 = data.data{ |
| | | let vc = CourseDetailVC(id: model.courseId, signUpCourseModel: m1) |
| | | self?.push(vc: vc) |
| | | } |
| | | }) { error in |
| | | |
| | | headView.pageMenu.setItems(models.map({$0.courseName}), selectedItemIndex: defaultIndex) |
| | | headView.pageMenu.delegate = self |
| | | headView.label_stuName.text = studentModel.stuName |
| | | headView.img_stuProfile.sd_setImage(with: URL(string: studentModel.stuImage),placeholderImage: nil) |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | |
| | | viewModel.beginRefresh() |
| | | } |
| | | } |
| | | |
| | | override func setUI() { |
| | | view.addSubview(tableView) |
| | | tableView.snp.makeConstraints { make in |
| | | make.edges.equalToSuperview() |
| | | } |
| | | viewModel.startTime.accept(Date()) |
| | | viewModel.lessionId.accept(models[defaultIndex].courseId) |
| | | viewModel.stuId.accept(studentModel.stuId) |
| | | |
| | | tableView.tableHeaderView = headView |
| | | headView.snp.makeConstraints { make in |
| | | make.width.equalToSuperview() |
| | | make.height.greaterThanOrEqualTo(0) |
| | | } |
| | | // tableView.jq_setEmptyView() |
| | | viewModel.configure(tableView,needMore: false) |
| | | headView.layoutIfNeeded() |
| | | } |
| | | headView.pageMenu.setItems(models.map({$0.courseName}), selectedItemIndex: defaultIndex) |
| | | headView.pageMenu.delegate = self |
| | | headView.label_stuName.text = studentModel.stuName |
| | | headView.img_stuProfile.sd_setImage(with: URL(string: studentModel.stuImage),placeholderImage: nil) |
| | | |
| | | @objc func fliterAction(){ |
| | | JQ_MenuView().show(self, tapView: sectionView.btn_filter, items: ["全部","增加","扣除"],tableHei: 160) {[weak self] index, str in |
| | | if index == 0{ |
| | | self?.sectionView.btn_filter.setTitle("全部记录", for: .normal) |
| | | self?.viewModel.type.accept(nil) |
| | | }else{ |
| | | self?.sectionView.btn_filter.setTitle(str, for: .normal) |
| | | self?.viewModel.type.accept(index) |
| | | } |
| | | self?.viewModel.beginRefresh() |
| | | } |
| | | } |
| | | viewModel.beginRefresh() |
| | | } |
| | | |
| | | @objc func datetimePickerAction(){ |
| | | CommonDatePickerView.show(before: 3, after: 0, type: .YM) { [weak self] year, month, _,_,_ in |
| | | let date = Date.jq_format(year: year!, month: month!, day: 2) |
| | | self?.sectionView.btn_datetime.setTitle(date!.jq_format("yyyy年MM月>"), for: .normal) |
| | | self?.viewModel.startTime.accept(date) |
| | | self?.viewModel.beginRefresh() |
| | | } |
| | | } |
| | | override func setUI() { |
| | | view.addSubview(tableView) |
| | | tableView.snp.makeConstraints { make in |
| | | make.edges.equalToSuperview() |
| | | } |
| | | |
| | | tableView.tableHeaderView = headView |
| | | headView.snp.makeConstraints { make in |
| | | make.width.equalToSuperview() |
| | | make.height.greaterThanOrEqualTo(0) |
| | | } |
| | | // tableView.jq_setEmptyView() |
| | | viewModel.configure(tableView,needMore: false) |
| | | headView.layoutIfNeeded() |
| | | } |
| | | |
| | | @objc func fliterAction(){ |
| | | JQ_MenuView().show(self, tapView: sectionView.btn_filter, items: ["全部","增加","扣除"],tableHei: 160) {[weak self] index, str in |
| | | if index == 0{ |
| | | self?.sectionView.btn_filter.setTitle("全部记录", for: .normal) |
| | | self?.viewModel.type.accept(nil) |
| | | }else{ |
| | | self?.sectionView.btn_filter.setTitle(str, for: .normal) |
| | | self?.viewModel.type.accept(index) |
| | | } |
| | | self?.viewModel.beginRefresh() |
| | | } |
| | | } |
| | | |
| | | @objc func datetimePickerAction(){ |
| | | CommonDatePickerView.show(before: 3, after: 0, type: .YM) { [weak self] year, month, _,_,_ in |
| | | let date = Date.jq_format(year: year!, month: month!, day: 2) |
| | | self?.sectionView.btn_datetime.setTitle(date!.jq_format("yyyy年MM月>"), for: .normal) |
| | | self?.viewModel.startTime.accept(date) |
| | | self?.viewModel.beginRefresh() |
| | | } |
| | | } |
| | | } |
| | | |
| | | extension StudentCourseDetailVC:UITableViewDelegate{ |
| | |
| | | } |
| | | |
| | | extension StudentCourseDetailVC:UITableViewDataSource{ |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | let model = viewModel.dataSource.value[indexPath.row] |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseChargeTCell") as! CourseChargeTCell |
| | | cell.courseRecordModel = model |
| | | return cell |
| | | } |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | let model = viewModel.dataSource.value[indexPath.row] |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseChargeTCell") as! CourseChargeTCell |
| | | cell.courseRecordModel = model |
| | | 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 |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { |
| | | return 67 |
| | | } |
| | | func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { |
| | | return 67 |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { |
| | | sectionView.btn_datetime.setTitle(viewModel.startTime.value?.jq_format("yyyy年MM月>"), for: .normal) |
| | | return sectionView |
| | | } |
| | | func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { |
| | | sectionView.btn_datetime.setTitle(viewModel.startTime.value?.jq_format("yyyy年MM月>"), for: .normal) |
| | | return sectionView |
| | | } |
| | | } |
| | | |
| | | private class HeaderInSectionView:UIView{ |
| | | |
| | | private(set) lazy var btn_datetime:QMUIButton = { |
| | | let btn = QMUIButton(type: .custom) |
| | | btn.setTitle(Date().jq_format("yyyy年M月>"), for: .normal) |
| | | btn.setTitleColor(UIColor(hexStr: "#0048FF"), for: .normal) |
| | | btn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium) |
| | | return btn |
| | | }() |
| | | private(set) lazy var btn_datetime:QMUIButton = { |
| | | let btn = QMUIButton(type: .custom) |
| | | btn.setTitle(Date().jq_format("yyyy年M月>"), for: .normal) |
| | | btn.setTitleColor(UIColor(hexStr: "#0048FF"), for: .normal) |
| | | btn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium) |
| | | return btn |
| | | }() |
| | | |
| | | private(set) lazy var btn_filter:QMUIButton = { |
| | | let btn = QMUIButton(type: .custom) |
| | | btn.setTitleColor(UIColor(hexStr: "#414141"), for: .normal) |
| | | btn.titleLabel?.font = UIFont.systemFont(ofSize: 16) |
| | | btn.jq_borderWidth = 1 |
| | | btn.jq_borderColor = UIColor(hexStr: "#D5D1D1") |
| | | btn.jq_cornerRadius = 4 |
| | | btn.setTitle("全部记录", for: .normal) |
| | | btn.setImage(UIImage(named: "icon_down_arrow"), for: .normal) |
| | | btn.imagePosition = .right |
| | | btn.spacingBetweenImageAndTitle = 5 |
| | | return btn |
| | | }() |
| | | private(set) lazy var btn_filter:QMUIButton = { |
| | | let btn = QMUIButton(type: .custom) |
| | | btn.setTitleColor(UIColor(hexStr: "#414141"), for: .normal) |
| | | btn.titleLabel?.font = UIFont.systemFont(ofSize: 16) |
| | | btn.jq_borderWidth = 1 |
| | | btn.jq_borderColor = UIColor(hexStr: "#D5D1D1") |
| | | btn.jq_cornerRadius = 4 |
| | | btn.setTitle("全部记录", for: .normal) |
| | | btn.setImage(UIImage(named: "icon_down_arrow"), for: .normal) |
| | | btn.imagePosition = .right |
| | | btn.spacingBetweenImageAndTitle = 5 |
| | | return btn |
| | | }() |
| | | |
| | | override init(frame: CGRect) { |
| | | super.init(frame: frame) |
| | | override init(frame: CGRect) { |
| | | super.init(frame: frame) |
| | | |
| | | backgroundColor = .white |
| | | backgroundColor = .white |
| | | |
| | | addSubview(btn_datetime) |
| | | addSubview(btn_filter) |
| | | addSubview(btn_datetime) |
| | | addSubview(btn_filter) |
| | | |
| | | btn_filter.snp.makeConstraints { make in |
| | | make.right.equalTo(-14) |
| | | make.height.equalTo(38) |
| | | make.width.equalTo(100) |
| | | make.bottom.equalTo(-16) |
| | | } |
| | | btn_filter.snp.makeConstraints { make in |
| | | make.right.equalTo(-14) |
| | | make.height.equalTo(38) |
| | | make.width.equalTo(100) |
| | | make.bottom.equalTo(-16) |
| | | } |
| | | |
| | | btn_datetime.snp.makeConstraints { make in |
| | | make.left.equalTo(14) |
| | | make.height.equalTo(22) |
| | | make.centerY.equalTo(btn_filter) |
| | | } |
| | | } |
| | | btn_datetime.snp.makeConstraints { make in |
| | | make.left.equalTo(14) |
| | | make.height.equalTo(22) |
| | | make.centerY.equalTo(btn_filter) |
| | | } |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | } |
| | | |
| | | extension StudentCourseDetailVC:SPPageMenuDelegate{ |
| | | func pageMenu(_ pageMenu: SPPageMenu, itemSelectedAt index: Int) { |
| | | defaultIndex = index |
| | | func pageMenu(_ pageMenu: SPPageMenu, itemSelectedAt index: Int) { |
| | | defaultIndex = index |
| | | |
| | | |
| | | |
| | | var totoalNum = 0 |
| | | var totalDeductedNum = 0 |
| | | var totalRemainingNum = 0 |
| | | var totoalNum = 0 |
| | | var totalDeductedNum = 0 |
| | | var totalRemainingNum = 0 |
| | | |
| | | for m in models{ |
| | | totoalNum += m.totalNums |
| | | totalDeductedNum += m.deductedNums |
| | | totalRemainingNum += m.remainingNums |
| | | } |
| | | for m in models{ |
| | | totoalNum += m.totalNums |
| | | totalDeductedNum += m.deductedNums |
| | | totalRemainingNum += m.remainingNums |
| | | } |
| | | |
| | | let model = models[index] |
| | | headView.label_deductedNums.text = "\(totalDeductedNum)" |
| | | headView.label_totalNums.text = "\(totoalNum)" |
| | | headView.label_remainingNums.text = "\(totalRemainingNum)" |
| | | let model = models[index] |
| | | headView.label_deductedNums.text = "\(totalDeductedNum)" |
| | | headView.label_totalNums.text = "\(totoalNum)" |
| | | headView.label_remainingNums.text = "\(totalRemainingNum)" |
| | | |
| | | headView.label_preDeductedNums.text = "\(model.deductedNums)" |
| | | headView.label_preTotalNums.text = "\(model.totalNums)" |
| | | headView.label_preRemainingNums.text = "\(model.remainingNums)" |
| | | |
| | | headView.label_preDeductedNums.text = "\(model.deductedNums)" |
| | | headView.label_preTotalNums.text = "\(model.totalNums)" |
| | | headView.label_preRemainingNums.text = "\(model.remainingNums)" |
| | | |
| | | headView.label_datetime.text = "有效期:\(model.periodOfValidity)" |
| | | headView.label_datetime.text = "有效期:\(model.periodOfValidity)" |
| | | |
| | | |
| | | viewModel.lessionId.accept(model.courseId) |
| | | viewModel.beginRefresh() |
| | | // |
| | | // Services.lessonDetails(lessonId: model.courseId, stuId: studentModel.stuId).subscribe(onNext: { data in |
| | | // |
| | | // }).disposed(by: disposeBag) |
| | | } |
| | | viewModel.lessionId.accept(model.courseId) |
| | | viewModel.beginRefresh() |
| | | // |
| | | // Services.lessonDetails(lessonId: model.courseId, stuId: studentModel.stuId).subscribe(onNext: { data in |
| | | // |
| | | // }).disposed(by: disposeBag) |
| | | } |
| | | } |