XFXQViewController.m 10 KB

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