• 曹云霄's avatar
    1、把按照类型筛选放到第一个位置,更风格对掉下。 · 653bf2df
    曹云霄 authored
    2、 红包促销拒绝的原因未能显示(在红包展示信息的时候要包含客户姓名及订单总金额)
    3、在客户界面的搜索框里,输入客户的手机号或则姓名 要支持模糊查询
    4、Ipad端我的红包—更多 点进去之后 显示订单号、时间;增加显示2个字段,客户姓名和订单总额
    5、Ipad闯关区—进入之后显示里去掉 结束时间显示
    6、邀请人显示 可以点击筛选本门店的设计师,弹框出来可以按照设计师的姓名或则电话号码进行模糊查询,选中后显示在界面上的是设计师的手机号码,ipad客户模块UI重新排版,具体参考邮件psd文件,后台会新建一个接口,获取当前门店下的设计师,根据选择的客户,获取到客户所关联的设计师
    653bf2df
ShoppingBagViewController.m 12.4 KB
//
//  ShoppingBagViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/6/6.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ShoppingBagViewController.h"
#import "OSSHelper.h"
@interface ShoppingBagViewController ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate,DZNEmptyDataSetSource,ChangeGoodsNumberDelegate,UIImagePickerControllerDelegate>

@end

@implementation ShoppingBagViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
    [self setDelegateandDataSource];
}

#pragma mark -UI
- (void)uiConfigAction
{
    self.view.backgroundColor = [UIColor clearColor];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissAction:)];
    tap.delegate = self;
    [self.view addGestureRecognizer:tap];
    [self.sureButton addCorner:4];
}

#pragma mark -数据源
- (void)setDatasArray:(NSMutableArray *)datasArray
{
    NSMutableArray *array = [NSMutableArray array];
    for (TOGoodsEntityModel *model in datasArray) {
        ShopcarModel *shopModel = [[ShopcarModel alloc]init];
        VOResellerGoodsEntity *newModel = [[VOResellerGoodsEntity alloc] initWithDictionary:[model toDictionary] error:nil];
        shopModel.goods = newModel;
        shopModel.costPrice = model.costPrice;
        shopModel.goodsNum = model.goodsNumber;
        [array addObject:shopModel];
    }
    _datasArray = [NSMutableArray arrayWithArray:array];
    [self.shoppingBagTableView reloadData];
}

#pragma mark -tableview
- (void)setDelegateandDataSource
{
    self.shoppingBagTableView.delegate = self;
    self.shoppingBagTableView.dataSource = self;
    self.shoppingBagTableView.emptyDataSetSource = self;
    self.shoppingBagTableView.tableFooterView = [UIView new];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ShoppingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Shopping" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = [self.datasArray objectAtIndex_opple:indexPath.row];
    cell.delegate = self;
    cell.cellindex = indexPath.row;
    cell.clinchTextfield.userInteractionEnabled = NO;
    cell.ClinchPriceBackView.backgroundColor = cell.backgroundColor;
    //cell选中回调
    WS(weakSelf);
    [cell setReturnCellblock:^(NSInteger index) {
        [weakSelf setSelectedButton:index];
    }];
    //提示框回调
    [cell setPromptStringBlock:^(NSString *string) {
        [weakSelf promptCustomerWithString:string];
    }];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datasArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}


#pragma mark -选中商品回调
- (void)setSelectedButton:(NSInteger)index;
{
    ShopcarModel *model = [self.datasArray objectAtIndex_opple:index];
    model.isSelected = !model.isSelected;
    NSInteger goodsNumber = 0;
    for (ShopcarModel *model in self.datasArray) {
        if (model.isSelected) {
            goodsNumber ++;
        }
    }
    if (goodsNumber == self.datasArray.count) {
        self.totalSelectedButton.selected = YES;
    }else
    {
        self.totalSelectedButton.selected = NO;
    }
    [self calculateSelectedGoodsAllprice];
    [self.sureButton setTitle:[NSString stringWithFormat:@"确认添加(%ld)",goodsNumber] forState:UIControlStateNormal];
}

