MyOrderViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. //
  2. // MyOrderViewController.m
  3. // DSH
  4. //
  5. // Created by 张毅成 on 2018/10/8.
  6. // Copyright © 2018 WZX. All rights reserved.
  7. //
  8. #import "MyOrderViewController.h"
  9. #import "MyOrderTableViewCell.h"
  10. #import "FeedbackViewController.h"
  11. //#import "OrderDetailViewController.h"
  12. //#import "OrderExpressViewController.h"
  13. //#import "TradingViewController.h"
  14. //#import "XHPayKit.h"
  15. //#import "WXApi.h"ßßßßßß
  16. //#import "TradingResultsViewController.h"
  17. @interface MyOrderViewController ()<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
  18. @property (strong, nonatomic) NSMutableArray *arrayTopButtons;
  19. @property (strong, nonatomic) NSMutableArray *arrayTopModel;
  20. @property (strong, nonatomic) NSMutableArray *arrayTableView;
  21. @property (strong, nonatomic) NSMutableArray *arrayData;
  22. @property (strong, nonatomic) NSMutableArray *arrayPageNo;
  23. @property (strong, nonatomic) UIScrollView *bgScrollView;
  24. @property (strong, nonatomic) UIView *topView;
  25. @property (strong, nonatomic) UIView *viewLine;
  26. @property (assign, nonatomic) NSInteger type;
  27. //@property (strong, nonatomic) BookPaySelectView *paySelectView;
  28. @property (copy, nonatomic) NSString *productId;
  29. @property (copy, nonatomic) NSString *orderId;
  30. @property (copy, nonatomic) NSString *productName;
  31. @property (copy, nonatomic) NSString *author;
  32. @property (assign, nonatomic) CGFloat price;
  33. //@property (strong, nonatomic) DSHPay *dshPay;
  34. @property (copy, nonatomic) NSString *cacheKey;
  35. /**
  36. 准备支付的model
  37. */
  38. @property (strong, nonatomic) MyOrderModel *modelPay;
  39. @end
  40. @implementation MyOrderViewController
  41. //- (BookPaySelectView *)paySelectView {
  42. // WeakSelf(self)
  43. // if (!_paySelectView) {
  44. // _paySelectView = [[[NSBundle mainBundle] loadNibNamed:@"BookPaySelectView" owner:self options:nil] lastObject];
  45. // _paySelectView.labelTitle.text = [NSString stringWithFormat:@"¥ %0.2f",self.price];
  46. // _paySelectView.labelAuthor.text = self.author;
  47. // _paySelectView.labelName.text = self.productName;
  48. // _paySelectView.blockDidTouchViewPay = ^(NSInteger tag) {
  49. // //tag == 0 wechat tag == 1 alipay
  50. // if (tag) {
  51. //// [weakself aliPay];
  52. // weakself.dshPay.payWay = [ZYCAliPay new];
  53. // }else{
  54. //// [weakself weixinPay];
  55. // weakself.dshPay.payWay = [ZYCWXPay new];
  56. // }
  57. // [weakself.dshPay.payWay PayWithOrderId:weakself.orderId AndPrice:weakself.price];
  58. // };
  59. // }
  60. // return _paySelectView;
  61. //}
  62. - (NSMutableArray *)arrayPageNo {
  63. if (!_arrayPageNo) {
  64. _arrayPageNo = @[].mutableCopy;
  65. }
  66. return _arrayPageNo;
  67. }
  68. - (NSMutableArray *)arrayData {
  69. if (!_arrayData) {
  70. _arrayData = @[@[].mutableCopy, @[].mutableCopy, @[].mutableCopy, @[].mutableCopy, @[].mutableCopy, @[].mutableCopy].mutableCopy;
  71. }
  72. return _arrayData;
  73. }
  74. - (NSMutableArray *)arrayTableView {
  75. if (!_arrayTableView) {
  76. _arrayTableView = @[].mutableCopy;
  77. }
  78. return _arrayTableView;
  79. }
  80. - (UIView *)topView {
  81. if (!_topView) {
  82. _topView = [UIView new];
  83. _topView.backgroundColor = [UIColor whiteColor];
  84. _topView.frame = CGRectMake(0, 0, kGXScreenWidth, 40);
  85. }
  86. return _topView;
  87. }
  88. - (UIView *)viewLine {
  89. if (!_viewLine) {
  90. _viewLine = [UIView new];
  91. _viewLine.height = 2.5;
  92. _viewLine.width = 25;
  93. _viewLine.backgroundColor = kMainColor;
  94. }
  95. return _viewLine;
  96. }
  97. - (NSMutableArray *)arrayTopButtons {
  98. if (!_arrayTopButtons) {
  99. _arrayTopButtons = @[].mutableCopy;
  100. }
  101. return _arrayTopButtons;
  102. }
  103. - (NSMutableArray *)arrayTopModel {
  104. if (!_arrayTopModel) {
  105. _arrayTopModel = @[@"全部", @"待付款", @"待评价", @"已取消"].mutableCopy;
  106. }
  107. return _arrayTopModel;
  108. }
  109. - (UIScrollView *)bgScrollView {
  110. if (!_bgScrollView) {
  111. _bgScrollView = [[UIScrollView alloc] initWithFrame:(CGRect){0,0,kGXScreenWidth,kGXScreenHeigh}];
  112. _bgScrollView.delegate = self;
  113. _bgScrollView.backgroundColor = kBackgroundColor;
  114. _bgScrollView.pagingEnabled = true;
  115. }
  116. return _bgScrollView;
  117. }
  118. - (void)NetworkOfList:(NSInteger)tag {
  119. UITableView *tableView = self.arrayTableView[tag];
  120. NSString *URL = @"my/orderList";
  121. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  122. if (tag == 2) {
  123. parameters[@"type"] = @(4);
  124. }else if (tag == 3) {
  125. parameters[@"type"] = @(5);
  126. }else
  127. parameters[@"type"] = @(tag);
  128. parameters[@"pageNo"] = self.arrayPageNo[tag];
  129. NSInteger pageNo = [self.arrayPageNo[tag] integerValue];
  130. [[HttpManager sharedHttpManager] GET:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  131. REMOVESHOW
  132. NSLog(@"%@",responseObject);
  133. if ([responseObject[@"code"] integerValue] == 0) {
  134. if ([self.arrayPageNo[tag] integerValue] == 1) {
  135. [self.arrayData replaceObjectAtIndex:tag withObject:@[].mutableCopy];
  136. }
  137. NSMutableArray *array = self.arrayData[tag];
  138. if (pageNo == 0 || pageNo == 1) {
  139. [array removeAllObjects];
  140. }
  141. NSArray *arrayTmp = [NSArray modelArrayWithClass:[MyOrderModel class] json:responseObject[@"data"][@"orderList"]];
  142. [array addObjectsFromArray:arrayTmp];
  143. [self.arrayData replaceObjectAtIndex:tag withObject:array];
  144. // [ZYCCache setCacheValue:self.arrayData ForCacheKey:self.cacheKey];
  145. [tableView reloadData];
  146. [self endRefreshWithMoreData:arrayTmp.count AndTableView:tableView];
  147. }else
  148. [self endRefreshWithMoreData:false AndTableView:tableView];
  149. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  150. REMOVESHOW
  151. [self endRefreshWithMoreData:false AndTableView:tableView];
  152. }];
  153. }
  154. /**
  155. 订单操作{type}: 1:取消,2:删除,3:付款,4:申请退款
  156. */
  157. - (void)NetworkOfOrderOperationWithType:(OrderOperationType)type AndOrderId:(NSString *)orderId {
  158. SHOWLOADING
  159. NSString *URL = @"order/operOrder";
  160. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  161. parameters[@"type"] = @(type);
  162. parameters[@"orderId"] = orderId;
  163. [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  164. REMOVESHOW
  165. NSLog(@"%@",responseObject);
  166. if ([responseObject[@"code"] integerValue] == 0) {
  167. SHOWSUCCESS(@"操作成功")
  168. UITableView *tableView = self.arrayTableView[self.type];
  169. [tableView.mj_header beginRefreshing];
  170. }else
  171. SHOWERROR(@"操作失败")
  172. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  173. REMOVESHOW
  174. SHOWERROR(@"操作失败")
  175. }];
  176. }
  177. - (void)viewDidLoad {
  178. [super viewDidLoad];
  179. [self.view addSubview:self.bgScrollView];
  180. self.bgScrollView.bounces = false;
  181. [self.view addSubview:self.topView];
  182. [self makeUI];
  183. self.cacheKey = [NSString stringWithFormat:@"MyOrderViewController%@",kUserId];
  184. // self.dshPay = [DSHPay new];
  185. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weiXinPay) name:@"wexinPay" object:nil];
  186. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aliPay) name:@"aliPay" object:nil];
  187. }
  188. //- (void)getCache {
  189. // if ([ZYCCache getCacheWithCacheKey:self.cacheKey]) {
  190. // self.arrayData = [ZYCCache getCacheWithCacheKey:self.cacheKey];
  191. // [self.arrayTableView enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  192. // UITableView *tableView = obj;
  193. // [tableView reloadData];
  194. // }];
  195. // }
  196. //}
  197. - (void)makeUI {
  198. self.title = @"订单";
  199. self.bgScrollView.contentSize = CGSizeMake(kGXScreenWidth * self.arrayTopModel.count, 0);
  200. [self.arrayTopModel enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  201. NSString *title = (NSString *)obj;
  202. UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
  203. [self.arrayTopButtons addObject:button];
  204. button.tag = idx;
  205. [button addTarget:self action:@selector(didTouchButtonTop:) forControlEvents:(UIControlEventTouchUpInside)];
  206. [button setTitle:title forState:(UIControlStateNormal)];
  207. [button setTitleColor:kMainColor forState:(UIControlStateSelected)];
  208. [button setTitleColor:[UIColor colorWithHexString:@"999999"] forState:(UIControlStateNormal)];
  209. button.titleLabel.font = [UIFont systemFontOfSize:15];
  210. button.width = kGXScreenWidth/self.arrayTopModel.count;
  211. button.height = 40;
  212. [self.topView addSubview:button];
  213. button.x = idx * button.width;
  214. button.y = 0;
  215. if (idx == 0) {
  216. button.selected = true;
  217. self.viewLine.centerX = button.centerX;
  218. self.viewLine.y = button.height - 2.5;
  219. }
  220. UITableView *tableView = [[UITableView alloc] initWithFrame:(CGRect){ idx * kGXScreenWidth,40,kGXScreenWidth,kIsHaveBang?(kGXScreenHeigh - 88 - 40):(kGXScreenHeigh - 64 - 40)} style:(UITableViewStyleGrouped)];
  221. tableView.delegate = self;
  222. tableView.dataSource = self;
  223. tableView.backgroundColor = kBackgroundColor;
  224. tableView.tag = idx;
  225. tableView.rowHeight = UITableViewAutomaticDimension;
  226. tableView.estimatedRowHeight = 220;
  227. tableView.tableFooterView = [UIView new];
  228. tableView.separatorStyle = 0;
  229. WeakSelf(self)
  230. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  231. StrongSelf(weakself)
  232. NSMutableArray *array = strongself.arrayData[tableView.tag];
  233. [array removeAllObjects];
  234. [strongself.arrayPageNo replaceObjectAtIndex:tableView.tag withObject:@(1)];
  235. [strongself NetworkOfList:tableView.tag];
  236. }];
  237. tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  238. StrongSelf(weakself)
  239. NSNumber *number = strongself.arrayPageNo[tableView.tag];
  240. NSInteger no = number.integerValue;
  241. no ++;
  242. [strongself.arrayPageNo replaceObjectAtIndex:tableView.tag withObject:@(no)];
  243. [strongself NetworkOfList:tableView.tag];
  244. }];
  245. [self.arrayTableView addObject:tableView];
  246. [self.arrayPageNo addObject:@(1)];
  247. }];
  248. [self makeTableView];
  249. [self makeTopView];
  250. }
  251. - (void)makeTopView {
  252. [self.topView addSubview:self.viewLine];
  253. }
  254. - (void)makeTableView {
  255. self.view.backgroundColor = kBackgroundColor;
  256. if (self.arrayTableView.count > 0) {
  257. [self.arrayTableView enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  258. UITableView *tableView = obj;
  259. [self.bgScrollView addSubview:tableView];
  260. if (idx == 0) {
  261. [tableView.mj_header beginRefreshing];
  262. }
  263. }];
  264. }
  265. // [self getCache];
  266. }
  267. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  268. NSMutableArray *array = self.arrayData[tableView.tag];
  269. return array.count;
  270. }
  271. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  272. NSMutableArray *array = self.arrayData[tableView.tag];
  273. MyOrderModel *model = array[section];
  274. //出版社cell + 金钱cell + button cell + 商品list
  275. // return 3 + model.orderProductList.count;
  276. if (model.orderType == 6) {
  277. return 3;
  278. }
  279. return 4;
  280. }
  281. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  282. UIView *view = [UIView new];
  283. [view setBackgroundColor:kBackgroundColor];
  284. return view;
  285. }
  286. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  287. UIView *view = [UIView new];
  288. [view setBackgroundColor:kBackgroundColor];
  289. return view;
  290. }
  291. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  292. if (section == 0) {
  293. return 10;
  294. }
  295. return 0.01;
  296. }
  297. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  298. // if (section == [tableView numberOfSections] - 1) {
  299. // return 10;
  300. // }
  301. return 10;
  302. }
  303. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  304. MyOrderTableViewCell *cell0 = [MyOrderTableViewCell cellWithTableView:tableView AndIndex:0];
  305. MyOrderTableViewCell *cell1 = [MyOrderTableViewCell cellWithTableView:tableView AndIndex:1];
  306. MyOrderTableViewCell *cell2 = [MyOrderTableViewCell cellWithTableView:tableView AndIndex:2];
  307. MyOrderTableViewCell *cell3 = [MyOrderTableViewCell cellWithTableView:tableView AndIndex:3];
  308. NSArray *array = self.arrayData[self.type];
  309. MyOrderModel *model = array[indexPath.section];
  310. // model.orderType = self.type;
  311. cell0.buttonDelete.hidden = true;
  312. //订单状态 01:待付款 04:待评价 05:已取消 06:已完成'
  313. if (model.orderType == 1 || model.orderType == 5) {//待付款
  314. if (model.orderType == 5) {
  315. // cell0.buttonDelete.hidden = false;
  316. cell0.blockDidTouchButtonDelete = ^{
  317. [ZYCTool alertControllerTwoButtonWithTitle:@"是否删除此订单?" message:@"删除后将不可恢复" target:self notarizeButtonTitle:nil cancelButtonTitle:nil notarizeAction:^{
  318. [self NetworkOfOrderOperationWithType:(OrderOperationTypeDelete) AndOrderId:model.orderId];
  319. } cancelAction:^{}];
  320. };
  321. }
  322. // else
  323. // cell0.buttonDelete.hidden = false;
  324. cell3.blockDidTouchButton0 = ^{
  325. NSLog(@"PAY");
  326. self.price = model.totalPrice;
  327. self.orderId = model.orderId;
  328. self.productName = model.productName;
  329. self.author = model.author;
  330. self.modelPay = model;
  331. // [self.paySelectView show];
  332. };
  333. }else if (model.orderType == 4) {//待评价
  334. // cell0.buttonDelete.hidden = false;
  335. cell0.blockDidTouchButtonDelete = ^{
  336. [ZYCTool alertControllerTwoButtonWithTitle:@"是否删除此订单?" message:@"删除后将不可恢复" target:self notarizeButtonTitle:nil cancelButtonTitle:nil notarizeAction:^{
  337. [self NetworkOfOrderOperationWithType:(OrderOperationTypeDelete) AndOrderId:model.orderId];
  338. } cancelAction:^{}];
  339. };
  340. cell3.blockDidTouchButton0 = ^{
  341. FeedbackViewController *controller = [FeedbackViewController new];
  342. controller.controllerType = FeedbackViewControllerTypeEvaluate;
  343. controller.URL = @"product/addProdEvaluation";
  344. controller.parameters[@"orderId"] = model.orderId;
  345. controller.blockFeedBack = ^{
  346. [tableView.mj_header beginRefreshing];
  347. };
  348. [self.navigationController pushViewController:controller animated:true];
  349. };
  350. }
  351. if (indexPath.row == 0) {
  352. [cell0 setModel:model];
  353. return cell0;
  354. }else{
  355. if (model.orderType == 6) {
  356. if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) {
  357. [cell2 setModel:model];
  358. return cell2;
  359. }else{
  360. [cell1 setModel:model];
  361. return cell1;
  362. }
  363. }else{
  364. if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 2) {
  365. [cell2 setModel:model];
  366. return cell2;
  367. }else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) {
  368. [cell3 setModel:model];
  369. return cell3;
  370. }else{
  371. [cell1 setModel:model];
  372. return cell1;
  373. }
  374. }
  375. }
  376. }
  377. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  378. // NSArray *array = self.arrayData[self.type];
  379. // MyOrderModel *model = array[indexPath.section];
  380. // OrderDetailViewController *controller = [OrderDetailViewController new];
  381. // controller.model = model;
  382. // [self.navigationController pushViewController:controller animated:true];
  383. }
  384. - (void)didTouchButtonTop:(UIButton *)button {
  385. [self.arrayTopButtons enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  386. UIButton *button = obj;
  387. button.selected = false;
  388. button.userInteractionEnabled = true;
  389. }];
  390. button.selected = true;
  391. [UIView animateWithDuration:0.2 animations:^{
  392. self.viewLine.centerX = button.centerX;
  393. }];
  394. [UIView animateWithDuration:0.2 animations:^{
  395. self.bgScrollView.contentOffset = CGPointMake(kGXScreenWidth * button.tag, 0);
  396. }];
  397. NSString *str = [NSString stringWithFormat:@"%0.0f",self.bgScrollView.contentOffset.x/kGXScreenWidth];
  398. NSMutableArray *array = self.arrayData[str.integerValue];
  399. if (array.count == 0) {
  400. [self NetworkOfList:str.integerValue];
  401. }
  402. self.type = button.tag;
  403. UITableView *tableView = self.arrayTableView[button.tag];
  404. [tableView reloadData];
  405. }
  406. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  407. if (self.arrayTopButtons.count > 0) {
  408. if (scrollView == self.bgScrollView) {
  409. UIButton *button;
  410. [self.arrayTopButtons enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  411. UIButton *button = obj;
  412. button.userInteractionEnabled = false;
  413. }];
  414. NSString *str = [NSString stringWithFormat:@"%0.0f",self.bgScrollView.contentOffset.x/kGXScreenWidth];
  415. if (self.bgScrollView.contentOffset.x == kGXScreenWidth * str.integerValue) {
  416. button = self.arrayTopButtons[str.integerValue];
  417. [self didTouchButtonTop:button];
  418. }
  419. }
  420. }
  421. }
  422. - (void)endRefreshWithMoreData:(BOOL)isHaveMoreData AndTableView:(UITableView *)tableView {
  423. [tableView.mj_header endRefreshing];
  424. if (!isHaveMoreData) {
  425. [tableView.mj_footer endRefreshingWithNoMoreData];
  426. }else
  427. [tableView.mj_footer endRefreshing];
  428. }
  429. - (void)weiXinPay {
  430. // TradingResultsViewController *controller = [TradingResultsViewController new];
  431. // controller.model = self.modelPay;
  432. // [self.navigationController pushViewController:controller animated:true];
  433. }
  434. - (void)aliPay {
  435. // TradingResultsViewController *controller = [TradingResultsViewController new];
  436. // controller.model = self.modelPay;
  437. // [self.navigationController pushViewController:controller animated:true];
  438. }
  439. @end