//
//  StewardTableViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2018/1/4.
//  Copyright © 2018年 上海勾芒科技有限公司. All rights reserved.
//

#import "StewardTableViewController.h"
#import "YXPickerManager.h"

@interface StewardTableViewController ()

@end

@implementation StewardTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

}

/**
 通过中文返回int类型
 */
- (NSString *)returnType:(NSString *)string
{
    if ([string isEqualToString:@"自提"]) {
        return @"1";
    }
    if ([string isEqualToString:@"送货上门"]) {
        return @"2";
    }
    if ([string isEqualToString:@"欧普到家"]) {
        return @"1";
    }
    if ([string isEqualToString:@"门店安装"]) {
        return @"2";
    }
    if ([string isEqualToString:@"不含安装"]) {
        return @"3";
    }
    return nil;
}

/**
 通过欧管家导购名返回对应id
 */
- (NSString *)returnStewardId:(NSString *)string
{
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"empName = %@", string];
    NSArray *arr = [self.resultModel.data filteredArrayUsingPredicate:pred];
    StewardModel_data *model = arr.firstObject;
    return model.empCode;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WS(weakSelf);
    switch (indexPath.row) {
        case 0:
        {
            [XBLoadingView showHUDViewWithDefault];;
            [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(GETSTEWARD),[[Shoppersmanager manager] shoppers].employee.currentDepart.fid] withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
                [XBLoadingView hideHUDViewWithDefault];
                if (RESULT(returnValue)) {
                    StewardModel *model = [[StewardModel alloc] initWithDictionary:returnValue error:nil];
                    weakSelf.resultModel = model;
                    NSMutableArray *stewardArray = [NSMutableArray array];
                    for (StewardModel_data *data in model.data) {
                        [stewardArray addObject:data.empName];
                    }
                    NSString *defaultString = [self.stewardLabel.text isEqualToString:@"请选择欧管家导购"] ? nil : self.stewardLabel.text;
                    [[YXPickerManager shareManager] showGeneralPickerView:kMainBlueColor dataArray:stewardArray defaultString:defaultString commitBlock:^(NSString *selectedItem, NSInteger index) {
                        weakSelf.stewardLabel.text = selectedItem;
                    } cancelBlock:^{
                        
                    }];
                }else {
                    [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
                }
                
            } withFailureBlock:^(NSError *error) {
                [XBLoadingView showHUDViewWithText:error.localizedDescription];
            }];
        }
            break;
        case 1:
        {
            NSString *defaultString = [self.shippingMethodLabel.text isEqualToString:@"请选择送货方式"] ? @"送货上门" : self.shippingMethodLabel.text;
            [[YXPickerManager shareManager] showGeneralPickerView:kMainBlueColor dataArray:@[@"自提",@"送货上门"] defaultString:defaultString commitBlock:^(NSString *selectedItem, NSInteger index) {
                weakSelf.shippingMethodLabel.text = selectedItem;
            } cancelBlock:^{
                
            }];
        }
            break;
        case 2:
        {
            NSString *defaultString = [self.installMethodLabel.text isEqualToString:@"请选择安装方式"] ? @"欧普到家" : self.installMethodLabel.text;
            [[YXPickerManager shareManager] showGeneralPickerView:kMainBlueColor dataArray:@[@"欧普到家",@"门店安装",@"不含安装"] defaultString:defaultString commitBlock:^(NSString *selectedItem, NSInteger index) {
                weakSelf.installMethodLabel.text = selectedItem;
            } cancelBlock:^{
                
            }];
        }
            break;
        case 3:
        {
            NSString *defaultString = [self.installDateLabel.text isEqualToString:@"请选择安装日期"] ?  [[NSDate date] httpParameterString] : [NSString stringWithFormat:@"%@ 00:00:00",self.installDateLabel.text];
            [[YXPickerManager shareManager] showDatePickerView:kMainBlueColor datePickerModel:UIDatePickerModeDate minimumDate:[NSDate date] maximumDate:nil defaultDate:defaultString commitBlock:^(NSString *date) {
                weakSelf.installDateLabel.text = [[date componentsSeparatedByString:@" "] firstObject];
            } cancelBlock:^{
                
            }];
        }

            break;
        default:
            break;
    }
}



@end

















