SaleInputListViewModel.m 3.17 KB
Newer Older
Sandy's avatar
Sandy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
//
//  SaleInputListViewModel.m
//  HDMall
//
//  Created by Javen on 2017/8/8.
//  Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//

#import "SaleInputListViewModel.h"
#import "NSDate+Additions.h"
#define KDateRangeTypeWeek @"最近一周"
#define KDateRangeTypeOneMonth @"最近一月"
#define KDateRangeTypeThreeMonth @"最近三月"
@implementation SaleInputListViewModel

- (instancetype)init {
    self = [super init];
    if (self) {
        self.arrDateTitles = @[KDateRangeTypeWeek, KDateRangeTypeOneMonth, KDateRangeTypeThreeMonth];
        self.arrStateTitles = @[@"全部",@"未生效", @"已生效"];
        self.arrDropMenu = @[self.arrDateTitles, self.arrStateTitles];
        
        //第一次请求,默认是最近一周
        NSDate *end = [NSDate date];
        NSDate *begin = [NSDate dateWithTimeInterval:-7 * 24 * 60 * 60 sinceDate:end];
        self.query.contracts = [AppGlobal getUserContractUuids];
        self.query.dateRange = [HMSaleInputQuery_dateRange new];
        self.query.dateRange.beginDate = begin.yearMonthDayString;
        self.query.dateRange.endDate = end.yearMonthDayString;
    }
    return self;
}

- (NSInteger)numberOfColumnsInMenu:(JSDropDownMenu *)menu {
    return 2;
}

- (NSInteger)menu:(JSDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow {
    return [self.arrDropMenu[column] count];
}

- (NSString *)menu:(JSDropDownMenu *)menu titleForColumn:(NSInteger)column {
    return [self.arrDropMenu[column] firstObject];
}

- (NSString *)menu:(JSDropDownMenu *)menu titleForRowAtIndexPath:(JSIndexPath *)indexPath {
    return [self.arrDropMenu[indexPath.column] objectAtIndex:indexPath.row];
}

- (BOOL)haveRightTableViewInColumn:(NSInteger)column {
    return NO;
}

- (CGFloat)widthRatioOfLeftColumn:(NSInteger)column {
    return 1;
}

- (NSInteger)currentLeftSelectedRow:(NSInteger)column {
    if (column == 0) {
        return self.dateTag;
    } else {
        return self.stateTag;
    }
}

- (void)menu:(JSDropDownMenu *)menu didSelectRowAtIndexPath:(JSIndexPath *)indexPath {
    NSString *title = [self.arrDropMenu[indexPath.column] objectAtIndex:indexPath.row];
    if (indexPath.column == 0) {
        self.dateTag = indexPath.row;
        NSDate *end = [NSDate date];
        NSDate *begin = nil;
        if ([title isEqualToString:KDateRangeTypeWeek]) {
            begin = [NSDate dateWithTimeInterval:-7 * 24 * 60 * 60 sinceDate:end];
        }else if ([title isEqualToString:KDateRangeTypeOneMonth]){
            begin = [NSDate dateWithTimeInterval:-30 * 24 * 60 * 60 sinceDate:end];
        }else if ([title isEqualToString:KDateRangeTypeThreeMonth]){
            begin = [NSDate dateWithTimeInterval:-90 * 24 * 60 * 60 sinceDate:end];
        }
        self.query.dateRange.beginDate = begin.yearMonthDayString;
        self.query.dateRange.endDate = end.yearMonthDayString;
    } else {
        self.stateTag = indexPath.row;
        if (indexPath.row == 0) {
            self.query.state = nil;
        }else{
            self.query.state = [SaleInputState stateWithText:title].code;
        }
    }
    self.blockRequest();
}

ZJLazy(HMSaleInputQuery, query);

@end