| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- //
- // ViewController.m
- // RA Image
- //
- // Created by Ray on 25/04/2017.
- // Copyright © 2017 USAI. All rights reserved.
- //
- #import "RootViewController.h"
- #import "LoginViewController.h"
- #import "RootModeCell.h"
- #import "PopModeViewController.h"
- #import "ModelModeViewController.h"
- #import "UploadSettingController.h"
- #import "PODModeViewController.h"
- #import "ReceivingPalletIDViewController.h"
- static NSString *kLastMode = @"lastChooseMode";
- @interface RootViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (strong, nonatomic) IBOutlet UILabel *companyNameLabel;
- @property (strong, nonatomic) IBOutlet UIImageView *companyIconView;
- @property (strong, nonatomic) IBOutlet UITableView *modeTable;
- @property (nonatomic,strong) NSArray *modeList;
- @property (nonatomic,assign) NSInteger lastChoosedIndex;
- @end
- @implementation RootViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- UIView *v = [UIView new];
- [self.view insertSubview:v atIndex:0];
- self.lastChoosedIndex = -1;
-
-
- #ifndef PROJ_RAMOBILE
- //如果是Redant Mobile 集成的,就没有logout
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logoutItemClick:)];
- #endif
-
- self.title = @"Select Mode";
- self.modeTable.tableFooterView = [UIView new];
-
- [self removeFirstResponderTap]; // 不然cell接受不了消息
-
- self.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
- self.companyNameLabel.text = nil;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self.modeTable reloadData];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- self.companyNameLabel.text = appDelegate.companyName;
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSString *lastChoosedMode = [self userDefaultsValue:kLastMode];
- NSArray *savedArr = [lastChoosedMode componentsSeparatedByString:@"<&&>"];
- NSString *lastLoginName = [savedArr firstObject];
- if (![lastLoginName isEqualToString:appDelegate.user]) { // 登录用户与上一次使用过模式的用户相同才进入上一次模式。
- appDelegate.shouldAutoShowModeVC = NO;
- return;
- }
- if (appDelegate.shouldAutoShowModeVC) {
- appDelegate.shouldAutoShowModeVC = NO;
- if (self.lastChoosedIndex > -1) {
- // RootModeCell *cell = [self.modeTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.lastChoosedIndex inSection:0]];
- // [self pushCurrentModeController:cell];
- [self tableView:self.modeTable didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:self.lastChoosedIndex inSection:0]];
- }
- }
- [self setUserDefaultsValue:nil forKey:kLastMode];
- self.lastChoosedIndex = -1;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)setCompanyIcon:(UIImage *)companyIcon {
- _companyIcon = companyIcon;
- self.companyIconView.image = companyIcon;
- }
- - (NSArray *)modeList {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- return appDelegate.modeList;
- }
- #pragma mark - DataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.modeList.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- RootModeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RootModeCell"];
- NSDictionary *mode = [self.modeList objectAtIndex:indexPath.row];
- NSString *name = [mode objectForKey:@"name"];
- NSString *desc = [mode objectForKey:@"description"];
- // cell.mode = name;
- [cell setMode:name desc:desc];
- NSString *codeName = [mode objectForKey:@"code_name"];
- cell.code_name = codeName;
-
- NSString *lastChoosedMode = [self userDefaultsValue:kLastMode];
- NSArray *savedArr = [lastChoosedMode componentsSeparatedByString:@"<&&>"];
- lastChoosedMode = [savedArr lastObject];
-
- if (lastChoosedMode.length) {
- if ([lastChoosedMode isEqualToString:name]) {
- self.lastChoosedIndex = indexPath.row;
- }
- }
- BOOL enable = [[mode objectForKey:@"enable"] boolValue];
- if (!enable) {
- cell.contentView.backgroundColor = [UIColor darkGrayColor];
- }
- else{
- cell.contentView.backgroundColor = [UIColor whiteColor];
- }
-
- return cell;
- }
- #pragma mark - Delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- RootModeCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- NSDictionary *mode = [self.modeList objectAtIndex:indexPath.row];
- BOOL enable = [[mode objectForKey:@"enable"] boolValue];
- if (enable) {
- NSString *name = cell.mode;
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- appDelegate.shouldAutoShowModeVC = NO;
- [self setUserDefaultsValue:[NSString stringWithFormat:@"%@<&&>%@",appDelegate.user,name] forKey:kLastMode];
- [self pushCurrentModeController:cell];
- }
- }
- #pragma mark - Private
- - (void)pushCurrentModeController:(RootModeCell *)cell {
- if (!cell) {
- return;
- }
- NSIndexPath *indexPath = [self.modeTable indexPathForCell:cell];
- NSDictionary *mode = [self.modeList objectAtIndex:indexPath.row];
- BasicModeViewController *modeVC = nil;
- if ([cell.mode isEqualToString:@"Model"]) {
- ModelModeViewController *vc = (ModelModeViewController *)[self viewControllerInStoryboard:@"Mode" withId:@"ModelModeViewController"];
- vc.manufacturerList = [mode objectForKey:@"manifacturer"];
- modeVC = vc;
- }else if ([cell.mode isEqualToString:@"POP"]||[cell.mode isEqualToString:@"Returns"]) {
- PopModeViewController *vc = [[UIStoryboard storyboardWithName:@"Mode" bundle:nil] instantiateViewControllerWithIdentifier:@"PopModeViewController"];
- if (![cell.mode isEqualToString:@"Receiving"]) {
- vc.inputKeyboardType = UIKeyboardTypeNumberPad;
- } else {
- vc.inputKeyboardType = UIKeyboardTypeDefault;
- }
- modeVC = vc;
- }
- else if([cell.mode isEqualToString:@"Receiving"])
- {
- if([cell.code_name isEqualToString:@"PO#"])
- {
- PopModeViewController *vc = [[UIStoryboard storyboardWithName:@"Mode" bundle:nil] instantiateViewControllerWithIdentifier:@"PopModeViewController"];
- vc.inputKeyboardType = UIKeyboardTypeNumberPad;
- modeVC = vc;
- }
- else
- {
- ReceivingPalletIDViewController *vc = [[UIStoryboard storyboardWithName:@"Mode" bundle:nil] instantiateViewControllerWithIdentifier:@"ReceivingPalletIDViewController"];
- vc.inputKeyboardType = UIKeyboardTypeDefault;
- modeVC = vc;
- }
- }
- else if ([cell.mode isEqualToString:@"POD"]) {
-
- PODModeViewController *vc = [PODModeViewController viewControllerFromStoryboard];
- vc.inputKeyboardType = UIKeyboardTypeDefault;
- modeVC = vc;
- }
-
- if (modeVC) {
- modeVC.barcodeTitle = cell.code_name;
- modeVC.name = cell.mode;
- [self.navigationController pushViewController:modeVC animated:YES];
- }
-
- }
- - (void)userLogout:(NSNotification *)notification {
-
- [self.modeTable reloadData];
- [super userLogout:notification];
- }
- #pragma mark - Action
- - (void)logoutItemClick:(UIBarButtonItem *)sender {
-
- #ifndef PROJ_RAMOBILE
- //如果是Redant Mobile 集成的,就没有logout
-
-
- __block UIAlertController* alertcontroller= [RAUtils waiting_alert:self title:@"Logout" completion:^{
- __weak typeof(self) weakself = self;
- [RANetwork request_logout:^(NSMutableDictionary *resulti) {
-
- NSDictionary *logoutDic = resulti;
- int result = [[logoutDic objectForKey:@"result"] intValue];
- dispatch_async(dispatch_get_main_queue(), ^{
- // [alert dismissWithClickedButtonIndex:0 animated:YES];
- [alertcontroller dismissViewControllerAnimated:true completion:^{
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (result == RESULT_TRUE) {
- weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
- [appDelegate logout];
- } else {
- __strong typeof(weakself) strongself = weakself;
- NSString *msg = [logoutDic objectForKey:@"err_msg"];
- [RAUtils message_alert:msg title:@"Warning" controller:strongself];
- }
- }];
-
- });
-
-
- }];
-
-
-
-
-
-
-
-
-
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // NSDictionary *logoutDic = [RANetwork logout];
- // int result = [[logoutDic objectForKey:@"result"] intValue];
- // dispatch_async(dispatch_get_main_queue(), ^{
- //// [alert dismissWithClickedButtonIndex:0 animated:YES];
- // [alertcontroller dismissViewControllerAnimated:true completion:^{
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // if (result == RESULT_TRUE) {
- // weakself.companyIcon = [UIImage imageNamed:@"AppIcon40x40"];
- // [appDelegate logout];
- // } else {
- // __strong typeof(weakself) strongself = weakself;
- // NSString *msg = [logoutDic objectForKey:@"err_msg"];
- // [RAUtils message_alert:msg title:@"Warning" controller:strongself];
- // }
- // }];
- //
- // });
- //
- //
- // });
- }];
- // UIAlertView *alert = [RAUtils waiting_alert:@"Please wait..." title:@"Logout"];
-
-
- #endif
-
- }
- - (IBAction)uploadSettingBtnClick:(UIButton *)sender {
-
- UploadSettingController *ups = (UploadSettingController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadSettingController"];
- [self.navigationController pushViewController:ups animated:YES];
-
- }
- @end
|