| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- //
- // DemanHallViewController.m
- // HappyWork
- //
- // Created by 张晓光 on 2019/9/19.
- // Copyright © 2019 张晓光. All rights reserved.
- //
- #import "DemanHallViewController.h"
- #import "DemanHallMenuFilterView.h"
- #import "DemanHallNaviBarView.h"
- #import "PersonalCenterViewController.h"//个人中心
- #import "DemanHallDetailViewController.h"//详情
- #import "DemanHallViewModel.h"
- #import "HWUpdateView.h"
- @interface DemanHallViewController ()
- <
- UITableViewDelegate,
- DemanHallMenuFilterViewDelegate
- >
- @property (nonatomic, strong) DemanHallMenuFilterView *menuFilterView;
- @property (nonatomic, strong) DemanHallNaviBarView *naviBarView;
- @property (nonatomic, strong) DemanHallViewModel *viewModel;
- @end
- @implementation DemanHallViewController
- - (void)viewWillAppear:(BOOL)animated {
-
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES animated:animated];
- }
- - (void)viewDidLoad {
-
- [super viewDidLoad];
- [self dealWithRequestResult];
-
- }
- #pragma mark – init
- - (void)initSubViews {
-
- self.view.backgroundColor = COLOR_GRAY_F5;
- [self.view addSubview:self.naviBarView];
- [self.view addSubview:self.tableView];
- self.tableView.delegate = self;
- self.tableView.dataSource = self.viewModel;
-
- [self.naviBarView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.left.right.top.equalTo(self.view).offset(0);
- }];
- [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)dealWithRequestResult {
-
- [self.view showLoadingView];
- [self.viewModel bannerRequirement];
- [self.viewModel appUpdateRequirement];
- __weak typeof(self) weakSelf = self;
-
- //banner
- self.viewModel.bannerDataBlock = ^{
-
- [weakSelf.tableView reloadData];
- };
- //更新
- self.viewModel.updateDataBlock = ^(NSDictionary * _Nonnull dataDict) {
-
- id isLatest = [dataDict valueForKeyPath:@"data.isLatest"];//[isLatest isKindOfClass:[NSNumber class]] &&
-
- if (![isLatest boolValue])
- {
- id isForceUpdate = [dataDict valueForKeyPath:@"data.hwVersion.isForceUpdate"];//1强制更新
- id description = [dataDict valueForKeyPath:@"data.hwVersion.description"];
- if ([isForceUpdate isKindOfClass:[NSNumber class]] && [description isKindOfClass:[NSString class]])
- {
- HWUpdateView *updateView = [[HWUpdateView alloc]init];
- updateView.update = [isForceUpdate boolValue];
- NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[description dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- updateView.detailLabel.attributedText = attrStr;
- }
- }
- };
- //列表
- [self.viewModel initWithResponseDataBlock:^(id _Nonnull data) {
-
- [weakSelf successfulRefreshOperation];
-
- weakSelf.lastPage = [data[@"data"][@"isLast"] boolValue];
- if (weakSelf.viewModel.listArray.count == 0)
- {//空页面是否显示(没有加载更多了)
- weakSelf.refreshFooter.noText = YES;
- }
- else
- {
- weakSelf.refreshFooter.noText = NO;
- }
-
- } fail:^(id _Nonnull data) {
-
- [weakSelf failRefreshOperation];
- [HWProgressHUD fb_showFailureWithStatus:data];
- }];
-
- }
- #pragma maek - super method
- /* 请求数据 */
- - (void)requestListData {
-
- [super requestListData];
- [self.viewModel getRequirementList:self.parametersDict];
- }
- /* 第一页 */
- - (void)loadNewData {
- [super loadNewData];
- [self.viewModel bannerRequirement];
- }
- /* 下一页*/
- - (void)loadMoreData {
- [super loadMoreData];
- }
- #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"];
- [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.parametersDict setValue:provinceCode forKey:@"province_code"];
- }
- else
- {
- [self.parametersDict removeObjectForKey:@"province_code"];
- }
- if (cityCode.length > 0)
- {
- [self.parametersDict setValue:cityCode forKey:@"city_code"];
- }
- else
- {
- [self.parametersDict removeObjectForKey:@"city_code"];
- }
- if (areaCode.length > 0)
- {
- [self.parametersDict setValue:areaCode forKey:@"country_code"];
- }
- else
- {
- [self.parametersDict removeObjectForKey:@"country_code"];
- }
- self.currentPage = 1;
- [self requestListData];
-
- }
- - (void)menuFilter:(DemanHallMenuFilterView *)menuFilter selectIndustry:(NSString *)industryName industryIndex:(NSString *)industryIndex {
-
- if ([industryIndex isEqualToString:@"-1"])
- {
- [self.parametersDict removeObjectForKey:@"trade_type"];
- }
- else
- {
- [self.parametersDict setValue:industryIndex forKey:@"trade_type"];
- }
- self.currentPage = 1;
- [self requestListData];
-
- }
- - (void)menuFilter:(DemanHallMenuFilterView *)menuFilter selectPrice:(NSString *)priceName priceIndex:(NSString *)priceIndex {
-
- [self.parametersDict setValue:priceIndex forKey:@"priceType"];
- self.currentPage = 1;
- [self requestListData];
-
- }
- #pragma mark - event response
- //个人中心
- - (void)headerButtonClick:(UIButton *)btn {
-
- PersonalCenterViewController *vc = [[PersonalCenterViewController alloc]init];
- [self.navigationController pushViewController:vc animated:YES];
- }
- #pragma mark - setter and getter
- - (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
|