JXZJListViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. //
  2. // JXZJListViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/8/17.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "JXZJListViewController.h"
  9. #import "SQFiltrateView.h"
  10. #import "JSZJlistCell.h"
  11. #import "ZJdetailViewController.h"
  12. #import "ZJlistModel.h"
  13. @interface JXZJListViewController ()<UITableViewDelegate,UITableViewDataSource>{
  14. SQFiltrateItem *item1;
  15. SQFiltrateView *filtrateView;
  16. UITableView *newtableView;
  17. NSMutableArray *dataArray;
  18. int pageIndex;
  19. int pageSize;
  20. int pageNumber;
  21. UIView *showView;
  22. NSMutableArray *leixingArr;
  23. NSMutableArray *leixingIDArr;
  24. NSString *hangyeleixing;
  25. NSString *timeorhaoping;
  26. }
  27. @end
  28. @implementation JXZJListViewController
  29. - (void)viewWillDisappear:(BOOL)animated {
  30. [super viewWillDisappear:animated];
  31. [filtrateView hideAllItemView];
  32. }
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. [self setNavTitle:@"专家列表"];
  36. [self dataInitialization];
  37. [self networkRequesthangyeleixing];
  38. [self loadsView];
  39. [self classificationview];
  40. [self addRefreshing];
  41. [self networkRequest:nil];
  42. // Do any additional setup after loading the view.
  43. }
  44. - (void)networkRequesthangyeleixing{
  45. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  46. [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewindustryList parameters:parameters onSuccess:^(id requestData) {
  47. if ([requestData[@"error"] count] !=0) {
  48. for (NSDictionary *dic in requestData[@"error"]) {
  49. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  50. }
  51. }else{
  52. for (NSDictionary *dic in requestData[@"data"]) {
  53. [leixingArr addObject:dic[@"name"]];
  54. [leixingIDArr addObject:dic[@"id"]];
  55. }
  56. [self classificationview];
  57. }
  58. } onFailure:^{
  59. }];
  60. }
  61. - (void)networkRequest:(id)object
  62. {
  63. int pageNumberIndex=1;
  64. if (!object) {
  65. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  66. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  67. pageNumberIndex = 1;
  68. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  69. pageNumberIndex = pageNumber+1;
  70. }
  71. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  72. [parameters safeSetObject:@(pageSize) forKey:@"pageSize"];
  73. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
  74. [parameters safeSetObject:self.seachStr forKey:@"name"];
  75. [parameters safeSetObject:hangyeleixing forKey:@"industry"];//行业
  76. [parameters safeSetObject:timeorhaoping forKey:@"sortType"];//排序 0时间倒序 1好评倒序
  77. [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewexpertsList parameters:parameters onSuccess:^(id requestData) {
  78. [self dismiss:object];
  79. if ([requestData[@"error"] count] !=0) {
  80. for (NSDictionary *dic in requestData[@"error"]) {
  81. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  82. }
  83. }else{
  84. pageNumber = pageNumberIndex;
  85. if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
  86. [dataArray removeAllObjects];
  87. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  88. NSMutableArray *arr = requestData[@"data"][@"list"];
  89. if ([arr count]<=0) {
  90. [[[UIApplication sharedApplication].delegate window] makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  91. return;
  92. }
  93. }
  94. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  95. ZJlistModel *model = [[ZJlistModel alloc] initWithDictionary:dic error:nil];
  96. [dataArray addObject:model];
  97. }
  98. //查询不到类型底图
  99. if (dataArray.count<=0) {
  100. [self addErrorLoadingFrame:CGRectMake(0, NavHeader+44, newtableView.width, newtableView.height) title:@"暂无数据" buttonTitle:nil imageString:NewNoDataErrorImage];
  101. }else {
  102. [self hideReloadingview];
  103. [newtableView reloadData];
  104. }
  105. }
  106. } onFailure:^{
  107. [self dismiss:object];
  108. }];
  109. }
  110. - (void)dataInitialization{
  111. dataArray = [NSMutableArray new];
  112. pageIndex = 1;
  113. pageSize = 10;
  114. pageNumber = 1;
  115. leixingIDArr = NewMutableArrayInit;
  116. leixingArr = NewMutableArrayInit;
  117. hangyeleixing = @"";
  118. timeorhaoping = @"0";
  119. [leixingIDArr addObject:@""];
  120. [leixingArr addObject:@"不限"];
  121. }
  122. #pragma mark -------分类-------------
  123. - (void)classificationview{
  124. UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, 1)];
  125. line.backgroundColor = NewLineGrayColor;
  126. [self.view addSubview:line];
  127. item1 = [[SQFiltrateItem alloc]init];
  128. item1.listType = OptionListType_Cell;
  129. item1.numberType = OptionNumberType_Single;
  130. // NSMutableArray *arr = NewMutableArrayInit;
  131. // for (NSDictionary *dic in industrytypeArray) {
  132. // [arr addObject:dic[@"name"]];
  133. // }
  134. item1.optionData = @[@"时间",@"好评率"];
  135. item1.title = @"时间";
  136. SQFiltrateItem *item2 = [[SQFiltrateItem alloc]init];
  137. item2.listType = OptionListType_Tag;
  138. item2.numberType = OptionNumberType_Single;
  139. /*
  140. 0--专利, 1--软著, 2--项目, 3--版权, 4--工业设计, 5--配方, 6--非标
  141. */
  142. item2.optionData = leixingArr;
  143. item2.title = @"行业类型";
  144. filtrateView = [[SQFiltrateView alloc]initWithFrame:CGRectMake(0, NavHeader+1, SCREEN_WIDTH, 44)
  145. filtrateItems:@[item1,item2]];
  146. [filtrateView touchBlock:^(SQFiltrateView * _Nonnull view, SQFiltrateItem * _Nonnull item) {
  147. NSLog(@"%@:%@",item.title,item.choseSet);
  148. if ([item.title isEqualToString:@"行业类型"]) {
  149. for (NSSet *luo in item.choseSet) {
  150. NSString *str = [NSString stringWithFormat:@"%@",luo];
  151. NSInteger i = [str intValue];
  152. NSLog(@"%@",leixingIDArr[i]);
  153. hangyeleixing = leixingIDArr[i];
  154. [self networkRequest:nil];
  155. }
  156. }else if([item.title isEqualToString:@"时间"]){
  157. for (NSSet *luo in item.choseSet) {
  158. NSString *str = [NSString stringWithFormat:@"%@",luo];
  159. NSInteger i = [str intValue];
  160. NSArray *arr = @[@"0",@"1"];
  161. timeorhaoping = arr[i];
  162. [self networkRequest:nil];
  163. }
  164. }
  165. }];
  166. [self.view addSubview:filtrateView];
  167. }
  168. #pragma mark -----加载界面-------
  169. - (void)loadsView{
  170. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader+44, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader-44) backgroundColor:NewLineGrayColor style:UITableViewStyleGrouped delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  171. newtableView.separatorStyle = NO;
  172. }
  173. #pragma mark-------------------------UITableView------------------------------------
  174. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  175. {
  176. return 1;
  177. }
  178. //返回每段行数
  179. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  180. {
  181. return dataArray.count;
  182. }
  183. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  184. {
  185. static NSString *Cell = @"Cell";
  186. JSZJlistCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  187. if (cell == nil) {
  188. cell = [[JSZJlistCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  189. }
  190. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  191. cell.accessoryType = UITableViewCellAccessoryNone;
  192. if (dataArray.count>0) {
  193. [cell assignment:dataArray[indexPath.row]];
  194. }
  195. return cell;
  196. }
  197. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  198. {
  199. return 150;
  200. }
  201. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  202. ZJdetailViewController *vc = [[ZJdetailViewController alloc] init];
  203. ZJlistModel *model = dataArray[indexPath.row];
  204. vc.ID = model.uid;
  205. NewPushViewController(vc);
  206. }
  207. // tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
  208. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  209. return CGFLOAT_MIN;
  210. }
  211. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  212. return CGFLOAT_MIN;
  213. }
  214. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  215. return [[UIView alloc] init];
  216. }
  217. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  218. return [[UIView alloc] init];
  219. }
  220. #pragma mark - 上拉下拉初始化
  221. - (void)addRefreshing
  222. {
  223. __weak typeof(self) weakSelf = self;
  224. __weak UITableView *tableView = newtableView;
  225. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  226. if ([NetworkRequestManager connectedToNetwork]) {
  227. [weakSelf networkRequest:tableView.mj_header];
  228. }else{
  229. [tableView.mj_header endRefreshing];
  230. }
  231. }];
  232. tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  233. if ([NetworkRequestManager connectedToNetwork]) {
  234. [weakSelf networkRequest:tableView.mj_footer];
  235. }else{
  236. [tableView.mj_footer endRefreshing];
  237. }
  238. }];
  239. }
  240. - (void)dismiss:(id)object
  241. {
  242. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  243. __weak UITableView *newvc = newtableView;
  244. [newvc.mj_header endRefreshing];
  245. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  246. __weak UITableView *newvc = newtableView;
  247. [newvc.mj_footer endRefreshing];
  248. }else {
  249. [MBProgressHUD hideHUDForView:self.view];
  250. }
  251. }
  252. #pragma mark- 外部触发自动刷新
  253. - (void)autoDownRefresh
  254. {
  255. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  256. [self autoRefresh];
  257. });
  258. }
  259. #pragma mark- 网络请求
  260. - (void)autoRefresh
  261. {
  262. __weak UITableView *tableView = newtableView;
  263. [tableView.mj_header beginRefreshing];
  264. }
  265. #pragma mark 初始化展示框
  266. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  267. {
  268. if(!showView)
  269. {
  270. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  271. [showView setHidden:NO];
  272. [showView setBackgroundColor:NewBgGrayColor];
  273. UIImage *NOimg = [UIImage imageNamed:image];
  274. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  275. [showView addSubview:tempIcon];
  276. tempIcon.sd_layout
  277. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  278. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  279. .widthIs(NOimg.size.width/2.0f)
  280. .heightIs(NOimg.size.height/2.0f);
  281. UILabel *tipLab = [UILabel new];
  282. [showView addSubview:tipLab];
  283. [tipLab setText:text];
  284. [tipLab setTextAlignment:NSTextAlignmentCenter];
  285. [tipLab setTextColor:NewLightGrayColor];
  286. [tipLab setBackgroundColor:NewClearColor];
  287. [tipLab setFont:NewAutoFont(16.0)];
  288. tipLab.sd_layout
  289. .leftEqualToView(showView)
  290. .rightEqualToView(showView)
  291. .topSpaceToView(tempIcon,10)
  292. .heightIs(20.0);
  293. if (buttonText.length>0) {
  294. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  295. [showView addSubview:button];
  296. [button setTitle:buttonText forState:UIControlStateNormal];
  297. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  298. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  299. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  300. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  301. button.sd_layout
  302. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  303. .topSpaceToView(tipLab, 30.0)
  304. .widthIs(width+35)
  305. .heightIs(34);
  306. }
  307. }
  308. [UIView beginAnimations:@"ShowArrow" context:nil];
  309. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  310. [UIView setAnimationDuration:0.25f];
  311. [UIView setAnimationDelegate:self];
  312. [showView setAlpha:1.0f];
  313. [UIView commitAnimations];
  314. }
  315. - (void)hideReloadingview
  316. {
  317. [UIView animateWithDuration:0.25 animations:^{
  318. showView.hidden = YES;
  319. } completion:^(BOOL finished) {
  320. for (id obj in showView.subviews) {
  321. [obj removeFromSuperview];
  322. }
  323. showView = nil;
  324. [showView removeFromSuperview];
  325. }];
  326. }
  327. - (void)didReceiveMemoryWarning {
  328. [super didReceiveMemoryWarning];
  329. // Dispose of any resources that can be recreated.
  330. }
  331. /*
  332. #pragma mark - Navigation
  333. // In a storyboard-based application, you will often want to do a little preparation before navigation
  334. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  335. // Get the new view controller using [segue destinationViewController].
  336. // Pass the selected object to the new view controller.
  337. }
  338. */
  339. @end