| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- //
- // RAOrderEditorViewController.m
- // iSales-NPD
- //
- // Created by Jack on 2017/11/7.
- // Copyright © 2017年 United Software Applications, Inc. All rights reserved.
- //
- #import "RAOrderEditorViewController.h"
- #import "AppDelegate.h"
- #import "MainViewController.h"
- #define CLOSE_ACTION 567
- @interface RAOrderEditorViewController ()
- @property (nonatomic,assign) BOOL isResume;///<恢复
- @property (nonatomic,assign) NSInteger userType;///<恢复使用
- @property (nonatomic,assign) NSInteger pageIndex;///<当前页码
- /**
- * 保存不同页码上行参数,最新的在最后。
- * 点击下一页时将当前页面上行参数写入数组尾
- * 退回到前一页后删除最后一个元素
- */
- @property (nonatomic,strong) NSMutableArray *pageUpParams;
- @property (nonatomic,strong) NSMutableArray *pageContentDownloadArray;///<保存不同页码content_data_download
- @property (nonatomic,strong) NSMutableArray *pageContentControlArray;///<保存不同页码content_data_control
- @property (nonatomic,strong) NSMutableArray *pageChangeDataArray;///<保存不同页码change_data
- @property (strong, nonatomic) IBOutlet UIToolbar *pageControlToolBar;
- @property (strong, nonatomic) IBOutlet UIBarButtonItem *frontBarItem;
- @property (strong, nonatomic) IBOutlet UIBarButtonItem *nextBarItem;
- @end
- @implementation RAOrderEditorViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.editable = YES;
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onCloseClick:)];
-
- self.navigationItem.leftBarButtonItem = closeButton;
-
- [self setupPageControlBar];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Lazy Load
- - (NSMutableArray *)pageUpParams {
- if (!_pageUpParams) {
- _pageUpParams = [NSMutableArray array];
- }
- return _pageUpParams;
- }
- - (NSMutableArray *)pageContentDownloadArray {
- if (!_pageContentDownloadArray) {
- _pageContentDownloadArray = [NSMutableArray array];
- }
- return _pageContentDownloadArray;
- }
- - (NSMutableArray *)pageContentControlArray {
- if (!_pageContentControlArray) {
- _pageContentControlArray = [NSMutableArray array];
- }
- return _pageContentControlArray;
- }
- - (NSMutableArray *)pageChangeDataArray {
- if (!_pageChangeDataArray) {
- _pageChangeDataArray = [NSMutableArray array];
- }
- return _pageChangeDataArray;
- }
- #pragma mark - Private
- - (void)onCloseClick:(UIButton *)sender {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if (self.resumeOrder) {
- [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
- return;
- }
-
-
- UIAlertView * alert = nil;
- if(appDelegate.order_status==0)
- {
- alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and cancel order", nil), nil];
-
- }
- else
- {
- alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil];
-
- }
-
- alert.tag = CLOSE_ACTION;
- [alert show];
- }
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
-
- if(alertView.tag == CLOSE_ACTION)
- {
- if(buttonIndex==1)
- {
-
- [self.navigationController popViewControllerAnimated:true];
- }
- if(buttonIndex==2)
- {
-
- [self.navigationController popViewControllerAnimated:false];
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) switchToOrder];
- }
- else if(buttonIndex==3)
- {
- // close order;
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- [appDelegate closeOrder];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) switchToHome];
-
- if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
- {
- [((MainViewController*)appDelegate.main_vc) Loginout:false];
- }
-
- [self prepareReturn:nil];
-
-
- [self.navigationController popViewControllerAnimated:true];
-
- }
- else
- {
- [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
- }
-
-
-
- });
- });
-
-
- }
- }
-
- }
- - (void)setupPageControlBar {
-
- int totalPage = 1;
- // 1. 控制ToolBar Item显隐
- NSMutableArray *items = [self.pageControlToolBar.items mutableCopy];
- if (self.pageIndex == 0) {
- // 首页不需要前一页
- if ([items containsObject:self.frontBarItem]) {
- [items removeObject:self.frontBarItem];
- }
-
- } else if (self.pageIndex == totalPage - 1) {
- // 尾页不需要后一页
- if ([items containsObject:self.nextBarItem]) {
- [items removeObject:self.nextBarItem];
- }
- } else {
- // 中间显示前一页、后一页按钮
- if (![items containsObject:self.frontBarItem]) {
- [items insertObject:self.frontBarItem atIndex:0];
- }
- if (![items containsObject:self.nextBarItem]) {
- [items addObject:self.nextBarItem];
- }
-
-
- }
- self.pageControlToolBar.items = items;
- }
- #pragma mark - BarItem Action
- - (IBAction)frontBarItemClick:(UIBarButtonItem *)sender {
- self.pageIndex--;
-
- // 1.恢复当前页面数据
- NSMutableDictionary* upparams = [self.pageUpParams lastObject]; // 当前页上行参数
- __weak typeof(self) weakSelf = self;
- [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- [weakSelf.params removeObjectForKey:key];
-
- }];
- [self.pageUpParams removeLastObject];
-
- self.content_data_control = [self.pageContentControlArray lastObject];
- [self.pageContentControlArray removeLastObject];
-
- self.content_data_download = [self.pageContentDownloadArray lastObject];
- [self.pageContentDownloadArray removeLastObject];
-
- self.changed_data = [self.pageChangeDataArray lastObject];
- [self.pageChangeDataArray removeLastObject];
-
- // 2.刷新页面
- [self.editorTable reloadData];
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
-
- [self setupPageControlBar];
- }
- - (IBAction)nextBarItemClick:(UIBarButtonItem *)sender {
- self.pageIndex++;
-
- NSMutableDictionary* upparams = [self check_cancommit:false]; // 当前页上行参数
-
- // 1.保存当前页面数据
- if (upparams == nil) {
- upparams = [NSMutableDictionary dictionary];
- }
- [self.pageUpParams addObject:upparams];
- if (self.content_data_control == nil) {
- self.content_data_control = [NSMutableArray array];
- }
- [self.pageContentControlArray addObject:self.content_data_control];
- if (self.content_data_download == nil) {
- self.content_data_download = [NSMutableDictionary dictionary];
- }
- [self.pageContentDownloadArray addObject:self.content_data_download];
-
- if (self.changed_data == nil) {
- self.changed_data = [NSMutableDictionary dictionary];
- }
- [self.pageChangeDataArray addObject:self.changed_data];
-
- // 2.请求下一页数据
- __weak typeof(self) weakSelf = self;
- [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- [weakSelf.params setObject:obj forKey:key];
-
- }];
-
- [self setupPageControlBar];
- [self refresh:nil];
- }
- #pragma mark - Override
- - (void)download_success {
-
- [self setupPageControlBar];
-
- }
- @end
|