暂保存

//

//  ShopCartViewController.m

//  MBuyGo

//

//  Created by fangqingmei on 15/10/9.

//  Copyright (c) 2015年 m6go.com. All rights reserved.

//

#import "ShopCartViewController.h"

#import "MLGHTTPRequestOperationManager.h"

#import "MLGSettlementViewController.h"

#import "MLGHomePageDoubleGoodsCell.h"

#import "CheckShoppingCartRequest.h"

#import "ShopCartProtocolDelegate.h"

#import "ShopCartTableHeaderView.h"

#import "MLGShopCarTableViewCell.h"

#import "SCExchangeShopViewController.h"

#import "GoodsDetailSourceMark.h"

#import "SCMerchantListModel.h"

#import "NSObject+MJKeyValue.h"

#import "ShopCartNoDataView.h"

#import "BottomAccountView.h"

#import "ShopRecommendGoodsModel.h"

#import "ShopCartModel.h"

#import "MerchantView.h"

#import "SCMerchantModel.h"

#import "SCDecreaseRuleModel.h"

#import "ProductTableViewCell.h"

#import "ActivityTypeView.h"

#import "GCDQueue.h"

#import "ShopCart.h"

#import "Masonry.h"

#import "Utility.h"

#import "ShopCartDef.h"

#import "ActivityModel.h"

#import "MLGLoadFailureView.h"

#import "MLGProgressView.h"

#import "InvalidModel.h"

@interface ShopCartViewController ()<UIGestureRecognizerDelegate,MLGHomePageDoubleGoodsCellDelegate,ShopCartProtocolDelegate,ShopCartProductCellDelegate>

@property (nonatomic, strong) UITableView               *firstGradeTableView;      ///<显示购物车商品的TableView

@property (nonatomic, strong) ShopCartTableHeaderView   *tableHeaderView;          ///<购物车头视图(登录提示语和button)

@property (nonatomic, strong) MLGLoadFailureView        *loadFailureView;          ///< 加载失败视图

@property (nonatomic, strong) NSMutableArray *shopRecommendGoodsModelArray;

@property (nonatomic, strong) NSMutableArray *moreGoodsArray;

@property (nonatomic, strong) NSMutableArray *activityArray;

@property (nonatomic, strong) NSMutableArray *editProductArray;

//换购模块的数据源数组

@property (nonatomic, strong) NSMutableArray *activitySelectGoodsArray;

@property (nonatomic, assign) NSInteger              start;                   ///< 起始位置(猜你喜欢)

@property (nonatomic, assign) NSInteger              rows;                    ///< 加载数量

@property (nonatomic, assign) NSInteger count;

@property (nonatomic, assign) NSInteger proAppearNum;

@property (nonatomic, assign) BOOL isEmptyData;

@property (nonatomic, assign) BOOL isHaveInvalidGoods;                       ///< 是否有失效商品

@property (nonatomic, assign) BOOL isSelectMerchatView;

@property (nonatomic, assign) BOOL isEdit;

@property (nonatomic, assign) BOOL isAllSelect;

@property (nonatomic, assign) BOOL isHaveRecommendData;

@property (nonatomic, assign) BOOL isRequestMainGoods;

@property (nonatomic, assign) BOOL isModifi;                                ///< 编辑状态下是否有改动

@property (nonatomic, assign) BOOL isSync;                                  ///< 是否同步数据

@property (nonatomic, strong) MerchantView *merchantView;

@property (nonatomic, strong) BottomAccountView *bottomAccountView;        ///< 底部结算view

@property (nonatomic, strong) ProductTableViewCell *proCell;

@property (nonatomic, strong) ShopCartModel *shopCartmodel;

@property (nonatomic, strong) ShopCartModel *payModel;

@end

@implementation ShopCartViewController

#pragma mark -重置结算view和firstGradeTableView的frame

- (void)resetBottomHidden:(BOOL)isHidden {

self.bottomAccountView.frame = isHidden?CGRectMake(0, -ScreenHeight, ScreenWidth, 0):CGRectMake(0, ScreenHeight-scBottomView_height, ScreenWidth, scBottomView_height);

self.firstGradeTableView.frame = isHidden?CGRectMake(0, self.titleBar.bottom , ScreenWidth, ScreenHeight-self.titleBar.bottom):CGRectMake(0, 64, ScreenWidth, ScreenHeight-64-50);

}

- (void)leftBtnClicked:(UIButton *)sender {

[APPDELEGATE.navigationController popViewControllerAnimated:YES];

}

- (void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:animated];

self.start = 0;

self.isSync = YES;

[self reloadDataSetTip];

[self readyForCarDataFromHttp];

[self prepareShopRecommendGoodsRequestData];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshShopCartData:) name:@"tongzhi" object:nil];

}

- (void)viewWillDisappear:(BOOL)animated {

[super viewWillDisappear:YES];

[MLGProgressView hide];

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"tongzhi" object:nil];

}

- (void)viewDidLoad {

[super viewDidLoad];

NSLog(@"bounds = %@",NSStringFromCGRect([UIScreen mainScreen].bounds));

self.shopRecommendGoodsModelArray = [NSMutableArray arrayWithCapacity:0];

self.moreGoodsArray = [NSMutableArray arrayWithCapacity:0];

self.activityArray = [NSMutableArray arrayWithCapacity:0];

self.activitySelectGoodsArray = [NSMutableArray arrayWithCapacity:0];

self.view.backgroundColor = [UIColor whiteColor];

[self.titleBar setTitleStr:@"购物车"];

[self createLoadFailureView];

[self createContent];

[self.bottomAccountView resetEmptyView];

self.rows  = 50; // 加载条数

NSLog(@"frame = %@,%f",NSStringFromCGRect(self.titleBar.frame),self.titleBar.bottom);

}

#pragma mark - 添加刷新方法

- (void)loadShops {

__weak typeof(UIScrollView *) weakScrollView = self.firstGradeTableView;

__weak typeof(self) weakSelf = self;

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC);

dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

//请求购物车数据

self.isSync = YES;

[weakSelf readyForCarDataFromHttp];

self.start = 0;

//请求商品推荐数据

[weakSelf prepareShopRecommendGoodsRequestData];

[weakScrollView finishLoading];

});

}

#pragma mark 创建加载失败的视图

- (void)createLoadFailureView {

WS(weakSelf)

self.loadFailureView = [MLGLoadFailureView loadFailureViewWithRetryBlock:^{

[self reloadDataSetTip];

self.isSync = YES;

[self readyForCarDataFromHttp];

self.start = 0;

[self prepareShopRecommendGoodsRequestData];

}];

self.loadFailureView.hidden = YES;

self.loadFailureView.backgroundColor = [UIColor clearColor];

[self.view addSubview:self.loadFailureView];

[self.loadFailureView mas_makeConstraints:^(MASConstraintMaker *make){

make.center.equalTo(weakSelf.view);

make.size.mas_equalTo(CGSizeMake(200, 230));

}];

}

