Skip to content

Commit

Permalink
盘点后续流程完成
Browse files Browse the repository at this point in the history
  • Loading branch information
有马 committed Sep 12, 2015
1 parent 881b719 commit 468089c
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@

+ (void)switchStore: (NSString *)storeId;

+ (void)registSuccessActionHandler:(DJCheckCartAxtionHandler)sHandler
failHandler:(DJCheckCartAxtionHandler)fHandler
forActionType: (DJCheckCartActionType)typeKey;
+ (void)registActionHandler:(DJCheckCartAxtionHandler)sHandler
forActionType: (DJCheckCartActionType)typeKey;

+ (DJCheckCartAxtionHandler)actionHandlerWithActionType: (DJCheckCartActionType)type;

+ (void)addCheckCartItemComponent: (id<DJCheckCartItemComponent>)item
withStoreId:(NSString *)storeId;

+ (NSArray<DJCheckCartItemComponent> *)chekCartItemComponents;

+ (void)removeAllItemComponentsWithStoreId:(NSString *)storeId;

+ (void)setCheckCartItemComponents: (NSArray<DJCheckCartItemComponent> *)components;

+ (void)deleteCheckCartItemComponents: (id<DJCheckCartItemComponent>)item;
Expand Down
16 changes: 12 additions & 4 deletions YHB_Prj/YHB_Prj/ProductCheck/CheckCart/DJCheckCartContexManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ + (void)switchStore: (NSString *)storeId {
+ (DJCheckCartContext *)currentContex {
return [[[self sharedManager] contextDic] objectForKey:[[self sharedManager] currentStoreId]];
}
+ (void)registSuccessActionHandler:(DJCheckCartAxtionHandler)sHandler
failHandler:(DJCheckCartAxtionHandler)fHandler
forActionType: (DJCheckCartActionType)typeKey {
[[self currentContex] registSuccessActionHandler:sHandler failHandler:fHandler forActionType:typeKey];

+ (void)registActionHandler:(DJCheckCartAxtionHandler)sHandler
forActionType: (DJCheckCartActionType)typeKey {
[[self currentContex] registActionHandler:sHandler forActionType:typeKey];
}

+ (DJCheckCartAxtionHandler)actionHandlerWithActionType: (DJCheckCartActionType)type {
return [[self currentContex] actionHandlerWithActionType:type];
}

+ (void)addCheckCartItemComponent: (id<DJCheckCartItemComponent>)item
Expand All @@ -68,6 +72,10 @@ + (void)addCheckCartItemComponent: (id<DJCheckCartItemComponent>)item
return [[self currentContex] chekCartItemComponents];
}

+ (void)removeAllItemComponentsWithStoreId:(NSString *)storeId {
[[[[self sharedManager] contextDic] objectForKey:storeId] removeAllItemComponents];
}

+ (void)setCheckCartItemComponents: (NSArray<DJCheckCartItemComponent> *)components {
[[self currentContex] setCheckCartItemComponents:components];
}
Expand Down
9 changes: 6 additions & 3 deletions YHB_Prj/YHB_Prj/ProductCheck/CheckCart/DJCheckCartContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@

@interface DJCheckCartContext : NSObject

- (void)registSuccessActionHandler:(DJCheckCartAxtionHandler)sHandler
failHandler:(DJCheckCartAxtionHandler)fHandler
forActionType: (DJCheckCartActionType)typeKey;
- (void)registActionHandler:(DJCheckCartAxtionHandler)sHandler
forActionType: (DJCheckCartActionType)typeKey;

- (void)addCheckCartItemComponent: (id<DJCheckCartItemComponent>)item;

- (void)removeAllItemComponents ;

- (NSMutableArray<DJCheckCartItemComponent> *)chekCartItemComponents;

- (DJCheckCartAxtionHandler)actionHandlerWithActionType: (DJCheckCartActionType)type;

- (void)setCheckCartItemComponents: (NSArray<DJCheckCartItemComponent> *)components;

@end
43 changes: 23 additions & 20 deletions YHB_Prj/YHB_Prj/ProductCheck/CheckCart/DJCheckCartContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,43 @@ @interface DJCheckCartContext()
@property (nonatomic, strong) NSString *storeId;
@property (nonatomic, strong) NSMutableArray<DJCheckCartItemComponent> *itemComponents;
@property (nonatomic, strong) DJCheckCartProcessor *processor;
@property (nonatomic, strong) NSMutableDictionary *successActionBlockDic;
@property (nonatomic, strong) NSMutableDictionary *failActionBlockDic;
@property (nonatomic, strong) NSMutableDictionary *actionBlockDic;
//@property (nonatomic, strong) NSMutableDictionary *failActionBlockDic;

@end

@implementation DJCheckCartContext
#pragma mark - getter and setter
- (NSMutableDictionary *)successActionBlockDic {
if (!_successActionBlockDic) {
_successActionBlockDic = [NSMutableDictionary dictionaryWithCapacity:4];
- (NSMutableDictionary *)actionBlockDic {
if (!_actionBlockDic) {
_actionBlockDic = [NSMutableDictionary dictionaryWithCapacity:4];
}
return _successActionBlockDic;
return _actionBlockDic;
}

- (NSMutableDictionary *)failActionBlockDic {
if (!_failActionBlockDic) {
_failActionBlockDic = [NSMutableDictionary dictionaryWithCapacity:4];
- (void)registActionHandler:(DJCheckCartAxtionHandler)sHandler
forActionType: (DJCheckCartActionType)typeKey {
if (sHandler) {
self.actionBlockDic[@(typeKey)] = [sHandler copy];
}
return _failActionBlockDic;

}

- (void)registSuccessActionHandler:(DJCheckCartAxtionHandler)sHandler
failHandler:(DJCheckCartAxtionHandler)fHandler
forActionType: (DJCheckCartActionType)typeKey {
if (sHandler) {
self.successActionBlockDic[@(typeKey)] = sHandler;
}
if (fHandler) {
self.failActionBlockDic[@(typeKey)] = fHandler;
}
- (DJCheckCartAxtionHandler)actionHandlerWithActionType: (DJCheckCartActionType)type {
return self.actionBlockDic[@(type)];
}

- (void)addCheckCartItemComponent:(id<DJCheckCartItemComponent>)item {
id<DJCheckCartItemComponent> removeItem = nil;
for (id<DJCheckCartItemComponent> citem in self.chekCartItemComponents) {
if ([citem.productId isEqualToString:item.productId]) {
[self.chekCartItemComponents removeObject:citem];
removeItem = item;
break;
}
}
if (removeItem) {
[self.chekCartItemComponents removeObject:removeItem];
}
if (!self.itemComponents) {
self.itemComponents = ( NSMutableArray<DJCheckCartItemComponent> *)[NSMutableArray array];
}
Expand All @@ -70,6 +69,10 @@ - (void)addCheckCartItemComponent:(id<DJCheckCartItemComponent>)item {
return self.itemComponents;
}

- (void)removeAllItemComponents {
[self.itemComponents removeAllObjects];
}

- (void)setCheckCartItemComponents: (NSArray<DJCheckCartItemComponent> *)components {
[self.itemComponents removeAllObjects];
[self.itemComponents addObjectsFromArray:components];
Expand Down
6 changes: 1 addition & 5 deletions YHB_Prj/YHB_Prj/ProductCheck/CheckCart/DJCheckCartEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@

+ (void)registActionHandler:(DJCheckCartAxtionHandler)sHandler forActionTyp: (DJCheckCartActionType)typeKey;

+ (void)registSuccessActionHandler:(DJCheckCartAxtionHandler)sHandler
failHandler:(DJCheckCartAxtionHandler)fHandler
forActionType: (DJCheckCartActionType)typeKey;

+ (void)addCheckCartItemComponent: (id<DJCheckCartItemComponent>)item withStoreId:(NSString *)storeId;

+ (NSArray<DJCheckCartItemComponent> *)chekCartItemComponents;

+ (void)submitCheckCartItemComponents;
+ (void)submitCheckCartItemComponentsWithStoreId:(NSString *)storeId;

+ (void)deleteCheckCartItemComponents: (id<DJCheckCartItemComponent>)item;

Expand Down
46 changes: 35 additions & 11 deletions YHB_Prj/YHB_Prj/ProductCheck/CheckCart/DJCheckCartEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "DJCheckCartNetService.h"
#import "JSONKit.h"
#import "DJProductCheckManager.h"
#import "AFNetworking.h"

@implementation DJCheckCartEngine

Expand All @@ -31,13 +32,11 @@ + (void)switchEngineWithStoreId: (NSString *)storeId {
}

+ (void)registActionHandler:(DJCheckCartAxtionHandler)sHandler forActionTyp: (DJCheckCartActionType)typeKey {
[self registSuccessActionHandler:sHandler failHandler:nil forActionType:typeKey];
[DJCheckCartContexManager registActionHandler:[sHandler copy] forActionType:typeKey];
}

+ (void)registSuccessActionHandler:(DJCheckCartAxtionHandler)sHandler
failHandler:(DJCheckCartAxtionHandler)fHandler
forActionType: (DJCheckCartActionType)typeKey {
[DJCheckCartContexManager registSuccessActionHandler:[sHandler copy] failHandler:[fHandler copy] forActionType:typeKey];
+ (DJCheckCartAxtionHandler)actionHandlerWIthType: (DJCheckCartActionType)typeKey {
return [DJCheckCartContexManager actionHandlerWithActionType:typeKey];
}

+ (void)addCheckCartItemComponent: (id<DJCheckCartItemComponent>)item
Expand All @@ -46,26 +45,51 @@ + (void)addCheckCartItemComponent: (id<DJCheckCartItemComponent>)item
return;
}
[DJCheckCartContexManager addCheckCartItemComponent:item withStoreId:storeId];
[[NSNotificationCenter defaultCenter] postNotificationName:DJCheckCartDataChangedNotification object:nil];
}

+ (NSArray<DJCheckCartItemComponent> *)chekCartItemComponents {
return [DJCheckCartContexManager chekCartItemComponents];
}

+ (void)deleteCheckCartItemComponents: (id<DJCheckCartItemComponent>)item; {

+ (void)deleteCheckCartItemComponents: (id<DJCheckCartItemComponent>)item {
if (!item) {
return;
}
[DJCheckCartContexManager deleteCheckCartItemComponents:item];
[[NSNotificationCenter defaultCenter] postNotificationName:DJCheckCartDataChangedNotification object:nil];
}

+ (void)submitCheckCartItemComponents {
+ (void)submitCheckCartItemComponentsWithStoreId:(NSString *)storeId {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[DJCheckCartContexManager chekCartItemComponents].count];
DJCheckCartAxtionHandler sHandler = [self actionHandlerWIthType:DJCheckCartActionTypeSubmitChecksSuccess];
DJCheckCartAxtionHandler fHandler = [self actionHandlerWIthType:DJCheckCartActionTypeSubmitFail];
DJCheckCartAxtionHandler reCheckHandler = [self actionHandlerWIthType:DJCheckCartActionTypeSubmitChecksNeedRechack];

for (id<DJCheckCartItemComponent> item in [DJCheckCartContexManager chekCartItemComponents])
{
[array addObject:[item dataDictionary]];
};
[DJProductCheckManager submitProductChecksWithCheckDicArray:array success:^(id resultModel) {

[DJProductCheckManager submitProductChecksWithCheckDicArray:array success:^(NSArray *result) {
[DJCheckCartContexManager removeAllItemComponentsWithStoreId:storeId];
if (result.count) {
[result enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
id<DJCheckCartItemComponent> item = [[DJCheckCartItemComponent alloc] initWithData:obj];
[DJCheckCartContexManager addCheckCartItemComponent:item withStoreId:storeId];
}];
if (reCheckHandler) {
reCheckHandler(nil);
}
}else {
if (sHandler) {
sHandler(nil);
}
}

} fail:^(id msg) {

if (fHandler) {
fHandler(nil);
}
}];

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ - (instancetype)initWithData: (NSDictionary *)data {
- (NSDictionary *)dataDictionary {
NSMutableDictionary *data = [NSMutableDictionary dictionary];

data[@"sid"] = self.sid;
data[@"sid"] = self.sid?:@"";
data[@"product_id"] = self.productId?:@"";
data[@"product_name"] = self.productName?:@"";
data[@"product_code"] = self.productCode?:@"";
// data[@"product_name"] = self.productName?:@"";
// data[@"product_code"] = self.productCode?:@"";
data[@"store_stock_id"] = self.storeStockId?:@"";
data[@"stock_qty"] = @(self.stockQuanity);
data[@"stay_qty"] = @(self.stayQuanity);
data[@"last_ck_time"] = self.lastCheckTime?:@"";
// data[@"last_ck_time"] = self.lastCheckTime?:@"";
data[@"chek_qty"] = @(self.checkQuanity);
data[@"check_name"] = self.checkName?:@"";

Expand Down
2 changes: 2 additions & 0 deletions YHB_Prj/YHB_Prj/ProductCheck/CheckCart/DJCheckCartPublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#ifndef YHB_Prj_DJCheckCartPublic_h
#define YHB_Prj_DJCheckCartPublic_h
//数据发生变化 通知
#define DJCheckCartDataChangedNotification @"cartChange"

typedef void (^DJCheckCartAxtionHandler)(id model);

Expand Down
47 changes: 41 additions & 6 deletions YHB_Prj/YHB_Prj/ProductCheck/DJCheckCartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
#import "DJCheckCartCell.h"
#import "DJScanViewController.h"
#import "ShangpinguanliVC.h"
#import "DJProductCheckViewManager.h"

#define StringValueWithNum(a) [NSString stringWithFormat:@"%ld",(NSInteger)a]

@interface DJCheckCartViewController ()<UITableViewDataSource,UITableViewDelegate>
@interface DJCheckCartViewController ()<UITableViewDataSource,UITableViewDelegate,DJProductCheckViewDataSoure>

@property (weak, nonatomic) IBOutlet DJProductSearchBar *searchBar;
@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) id<DJCheckCartItemComponent> currentCheckItem;

@end

Expand All @@ -30,6 +32,8 @@ @implementation DJCheckCartViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setExtraCellLineHidden:self.tableView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshUI) name:DJCheckCartDataChangedNotification object:nil];
[self registEnigine];

[self.searchBar setNeedShowSearchVCHandler:^{
//TODO:跳转搜索框
Expand Down Expand Up @@ -61,19 +65,25 @@ - (void)setExtraCellLineHidden: (UITableView *)tableView

- (void)registEnigine {
__weak typeof(self) weakself = self;
[DJCheckCartEngine registSuccessActionHandler:^(id model) {
[DJCheckCartEngine registActionHandler:^(id model) {
[SVProgressHUD dismissWithSuccess:@"成功"];
[weakself refreshUI];
} failHandler:^(id model) {
} forActionTyp:DJCheckCartActionTypeSubmitChecksSuccess];

[DJCheckCartEngine registActionHandler:^(id model) {
[SVProgressHUD dismissWithError:@"上传盘点失败,请重试"];
[weakself refreshUI];
} forActionType:DJCheckCartActionTypeSubmitChecksSuccess];
} forActionTyp:DJCheckCartActionTypeSubmitFail];

[DJCheckCartEngine registActionHandler:^(id model) {
[SVProgressHUD dismissWithError:@"上传盘点失败,请重试"];
[weakself refreshUI];
} forActionTyp:DJCheckCartActionTypeSubmitFail];

[DJCheckCartEngine registActionHandler:^(id model) {
[SVProgressHUD showErrorWithStatus:@"本次盘点期间这些库存发生变化,请重新盘点" cover:YES offsetY:0];
[weakself refreshUI];
} forActionTyp:DJCheckCartActionTypeSubmitChecksNeedRechack];

}


Expand Down Expand Up @@ -108,6 +118,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row < [DJCheckCartEngine chekCartItemComponents].count) {
id<DJCheckCartItemComponent> item = [DJCheckCartEngine chekCartItemComponents][indexPath.row];
if (item) {
self.currentCheckItem = item;
[[DJProductCheckViewManager sharedInstance] showCheckViewFromViewController:self withDataSource:self];
return;
}
}
//由于check中数量顺序等会变化,所以不给于连续下一下检索功能
self.currentCheckItem = nil;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
if ([DJCheckCartEngine chekCartItemComponents].count > indexPath.row) {
Expand All @@ -117,13 +141,24 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
}
}

#pragma mark - check DataSource
- (id<DJCheckCartItemComponent>)nextItem {
id<DJCheckCartItemComponent> item = self.currentCheckItem;
self.currentCheckItem = nil;
return item;
}

#pragma mark - action
#pragma mark submit
- (IBAction)touchSubmitButton:(UIButton *)sender {
if ([DJCheckCartEngine chekCartItemComponents].count > 0) {
[SVProgressHUD showWithStatus:@"上传中..." cover:YES offsetY:0];
[DJCheckCartEngine submitCheckCartItemComponents];
[DJCheckCartEngine submitCheckCartItemComponentsWithStoreId:[[LoginManager shareLoginManager] getStoreId]];
}
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
Loading

0 comments on commit 468089c

Please sign in to comment.