| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- //
- // DemanHallViewController.m
- // HappyWork
- //
- // Created by 张晓光 on 2019/9/19.
- // Copyright © 2019 张晓光. All rights reserved.
- //
- #import "DemanHallViewController.h"
- #import "DemanHallMenuFilterView.h"
- #import "DemanHallNaviBarView.h"
- #import "AgreementPolicyView.h"
- #import "RegisterAgreementViewController.h"
- #import "PersonalCenterViewController.h"//个人中心
- #import "DemanHallDetailViewController.h"//详情
- #import "DemanHallViewModel.h"
- @interface DemanHallViewController ()
- <
- UITableViewDelegate,
- DemanHallMenuFilterViewDelegate,
- PageListTableViewDelegate
- >
- @property (nonatomic, strong) PageListTableView *tableView;
- @property (nonatomic, strong) DemanHallMenuFilterView *menuFilterView;
- @property (nonatomic, strong) DemanHallNaviBarView *naviBarView;
- @property (nonatomic, strong) DemanHallViewModel *viewModel;
- @end
- @implementation DemanHallViewController
- #pragma mark - life cycle
- - (void)dealloc {
-
- [[NSNotificationCenter defaultCenter] removeObserver:self name:loginRefreshNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:refreshDemandHallNotification object:nil];
- }
- - (void)viewWillAppear:(BOOL)animated {
-
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES animated:animated];
- }
- - (void)viewDidLoad {
-
- [super viewDidLoad];
- NAVI_BACK_TITLE;
- [self makeConstraints];
- [self dealWithNetworkRequestResult];
-
- //添加登录刷新通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginRefresh:) name:loginRefreshNotification object:nil];
-
- //添加取消报名刷新通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshHallSignup:) name:refreshDemandHallNotification object:nil];
-
- [self showAgreementAndPolicyView];
- }
- - (void)test{
-
- NSLog(@"分支测试");
- }
- #pragma mark - event response 通知
- /* 登录刷新 */
- - (void)loginRefresh:(NSNotification *)notification {
-
- self.tableView.currentPage = 1;
- [self.tableView.parametersDict setValue:@(self.tableView.currentPage) forKey:@"pageNo"];
- [self dealWithNetworkRequestListResult];
- }
- /* 报名和取消报名 */
- - (void)refreshHallSignup:(NSNotification *)notification {
-
- NSDictionary *dict = notification.userInfo;
- NSString *requirementId = [NSString stringWithFormat:@"%@",dict[@"requirementId"]];
-
- for (int i = 0; i < self.viewModel.listArray.count; i ++ )
- {
- NSString *ID = [NSString stringWithFormat:@"%@",self.viewModel.listArray[i][@"id"]];
- if ([requirementId isEqualToString:ID])
- {
- NSMutableDictionary *indexDict=[self.viewModel.listArray[i] mutableCopy];
- if ([dict[@"cancel"] boolValue])
- {//取消报名
- [indexDict setValue:@(NO) forKey:@"isEnrollment"];
- }
- else
- {//报名
- [indexDict setValue:@(YES) forKey:@"isEnrollment"];
- }
- [self.viewModel.listArray setObject:indexDict atIndexedSubscript:i];
-
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:1];
-
- [self.tableView.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
-
- return;
- }
- }
- }
- #pragma mark – init
- - (void)makeConstraints {
-
- self.view.backgroundColor = COLOR_F5F5F5;
- [self.view addSubview:self.naviBarView];
- [self.view addSubview:self.tableView];
-
- [self.naviBarView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.left.right.top.equalTo(self.view).offset(0);
- make.height.mas_equalTo(STATUS_BAR_H + 44);
- }];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.left.right.equalTo(self.view).offset(0);
- make.top.equalTo(self.naviBarView.mas_bottom).offset(0);
- make.bottom.equalTo(self.view.mas_bottom).offset(0);
-
- }];
- }
- #pragma mark - private metnod
- /* 显示协议政策 */
- - (void)showAgreementAndPolicyView {
-
- BOOL flag = [[NSUserDefaults standardUserDefaults] boolForKey:@"agreementPolicy"];
-
- if (!flag)
- {
- AgreementPolicyView *apView = [[AgreementPolicyView alloc] init];
- [self.view addSubview:apView];
-
- apView.readAgreementBlock = ^(NSInteger flag) {
-
- RegisterAgreementViewController *registerAgreement = [[RegisterAgreementViewController alloc]init];
- registerAgreement.type = flag;
- [self.navigationController pushViewController:registerAgreement animated:YES];
- };
- }
- }
- /* 处理请求结果 */
- - (void)dealWithNetworkRequestResult {
-
- __weak typeof(self) weakSelf = self;
-
- //更新
- [self.viewModel appUpdateRequirement];
-
- //banner
- [self.viewModel bannerRequirement:^{
-
- [weakSelf.tableView.tableView reloadData];
- }];
- //列表
- [self dealWithNetworkRequestListResult];
- }
- /* 需求列表 */
- - (void)dealWithNetworkRequestListResult {
-
- __weak typeof(self) weakSelf = self;
-
- [self.viewModel getRequirementList:self.tableView.parametersDict successful:^(NSDictionary * _Nonnull data) {
-
- weakSelf.tableView.lastPage = [data[@"data"][@"isLast"] boolValue];
- [weakSelf.tableView successfulRefreshOperation];
-
- if (weakSelf.viewModel.listArray.count == 0)
- {//空页面是否显示(没有加载更多了)
- weakSelf.tableView.refreshFooter.hiddenText = YES;
- }
- else
- {
- weakSelf.tableView.refreshFooter.hiddenText = NO;
- }
-
- [weakSelf.tableView.tableView reloadData];
-
- } failure:^(NSString * _Nonnull failureMessage) {
-
- [weakSelf.tableView failRefreshOperation];
- [HWProgressHUD fb_showFailureWithStatus:failureMessage];
-
- }];
- }
- #pragma mark - PageListTableViewDelegate
- - (void)refreshData {
-
- [self dealWithNetworkRequestResult];
- }
- #pragma mark - UITableViewDelegate
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
-
- if (section == 1)
- {
- return self.menuFilterView;
- }
- else
- {
- return nil;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
-
- if (section == 1)
- {
- return 59;
- }
- else
- {
- return CGFLOAT_MIN;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (indexPath.section == 1)
- {
- if (self.viewModel.listArray.count > 0 )
- {
- DemanHallDetailViewController *detail = [[DemanHallDetailViewController alloc]init];
- detail.hwRequirementId = self.viewModel.listArray[indexPath.row][@"id"];
- detail.type = HWDemanDetailTypeHall;
- [self.navigationController pushViewController:detail animated:YES];
- }
- }
- }
- #pragma mark - DemanHallMenuFilterViewDelegate
- - (void)menuFilter:(DemanHallMenuFilterView *)menuFilter selectProvince:(NSString *)provinceCode city:(NSString *)cityCode area:(NSString *)areaCode {
-
- if (provinceCode.length > 0)
- {
- [self.tableView.parametersDict setValue:provinceCode forKey:@"province_code"];
- }
- else
- {
- [self.tableView.parametersDict removeObjectForKey:@"province_code"];
- }
- if (cityCode.length > 0)
- {
- [self.tableView.parametersDict setValue:cityCode forKey:@"city_code"];
- }
- else
- {
- [self.tableView.parametersDict removeObjectForKey:@"city_code"];
- }
- if (areaCode.length > 0)
- {
- [self.tableView.parametersDict setValue:areaCode forKey:@"country_code"];
- }
- else
- {
- [self.tableView.parametersDict removeObjectForKey:@"country_code"];
- }
- self.tableView.currentPage = 1;
- [self.tableView.parametersDict setValue:@(self.tableView.currentPage ) forKey:@"pageNo"];
- [self dealWithNetworkRequestListResult];
-
- }
- - (void)menuFilter:(DemanHallMenuFilterView *)menuFilter selectIndustry:(NSString *)industryName industryIndex:(NSString *)industryIndex {
-
- if ([industryIndex isEqualToString:@"-1"])
- {
- [self.tableView.parametersDict removeObjectForKey:@"trade_type"];
- }
- else
- {
- [self.tableView.parametersDict setValue:industryIndex forKey:@"trade_type"];
- }
- self.tableView.currentPage = 1;
- [self.tableView.parametersDict setValue:@(self.tableView.currentPage ) forKey:@"pageNo"];
- [self dealWithNetworkRequestListResult];
- }
- - (void)menuFilter:(DemanHallMenuFilterView *)menuFilter selectPrice:(NSString *)priceName priceIndex:(NSString *)priceIndex {
-
- [self.tableView.parametersDict setValue:priceIndex forKey:@"priceType"];
- self.tableView.currentPage = 1;
- [self.tableView.parametersDict setValue:@(self.tableView.currentPage) forKey:@"pageNo"];
- [self dealWithNetworkRequestListResult];
- }
- #pragma mark - event response
- /* 个人中心 */
- - (void)headerButtonClick:(UIButton *)btn {
-
-
- if (ISLOGIN)
- {
- PersonalCenterViewController *vc = [[PersonalCenterViewController alloc]init];
- [self.navigationController pushViewController:vc animated:YES];
- }
- else
- {
- AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate pushLoginViewController];
- }
-
-
- }
- #pragma mark - lazy
- - (PageListTableView *)tableView {
-
- if (_tableView == nil)
- {
- _tableView = [[PageListTableView alloc] init];
- _tableView.delagete = self;
- _tableView.tableView.delegate = self;
- _tableView.tableView.dataSource = self.viewModel;
- }
- return _tableView;
- }
- - (DemanHallNaviBarView *)naviBarView {
-
- if (_naviBarView == nil)
- {
- _naviBarView = [[DemanHallNaviBarView alloc]init];
- _naviBarView.titleLabel.text = @"需求大厅";
- [_naviBarView.rigthBtn setImage:[UIImage imageNamed:@"people_icon"] forState:UIControlStateNormal];
- [_naviBarView.rigthBtn addTarget:self action:@selector(headerButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _naviBarView;
- }
- - (DemanHallMenuFilterView *)menuFilterView {
-
- if (_menuFilterView == nil)
- {
- _menuFilterView = [[DemanHallMenuFilterView alloc]init];
- _menuFilterView.delegate = self;
- }
- return _menuFilterView;
- }
- - (DemanHallViewModel *)viewModel {
-
- if (_viewModel == nil)
- {
- _viewModel = [[DemanHallViewModel alloc]init];
- }
- return _viewModel;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|