- (void)loadFailure {

dispatch_async(dispatch_get_main_queue(), ^{

self.loadFailureView.hidden = NO;

[self hideContentView:YES];

});

}

- (void)loadSuccess {

dispatch_async(dispatch_get_main_queue(), ^{

self.loadFailureView.hidden = YES;

[self hideContentView:NO];

});

}

- (void)refreshShopCartData:(NSNotification *)notification {

[self reloadDataSetTip];

[self.bottomAccountView resetEmptyView];

self.isSync = YES;

[self readyForCarDataFromHttp];

self.start = 0;

[self prepareShopRecommendGoodsRequestData];

}

- (void)hideContentView:(BOOL)hide {

self.firstGradeTableView.hidden = hide;

self.bottomAccountView.hidden = hide;

}

#pragma mark 结算

- (void)buyAction:(UIButton*)sender {

__weak typeof(self) weakSelf = self;

NSMutableArray *selectGoodsArray = [NSMutableArray arrayWithCapacity:0];

for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++) {

NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if (shopCart.isSelected.integerValue==1) {

[selectGoodsArray addObject:shopCart];

}

}

if(selectGoodsArray.count < 1) {

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"您未选购商品" message:nil delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

[alertView show];

return;

}

if(![NetworkCheck isConnect])

return;

sender.enabled = NO;

NSString *auth = [Utility getUserAuth];

NSNumber *userId = [Utility getUserID];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];

NSMutableArray *productArray = [NSMutableArray arrayWithCapacity:0];

NSMutableArray *selectedActivityArray = [NSMutableArray arrayWithCapacity:0];

[MLGProgressView show];

for (int i = 0; i < selectGoodsArray.count; i++) {

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

ShopCart *shopCart = selectGoodsArray[i];

[dict setValue:shopCart.goodsId forKey:@"goodsId"];

[dict setValue:shopCart.goodsCount forKey:@"goodsCount"];

[dict setValue:shopCart.goodsSkuId forKey:@"goodsSkuId"];

[dict setValue:shopCart.salesId forKey:@"salesId"];

[dict setValue:shopCart.goodsSourceType forKey:@"goodsSourceType"];

[dict setValue:shopCart.pageSourceMark forKey:@"pageSourceMark"];

[productArray addObject:dict];

}

for(int i = 0; i<weakSelf.activitySelectGoodsArray.count;i++) {

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

SCActivityGoodsModel *acModel = weakSelf.activitySelectGoodsArray[i];

if(acModel.aIsSelected == 1){

[dict setValue:@(acModel.aGoodsId) forKey:@"goodsId"];

[dict setValue:@(acModel.aGoodsSkuId) forKey:@"goodsSkuId"];

[selectedActivityArray addObject:dict];

}

}

[params setObject:userId forKey:@"userId"];

[params setObject:auth forKey:@"auth"];

[params setObject:productArray forKey:@"products"];

[params setObject:selectedActivityArray forKey:@"selectedActivityGoods"];

NSString *shopCartStr = [Configuration sharedConfiguration].iPadShoppingCartBuyAction_url;

MLGHTTPRequestOperationManager *manager = [[MLGHTTPRequestOperationManager alloc] init];

[manager POST:shopCartStr parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {

[MLGProgressView hide];

sender.enabled = YES;

NSDictionary *msgDict = responseObject[@"msg"];

NSString *code = [responseObject objectForKey:@"code"];

if (code.integerValue == 200) {

weakSelf.payModel = [ShopCartModel objectWithKeyValues:msgDict];

if(weakSelf.payModel.canBuyType==0){

MLGSettlementViewController *setVC = [[MLGSettlementViewController alloc] initSelectedGoodsArray:selectGoodsArray exchangedGoodsArray:weakSelf.activitySelectGoodsArray isBuyNowGoods:NO isCycle:NO];

[weakSelf.navigationController pushViewController:setVC animated:YES];

}else{

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:weakSelf.payModel.showAlertText message:nil delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

[alertView show];

}

}

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

sender.enabled = YES;

[MLGProgressView hide];

}];

}

#pragma mark 创建购物车显示的列表视图和结算视图

- (void)createContent {

self.firstGradeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.titleBar.bottom, ScreenWidth, ScreenHeight-self.titleBar.bottom-50) style:UITableViewStyleGrouped];

self.firstGradeTableView.backgroundColor = [UIColor redColor];

self.firstGradeTableView.delegate = self;

self.firstGradeTableView.dataSource = self;

self.firstGradeTableView.showsHorizontalScrollIndicator = NO;

self.firstGradeTableView.showsVerticalScrollIndicator = NO;

self.firstGradeTableView.tableFooterView = [[UIView alloc] init];

[self.firstGradeTableView addFooterTarget:self action:@selector(loadMoreShops)];

[self.view addSubview:self.firstGradeTableView];

//下拉刷新 同步购物车

__weak typeof(self) weakSelf = self;

[self.firstGradeTableView addPullToRefreshWithPullText:PullText pullTextColor:[UIColor blackColor] pullTextFont:DefaultTextFont refreshingText:RefreshingText refreshingTextColor:[UIColor blueColor] refreshingTextFont:DefaultTextFont1 action:^{

[weakSelf loadShops];

}];

self.bottomAccountView = [[BottomAccountView alloc] initWithFrame:CGRectMake(0, ScreenHeight-50-49, ScreenWidth, bottom_height)];

self.bottomAccountView.selectedBlock = ^(UIButton *sender){

if(sender.tag == BottomViewAllSelectCircle){ //全选按钮

weakSelf.count =  sender.selected?APPDELEGATE.arrayShopCartPostParam.count:0;

for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++)

{

NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

shopCart.isSelected = @(sender.selected);

data = [NSKeyedArchiver archivedDataWithRootObject:shopCart];

[APPDELEGATE.arrayShopCartPostParam replaceObjectAtIndex:i withObject:data];

}

weakSelf.isSync = NO;

[weakSelf readyForCarDataFromHttp];

}

else if(sender.tag == BottomViewPayButton) //结算按钮

{

APPDELEGATE.loginVC.shouldBackVCType = 2;

if (![Utility getAuth]) {

[APPDELEGATE goToCheckLogin];

return;

}

[weakSelf buyAction:sender];

}

else if(sender.tag == BottomViewDeleteButton) //删除按钮

{

if(weakSelf.count == 0){

return;

}

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"确定删除这%@种商品吗",@(weakSelf.count)] delegate:weakSelf cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

[alert show];

}

else if(sender.tag == BottomViewCollectionButton) //移入收藏夹

{

//点击“移入收藏夹”按钮处理事件(h5,待写)

}

};

[self.bottomAccountView buttonSelected:self.bottomAccountView.chooseButton];

[self.view addSubview:self.bottomAccountView];

}

- (void)loadMoreShops

