MyOrderVC.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. //
  2. // MyOrderVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/5/27.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "MyOrderVC.h"
  9. #import "STSegView.h"
  10. #import "HolderView.h"
  11. #import "DateView.h"
  12. #import "OrderCell.h"
  13. #import "APViewController.h"
  14. @interface MyOrderVC ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
  15. {
  16. STSegView *seg;
  17. UIScrollView *scroll;
  18. UITableView *mainTableView;
  19. UIBarButtonItem *item;
  20. UIView *backView;
  21. UIButton *beginBtn;
  22. UIButton *endBtn;
  23. HolderView *holder;
  24. NSMutableArray *dataArray;
  25. NSString *beginDate;
  26. NSString *endDate;
  27. NSInteger currentPage;
  28. NSString *orderState;
  29. }
  30. @end
  31. @implementation MyOrderVC
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. //测试微信支付 可以直接从这里进入
  35. // APViewController *ap = [[APViewController alloc] init];
  36. // ap.orderDic = _dataDic;
  37. // [self.navigationController pushViewController:ap animated:YES];
  38. [self myInit];
  39. }
  40. -(void)viewWillAppear:(BOOL)animated{
  41. [super viewWillAppear:animated];
  42. currentPage = 1;
  43. [self getMyOrderInfo];
  44. }
  45. -(void)myInit
  46. {
  47. [self.view setBackgroundColor:[UIColor whiteColor]];
  48. [self setTitle:@"查看我的订单"];
  49. [self configNavigationBar];
  50. currentPage = 1;
  51. orderState = @"0";
  52. beginDate = @"";
  53. endDate = @"";
  54. dataArray = [NSMutableArray array];
  55. item = [[UIBarButtonItem alloc] initWithTitle:@"查找" style:UIBarButtonItemStyleDone target:self action:@selector(clickToSearch)];
  56. [item setTintColor:defGreen];
  57. [self.navigationItem setRightBarButtonItem:item];
  58. CGFloat x,y,w,h;
  59. x = y = 0;
  60. w = kSize.width;
  61. h = 50;
  62. seg = [[STSegView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  63. [seg setTitles:@[@"计时中",@"待支付",@"待评价",@"已完成",@"已投诉"]];
  64. seg.selectedIndex = 0;
  65. [self.view addSubview:seg];
  66. y += h;
  67. h = kSize.height - y - kNavOffSet;
  68. mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(x, y, w, h) style:UITableViewStyleGrouped];
  69. mainTableView.delegate = self;
  70. mainTableView.dataSource = self;
  71. mainTableView.rowHeight = 174;
  72. [self.view addSubview:mainTableView];
  73. [seg click:^(NSString* sInd) {
  74. currentPage = 1;
  75. orderState = sInd;
  76. beginDate = @"";
  77. endDate = @"";
  78. [self getMyOrderInfo];
  79. }];
  80. holder = [[HolderView alloc] initWithFrame:mainTableView.frame];
  81. [holder freshBlock:^{
  82. currentPage = 1;
  83. [self getMyOrderInfo];
  84. }];
  85. [self.view addSubview:holder];
  86. }
  87. -(void)clickToSearch
  88. {
  89. item.enabled = NO;
  90. backView = [[UIView alloc] initWithFrame:kFrame];
  91. backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5];
  92. [self.view addSubview:backView];
  93. CGFloat x, y, w, h, bd;
  94. x = 20;
  95. y = (kSize.height - 250 - kNavOffSet)/2.0;
  96. w = kSize.width - 40;
  97. h = 250;
  98. UIView *searchView = [[UIView alloc] setxywh];
  99. searchView.backgroundColor = backGroundColor;
  100. searchView.layer.masksToBounds = YES;
  101. searchView.layer.cornerRadius = 5;
  102. [backView addSubview:searchView];
  103. x = y = bd = 15;
  104. w = searchView.width - 30;
  105. h = 50;
  106. NSArray *imgArray = @[@"beginDate",@"endDate"];
  107. NSString *beginDateStr = @"订单开始日期";
  108. NSString *endDateStr = @"订单结束日期";
  109. if (beginDate.length > 0) {
  110. beginDateStr = beginDate;
  111. }
  112. if (endDate.length > 0) {
  113. endDateStr = endDate;
  114. }
  115. NSArray *titles = @[beginDateStr,endDateStr];
  116. NSMutableArray *btns = [NSMutableArray arrayWithCapacity:3];
  117. for (int i = 0; i < 2; i ++) {
  118. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x + bd, 2*y + i*(h + bd), 20, 20)];
  119. imageView.image = [[UIImage imageNamed:imgArray[i]] tint:defGreen];
  120. [searchView addSubview:imageView];
  121. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)];
  122. [button setTitle:titles[i] textColor:contentTextColor font:16 fotState:UIControlStateNormal];
  123. button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  124. button.titleEdgeInsets = UIEdgeInsetsMake(0, 3*bd, 0, 0);
  125. [button borderColor:KlineColor width:2 cornorRadios:5];
  126. [button target:self tag:i];
  127. [searchView addSubview:button];
  128. [btns addObject:button];
  129. }
  130. beginBtn = btns[0];
  131. endBtn = btns[1];
  132. y += 2*(h + bd);
  133. w = (w - 2*bd)/2.0;
  134. NSArray *titleArrays = @[@"取消",@"查询"];
  135. for (int i = 0; i < 2; i ++) {
  136. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)];
  137. [button setTitle:titleArrays[i] textColor:defGreen font:16 fotState:UIControlStateNormal];
  138. [button borderColor:KlineColor width:2 cornorRadios:5];
  139. [button target:self tag:i + 2];
  140. [searchView addSubview:button];
  141. }
  142. }
  143. -(void)btnClick:(UIButton *)sender
  144. {
  145. switch (sender.tag) {
  146. case 0:
  147. {
  148. DateView *dateV = [[DateView alloc] init];
  149. [dateV setStyle:0];
  150. [dateV showWithComplete:^(NSString * result) {
  151. beginDate = result;
  152. [beginBtn setTitle:beginDate forState:UIControlStateNormal];
  153. }];
  154. }
  155. break;
  156. case 1:
  157. {
  158. DateView *dateV = [[DateView alloc] init];
  159. [dateV setStyle:0];
  160. [dateV showWithComplete:^(NSString * result) {
  161. endDate = result;
  162. [endBtn setTitle:endDate forState:UIControlStateNormal];
  163. }];
  164. }
  165. break;
  166. case 2:
  167. {
  168. if (backView) {
  169. [backView removeFromSuperview];
  170. }
  171. item.enabled = YES;
  172. }
  173. break;
  174. case 3:
  175. {
  176. if (backView) {
  177. [backView removeFromSuperview];
  178. }
  179. item.enabled = YES;
  180. //如果是重新选择时间 需要将currentPage重置为1
  181. currentPage = 1;
  182. [self getMyOrderInfo];
  183. }
  184. break;
  185. default:
  186. break;
  187. }
  188. }
  189. #pragma mark tableView
  190. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  191. {
  192. return dataArray.count;
  193. }
  194. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  195. {
  196. return 1;
  197. }
  198. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  199. {
  200. OrderCell *cell = [OrderCell cellForTabelView:tableView];
  201. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  202. cell.type = orderState;
  203. [cell setDataDic:dataArray[indexPath.section]];
  204. cell.skipVC = self;
  205. return cell;
  206. }
  207. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  208. {
  209. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 15)];
  210. view.backgroundColor = KlineColor;
  211. return view;
  212. }
  213. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  214. {
  215. return 15;
  216. }
  217. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  218. {
  219. UIView *view = [UIView new];
  220. return view;
  221. }
  222. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  223. {
  224. return .1;
  225. }
  226. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  227. {
  228. CGPoint off = scrollView.contentOffset;
  229. if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
  230. [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
  231. // NSLog(@"AT bottom");
  232. [self getMyOrderInfo];
  233. }
  234. }
  235. #pragma mark 数据请求
  236. -(void)getMyOrderInfo
  237. {
  238. if (![Util connectedToNetWork]) {
  239. return;
  240. }
  241. NSMutableArray *arr=[NSMutableArray array];
  242. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  243. [arr addPro:@"cx" Value:defUser.userDict[@"carType"]];
  244. [arr addPro:@"type" Value:@"1"];// 1 学员端 2 教练端
  245. [arr addPro:@"zjhm" Value:defUser.userDict[@"loginCode"]];
  246. [arr addPro:@"startTime" Value:beginDate];
  247. [arr addPro:@"endTime" Value:endDate];
  248. [arr addPro:@"status" Value:orderState];
  249. [arr addPro:@"isPage" Value:@"1"];
  250. [arr addPro:@"pageSize" Value:@"15"];
  251. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
  252. NSString* method = @"getMyReserveOrders";
  253. [MBProgressHUD showLoadToView:self.view];
  254. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  255. [MBProgressHUD hideHUDForView:self.view];
  256. if (currentPage == 1) {
  257. holder.hidden = NO;
  258. [dataArray removeAllObjects];
  259. }
  260. if (!root) {
  261. ShowMsgFailed();
  262. return;
  263. }
  264. if ([root[@"code"] isEqualToString:@"1"]) {
  265. ShowMsg(root[@"body"]);
  266. return;
  267. }
  268. NSArray *array = root[@"body"];
  269. if ([array count] < 1) {
  270. ShowMsg(@"已加载全部");
  271. [mainTableView reloadData];
  272. return;
  273. }
  274. [dataArray addObjectsFromArray:array];
  275. currentPage += 1;
  276. holder.hidden = YES;
  277. [mainTableView reloadData];
  278. }];
  279. }
  280. - (void)didReceiveMemoryWarning {
  281. [super didReceiveMemoryWarning];
  282. }
  283. @end