#pragma mark -计算选中后的商品总金额
- (void)calculateSelectedGoodsAllprice
{
    CGFloat allPrice = 0;
    for (ShopcarModel *model in self.datasArray) {
        if (model.isSelected) {
            allPrice += ([model.costPrice floatValue]?[model.costPrice floatValue]:[model.goods.tagPrice floatValue]) * model.goodsNum;
        }
    }
    self.totalPriceLabe.text = [NSString stringWithFormat:@"¥%.2f",allPrice];
}


#pragma mark -全选
- (IBAction)totalButtonSelectedAction:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    if (sender.selected) {
        
        //全部选中
        for (ShoppingTableViewCell *cell in self.shoppingBagTableView.visibleCells) {
            cell.selectedButton.selected = YES;
        }
        for (ShopcarModel *model in self.datasArray) {
            model.isSelected = YES;
        }
        [self.sureButton setTitle:[NSString stringWithFormat:@"确认添加(%ld)",self.datasArray.count] forState:UIControlStateNormal];
    }else
    {
        //取消全部选中
        for (ShoppingTableViewCell *cell in self.shoppingBagTableView.visibleCells) {
            cell.selectedButton.selected = NO;
        }
        for (ShopcarModel *model in self.datasArray) {
            model.isSelected = NO;
        }
        [self.sureButton setTitle:@"确认添加(0)" forState:UIControlStateNormal];
    }
    //计算总金额
    [self calculateSelectedGoodsAllprice];
}

#pragma mark -删除
- (IBAction)delectedButtonSelectedAction:(UIButton *)sender {
    
    NSMutableArray *indexpathArray = [NSMutableArray array];
    NSMutableArray *delectedModelArray = [NSMutableArray array];
    for (int i=0; i < self.datasArray.count; i++) {
        ShopcarModel *model = [self.datasArray objectAtIndex_opple:i];
        if (model.isSelected) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
            [indexpathArray addObject:indexPath];
            [delectedModelArray addObject:model];
        }
    }
    if (!indexpathArray.count) {
        [XBLoadingView showHUDViewWithText:@"未选中任何商品"];
    }else
    {
        for (ShopcarModel *model in delectedModelArray) {
            [self.datasArray removeObject:model];
        }
        [self.sureButton setTitle:@"确认添加(0)" forState:UIControlStateNormal];
        self.totalSelectedButton.selected = NO;
        self.totalPriceLabe.text = nil;
        [self.shoppingBagTableView deleteRowsAtIndexPaths:indexpathArray withRowAnimation:UITableViewRowAnimationLeft];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.shoppingBagTableView reloadData];
        });
    }
}