{

[self.firstGradeTableView footerEndRefreshing];

}

#pragma mark=================购物车数据请求===================

- (void)readyForCarDataFromHttp

{

self.isRequestMainGoods = NO;

// 断网

if(![NetworkCheck isConnect]){

[self loadFailure];

return;

}

//购物车为空

if(APPDELEGATE.arrayShopCartPostParam.count == 0){

if (APPDELEGATE.arrayInvalidParam.count == 0) {

self.isEmptyData = YES;

}

else{

self.isEmptyData = NO;

}

//self.firstGradeTableView.tableHeaderView = [[ShopCartTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.1)];

self.tableHeaderView = nil;

[self.bottomAccountView resetEmptyView];

[self resetBottomHidden:YES];

[self loadSuccess];

[self.firstGradeTableView reloadData];

[self reloadDataSetTip];

//[APPDELEGATE.tabBarViewController setItemTip:@"" withIndex:3];

if (![Utility getAuth]) {

return;

}

}

NSString *auth = @"";

NSNumber *userId = [Utility getUserID];

auth = [Utility getUserAuth];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];

NSMutableArray *productArray = [NSMutableArray arrayWithCapacity:0];

NSMutableArray *selectedActivityArray = [NSMutableArray arrayWithCapacity:0];

[MLGProgressView show];

//遍历普通商品

for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++) {

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

[dict setValue:shopCart.goodsId forKey:@"goodsId"];

[dict setValue:shopCart.goodsCount forKey:@"goodsCount"];

[dict setValue:shopCart.goodsSkuId forKey:@"goodsSkuId"];

[dict setValue:shopCart.salesId forKey:@"salesId"];

[dict setValue:shopCart.goodsSourceType forKey:@"goodsSourceType"];

[dict setValue:shopCart.isSelected forKey:@"isSelected"];

//服务器有问题,暂时换成空串,operationTime暂时注掉

[dict setValue:@"" forKey:@"pageSourceMark"];

//        [dict setValue:shopCart.pageSourceMark forKey:@"pageSourceMark"];

//        [dict setValue:shopCart.operationTime forKey:@"operationTime"];

[productArray addObject:dict];

}

//遍历失效商品

for(int i = 0;i< APPDELEGATE.arrayInvalidParam.count;i++){

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

NSData *data = APPDELEGATE.arrayInvalidParam[i];

//解档

ShopCart *invalidModel = [NSKeyedUnarchiver unarchiveObjectWithData:data];

[dict setValue:invalidModel.goodsId forKey:@"goodsId"];

[dict setValue:invalidModel.goodsCount forKey:@"goodsCount"];

[dict setValue:invalidModel.goodsSkuId forKey:@"goodsSkuId"];

[dict setValue:@(0) forKey:@"salesId"];

[dict setValue:invalidModel.goodsSourceType forKey:@"goodsSourceType"];

[dict setValue:@"" forKey:@"operationTime"];

[dict setValue:@(0) forKey:@"isSelected"];

[dict setValue:@"" forKey:@"pageSourceMark"];

[productArray addObject:dict];

}

//遍历换购商品

for(int i = 0; i< APPDELEGATE.arrayActivityParam.count; i++){

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

NSData *data = APPDELEGATE.arrayActivityParam[i];

ActivityModel *acModel = [NSKeyedUnarchiver unarchiveObjectWithData:data];

[dict setValue:acModel.goodsId forKey:@"goodsId"];

[dict setValue:acModel.goodsSkuId forKey:@"goodsSkuId"];

[selectedActivityArray addObject:dict];

}

[params setObject:userId forKey:@"userId"];

[params setObject:auth forKey:@"auth"];

[params setObject:[NSNumber numberWithBool:self.isSync] forKey:@"IsSync"];//是否同步

[params setObject:productArray forKey:@"products"];

[params setObject:selectedActivityArray forKey:@"selectedActivityGoods"];

NSString *shopCartStr = [Configuration sharedConfiguration].iPadcheckShoppingCart_url;

TICK

MLGHTTPRequestOperationManager *manager = [[MLGHTTPRequestOperationManager alloc] init];

WS(weakSelf)

[manager POST:shopCartStr parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {

TOCK

[MLGProgressView hide];

//        NSString *path = [[NSBundle mainBundle] pathForResource:@"testDdata.txt" ofType:nil];

//        NSDictionary *dic = [[NSDictionary alloc]initWithContentsOfFile:path];

//        NSDictionary *msgDict = dic[@"msg"];

//        NSString *code = [dic objectForKey:@"code"];

NSDictionary *msgDict = responseObject[@"msg"];

NSString *code = [responseObject objectForKey:@"code"];

NSLog(@"购物车数据:%@",responseObject);

if (code.integerValue == 200) {

self.shopCartmodel = [ShopCartModel objectWithKeyValues:msgDict];

//同步得到的数据插入本地数据库

[self updateGoodSourceType];

//购物车为空

if(APPDELEGATE.arrayShopCartPostParam.count == 0&&APPDELEGATE.arrayInvalidParam.count==0){

self.isEmptyData = YES;

//self.firstGradeTableView.tableHeaderView = [[ShopCartTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.1)];

self.tableHeaderView = nil;

[self.bottomAccountView resetEmptyView];

[self resetBottomHidden:YES];

[self loadSuccess];

[self.firstGradeTableView reloadData];

[self reloadDataSetTip];

return;

}

[self resetBottomHidden:NO];

if(self.shopCartmodel.ifShowAlert == 1) {

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:self.shopCartmodel.showAlertText message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

[alertView show];

}

if(self.shopCartmodel.invalidProductList.count!=0){

self.isHaveInvalidGoods = YES;

}

else{

self.isHaveInvalidGoods = NO;

}

[self.activitySelectGoodsArray removeAllObjects];

//更新本地换购商品的数据

NSInteger num = 0;

for(SCActivityGoodsModel *acModel in self.shopCartmodel.activityGoodsList){

if(acModel.aIsSelected == 1){

num++;

[self.activitySelectGoodsArray addObject:acModel];

}

}

[APPDELEGATE.arrayActivityParam removeAllObjects];

for(SCActivityGoodsModel *model in self.activitySelectGoodsArray){

ActivityModel *activityModel = [[ActivityModel alloc] init];

activityModel.goodsId = @(model.aGoodsId);

activityModel.goodsSkuId = @(model.aGoodsSkuId);

activityModel.type = @(model.aType);

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:activityModel];

[APPDELEGATE.arrayActivityParam addObject:data];

}

self.isEmptyData = NO;

if (![Utility getAuth]){

//self.firstGradeTableView.tableHeaderView = [[ShopCartTableHeaderView alloc] initWithFrame:CGRectMake(0, self.titleBar.bottom, ScreenWidth, scHeaderView_height)];

//                self.tableHeaderView = nil;

} else {

if([self.shopCartmodel.firstOrderPrompt isEqualToString:@""]){

//self.firstGradeTableView.tableHeaderView = [[ShopCartTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.1)];

self.tableHeaderView = nil;

}else{

//self.firstGradeTableView.tableHeaderView = [[ShopCartTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, scHeaderView_height)];

//                    self.tableHeaderView = self.firstGradeTableView.tableHeaderView;

//                    self.tableHeaderView.title = self.shopCartmodel.firstOrderPrompt;

}

}

[self.firstGradeTableView reloadData];

self.isRequestMainGoods = YES;

self.bottomAccountView.shopCartModel = self.shopCartmodel;

[self reloadDataSetTip];

[self loadSuccess];

}else{

[self loadFailure];

}

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

[self loadFailure];

[MLGProgressView hide];

}];

}

