美文网首页
购物车计算价格主要逻辑代码

购物车计算价格主要逻辑代码

作者: 高乔人 | 来源:发表于2018-01-13 10:38 被阅读8次

//cell的按钮的block方法,把选中的相应模型里面的数据给另一个数组保存

cell.goodsSelectedBlock = ^(BOOL cellSelected) {

        if (cellSelected) {

//添加到要保存的数组中

           [self.resultArray addObject:self.dataArray2[indexPath.row]];

        }

        else{

//从数组中删除相应的数据

        [self.resultArray removeObject:self.dataArray2[indexPath.row]];

        }

           [self calculateTheTotalPrice];

    };

/////////////这里是计算的具体的方法

- (void)calculateTheTotalPrice{

    CGFloat totalPrice = 0.00;

    for (goodsListModelT *model in self.resultArray)

    {

        CGFloat a = 0.00;

        if ([model.goodsNum floatValue] <= _dataArray2.count+1)

        {

            a = [model.goodsNum floatValue]* [model.price floatValue];

        }

        else

        {

            a = [model.goodsNum floatValue]* [model.price doubleValue];

        }

        totalPrice = totalPrice + a;

    }

    self.priviceLabel.text = [NSString stringWithFormat:@"¥%.2f", totalPrice];

}

水平有限不喜勿喷,

相关文章

网友评论

      本文标题:购物车计算价格主要逻辑代码

      本文链接:https://www.haomeiwen.com/subject/vlqcoxtx.html