DemanHallViewController.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. //
  2. // DemanHallViewController.m
  3. // HappyWork
  4. //
  5. // Created by 张晓光 on 2019/9/19.
  6. // Copyright © 2019 张晓光. All rights reserved.
  7. //
  8. #import "DemanHallViewController.h"
  9. #import "DemanHallMenuFilterView.h"
  10. #import "DemanHallNaviBarView.h"
  11. #import "PersonalCenterViewController.h"//个人中心
  12. #import "DemanHallDetailViewController.h"//详情
  13. #import "DemanHallViewModel.h"
  14. #import "HWUpdateView.h"
  15. @interface DemanHallViewController ()
  16. <
  17. UITableViewDelegate,
  18. DemanHallMenuFilterViewDelegate
  19. >
  20. @property (nonatomic, strong) DemanHallMenuFilterView *menuFilterView;
  21. @property (nonatomic, strong) DemanHallNaviBarView *naviBarView;
  22. @property (nonatomic, strong) DemanHallViewModel *viewModel;
  23. @end
  24. @implementation DemanHallViewController
  25. - (void)viewWillAppear:(BOOL)animated {
  26. [super viewWillAppear:animated];
  27. [self.navigationController setNavigationBarHidden:YES animated:animated];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. [self dealWithRequestResult];
  32. }
  33. #pragma mark – init
  34. - (void)initSubViews {
  35. self.view.backgroundColor = COLOR_GRAY_F5;
  36. [self.view addSubview:self.naviBarView];
  37. [self.view addSubview:self.tableView];
  38. self.tableView.delegate = self;
  39. self.tableView.dataSource = self.viewModel;
  40. [self.naviBarView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.right.top.equalTo(self.view).offset(0);
  42. }];
  43. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.right.equalTo(self.view).offset(0);
  45. make.top.equalTo(self.naviBarView.mas_bottom).offset(0);
  46. make.bottom.equalTo(self.view.mas_bottom).offset(0);
  47. }];
  48. }
  49. #pragma mark - private metnod
  50. /* 处理请求结果 */
  51. - (void)dealWithRequestResult {
  52. [self.view showLoadingView];
  53. [self.viewModel bannerRequirement];
  54. [self.viewModel appUpdateRequirement];
  55. __weak typeof(self) weakSelf = self;
  56. //banner
  57. self.viewModel.bannerDataBlock = ^{
  58. [weakSelf.tableView reloadData];
  59. };
  60. //更新
  61. self.viewModel.updateDataBlock = ^(NSDictionary * _Nonnull dataDict) {
  62. id isLatest = [dataDict valueForKeyPath:@"data.isLatest"];//[isLatest isKindOfClass:[NSNumber class]] &&
  63. if (![isLatest boolValue])
  64. {
  65. id isForceUpdate = [dataDict valueForKeyPath:@"data.hwVersion.isForceUpdate"];//1强制更新
  66. id description = [dataDict valueForKeyPath:@"data.hwVersion.description"];
  67. if ([isForceUpdate isKindOfClass:[NSNumber class]] && [description isKindOfClass:[NSString class]])
  68. {
  69. HWUpdateView *updateView = [[HWUpdateView alloc]init];
  70. updateView.update = [isForceUpdate boolValue];
  71. NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[description dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
  72. updateView.detailLabel.attributedText = attrStr;
  73. }
  74. }
  75. };
  76. //列表
  77. [self.viewModel initWithResponseDataBlock:^(id _Nonnull data) {
  78. [weakSelf successfulRefreshOperation];
  79. weakSelf.lastPage = [data[@"data"][@"isLast"] boolValue];
  80. if (weakSelf.viewModel.listArray.count == 0)
  81. {//空页面是否显示(没有加载更多了)
  82. weakSelf.refreshFooter.noText = YES;
  83. }
  84. else
  85. {
  86. weakSelf.refreshFooter.noText = NO;
  87. }
  88. } fail:^(id _Nonnull data) {
  89. [weakSelf failRefreshOperation];
  90. [HWProgressHUD fb_showFailureWithStatus:data];
  91. }];
  92. }
  93. #pragma maek - super method
  94. /* 请求数据 */
  95. - (void)requestListData {
  96. [super requestListData];
  97. [self.viewModel getRequirementList:self.parametersDict];
  98. }
  99. /* 第一页 */
  100. - (void)loadNewData {
  101. [super loadNewData];
  102. [self.viewModel bannerRequirement];
  103. }
  104. /* 下一页*/
  105. - (void)loadMoreData {
  106. [super loadMoreData];
  107. }
  108. #pragma mark - UITableViewDelegate
  109. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  110. if (section == 1)
  111. {
  112. return self.menuFilterView;
  113. }
  114. else
  115. {
  116. return nil;
  117. }
  118. }
  119. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  120. if (section == 1)
  121. {
  122. return 59;
  123. }
  124. else
  125. {
  126. return CGFLOAT_MIN;
  127. }
  128. }
  129. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  130. if (indexPath.section == 1)
  131. {
  132. if (self.viewModel.listArray.count > 0 )
  133. {
  134. DemanHallDetailViewController *detail = [[DemanHallDetailViewController alloc]init];
  135. detail.hwRequirementId = self.viewModel.listArray[indexPath.row][@"id"];
  136. [self.navigationController pushViewController:detail animated:YES];
  137. }
  138. }
  139. }
  140. #pragma mark - DemanHallMenuFilterViewDelegate
  141. - (void)menuFilter:(DemanHallMenuFilterView *)menuFilter selectProvince:(NSString *)provinceCode city:(NSString *)cityCode area:(NSString *)areaCode {
  142. if (provinceCode.length > 0)
  143. {
  144. [self.parametersDict setValue:provinceCode forKey:@"province_code"];
  145. }
  146. else
  147. {
  148. [self.parametersDict removeObjectForKey:@"province_code"];
  149. }
  150. if (cityCode.length > 0)
  151. {
  152. [self.parametersDict setValue:cityCode forKey:@"city_code"];
  153. }
  154. else
  155. {
  156. [self.parametersDict removeObjectForKey:@"city_code"];
  157. }
  158. if (areaCode.length > 0)
  159. {
  160. [self.parametersDict setValue:areaCode forKey:@"country_code"];
  161. }
  162. else
  163. {
  164. [self.parametersDict removeObjectForKey:@"country_code"];
  165. }
  166. self.currentPage = 1;
  167. [self requestListData];
  168. }
  169. - (void)menuFilter:(DemanHallMenuFilterView *)menuFilter selectIndustry:(NSString *)industryName industryIndex:(NSString *)industryIndex {
  170. if ([industryIndex isEqualToString:@"-1"])
  171. {
  172. [self.parametersDict removeObjectForKey:@"trade_type"];
  173. }
  174. else
  175. {
  176. [self.parametersDict setValue:industryIndex forKey:@"trade_type"];
  177. }
  178. self.currentPage = 1;
  179. [self requestListData];
  180. }
  181. - (void)menuFilter:(DemanHallMenuFilterView *)menuFilter selectPrice:(NSString *)priceName priceIndex:(NSString *)priceIndex {
  182. [self.parametersDict setValue:priceIndex forKey:@"priceType"];
  183. self.currentPage = 1;
  184. [self requestListData];
  185. }
  186. #pragma mark - event response
  187. //个人中心
  188. - (void)headerButtonClick:(UIButton *)btn {
  189. PersonalCenterViewController *vc = [[PersonalCenterViewController alloc]init];
  190. [self.navigationController pushViewController:vc animated:YES];
  191. }
  192. #pragma mark - setter and getter
  193. - (DemanHallNaviBarView *)naviBarView {
  194. if (_naviBarView == nil)
  195. {
  196. _naviBarView = [[DemanHallNaviBarView alloc]init];
  197. _naviBarView.titleLabel.text = @"需求大厅";
  198. [_naviBarView.rigthBtn setImage:[UIImage imageNamed:@"people_icon"] forState:UIControlStateNormal];
  199. [_naviBarView.rigthBtn addTarget:self action:@selector(headerButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  200. }
  201. return _naviBarView;
  202. }
  203. - (DemanHallMenuFilterView *)menuFilterView {
  204. if (_menuFilterView == nil)
  205. {
  206. _menuFilterView = [[DemanHallMenuFilterView alloc]init];
  207. _menuFilterView.delegate = self;
  208. }
  209. return _menuFilterView;
  210. }
  211. - (DemanHallViewModel *)viewModel {
  212. if (_viewModel == nil)
  213. {
  214. _viewModel = [[DemanHallViewModel alloc]init];
  215. }
  216. return _viewModel;
  217. }
  218. /*
  219. #pragma mark - Navigation
  220. // In a storyboard-based application, you will often want to do a little preparation before navigation
  221. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  222. // Get the new view controller using [segue destinationViewController].
  223. // Pass the selected object to the new view controller.
  224. }
  225. */
  226. @end