//为了防止最新的GoodSourceType与加入购物车时不一致从而导致商品无法删除无法编辑等问题

- (void)updateGoodSourceType

{

[APPDELEGATE.arrayShopCartPostParam removeAllObjects];

for(SCMerchantModel *merchantModel in self.shopCartmodel.merchantModule){

for(SCDecreaseRuleModel *decreaseModel in merchantModel.goodsGroupingModule){

for(SCProductModel *productModel in decreaseModel.goodsList){

ShopCart *cart = [[ShopCart alloc] init];

cart.salesId            = @(productModel.salesId);

cart.goodsId            = @(productModel.goodsId);

cart.goodsSkuId = @(productModel.goodsSkuId);

cart.goodsCount         = @(productModel.goodsCount);

cart.goodsSourceType    = @(productModel.serviceGoodsSourceType);

cart.operationTime = productModel.operationTime;

cart.pageSourceMark = productModel.pageSourceMark;

cart.isSelected = @(productModel.isSelected);

//归档

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:cart];

[APPDELEGATE.arrayShopCartPostParam addObject:data];

}

}

}

[APPDELEGATE.arrayInvalidParam removeAllObjects];

for(SCInvalidProductModel *model in self.shopCartmodel.invalidProductList){

InvalidModel *invalidModel = [[InvalidModel alloc] init];

invalidModel.goodsId = @(model.invalidGoodsId);

invalidModel.goodsSkuId = @(model.invalidGoodsSkuId);

invalidModel.goodsCount = @(model.invalidGoodsCount);

invalidModel.goodsSourceType = @(model.goodsSourceType);

ShopCart *cart = [[ShopCart alloc] init];

cart.goodsId = invalidModel.goodsId;

cart.goodsSkuId = invalidModel.goodsSkuId;

cart.goodsCount = invalidModel.goodsCount;

cart.goodsSourceType = invalidModel.goodsSourceType;

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:cart];

[APPDELEGATE.arrayInvalidParam addObject:data];

}

}

#pragma mark==================商品推荐部分===================

- (void)prepareShopRecommendGoodsRequestData {

if(self.moreGoodsArray.count != 0){

self.isHaveRecommendData = YES;

[self.firstGradeTableView setFooterHidden:NO];

}else{

self.isHaveRecommendData = NO;

[self.firstGradeTableView setFooterHidden:YES];

}

NSString *idStr = @"";

for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++) {

NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if(![idStr isEqualToString:@""])

idStr = [idStr stringByAppendingString:[NSString stringWithFormat:@",%@",shopCart.goodsId]];

else

idStr = [idStr stringByAppendingString:shopCart.goodsId.stringValue];

}

NSString *urlStr = [Configuration sharedConfiguration].shopRecommendGoods_231_url;

NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];

[postDic setObject:[Utility getUserID] forKey:@"userId"];

[postDic setObject:[NSNumber numberWithInteger:self.start] forKey:@"start"];

[postDic setObject:[NSNumber numberWithInteger:self.rows]  forKey:@"rows"];

[postDic setObject:idStr forKey:@"goodsId"];

MLGHTTPRequestOperationManager *manager = [[MLGHTTPRequestOperationManager alloc] init];

[manager POST:urlStr parameters:postDic success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSLog(@"ShopRecommendGoodsResponseObject=%@",responseObject);

NSDictionary *msgDict = responseObject[@"msg"];

NSString *code = [responseObject objectForKey:@"code"];

if (code.integerValue == 200) {

[self.shopRecommendGoodsModelArray removeAllObjects];

self.shopRecommendGoodsModelArray = [ShopRecommendGoodsModel  objectArrayWithKeyValuesArray:msgDict[@"goodsList"]];

[GCDQueue executeInMainQueue:^{

if (self.start == 0 && self.shopRecommendGoodsModelArray.count <=50) {

[self.moreGoodsArray removeAllObjects];

[self.moreGoodsArray addObjectsFromArray:self.shopRecommendGoodsModelArray];

[self.firstGradeTableView setFooterHidden:NO];

self.firstGradeTableView.footerPullToRefreshText = @"本次探险结束!";

}

if(self.moreGoodsArray.count != 0){

self.isHaveRecommendData = YES;

[self.firstGradeTableView setFooterHidden:NO];

if(self.isEmptyData){

[self.firstGradeTableView reloadData];

}else if (self.isRequestMainGoods){

[self.firstGradeTableView reloadData];

}

}else{

self.isHaveRecommendData = NO;

[self.firstGradeTableView setFooterHidden:YES];

}

}];

} else if (code.integerValue == 411) { // 如果验签失败, 再获一次token

[APPDELEGATE fetchAccessTokenRequest];

} else {

}

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

}

// 商品推荐的Item的点击事件

- (void)clickHomePageDoubleGood:(MLGHomePageDoubleGoodsCell *)cell and:(NSInteger)index {

ShopRecommendGoodsModel *dataModel = [cell.infoArray objectAtIndex:index];

[[MLGGotoVCManager sharedInstance] gotoProductDetailVCWithGoodId:[NSNumber numberWithInteger:dataModel.goodsId] andStockId:[NSNumber numberWithInteger:0] andGoodsSourceType:[NSNumber numberWithInteger:0] andSalesId:[NSNumber numberWithInteger:0] andPageSourceMark:App_Cart_GuessYouLike  isFilterSkuStock:[NSNumber numberWithInteger:1]];

}

- (void)setShopRecommendGoodsModelArray:(NSMutableArray *)shopRecommendGoodsModelArray {

_shopRecommendGoodsModelArray = shopRecommendGoodsModelArray;

if (shopRecommendGoodsModelArray.count == 0) return;

}

- (NSInteger)getNumberOfRows {

if (self.moreGoodsArray.count > 0) {

NSInteger totalCount = self.moreGoodsArray.count;

NSInteger rowcount   = (totalCount - 1)/2 + 1;

return rowcount;

}

return 0;

}

#pragma mark==================tableViewDelegate===================

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

NSInteger num=0;

if(self.isEmptyData && self.isHaveRecommendData)

return 2;

else if (self.isEmptyData && !self.isHaveRecommendData)

