您的位置:首页 > 其它

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

2016-06-21 11:27 211 查看


需求合并订单,要实现合并多个单个,也可以不合并,一个都不合并的时候隐藏合并付款按钮,还有现在支付的订单是不能合并的得注意这一点,因为一开始思考就思考错了,导致老在一个地方卡住,开始我没有以数据为考虑中心,而是以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;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: