|
@@ -14,7 +14,7 @@
|
|
|
|
|
|
@property (nonatomic, copy) NSString *typeid;
|
|
@property (nonatomic, copy) NSString *typeid;
|
|
|
|
|
|
-@property (nonatomic, strong) ASProductListViewModel *vm;
|
|
|
|
|
|
+
|
|
|
|
|
|
@property (nonatomic,strong) UIButton *clearBt;
|
|
@property (nonatomic,strong) UIButton *clearBt;
|
|
@property (nonatomic, strong) UIButton *doneBt;
|
|
@property (nonatomic, strong) UIButton *doneBt;
|
|
@@ -29,24 +29,6 @@
|
|
@implementation KWProductMenuFilterView
|
|
@implementation KWProductMenuFilterView
|
|
|
|
|
|
|
|
|
|
-- (void)configTypeId:(NSString *)typeId {
|
|
|
|
- self.typeid = typeId;
|
|
|
|
- self.vm.selectDic = [NSMutableDictionary dictionary];
|
|
|
|
- [self getFilterData];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-- (void)getFilterData {
|
|
|
|
-// if (self.vm.sourceArr.count != 0) {
|
|
|
|
-// return;
|
|
|
|
-// }
|
|
|
|
-// [self.vm reqFilterListByType:self.typeid view:self callBack:^{
|
|
|
|
-// [self.collectV reloadData];
|
|
|
|
-// }];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-- (void)configBottomBt {
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
if (self) {
|
|
@@ -150,6 +132,26 @@
|
|
}
|
|
}
|
|
|
|
|
|
- (void)doneBtAction {
|
|
- (void)doneBtAction {
|
|
|
|
+ for (KWProductListFilterModel *mainM in self.vm.sourceArr) {
|
|
|
|
+ if ([mainM.attribute_id isEqualToString:@"price"]) {
|
|
|
|
+ KWProductListFilterSubModel *subM = mainM.attribute_data.firstObject;
|
|
|
|
+ if (subM.inputMax.length > 0 && subM.inputMin.length > 0) {
|
|
|
|
+ NSMutableArray *tempSubs = self.vm.selectDic[mainM.attribute_id];
|
|
|
|
+ if (tempSubs == nil) {
|
|
|
|
+ tempSubs = [NSMutableArray array];
|
|
|
|
+ }
|
|
|
|
+ [tempSubs addObject:subM];
|
|
|
|
+ self.vm.selectDic[mainM.attribute_id] = tempSubs;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (subM.inputMax.length <= 0 && subM.inputMin.length <= 0) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ [self makeToast:@"Both Max and Min prices need to be set or removed simultaneously"];
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
[self closeAction:^{
|
|
[self closeAction:^{
|
|
if (self.resultFilterDic) {
|
|
if (self.resultFilterDic) {
|
|
self.resultFilterDic(self.vm.selectDic);
|
|
self.resultFilterDic(self.vm.selectDic);
|
|
@@ -163,10 +165,10 @@
|
|
[self.collectV reloadData];
|
|
[self.collectV reloadData];
|
|
}
|
|
}
|
|
|
|
|
|
-- (void)showAnimate:(NSMutableDictionary<NSString *,KWProductListFilterSubModel *> *)arr {
|
|
|
|
|
|
+- (void)showAnimate:(NSMutableDictionary<NSString *,NSMutableArray<KWProductListFilterSubModel *> *> *)arr {
|
|
self.hidden = false;
|
|
self.hidden = false;
|
|
self.vm.selectDic = [NSMutableDictionary dictionaryWithDictionary:arr];
|
|
self.vm.selectDic = [NSMutableDictionary dictionaryWithDictionary:arr];
|
|
- [self getFilterData];
|
|
|
|
|
|
+ [self.collectV reloadData];
|
|
CGRect oldFrame = self.frame;
|
|
CGRect oldFrame = self.frame;
|
|
self.frame = CGRectMake(0, -oldFrame.size.height, oldFrame.size.width, oldFrame.size.height);
|
|
self.frame = CGRectMake(0, -oldFrame.size.height, oldFrame.size.width, oldFrame.size.height);
|
|
self.hidden = false;
|
|
self.hidden = false;
|
|
@@ -245,74 +247,64 @@
|
|
}
|
|
}
|
|
|
|
|
|
- (BOOL)hadSelectIndex:(NSIndexPath *)index {
|
|
- (BOOL)hadSelectIndex:(NSIndexPath *)index {
|
|
- KWProductListFilterModel *mainM = self.vm.showArr[index.section];
|
|
|
|
|
|
+ if (self.vm.sourceArr.count < index.section) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ KWProductListFilterModel *mainM = self.vm.sourceArr[index.section];
|
|
|
|
+ if (mainM.attribute_data.count < index.item) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
KWProductListFilterSubModel *subM = mainM.attribute_data[index.item];
|
|
KWProductListFilterSubModel *subM = mainM.attribute_data[index.item];
|
|
|
|
|
|
- KWProductListFilterSubModel *selectSubM = self.vm.selectDic[mainM.attribute_id];
|
|
|
|
- if (selectSubM && [selectSubM.Id isEqualToString:subM.Id]) {
|
|
|
|
|
|
+ NSMutableArray *selectSubMs = self.vm.selectDic[mainM.attribute_id];
|
|
|
|
+ if (selectSubMs.count > 0 && [selectSubMs containsObject:subM]) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-// if (index.section < self.vm.selectArr.count) {
|
|
|
|
-// return true;
|
|
|
|
-// }
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- (void)selectIndex:(NSIndexPath *)index {
|
|
- (void)selectIndex:(NSIndexPath *)index {
|
|
|
|
+ if (self.vm.sourceArr.count < index.section) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ KWProductListFilterModel *mainM = self.vm.sourceArr[index.section];
|
|
|
|
+ if (mainM.attribute_data.count < index.item) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ KWProductListFilterSubModel *subM = mainM.attribute_data[index.item];
|
|
BOOL isselct = [self hadSelectIndex:index];
|
|
BOOL isselct = [self hadSelectIndex:index];
|
|
if (isselct) {
|
|
if (isselct) {
|
|
- KWProductListFilterModel *m = self.vm.showArr[index.section];
|
|
|
|
- //self.vm.selectArr[index.section];
|
|
|
|
- self.vm.selectDic[m.attribute_id] = nil;
|
|
|
|
-
|
|
|
|
-// if (m.attribute_data.count > index.row) {
|
|
|
|
-// [m.attribute_data removeObjectAtIndex:index.row];
|
|
|
|
-// }
|
|
|
|
-// if (m.attribute_data.count == 0) {
|
|
|
|
-// [self.vm.selectArr removeObjectAtIndex:index.section];
|
|
|
|
-// }
|
|
|
|
|
|
+ NSMutableArray *tempSubs = self.vm.selectDic[mainM.attribute_id];
|
|
|
|
+ if (tempSubs != nil && [tempSubs containsObject:subM]) {
|
|
|
|
+ [tempSubs removeObject:subM];
|
|
|
|
+ }
|
|
[self.collectV reloadData];
|
|
[self.collectV reloadData];
|
|
-// [self getFilterData];
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ NSMutableArray *tempSubs = self.vm.selectDic[mainM.attribute_id];
|
|
|
|
+ if (tempSubs == nil) {
|
|
|
|
+ tempSubs = [NSMutableArray array];
|
|
|
|
+ }
|
|
|
|
+ [tempSubs addObject:subM];
|
|
|
|
+ self.vm.selectDic[mainM.attribute_id] = tempSubs;
|
|
|
|
|
|
- KWProductListFilterModel *m = self.vm.showArr[index.section];
|
|
|
|
- KWProductListFilterSubModel *subm = m.attribute_data[index.row];
|
|
|
|
-
|
|
|
|
-// KWProductListFilterModel *newM = [m copySelf];
|
|
|
|
- KWProductListFilterSubModel *newSubm = [subm copySelf];
|
|
|
|
- self.vm.selectDic[m.attribute_id] = newSubm;
|
|
|
|
-
|
|
|
|
-// [newM.attribute_data addObject:newSubm];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// [self.vm.selectArr addObject:newM];
|
|
|
|
[self.collectV reloadData];
|
|
[self.collectV reloadData];
|
|
-// [self getFilterData];
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- if ([self.vm.showArr[indexPath.section].attribute_id isEqualToString: @"-100"]) {
|
|
|
|
|
|
+ if ([self.vm.sourceArr[indexPath.section].attribute_id isEqualToString: @"price"]) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
-// NSMutableArray<NSIndexPath *> *tempArr = self.currentIndexs;
|
|
|
|
-// NSInteger arrIndex = [self hadSelectIndex:indexPath];
|
|
|
|
-// if (arrIndex >= 0) {
|
|
|
|
-// [tempArr removeObjectAtIndex:arrIndex];
|
|
|
|
-// } else {
|
|
|
|
-// [tempArr addObject:indexPath];
|
|
|
|
-// }
|
|
|
|
-// self.currentIndexs = tempArr;
|
|
|
|
[self selectIndex:indexPath];
|
|
[self selectIndex:indexPath];
|
|
}
|
|
}
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|
- return self.vm.showArr.count;
|
|
|
|
|
|
+ return self.vm.sourceArr.count;
|
|
}
|
|
}
|
|
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
- NSArray *subModels = self.vm.showArr[section].attribute_data;
|
|
|
|
|
|
+ NSArray *subModels = self.vm.sourceArr[section].attribute_data;
|
|
if (subModels == nil) {
|
|
if (subModels == nil) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -321,21 +313,27 @@
|
|
}
|
|
}
|
|
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- if ([self.vm.showArr[indexPath.section].attribute_id isEqualToString: @"-100"]) {
|
|
|
|
|
|
+ if ([self.vm.sourceArr[indexPath.section].attribute_id isEqualToString: @"price"]) {
|
|
ASProductlistFilterPriceCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ASProductlistFilterPriceCollectCell" forIndexPath:indexPath];
|
|
ASProductlistFilterPriceCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ASProductlistFilterPriceCollectCell" forIndexPath:indexPath];
|
|
- NSArray<KWProductListFilterSubModel *> *subModels = self.vm.showArr[indexPath.section].attribute_data;
|
|
|
|
|
|
+ NSArray<KWProductListFilterSubModel *> *subModels = self.vm.sourceArr[indexPath.section].attribute_data;
|
|
if (indexPath.item >= subModels.count ){
|
|
if (indexPath.item >= subModels.count ){
|
|
return cell;
|
|
return cell;
|
|
}
|
|
}
|
|
KWProductListFilterSubModel *m = subModels[indexPath.item];
|
|
KWProductListFilterSubModel *m = subModels[indexPath.item];
|
|
- cell.minTf.text = m.minPrice;
|
|
|
|
- cell.maxTf.text = m.maxPrice;
|
|
|
|
|
|
+ cell.model = m;
|
|
|
|
+ cell.minTf.text = m.inputMin;
|
|
|
|
+ cell.maxTf.text = m.inputMax;
|
|
|
|
+ if (m.status <= 0) {
|
|
|
|
+ cell.minTf.placeholder = m.minPrice;
|
|
|
|
+ cell.maxTf.placeholder = m.maxPrice;
|
|
|
|
+ }
|
|
|
|
+
|
|
return cell;
|
|
return cell;
|
|
}
|
|
}
|
|
KWProductFilterItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KWProductFilterItemCell" forIndexPath:indexPath];
|
|
KWProductFilterItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KWProductFilterItemCell" forIndexPath:indexPath];
|
|
NSInteger isSelect = [self hadSelectIndex:indexPath];
|
|
NSInteger isSelect = [self hadSelectIndex:indexPath];
|
|
|
|
|
|
- NSArray<KWProductListFilterSubModel *> *subModels = self.vm.showArr[indexPath.section].attribute_data;
|
|
|
|
|
|
+ NSArray<KWProductListFilterSubModel *> *subModels = self.vm.sourceArr[indexPath.section].attribute_data;
|
|
if (subModels == nil) {
|
|
if (subModels == nil) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -361,7 +359,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
- if ([self.vm.showArr[indexPath.section].attribute_id isEqualToString: @"-100"]) {
|
|
|
|
|
|
+ if ([self.vm.sourceArr[indexPath.section].attribute_id isEqualToString: @"price"]) {
|
|
return CGSizeMake(KScreenWidth-8*2, 45);;
|
|
return CGSizeMake(KScreenWidth-8*2, 45);;
|
|
}
|
|
}
|
|
CGFloat wid = (KScreenWidth-8*3)/2-1;
|
|
CGFloat wid = (KScreenWidth-8*3)/2-1;
|
|
@@ -372,7 +370,7 @@
|
|
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
|
|
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
|
|
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
|
|
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
|
|
KWProductMenuFilterItemHeaderView *v = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"KWProductMenuFilterItemHeaderView" forIndexPath:indexPath];
|
|
KWProductMenuFilterItemHeaderView *v = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"KWProductMenuFilterItemHeaderView" forIndexPath:indexPath];
|
|
- NSString *ti = [NSString stringWithFormat:@"%@",self.vm.showArr[indexPath.section].attribute_name];
|
|
|
|
|
|
+ NSString *ti = [NSString stringWithFormat:@"%@",self.vm.sourceArr[indexPath.section].attribute_name];
|
|
v.titleLb.text = ti;
|
|
v.titleLb.text = ti;
|
|
return v;
|
|
return v;
|
|
}
|
|
}
|