return 1;

else{

if(self.shopCartmodel.activityGoodsList.count!=0)

num++;

if(self.shopCartmodel.invalidProductList.count!=0)

num++;

if( !self.isHaveRecommendData){

return self.shopCartmodel.merchantModule.count+num;

}else

return self.shopCartmodel.merchantModule.count+num+1;

}

}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

__weak typeof(self) weakSelf = self;

if (section == tableView.numberOfSections-1 && self.isHaveRecommendData){//如果是最后一个section,且非编辑状态,切含有推荐商品

UILabel *sectionView = [[UILabel alloc] init];

sectionView.backgroundColor = [UIColor whiteColor];

if(self.isEmptyData){ //如果购物车数据为空,则显示“看看热卖”,否则显示“你可能还想要"

sectionView.text = @"看看热卖";

}else

{

sectionView.text = @"你可能还想要";

}

sectionView.textAlignment = NSTextAlignmentCenter;

return sectionView;

}else{

if(self.isEmptyData){//购物车为空显示去逛逛

if (![Utility getAuth]) {

//                self.firstGradeTableView.tableHeaderView = [[ShopCartTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, scHeaderView_height)];

//

//                self.tableHeaderView = self.firstGradeTableView.tableHeaderView;

}

ShopCartNoDataView *empatyView = [[ShopCartNoDataView alloc] init];

empatyView.backgroundColor = [UIColor yellowColor];

return empatyView;

}else{

if(self.shopCartmodel.merchantModule.count!=0){

if(section<self.shopCartmodel.merchantModule.count)

{

self.merchantView = [[MerchantView alloc] init];

self.merchantView.merchantModel = self.shopCartmodel.merchantModule[section];

SCMerchantModel *merchantModel = self.shopCartmodel.merchantModule[section];

self.merchantView.nextBtnSelectBlock = ^(UIButton *sender)

{

[[MLGGotoVCManager sharedInstance] gotoHTML5VCWithURLString:merchantModel.gatherGoodsUrl andNavTitle:@"凑单"];

};

//全选一组

self.merchantView.chooseBtnSelectBlock = ^(UIButton *sender)

{

for(SCDecreaseRuleModel *decreaseModel in merchantModel.goodsGroupingModule)

{

//                            if(weakSelf.isEditState)

//                            {

if(sender.selected)

{

weakSelf.count = weakSelf.count+decreaseModel.goodsList.count;

for(SCProductModel *productModel in decreaseModel.goodsList)

{

if(productModel.isSelected==1)

weakSelf.count--;

}

}

else

weakSelf.count = weakSelf.count-decreaseModel.goodsList.count;

for(SCProductModel *productModel in decreaseModel.goodsList)

{

productModel.isSelected = sender.selected;

if(weakSelf.count == 0)

{

[weakSelf.editProductArray removeAllObjects];

}else

{

[weakSelf shopCartEditProductModel:productModel];

}

[weakSelf.firstGradeTableView reloadData];

}

[weakSelf resetBottomViewWithIsAllSelected:[weakSelf panEditStateIsAllSelected] Count:weakSelf.count];

//                            }else{

for(SCProductModel *productModel in decreaseModel.goodsList){

productModel.isSelected = sender.selected;

for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++)

{

NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if (shopCart.goodsId.intValue == productModel.goodsId && shopCart.goodsSkuId.intValue == productModel.goodsSkuId && shopCart.goodsSourceType.intValue == productModel.serviceGoodsSourceType)

{

shopCart.salesId = @(productModel.salesId);

shopCart.goodsId = @(productModel.goodsId);

shopCart.goodsSkuId = @(productModel.goodsSkuId);

shopCart.goodsCount = @(productModel.goodsCount);

shopCart.goodsSourceType = @(productModel.serviceGoodsSourceType);

shopCart.isSelected = @(productModel.isSelected);

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:shopCart];

[APPDELEGATE.arrayShopCartPostParam replaceObjectAtIndex:i withObject:data];

}

}

//}

}

}

weakSelf.isSync = NO;

[weakSelf readyForCarDataFromHttp];

};

self.isSelectMerchatView = YES;

for(SCDecreaseRuleModel *decreaseModel in merchantModel.goodsGroupingModule){

for(SCProductModel *productModel in decreaseModel.goodsList){

if(productModel.isSelected==0){

self.isSelectMerchatView = NO;

}

}

}

[self.merchantView setChooseBtnState:self.isSelectMerchatView];

return self.merchantView;

}

}

if(self.shopCartmodel.invalidProductList.count!=0){

if(section == self.shopCartmodel.merchantModule.count){

return [[UIView alloc] init];

}

}

if(self.shopCartmodel.activityGoodsList.count!=0){

if(section == self.shopCartmodel.merchantModule.count + self.isHaveInvalidGoods?1:0){

ActivityTypeView *activityView = [[ActivityTypeView alloc] init];

[activityView activityView];

activityView.ExchangeShopBlock = ^(UIButton *sender){

SCExchangeShopViewController *vc = [[SCExchangeShopViewController alloc] initWithDataArray:self.shopCartmodel.activityGoodsList];

[APPDELEGATE.navigationController pushViewController:vc animated:YES];

};

return activityView;

}

}

}

}

return [[UIView alloc]init];

}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

