订单合并(单选多选)遇到的问题

这里写图片描述

需求合并订单,要实现合并多个单个,也可以不合并,一个都不合并的时候隐藏合并付款按钮,还有现在支付的订单是不能合并的得注意这一点,因为一开始思考就思考错了,导致老在一个地方卡住,开始我没有以数据为考虑中心,而是以UI为考虑中心,后来卡了很久就问胡哥(同事),他就告诉我:
准则:
1、已数据为中心,model里面设置一个BOOL属性记录选中状态,默认为YES
2、UI布局只根据model来,model里面的为YES就是选中,为NO就不勾选
3、点击按钮,通过对应的section(或者index)可以得到array对应位置的model,然后改变BOOL属性

4、block回调不需要传参数,在VC里面的block里面直接对table.Array进行遍历就可以得到选中的订单数据
我开始就是在第4点哪里下的手,发觉别人和我下手的逻辑就不一样了,真是笨啊,胡哥还特地打电话来对我说,害我第二天睡觉醒来上洗手间就突然明白了他说我没有一数据为中心的问题,原来我开始实现只顾着UI了哈哈,

viewTable里面实现的代码
NSInteger flag[100];用来标记我选中和取消的按钮

UIButton *selecteBnt = [UIButton buttonWithType:UIButtonTypeCustom];
selecteBnt.frame = CGRectMake(KScreenWidth-(size.width/2)-40, moneyLabel.bottom, 20, 20);
[selecteBnt addTarget:self action:@selector(selecteButtonClick:) forControlEvents:UIControlEventTouchUpInside];
selecteBnt.tag = indexPath.section+9000;
[selecteBnt setImage:[UIImage imageNamed:@”shoppingcar_unselected”] forState:UIControlStateNormal];
[selecteBnt setImage:[UIImage imageNamed:@”shoppingcar_selected”] forState:UIControlStateSelected];
[cell.contentView addSubview:selecteBnt];

        if (flag[indexPath.section] == 0) {
            selecteBnt.selected = YES;
        }else{
            selecteBnt.selected = NO;
        }

        [cell.contentView addSubview:selecteBnt];
  • (void)selecteButtonClick:(UIButton*)sender
    {

    if (_selecteButton !=nil) {

    //change status
    flag[sender.tag-9000] = !flag[sender.tag-9000];
    sender.selected= !sender.selected;
    
    if(sender.tag-9000 < self.allArray.count)
    {       
    PurchaseOrderModel *orderModel = self.allArray[sender.tag-9000];   
        //注意订单的前提:代付款订单--选中/取消
        //与按钮的状态一致
    orderModel.selectToPay = sender.selected;
    } 
    //block 刷新界面,比如合并后的金额
    _selecteButton(sender);
    

    }

}//选择按钮

  视图控制器里面的代码


NSMutableArray *allArray = [NSMutableArray array];
if(![data[@"backinfo"] isEqual:[NSNull null]])
{
    for (id value in data[@"backinfo"])
    {
        PurchaseOrderModel *orderModel = [PurchaseOrderModel initWithDictionary:value];

        //默认状态下,未付款订单是全部勾选的(合并全部)
        orderModel.selectedHebing = YES;
        orderModel.selectToPay = YES;

        [allArray addObject:orderModel];

    }





    //选中订单合并中

    self.purchaseOrderTV.selecteButton = ^(UIButton *button){
        NSInteger index = 0;
        for (int i = 0; i < VC.purchaseOrderTV.allArray.count; i++)
        {
            PurchaseOrderModel *model = VC.purchaseOrderTV.allArray[i];
            //先判断:未付款订单 -- 选中的订单
            if (model.selectToPay == YES)
            {
                index++;
            }
        }
        一个订单都没有合并的时候隐藏合并付款按钮
        if (index == 0) {
            VC.bottomView.hidden = YES;
            VC.line.hidden = YES;
        }else {

            VC.bottomView.hidden = NO;
            VC.line.hidden = NO;  
        }           
    };
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值