#pragma mark -添加至购物车
- (IBAction)addShoppingBagButtonClickAction:(UIButton *)sender {
    
    if (![Shoppersmanager manager].currentCustomer) {
        [XBLoadingView showHUDViewWithText:@"请先设置当前客户"];return;
    }
    NSMutableArray *array = [NSMutableArray array];
    for (int i=0; i<self.datasArray.count; i++) {
        ShopcarModel *model = [self.datasArray objectAtIndex_opple:i];
        if (model.isSelected) {
            [array addObject:model];
        }
    }
    if (!array.count) {
        [XBLoadingView showHUDViewWithText:@"请先勾选商品"];
        return;
    }
    //选中商品截图
    if ([self.delegate respondsToSelector:@selector(addToShoppingCar:finish:)]) {
        [self.delegate addToShoppingCar:array finish:^(NSString *osskey) {
            [XBLoadingView showHUDViewWithDefault];
            NSMutableString *goodsIds = [[NSMutableString alloc]init];
            NSMutableString *goodsCounts = [[NSMutableString alloc]init];
            NSMutableString *attachmentString = [[NSMutableString alloc]init];
            for (ShopcarModel *model in self.datasArray) {
                if (model.isSelected) {
                    [goodsIds appendFormat:@"%@,",model.goods.fid];
                    [goodsCounts appendFormat:@"%ld,",(long)model.goodsNum];
                    [attachmentString appendFormat:@"%@,",[OSSHelper getCompleteImageURLWithOSSkey:osskey]];
                }
            }
            SaveShoppingCartRequest *shopCar = [[SaveShoppingCartRequest alloc]init];
            shopCar.consumerId = [Customermanager manager].model.consumer.fid;
            shopCar.goodsId = [goodsIds substringToIndex:goodsIds.length-1];
            shopCar.count = [goodsCounts substringToIndex:goodsCounts.length-1];
            shopCar.attachmentUrl = [attachmentString substringToIndex:attachmentString.length-1];
            WS(weakSelf);
            [HTTP networkRequestWithURL:SERVERREQUESTURL(ADDSHOPPINGBAG) withRequestType:ZERO withParameter:shopCar withReturnValueBlock:^(id returnValue) {
                [XBLoadingView hideHUDViewWithDefault];
                if (RESULT(returnValue)) {
                    if (weakSelf.dismissBlock) {
                        weakSelf.dismissBlock();
                    }
                    [weakSelf dismissViewControllerAnimated:YES completion:nil];
                    [weakSelf queryShoppingCarNumber];
                    [XBLoadingView showHUDViewWithSuccessText:@"加入购物车成功" completeBlock:nil];
                }else
                {
                    [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
                }
            }withFailureBlock:^(NSError *error) {
                [XBLoadingView showHUDViewWithText:error.localizedDescription];
            }];
        }];
    }
}


#pragma mark -系统提示框
- (void)promptCustomerWithString:(NSString *)message
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [alertVC dismissViewControllerAnimated:YES completion:nil];
    }]];
    [self presentViewController:alertVC animated:YES completion:nil];
}

#pragma mark -修改单个商品数量、价格
- (void)changeGoodsNumber:(NSInteger)goodsNumber WithcostPrice:(CGFloat)costprice Withcellindex:(NSInteger)cellindex returnValue:(void (^)(id))result
{
    [XBLoadingView showHUDViewWithDefault];
    //保存商品数量
    ShopcarModel *model = [self.datasArray objectAtIndex_opple:cellindex];
    model.goodsNum = goodsNumber;
    //保存成交价格
    model.costPrice = [NSNumber numberWithFloat:costprice];
    //在服务器保存数量、成交价
    //购物车ID
    NSString *carid = model.fid;
    //商品id
    NSString *goodsis = model.goodsId;
    //成交价
    NSString *costpriceString = [NSString stringWithFormat:@"%.2f",costprice];
    //商品数量
    NSString *goodsNumberString = [NSString stringWithFormat:@"%ld",(long)goodsNumber];
    WS(weakSelf);
    [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@/%@/%@/%@",SERVERREQUESTURL(CHANGESHOPPINGBAGNUMBERPRICE),carid,goodsis,costpriceString,goodsNumberString]  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
        
        [XBLoadingView hideHUDViewWithDefault];
        result(returnValue);//提供是否支持修改的参数
        if (RESULT(returnValue)) {
            [weakSelf calculateSelectedGoodsAllprice];
            [weakSelf queryShoppingCarNumber];
        }else{
            
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
        }
    }withFailureBlock:^(NSError *error) {
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
    }];
}

#pragma mark -销毁
- (void)dismissAction:(UITapGestureRecognizer *)tap
{
    if (self.dismissBlock) {
        self.dismissBlock();
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark -UIGestureRecognizerDelegate代理
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    //取消子视图的的时间穿透,否则子视图的点击无效,会被传递到父视图响应
    if (CGRectContainsPoint(self.shoppingBagBackView.frame, [touch locationInView:self.view.window])) {
        
        return NO;
    }
    return YES;
}

#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return kNoDataImage;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc]initWithString:@"暂无数据" attributes:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end