{

UIView *sectionFooderView = [[UIView alloc] init];

sectionFooderView.backgroundColor = RGBCOLOR(235, 235, 235);

return sectionFooderView;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

if(section == tableView.numberOfSections-1 && self.isHaveRecommendData)

return 40;

else{

if(self.isEmptyData)

return ScreenHeight - self.titleBar.bottom;

else{

if(self.shopCartmodel.merchantModule.count!=0){

if(section<self.shopCartmodel.merchantModule.count){

return merchant_merchantView_height+activity_viewHeight;

}

}

if(self.shopCartmodel.invalidProductList.count!=0){

if(section == self.shopCartmodel.merchantModule.count){

return 0.1;

}

}

if(self.shopCartmodel.activityGoodsList.count!=0){

if(section == self.shopCartmodel.merchantModule.count + self.isHaveInvalidGoods?1:0){

return activity_viewHeight;

}

}

return 0.1;

}

}

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

return shopCart_fooderHeight;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

if(indexPath.section == tableView.numberOfSections-1  && self.isHaveRecommendData)

return MLGLayoutHeight(215);

else{

if(self.shopCartmodel.merchantModule.count!=0){

if(indexPath.section<self.shopCartmodel.merchantModule.count){

MLGShopCarTableViewCell *cell = [[MLGShopCarTableViewCell alloc] initWithMerchantModel:self.shopCartmodel.merchantModule[indexPath.section]];

NSLog(@"cellheight == %d",[cell getCellHeight]);

return [cell getCellHeight];

}

}

if(self.shopCartmodel.invalidProductList.count!=0){

if(indexPath.section == self.shopCartmodel.merchantModule.count){

MLGShopCarTableViewCell *cell = [[MLGShopCarTableViewCell alloc] initWithShopCartModel:self.shopCartmodel];

NSLog(@"cellheight == %d",[cell getCellHeight]);

return [cell getCellHeight];

}

}

if(self.shopCartmodel.activityGoodsList.count!=0){

if(indexPath.section == self.shopCartmodel.merchantModule.count + self.isHaveInvalidGoods?1:0){

return product_viewHeight;

}

}

return 0;

}

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

if(section == tableView.numberOfSections-1  && self.isHaveRecommendData)

return [self getNumberOfRows];

else{

if(self.isEmptyData)

return 0;

else{

if(self.shopCartmodel.merchantModule.count!=0){

if(section<self.shopCartmodel.merchantModule.count){

return 1;

}

}

if(self.shopCartmodel.invalidProductList.count!=0){

if(section == self.shopCartmodel.merchantModule.count){

return 1;

}

}

if(self.shopCartmodel.activityGoodsList.count!=0){

if(section == self.shopCartmodel.merchantModule.count + self.isHaveInvalidGoods?1:0){

return self.activitySelectGoodsArray.count;

}

}

return 0;

}

}

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

if(indexPath.section == tableView.numberOfSections - 1  && self.isHaveRecommendData){//推荐商品,暂时不做

static NSString *cellID = @"ShopRecommendGoodsCell";

MLGHomePageDoubleGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

if (cell == nil) {

cell = [[MLGHomePageDoubleGoodsCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];

cell.selectionStyle  = UITableViewCellSelectionStyleNone;

}

cell.delegate = self;

cell.row = indexPath.row;

cell.backgroundColor = [UIColor whiteColor];

cell.separatorInset = UIEdgeInsetsMake(0, 750, 0, 0);

NSInteger remainCount = [self.moreGoodsArray count] - indexPath.row * 2;

if(remainCount > 0){

if (remainCount > 2) {

cell.infoArray = [self.moreGoodsArray subarrayWithRange:NSMakeRange(indexPath.row * 2, 2)];

}else{

cell.infoArray = [self.moreGoodsArray subarrayWithRange:NSMakeRange(indexPath.row * 2, remainCount)];

}

}

[cell initFun];

return cell;

} else {

if(self.shopCartmodel.merchantModule.count!=0){//商家对象集合个数

if(indexPath.section<self.shopCartmodel.merchantModule.count){

MLGShopCarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

if(cell == nil){

cell = [[MLGShopCarTableViewCell alloc] initWithMerchantModel:self.shopCartmodel.merchantModule[indexPath.section]];

[cell setTarget:self action:@selector(buttonClicked:)];

cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

}

return cell;

}

}

if(self.shopCartmodel.invalidProductList.count != 0){

if(indexPath.section == self.shopCartmodel.merchantModule.count){

MLGShopCarTableViewCell *cell = [[MLGShopCarTableViewCell alloc] initWithShopCartModel:self.shopCartmodel];

[cell setTarget:self action:@selector(buttonClicked:)];

cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

return cell;

}

}

if(self.shopCartmodel.activityGoodsList.count!=0){

if(indexPath.section == self.shopCartmodel.merchantModule.count + self.isHaveInvalidGoods?1:0){

if(self.activitySelectGoodsArray.count != 0 && indexPath.row < self.activitySelectGoodsArray.count) {

SCActivityGoodsModel *acModel = self.activitySelectGoodsArray[indexPath.row];

ProductTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

if (cell == nil) {

cell = [[ProductTableViewCell alloc] init];

}

cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

cell.activityModel = acModel;

return cell;

} else {

SCActivityGoodsModel *activitymodel = self.shopCartmodel.activityGoodsList[0];

ProductTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

if (cell == nil) {

cell = [[ProductTableViewCell alloc] init];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

cell.activityModel = activitymodel;

return cell;

}

}

}

}

}

return [[UITableViewCell alloc]init];

}

//解决当商品推荐为单数时点击空白处会崩溃bug

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

if(indexPath.section == tableView.numberOfSections - 1  && self.isHaveRecommendData)

{

}else{

SCActivityGoodsModel *activityModel = self.activitySelectGoodsArray[indexPath.row];

[[MLGGotoVCManager sharedInstance] gotoProductDetailVCWithGoodId:@(activityModel.aGoodsId) andStockId:@(activityModel.aGoodsSkuId) andGoodsSourceType:@(0) andSalesId:@(0) andPageSourceMark:App_ShoppingCart isFilterSkuStock:[NSNumber numberWithInteger:0]];

}

}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

return NO;

}

#pragma mark --点击事件--

- (void)buttonClicked:(NSDictionary*)dict

{

NSNumber *selectNum = dict[@"params"];

for(UIView *view in self.firstGradeTableView.subviews){

if([view isKindOfClass:[MerchantView class]]){

self.merchantView = view;

self.merchantView.chooseButton.selected = selectNum.boolValue;

}

}

}

#pragma mark 更改删除商品同步购物车的请求

- (void)modificatSyncShopCartData:(NSMutableArray *)products :(BOOL)isDelete

{

//登录状态才去同步数据

if ([Utility getAuth]) {

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];

NSMutableArray *productArray = [NSMutableArray arrayWithCapacity:0];

for(ShopCart *model in products){

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

[dict setValue:model.goodsId forKey:@"goodsId"];

[dict setValue:isDelete?[NSNumber numberWithInt:0]:model.goodsCount forKey:@"goodsCount"];

[dict setValue:model.goodsSkuId forKey:@"goodsSkuId"];

[dict setValue:model.goodsSourceType forKey:@"goodsSourceType"];

[productArray addObject:dict];

}

NSNumber *userId = [Utility getUserID];

[params setValue:userId forKey:@"userId"];

[params setValue:productArray forKey:@"products"];

NSString *urlStr = [Configuration sharedConfiguration].iPadShoppingCartChange_url;

MLGHTTPRequestOperationManager *manager = [[MLGHTTPRequestOperationManager alloc] init];

[manager POST:urlStr parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSLog(@"更改删除同步返回=%@",responseObject);

NSDictionary *msgDict = responseObject[@"msg"];

NSString *code = [responseObject objectForKey:@"code"];

if (code.integerValue == 200) {

} else if (code.integerValue == 411) { // 如果验签失败, 再获一次token

[APPDELEGATE fetchAccessTokenRequest];

} else {

}

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

}

}

#pragma mark 左滑手势删除单个商品

- (void)shopCartDeleteWithProductModel:(id)model

{

NSMutableArray *deleteArr = [NSMutableArray array];

if([model isKindOfClass:[SCProductModel class]]){

SCProductModel *productModel = model;

for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++)

{

NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if (shopCart.goodsId.integerValue == productModel.goodsId && shopCart.goodsSkuId.integerValue == productModel.goodsSkuId && shopCart.goodsSourceType.integerValue == productModel.serviceGoodsSourceType) {

[APPDELEGATE.arrayShopCartPostParam removeObjectAtIndex:i];

self.count--;

[deleteArr addObject:shopCart];

[self modificatSyncShopCartData:deleteArr :YES];

}

}

}

