CollectionXQViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // CollectionXQViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/8/13.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "CollectionXQViewController.h"
  9. #import "CollectionCGCell.h"
  10. #import "NewshoucangModel.h"
  11. #import "NewDemandDetailsViewController.h"
  12. @interface CollectionXQViewController ()<UITableViewDelegate,UITableViewDataSource>{
  13. UITableView *newtableView;
  14. NSMutableArray *dataArray;
  15. int pageIndex;
  16. int pageSize;
  17. int pageNumber;
  18. UIView *showView;
  19. }
  20. @end
  21. @implementation CollectionXQViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self dataInitialization];
  25. [self loadsView];
  26. [self addRefreshing];
  27. [self networkRequest:nil];
  28. // Do any additional setup after loading the view.
  29. }
  30. - (void)dataInitialization{
  31. dataArray = NewMutableArrayInit;
  32. pageIndex = 1;
  33. pageSize = 10;
  34. pageNumber = 1;
  35. }
  36. - (void)networkRequest:(id)object
  37. {
  38. int pageNumberIndex=1;
  39. if (!object) {
  40. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  41. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  42. pageNumberIndex = 1;
  43. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  44. pageNumberIndex = pageNumber+1;
  45. }
  46. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  47. [parameters safeSetObject:@(pageSize) forKey:@"pageSize"];
  48. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
  49. [parameters safeSetObject:@"1" forKey:@"type"];
  50. [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewappMyCollection parameters:parameters onSuccess:^(id requestData) {
  51. [self dismiss:object];
  52. if ([requestData[@"error"] count] !=0) {
  53. for (NSDictionary *dic in requestData[@"error"]) {
  54. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  55. }
  56. }else{
  57. pageNumber = pageNumberIndex;
  58. if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
  59. [dataArray removeAllObjects];
  60. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  61. NSMutableArray *arr = requestData[@"data"][@"list"];
  62. if ([arr count]<=0) {
  63. [[[UIApplication sharedApplication].delegate window] makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  64. return;
  65. }
  66. }
  67. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  68. NewshoucangModel *model = [[NewshoucangModel alloc] initWithDictionary:dic error:nil];
  69. [dataArray addObject:model];
  70. }
  71. //查询不到类型底图
  72. if (dataArray.count<=0) {
  73. [self addErrorLoadingFrame:CGRectMake(0, 44, newtableView.width, newtableView.height) title:@"暂无数据" buttonTitle:nil imageString:NewNoDataErrorImage];
  74. }else {
  75. [self hideReloadingview];
  76. [newtableView reloadData];
  77. }
  78. }
  79. } onFailure:^{
  80. [self dismiss:object];
  81. }];
  82. }
  83. #pragma mark ----加载界面
  84. - (void)loadsView{
  85. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-(NavHeader+64)) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  86. newtableView.separatorStyle = NO;
  87. }
  88. #pragma mark-------------------------UITableView------------------------------------
  89. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  90. {
  91. return 1;
  92. }
  93. //返回每段行数
  94. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  95. {
  96. return dataArray.count;
  97. }
  98. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  99. {
  100. static NSString *Cell = @"Cell";
  101. CollectionCGCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  102. if (cell == nil) {
  103. cell = [[CollectionCGCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  104. }
  105. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  106. cell.accessoryType = UITableViewCellAccessoryNone;
  107. if (dataArray.count>0) {
  108. [cell assignment:dataArray[indexPath.row] type:@"需求"];
  109. }
  110. return cell;
  111. }
  112. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. return 145;
  115. }
  116. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  117. NewDemandDetailsViewController *vc = [[NewDemandDetailsViewController alloc] init];
  118. NewshoucangModel *model = dataArray[indexPath.row];
  119. vc.ID = model.ID;
  120. vc.type = @"立即购买";
  121. NewPushViewController(vc);
  122. }
  123. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  124. return CGFLOAT_MIN;
  125. }
  126. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  127. return CGFLOAT_MIN;
  128. }
  129. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  130. return [[UIView alloc] init];
  131. }
  132. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  133. return [[UIView alloc] init];
  134. }
  135. #pragma mark - 上拉下拉初始化
  136. - (void)addRefreshing
  137. {
  138. __weak typeof(self) weakSelf = self;
  139. __weak UITableView *tableView = newtableView;
  140. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  141. if ([NetworkRequestManager connectedToNetwork]) {
  142. [weakSelf networkRequest:tableView.mj_header];
  143. }else{
  144. [tableView.mj_header endRefreshing];
  145. }
  146. }];
  147. tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  148. if ([NetworkRequestManager connectedToNetwork]) {
  149. [weakSelf networkRequest:tableView.mj_footer];
  150. }else{
  151. [tableView.mj_footer endRefreshing];
  152. }
  153. }];
  154. }
  155. - (void)dismiss:(id)object
  156. {
  157. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  158. __weak UITableView *newvc = newtableView;
  159. [newvc.mj_header endRefreshing];
  160. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  161. __weak UITableView *newvc = newtableView;
  162. [newvc.mj_footer endRefreshing];
  163. }else {
  164. [MBProgressHUD hideHUDForView:self.view];
  165. }
  166. }
  167. #pragma mark- 外部触发自动刷新
  168. - (void)autoDownRefresh
  169. {
  170. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  171. [self autoRefresh];
  172. });
  173. }
  174. #pragma mark- 网络请求
  175. - (void)autoRefresh
  176. {
  177. __weak UITableView *tableView = newtableView;
  178. [tableView.mj_header beginRefreshing];
  179. }
  180. #pragma mark 初始化展示框
  181. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  182. {
  183. if(!showView)
  184. {
  185. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  186. [showView setHidden:NO];
  187. [showView setBackgroundColor:NewBgGrayColor];
  188. UIImage *NOimg = [UIImage imageNamed:image];
  189. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  190. [showView addSubview:tempIcon];
  191. tempIcon.sd_layout
  192. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  193. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  194. .widthIs(NOimg.size.width/2.0f)
  195. .heightIs(NOimg.size.height/2.0f);
  196. UILabel *tipLab = [UILabel new];
  197. [showView addSubview:tipLab];
  198. [tipLab setText:text];
  199. [tipLab setTextAlignment:NSTextAlignmentCenter];
  200. [tipLab setTextColor:NewLightGrayColor];
  201. [tipLab setBackgroundColor:NewClearColor];
  202. [tipLab setFont:NewAutoFont(16.0)];
  203. tipLab.sd_layout
  204. .leftEqualToView(showView)
  205. .rightEqualToView(showView)
  206. .topSpaceToView(tempIcon,10)
  207. .heightIs(20.0);
  208. if (buttonText.length>0) {
  209. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  210. [showView addSubview:button];
  211. [button setTitle:buttonText forState:UIControlStateNormal];
  212. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  213. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  214. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  215. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  216. button.sd_layout
  217. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  218. .topSpaceToView(tipLab, 30.0)
  219. .widthIs(width+35)
  220. .heightIs(34);
  221. }
  222. }
  223. [UIView beginAnimations:@"ShowArrow" context:nil];
  224. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  225. [UIView setAnimationDuration:0.25f];
  226. [UIView setAnimationDelegate:self];
  227. [showView setAlpha:1.0f];
  228. [UIView commitAnimations];
  229. }
  230. - (void)hideReloadingview
  231. {
  232. [UIView animateWithDuration:0.25 animations:^{
  233. showView.hidden = YES;
  234. } completion:^(BOOL finished) {
  235. for (id obj in showView.subviews) {
  236. [obj removeFromSuperview];
  237. }
  238. showView = nil;
  239. [showView removeFromSuperview];
  240. }];
  241. }
  242. - (void)didReceiveMemoryWarning {
  243. [super didReceiveMemoryWarning];
  244. // Dispose of any resources that can be recreated.
  245. }
  246. /*
  247. #pragma mark - Navigation
  248. // In a storyboard-based application, you will often want to do a little preparation before navigation
  249. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  250. // Get the new view controller using [segue destinationViewController].
  251. // Pass the selected object to the new view controller.
  252. }
  253. */
  254. @end