123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- //
- // MyOrderViewController.m
- // DSH
- //
- // Created by 张毅成 on 2018/10/8.
- // Copyright © 2018 WZX. All rights reserved.
- //
- #import "MyOrderViewController.h"
- #import "MyOrderTableViewCell.h"
- #import "FeedbackViewController.h"
- //#import "OrderDetailViewController.h"
- //#import "OrderExpressViewController.h"
- //#import "TradingViewController.h"
- //#import "XHPayKit.h"
- //#import "WXApi.h"ßßßßßß
- //#import "TradingResultsViewController.h"
- @interface MyOrderViewController ()<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
- @property (strong, nonatomic) NSMutableArray *arrayTopButtons;
- @property (strong, nonatomic) NSMutableArray *arrayTopModel;
- @property (strong, nonatomic) NSMutableArray *arrayTableView;
- @property (strong, nonatomic) NSMutableArray *arrayData;
- @property (strong, nonatomic) NSMutableArray *arrayPageNo;
- @property (strong, nonatomic) UIScrollView *bgScrollView;
- @property (strong, nonatomic) UIView *topView;
- @property (strong, nonatomic) UIView *viewLine;
- @property (assign, nonatomic) NSInteger type;
- //@property (strong, nonatomic) BookPaySelectView *paySelectView;
- @property (copy, nonatomic) NSString *productId;
- @property (copy, nonatomic) NSString *orderId;
- @property (copy, nonatomic) NSString *productName;
- @property (copy, nonatomic) NSString *author;
- @property (assign, nonatomic) CGFloat price;
- //@property (strong, nonatomic) DSHPay *dshPay;
- @property (copy, nonatomic) NSString *cacheKey;
- /**
- 准备支付的model
- */
- @property (strong, nonatomic) MyOrderModel *modelPay;
- @end
- @implementation MyOrderViewController
- //- (BookPaySelectView *)paySelectView {
- // WeakSelf(self)
- // if (!_paySelectView) {
- // _paySelectView = [[[NSBundle mainBundle] loadNibNamed:@"BookPaySelectView" owner:self options:nil] lastObject];
- // _paySelectView.labelTitle.text = [NSString stringWithFormat:@"¥ %0.2f",self.price];
- // _paySelectView.labelAuthor.text = self.author;
- // _paySelectView.labelName.text = self.productName;
- // _paySelectView.blockDidTouchViewPay = ^(NSInteger tag) {
- // //tag == 0 wechat tag == 1 alipay
- // if (tag) {
- //// [weakself aliPay];
- // weakself.dshPay.payWay = [ZYCAliPay new];
- // }else{
- //// [weakself weixinPay];
- // weakself.dshPay.payWay = [ZYCWXPay new];
- // }
- // [weakself.dshPay.payWay PayWithOrderId:weakself.orderId AndPrice:weakself.price];
- // };
- // }
- // return _paySelectView;
- //}
- - (NSMutableArray *)arrayPageNo {
- if (!_arrayPageNo) {
- _arrayPageNo = @[].mutableCopy;
- }
- return _arrayPageNo;
- }
- - (NSMutableArray *)arrayData {
- if (!_arrayData) {
- _arrayData = @[@[].mutableCopy, @[].mutableCopy, @[].mutableCopy, @[].mutableCopy, @[].mutableCopy, @[].mutableCopy].mutableCopy;
- }
- return _arrayData;
- }
- - (NSMutableArray *)arrayTableView {
- if (!_arrayTableView) {
- _arrayTableView = @[].mutableCopy;
- }
- return _arrayTableView;
- }
- - (UIView *)topView {
- if (!_topView) {
- _topView = [UIView new];
- _topView.backgroundColor = [UIColor whiteColor];
- _topView.frame = CGRectMake(0, 0, kGXScreenWidth, 40);
- }
- return _topView;
- }
- - (UIView *)viewLine {
- if (!_viewLine) {
- _viewLine = [UIView new];
- _viewLine.height = 2.5;
- _viewLine.width = 25;
- _viewLine.backgroundColor = kMainColor;
- }
- return _viewLine;
- }
- - (NSMutableArray *)arrayTopButtons {
- if (!_arrayTopButtons) {
- _arrayTopButtons = @[].mutableCopy;
- }
- return _arrayTopButtons;
- }
- - (NSMutableArray *)arrayTopModel {
- if (!_arrayTopModel) {
- _arrayTopModel = @[@"全部", @"待付款", @"待评价", @"已取消"].mutableCopy;
- }
- return _arrayTopModel;
- }
- - (UIScrollView *)bgScrollView {
- if (!_bgScrollView) {
- _bgScrollView = [[UIScrollView alloc] initWithFrame:(CGRect){0,0,kGXScreenWidth,kGXScreenHeigh}];
- _bgScrollView.delegate = self;
- _bgScrollView.backgroundColor = kBackgroundColor;
- _bgScrollView.pagingEnabled = true;
- }
- return _bgScrollView;
- }
- - (void)NetworkOfList:(NSInteger)tag {
- UITableView *tableView = self.arrayTableView[tag];
- NSString *URL = @"my/orderList";
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- if (tag == 2) {
- parameters[@"type"] = @(4);
- }else if (tag == 3) {
- parameters[@"type"] = @(5);
- }else
- parameters[@"type"] = @(tag);
- parameters[@"pageNo"] = self.arrayPageNo[tag];
- NSInteger pageNo = [self.arrayPageNo[tag] integerValue];
- [[HttpManager sharedHttpManager] GET:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- REMOVESHOW
- NSLog(@"%@",responseObject);
- if ([responseObject[@"code"] integerValue] == 0) {
- if ([self.arrayPageNo[tag] integerValue] == 1) {
- [self.arrayData replaceObjectAtIndex:tag withObject:@[].mutableCopy];
- }
- NSMutableArray *array = self.arrayData[tag];
- if (pageNo == 0 || pageNo == 1) {
- [array removeAllObjects];
- }
- NSArray *arrayTmp = [NSArray modelArrayWithClass:[MyOrderModel class] json:responseObject[@"data"][@"orderList"]];
- [array addObjectsFromArray:arrayTmp];
- [self.arrayData replaceObjectAtIndex:tag withObject:array];
- // [ZYCCache setCacheValue:self.arrayData ForCacheKey:self.cacheKey];
- [tableView reloadData];
- [self endRefreshWithMoreData:arrayTmp.count AndTableView:tableView];
- }else
- [self endRefreshWithMoreData:false AndTableView:tableView];
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- REMOVESHOW
- [self endRefreshWithMoreData:false AndTableView:tableView];
- }];
- }
- /**
- 订单操作{type}: 1:取消,2:删除,3:付款,4:申请退款
- */
- - (void)NetworkOfOrderOperationWithType:(OrderOperationType)type AndOrderId:(NSString *)orderId {
- SHOWLOADING
- NSString *URL = @"order/operOrder";
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- parameters[@"type"] = @(type);
- parameters[@"orderId"] = orderId;
- [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- REMOVESHOW
- NSLog(@"%@",responseObject);
- if ([responseObject[@"code"] integerValue] == 0) {
- SHOWSUCCESS(@"操作成功")
- UITableView *tableView = self.arrayTableView[self.type];
- [tableView.mj_header beginRefreshing];
- }else
- SHOWERROR(@"操作失败")
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR(@"操作失败")
- }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.view addSubview:self.bgScrollView];
- self.bgScrollView.bounces = false;
- [self.view addSubview:self.topView];
- [self makeUI];
- self.cacheKey = [NSString stringWithFormat:@"MyOrderViewController%@",kUserId];
- // self.dshPay = [DSHPay new];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weiXinPay) name:@"wexinPay" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aliPay) name:@"aliPay" object:nil];
- }
- //- (void)getCache {
- // if ([ZYCCache getCacheWithCacheKey:self.cacheKey]) {
- // self.arrayData = [ZYCCache getCacheWithCacheKey:self.cacheKey];
- // [self.arrayTableView enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- // UITableView *tableView = obj;
- // [tableView reloadData];
- // }];
- // }
- //}
- - (void)makeUI {
- self.title = @"订单";
- self.bgScrollView.contentSize = CGSizeMake(kGXScreenWidth * self.arrayTopModel.count, 0);
- [self.arrayTopModel enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- NSString *title = (NSString *)obj;
- UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
- [self.arrayTopButtons addObject:button];
- button.tag = idx;
- [button addTarget:self action:@selector(didTouchButtonTop:) forControlEvents:(UIControlEventTouchUpInside)];
- [button setTitle:title forState:(UIControlStateNormal)];
- [button setTitleColor:kMainColor forState:(UIControlStateSelected)];
- [button setTitleColor:[UIColor colorWithHexString:@"999999"] forState:(UIControlStateNormal)];
- button.titleLabel.font = [UIFont systemFontOfSize:15];
- button.width = kGXScreenWidth/self.arrayTopModel.count;
- button.height = 40;
- [self.topView addSubview:button];
- button.x = idx * button.width;
- button.y = 0;
- if (idx == 0) {
- button.selected = true;
- self.viewLine.centerX = button.centerX;
- self.viewLine.y = button.height - 2.5;
- }
- UITableView *tableView = [[UITableView alloc] initWithFrame:(CGRect){ idx * kGXScreenWidth,40,kGXScreenWidth,kIsHaveBang?(kGXScreenHeigh - 88 - 40):(kGXScreenHeigh - 64 - 40)} style:(UITableViewStyleGrouped)];
- tableView.delegate = self;
- tableView.dataSource = self;
- tableView.backgroundColor = kBackgroundColor;
- tableView.tag = idx;
- tableView.rowHeight = UITableViewAutomaticDimension;
- tableView.estimatedRowHeight = 220;
- tableView.tableFooterView = [UIView new];
- tableView.separatorStyle = 0;
- WeakSelf(self)
- tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- StrongSelf(weakself)
- NSMutableArray *array = strongself.arrayData[tableView.tag];
- [array removeAllObjects];
- [strongself.arrayPageNo replaceObjectAtIndex:tableView.tag withObject:@(1)];
- [strongself NetworkOfList:tableView.tag];
- }];
- tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
- StrongSelf(weakself)
- NSNumber *number = strongself.arrayPageNo[tableView.tag];
- NSInteger no = number.integerValue;
- no ++;
- [strongself.arrayPageNo replaceObjectAtIndex:tableView.tag withObject:@(no)];
- [strongself NetworkOfList:tableView.tag];
- }];
- [self.arrayTableView addObject:tableView];
- [self.arrayPageNo addObject:@(1)];
- }];
- [self makeTableView];
- [self makeTopView];
- }
- - (void)makeTopView {
- [self.topView addSubview:self.viewLine];
- }
- - (void)makeTableView {
- self.view.backgroundColor = kBackgroundColor;
- if (self.arrayTableView.count > 0) {
- [self.arrayTableView enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- UITableView *tableView = obj;
- [self.bgScrollView addSubview:tableView];
- if (idx == 0) {
- [tableView.mj_header beginRefreshing];
- }
- }];
- }
- // [self getCache];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- NSMutableArray *array = self.arrayData[tableView.tag];
- return array.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- NSMutableArray *array = self.arrayData[tableView.tag];
- MyOrderModel *model = array[section];
- //出版社cell + 金钱cell + button cell + 商品list
- // return 3 + model.orderProductList.count;
- if (model.orderType == 6) {
- return 3;
- }
- return 4;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *view = [UIView new];
- [view setBackgroundColor:kBackgroundColor];
- return view;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- UIView *view = [UIView new];
- [view setBackgroundColor:kBackgroundColor];
- return view;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return 10;
- }
- return 0.01;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- // if (section == [tableView numberOfSections] - 1) {
- // return 10;
- // }
- return 10;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- MyOrderTableViewCell *cell0 = [MyOrderTableViewCell cellWithTableView:tableView AndIndex:0];
- MyOrderTableViewCell *cell1 = [MyOrderTableViewCell cellWithTableView:tableView AndIndex:1];
- MyOrderTableViewCell *cell2 = [MyOrderTableViewCell cellWithTableView:tableView AndIndex:2];
- MyOrderTableViewCell *cell3 = [MyOrderTableViewCell cellWithTableView:tableView AndIndex:3];
- NSArray *array = self.arrayData[self.type];
- MyOrderModel *model = array[indexPath.section];
- // model.orderType = self.type;
- cell0.buttonDelete.hidden = true;
- //订单状态 01:待付款 04:待评价 05:已取消 06:已完成'
- if (model.orderType == 1 || model.orderType == 5) {//待付款
- if (model.orderType == 5) {
- // cell0.buttonDelete.hidden = false;
- cell0.blockDidTouchButtonDelete = ^{
- [ZYCTool alertControllerTwoButtonWithTitle:@"是否删除此订单?" message:@"删除后将不可恢复" target:self notarizeButtonTitle:nil cancelButtonTitle:nil notarizeAction:^{
- [self NetworkOfOrderOperationWithType:(OrderOperationTypeDelete) AndOrderId:model.orderId];
- } cancelAction:^{}];
- };
- }
- // else
- // cell0.buttonDelete.hidden = false;
- cell3.blockDidTouchButton0 = ^{
- NSLog(@"PAY");
- self.price = model.totalPrice;
- self.orderId = model.orderId;
- self.productName = model.productName;
- self.author = model.author;
- self.modelPay = model;
- // [self.paySelectView show];
- };
- }else if (model.orderType == 4) {//待评价
- // cell0.buttonDelete.hidden = false;
- cell0.blockDidTouchButtonDelete = ^{
- [ZYCTool alertControllerTwoButtonWithTitle:@"是否删除此订单?" message:@"删除后将不可恢复" target:self notarizeButtonTitle:nil cancelButtonTitle:nil notarizeAction:^{
- [self NetworkOfOrderOperationWithType:(OrderOperationTypeDelete) AndOrderId:model.orderId];
- } cancelAction:^{}];
- };
- cell3.blockDidTouchButton0 = ^{
- FeedbackViewController *controller = [FeedbackViewController new];
- controller.controllerType = FeedbackViewControllerTypeEvaluate;
- controller.URL = @"product/addProdEvaluation";
- controller.parameters[@"orderId"] = model.orderId;
- controller.blockFeedBack = ^{
- [tableView.mj_header beginRefreshing];
- };
- [self.navigationController pushViewController:controller animated:true];
- };
- }
- if (indexPath.row == 0) {
- [cell0 setModel:model];
- return cell0;
- }else{
- if (model.orderType == 6) {
- if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) {
- [cell2 setModel:model];
- return cell2;
- }else{
- [cell1 setModel:model];
- return cell1;
- }
- }else{
- if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 2) {
- [cell2 setModel:model];
- return cell2;
- }else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) {
- [cell3 setModel:model];
- return cell3;
- }else{
- [cell1 setModel:model];
- return cell1;
- }
- }
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- // NSArray *array = self.arrayData[self.type];
- // MyOrderModel *model = array[indexPath.section];
- // OrderDetailViewController *controller = [OrderDetailViewController new];
- // controller.model = model;
- // [self.navigationController pushViewController:controller animated:true];
- }
- - (void)didTouchButtonTop:(UIButton *)button {
- [self.arrayTopButtons enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- UIButton *button = obj;
- button.selected = false;
- button.userInteractionEnabled = true;
- }];
- button.selected = true;
- [UIView animateWithDuration:0.2 animations:^{
- self.viewLine.centerX = button.centerX;
- }];
- [UIView animateWithDuration:0.2 animations:^{
- self.bgScrollView.contentOffset = CGPointMake(kGXScreenWidth * button.tag, 0);
- }];
- NSString *str = [NSString stringWithFormat:@"%0.0f",self.bgScrollView.contentOffset.x/kGXScreenWidth];
- NSMutableArray *array = self.arrayData[str.integerValue];
- if (array.count == 0) {
- [self NetworkOfList:str.integerValue];
- }
- self.type = button.tag;
- UITableView *tableView = self.arrayTableView[button.tag];
- [tableView reloadData];
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (self.arrayTopButtons.count > 0) {
- if (scrollView == self.bgScrollView) {
- UIButton *button;
- [self.arrayTopButtons enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- UIButton *button = obj;
- button.userInteractionEnabled = false;
- }];
- NSString *str = [NSString stringWithFormat:@"%0.0f",self.bgScrollView.contentOffset.x/kGXScreenWidth];
- if (self.bgScrollView.contentOffset.x == kGXScreenWidth * str.integerValue) {
- button = self.arrayTopButtons[str.integerValue];
- [self didTouchButtonTop:button];
- }
- }
- }
- }
- - (void)endRefreshWithMoreData:(BOOL)isHaveMoreData AndTableView:(UITableView *)tableView {
- [tableView.mj_header endRefreshing];
- if (!isHaveMoreData) {
- [tableView.mj_footer endRefreshingWithNoMoreData];
- }else
- [tableView.mj_footer endRefreshing];
- }
- - (void)weiXinPay {
- // TradingResultsViewController *controller = [TradingResultsViewController new];
- // controller.model = self.modelPay;
- // [self.navigationController pushViewController:controller animated:true];
- }
- - (void)aliPay {
- // TradingResultsViewController *controller = [TradingResultsViewController new];
- // controller.model = self.modelPay;
- // [self.navigationController pushViewController:controller animated:true];
- }
- @end
|