else if ([model isKindOfClass:[SCInvalidProductModel class]]){

SCInvalidProductModel *invalidproductModel = model;

for (int i = 0; i < APPDELEGATE.arrayInvalidParam.count; i++)

{

NSData *data = APPDELEGATE.arrayInvalidParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if (shopCart.goodsId.integerValue == invalidproductModel.invalidGoodsId && shopCart.goodsSkuId.integerValue == invalidproductModel.invalidGoodsSkuId) {

[APPDELEGATE.arrayInvalidParam removeObjectAtIndex:i];

[deleteArr addObject:shopCart];

[self modificatSyncShopCartData:deleteArr :YES];

}

}

for(int i = 0; i < APPDELEGATE.arrayActivityParam.count; i++){

NSData *data = APPDELEGATE.arrayActivityParam[i];

ActivityModel *acModel = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if(acModel.goodsId.integerValue == invalidproductModel.invalidGoodsId && acModel.goodsSkuId.integerValue == invalidproductModel.invalidGoodsSkuId){

[APPDELEGATE.arrayActivityParam removeObjectAtIndex:i];

}

}

}

#warning 同步接口通了之后打开

self.isSync = NO;

[self readyForCarDataFromHttp];

}

#pragma mark 清空失效商品

- (void)shopCartCleanInvalidProducts

{

NSMutableArray *deleteArr = [NSMutableArray array];

for(SCInvalidProductModel *invalidproductModel in self.shopCartmodel.invalidProductList){

for (int i = 0; i < APPDELEGATE.arrayInvalidParam.count; i++)

{

NSData *data = APPDELEGATE.arrayInvalidParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if (shopCart.goodsId.integerValue == invalidproductModel.invalidGoodsId && shopCart.goodsSkuId.integerValue == invalidproductModel.invalidGoodsSkuId) {

[deleteArr addObject:shopCart];

[APPDELEGATE.arrayInvalidParam removeObjectAtIndex:i];

}

}

for(int i = 0; i < APPDELEGATE.arrayActivityParam.count; i++){

NSData *data = APPDELEGATE.arrayActivityParam[i];

ActivityModel *acModel = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if(acModel.goodsId.integerValue == invalidproductModel.invalidGoodsId && acModel.goodsSkuId.integerValue == invalidproductModel.invalidGoodsSkuId){

[APPDELEGATE.arrayActivityParam removeObjectAtIndex:i];

}

}

}

#warning 接口通了 打开

[self modificatSyncShopCartData:deleteArr :YES];

self.isSync = NO;

[self readyForCarDataFromHttp];

}

//勾选复选按钮时改变商品缓存是否选中状态

- (void)shopCartSelectedProductModel:(id)model

{

if([model isKindOfClass:[SCProductModel class]]){

SCProductModel *productModel = model;

for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++) {

NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if (shopCart.goodsId.intValue == productModel.goodsId && shopCart.goodsSkuId.intValue == productModel.goodsSkuId && shopCart.goodsSourceType.intValue == productModel.serviceGoodsSourceType) {

shopCart.isSelected = @(productModel.isSelected);

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:shopCart];

[APPDELEGATE.arrayShopCartPostParam replaceObjectAtIndex:i withObject:data];

}

}

}

self.isSync = NO;

[self readyForCarDataFromHttp];

}

#pragma mark 编辑状态时所选择的商品

- (void)shopCartEditProductModel:(id)model {

if([model isKindOfClass:[SCProductModel class]]){

BOOL isExist = NO;

SCProductModel *productModel = model;

for (int i = 0; i < self.editProductArray.count; i++)

{

NSLog(@"编辑数组加前:%d",self.editProductArray.count);

SCProductModel *proModel = self.editProductArray[i];

if (productModel.goodsId == proModel.goodsId &&

productModel.goodsSkuId == proModel.goodsSkuId && productModel.serviceGoodsSourceType == proModel.serviceGoodsSourceType

) {

if(productModel.isSelected == 1){

if(proModel.isSelected==1) [self.editProductArray removeObject:proModel];

[self.editProductArray addObject:productModel];

}else{

[self.editProductArray removeObject:productModel];

}

isExist = YES;

}

}

if(!isExist){

if(productModel.isSelected==1)

[self.editProductArray addObject:productModel];

}

}

NSLog(@"编辑数组加后:%d",self.editProductArray.count);

}

//方便外部判断主控制器是不是编辑状态

//- (BOOL)isEditState

//{

//    return self.isEdit;

//}

//重置购物车底部按钮状态以及删除数量

- (void)resetBottomViewWithIsAllSelected:(BOOL)isAllSelected Count:(NSInteger)count

{

[self.firstGradeTableView reloadData];

[self.bottomAccountView resetStateWithIsAllSelected:isAllSelected andDeleteCount:count];

}

//编辑时删除几项商品

- (NSInteger)addCountWithAdd:(BOOL)add

{

if(add)

self.count++;

else

self.count--;

return self.count;

}

//判断有没有全选

- (BOOL)panEditStateIsAllSelected {

BOOL isAllSelected = YES;

for(SCMerchantModel *merchantModel in self.shopCartmodel.merchantModule){

for(SCDecreaseRuleModel *decreaseModel in merchantModel.goodsGroupingModule){

for(SCProductModel *productModel in decreaseModel.goodsList){

if(productModel.isSelected==0){

isAllSelected = NO;

}

}

}

}

return isAllSelected;

}

#pragma mark 编辑时确定删除提示

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if(buttonIndex == 1){

//全选按钮选中时,删掉所有数据

if (self.bottomAccountView.chooseButton.selected) {

[APPDELEGATE.arrayShopCartPostParam removeAllObjects];

self.count = 0;

}

// 先批量删除本地的数据

//        NSMutableArray *deleteArr = [NSMutableArray array];

//

//        for(SCProductModel *productModel in self.editProductArray)

//        {

//            for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++)

//            {

//                NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//                // 解档

//                ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

//                NSLog(@"%d %d %d %d %d %d",shopCart.goodsId.intValue,shopCart.goodsSkuId.intValue,shopCart.goodsSourceType.intValue,productModel.goodsId,productModel.goodsSkuId,productModel.serviceGoodsSourceType);

//                if (shopCart.goodsId.intValue == productModel.goodsId && shopCart.goodsSkuId.intValue == productModel.goodsSkuId && shopCart.goodsSourceType.intValue == productModel.serviceGoodsSourceType)

//                {

//                    [APPDELEGATE.arrayShopCartPostParam removeObjectAtIndex:i];

//                    [deleteArr addObject:shopCart];

//                }

//            }

//    }

//判断是否需要同步

//  [self modificatSyncShopCartData:deleteArr :YES];

self.isSync = NO;

[self readyForCarDataFromHttp];

self.start = 0;

[self prepareShopRecommendGoodsRequestData];

}

}

#pragma mark 数量选择器点击事件

- (void)shopCartWithCountStepper:(NSInteger)count withCell:(ProductTableViewCell *)cell withGoodsSourceType:(NSNumber *)_goodsSourceType withIndexPath:(NSIndexPath *)path withGoodId:(NSNumber *)goodId withGoodStockId:(NSNumber *)goodStockId withGoodSourceType:(NSNumber *)goodSourceType

{

self.proCell = cell;

float currentGoodsCount = cell.tfStepper.Current;

for (int i = 0; i < APPDELEGATE.arrayShopCartPostParam.count; i++)

{

NSData *data = APPDELEGATE.arrayShopCartPostParam[i];

//解档

ShopCart *shopCart = [NSKeyedUnarchiver unarchiveObjectWithData:data];

if (shopCart.goodsId.integerValue == goodId.integerValue && shopCart.goodsSkuId.integerValue == goodStockId.integerValue && shopCart.goodsSourceType.integerValue == goodSourceType.integerValue)

{

shopCart.goodsCount = [NSNumber numberWithFloat:currentGoodsCount];

//归档

NSData *data1 = [NSKeyedArchiver archivedDataWithRootObject:shopCart];

[APPDELEGATE.arrayShopCartPostParam replaceObjectAtIndex:i withObject:data1];

//修改商品数量的时候同步

NSArray *addProductArr = [NSArray arrayWithObject:shopCart];

[self modificatSyncShopCartData:addProductArr :NO];

}

}

self.isSync = NO;

[self readyForCarDataFromHttp];

}

#pragma mark-- 滚动代理,隐藏返回顶部按钮

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

_btnScrollTop.hidden = YES;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

}

@end

时间: 2024-10-13 01:36:52

暂保存的相关文章

Tensorflow模型的 暂存 恢复 微调 保存 加载

暂存模型(*.index为参数名称,*.meta为模型图,*.data*为参数) tf.reset_default_graph() weights = tf.Variable(tf.random_normal([10, 10], stddev=0.1), name="weights") biases = tf.Variable(0, name="biases") saver = tf.train.Saver() sess = tf.Session() sess.ru

git 教程(5)--工作区和暂存区

Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 工作区(working directory) 就是你在电脑里能看到的目录,比如我的learngit文件夹就是一个工作区: 版本库 (repository) 工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库. Git的版本库里存了很多东西,其中最重要的就是称为stage(或者叫index)的暂存区,还有Git为我们自动创建的第一个分支master,以及指向master的一个指针叫HEAD. 分支和HEAD的概念我们

sed模式空间和暂存空间的区别

学了sed,觉得模式空间和暂存空间比较乱 整理一下 sed编辑器逐行处理文件,并将输出结果打印到屏幕上.sed命令将当前处理的行读入模式空间(pattern  space)进行处理,sed在该行上执行完所有命令后就将处理好的行打印到屏幕上(除非之前的命令删除了该行),sed处理完一行就将其从模式空间中删除,然后将下一行读入模式空间,进行处理.显示.处理完文件的最后一行,sed便结束运行.sed在临时缓冲区(模式空间)对文件进行处理,所以不会修改原文件,除非显示指明-i选项. 与模式空间和暂存空间

Activity-数据状态的保存

由于手机是便捷式移动设备,掌握在用户的手中,它的展示方向我们是无法预知的,具有不确定性.平时我们拿着手机多数为竖屏,但有时候我们感觉累了也会躺着去使用手机,那么这时手机屏幕的展示方向可能已经被用户切换成横屏,由于竖屏和横屏的界面宽高比例不同,那么我们的布局界面就会发生改变,所以是件很麻烦的事情,我们需要去准备两套UI布局,当然很多时候我们为了节省设计成本,只准备一套UI布局(竖屏或者横屏),使程序固定在一个方向,让其不跟随着屏幕的旋转而旋转.在这里我们先不去管这些东西,我们来看看当屏幕旋转的时候

保留代码,狼羊过河的问题(暂未理解)

题目:有3只狼和3只羊要过河,只有一条船,一次最多只能坐两只动物并且每次必须有动物开船,如果某一边的狼的个数大于羊的个数,羊将被吃掉,编程给出解. 关于编程思路,参考:Java编程能力强化(2)--搜索解决方案类问题的通用解法 参考答案: package ch1; public class LangAndYang { public static void main(String[] args) {  int state[] = {3,3};   // 第1.2个元素表示左岸的狼和羊的数量  ne

Photoshop入门教程(二):暂存盘设置与标尺设置

新建文档之后大家就可以对图像进行编辑.在对图像进行编辑之前,先来了解一下如何查看图像的一些基本信息.在软件左下角,会有这样的信息显示窗口. 1窗口表示当前图像显示比例,200%代表当前为放大两倍显示.左键双击可修改显示比例. 2窗口显示当前文档所占空间,鼠标放到图示位置按住左键不放,出现3窗口,显示当前图像信息. 暂存盘设置 Photoshop暂存盘默认情况下是在C盘,但是C盘作为系统盘空间有限,当处理大型文档时,C盘空间就会不够用.同时系统响应速度也会下降.那么如何修改暂存盘? 菜单栏:编辑—

以普通用户启动的Vim如何保存需要root权限的文件

在Linux上工作的朋友很可能遇到过这样一种情况,当你用Vim编辑完一个文件时,运行:wq保存退出,突然蹦出一个错误: E45: 'readonly' option is set (add ! to override) 这表明文件是只读的,按照提示,加上!强制保存::w!,结果又一个错误出现: "readonly-file-name" E212: Can't open file for writing 文件明明存在,为何提示无法打开?这错误又代表什么呢?查看文档:help E212:

Canvas 保存状态

1.保存和恢复绘图状态: 在绘制图形时,难免会重复使用某个样式,甚至有时会在不同颜色之间来回切换. 那么为了减少代码冗余,我们可以调用画布中的save()方法,来帮我们 保存一些样式和属性,这样我们就可以调用画布中的restore() 方法,来再次使用这些我们曾保存好的样式和属性了! 下面看下具体代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <met

GDI+学习笔记(七)保存简单图像

请尊重本人的工作成果,转载请留言,并说明转载地址,谢谢.地址如下: http://blog.csdn.net/fukainankai/article/details/27710883 前几节中,我们利用GDI+在窗口中绘制了各种各样的图形.图像,这一节,我们将会将这些图像保存成简单图像.所谓简单图像,指的是bmp/jpg/png等图像或者单帧的gif图像.保存成多帧的gif图像稍微复杂一点,本节中暂时不做说明.保存成动态的tiff文件也比较简单,但这里也不做说明,下次有机会和gif一起介绍. 另