ApplyPrizeViewController.m 5.54 KB
Newer Older
1 2 3 4 5 6 7 8 9
//
//  ApplyPrizeViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/11/22.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ApplyPrizeViewController.h"
10 11
#import "MOFSPickerManager.h"
@interface ApplyPrizeViewController ()<UITextFieldDelegate>
12 13


14 15 16 17 18
/**
 保存兑奖单
 */
@property (nonatomic,strong) RsPrizeBill *prizeBill;

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
@end

@implementation ApplyPrizeViewController

#pragma mark -取消弹出的圆角
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.view.superview.layer.cornerRadius = 0;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpTextFieldAction];
}

#pragma mark - 设置UITextField
- (void)setUpTextFieldAction
{
    UIView *leftView1 = [[UIView alloc]init];
    leftView1.frame = CGRectMake(0, 0, 10, 1);
    self.consigneeTextField.leftView = leftView1;
    self.consigneeTextField.leftViewMode = UITextFieldViewModeAlways;
    UIView *leftView2 = [[UIView alloc]init];
    leftView2.frame = CGRectMake(0, 0, 10, 1);
    self.mobileTextField.leftView = leftView2;
    self.mobileTextField.leftViewMode = UITextFieldViewModeAlways;
    UIView *leftView4 = [[UIView alloc]init];
    leftView4.frame = CGRectMake(0, 0, 10, 1);
    self.addressDetailsTextField.leftView = leftView4;
    self.addressDetailsTextField.leftViewMode = UITextFieldViewModeAlways;
50
    [self.addressButton addTarget:self action:@selector(selectedCityClickAction) forControlEvents:UIControlEventTouchUpInside];
51 52
}

53 54
#pragma mark - 选中礼品
- (void)setSelectArray:(NSArray<PrizeListModel *> *)selectArray
55
{
56 57 58 59 60 61
    _selectArray = selectArray;
    CGFloat width = 70;//宽度
    CGFloat interval = 10;//间隔
    for (int i=0; i<_selectArray.count; i++) {
        PrizeListModel *model = _selectArray[i];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*width+i*interval, 0, width, width)];
62
        [imageView sd_setImageWithURL:[NSURL URLWithString:model.attachment.fileUrl] placeholderImage:REPLACEIMAGE];
63
        [self.exchangeScrollView addSubview:imageView];
64
    }
65
    self.exchangeScrollView.contentSize = CGSizeMake(width*_selectArray.count+interval*_selectArray.count-1, 0);
66 67 68 69 70
}

#pragma mark -城市选择器
- (void)selectedCityClickAction
{
71 72 73 74
    [[MOFSPickerManager shareManger] showMOFSAddressPickerWithTitle:@"选择城市" cancelTitle:@"取消" commitTitle:@"完成" commitBlock:^(NSString *address, NSString *zipcode) {
        [self.addressButton setTitle:address forState:UIControlStateNormal];
    } cancelBlock:^{
        
75
    }];
76
    
77
}
78 79 80 81 82 83 84 85 86

#pragma mark - 取消
- (IBAction)cancelButtonClickAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 提交
- (IBAction)submitButtonClickAction:(UIButton *)sender {
    
87
    if ([[self class] isBlankString:self.consigneeTextField.text]) {
88
        [XBLoadingView showHUDViewWithText:@"收货人不能为空"];return;
89 90
    }
    if ([[self class] isBlankString:self.mobileTextField.text]) {
91
        [XBLoadingView showHUDViewWithText:@"联系电话不能为空"];return;
92
    }
93 94 95
    if (![HENLENSONG isValidateMobile:self.mobileTextField.text]) {
        [XBLoadingView showHUDViewWithText:@"手机号码格式不正确"];return;
    }
96
    if ([[self class] isBlankString:self.addressButton.currentTitle]) {
97
        [XBLoadingView showHUDViewWithText:@"地址不能为空"];return;
98 99
    }
    if ([[self class] isBlankString:self.addressDetailsTextField.text]) {
100
        [XBLoadingView showHUDViewWithText:@"详细地址不能为空"];return;
101 102 103 104 105 106 107 108
    }
    [self savePrizeRecord];
}

#pragma mark - 保存兑奖单
- (void)savePrizeRecord
{
    WS(weakSelf);
109 110
    [XBLoadingView showHUDViewWithDefault];
    NSLog(@"%@",[[self.prizeBill toDictionary] JSONString]);
曹云霄's avatar
曹云霄 committed
111
    [HTTP networkRequestWithURL:SERVERREQUESTURL(SAVEPRIZEBILL) withRequestType:ZERO withParameter:self.prizeBill withReturnValueBlock:^(id returnValue) {
112
        
113
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
114
        if (RESULT(returnValue)) {
115
            [XBLoadingView showHUDViewWithSuccessText:@"申请成功" completeBlock:^{
116 117 118
                if (weakSelf.requestFinishBlock) {
                    weakSelf.requestFinishBlock();
                }
119 120 121
                [weakSelf dismissViewControllerAnimated:YES completion:nil];
            }];
            
122
        }else {
123
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
124
        }
125
    } withFailureBlock:^(NSError *error) {
126
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
127
    }];
128 129 130 131 132
}



#pragma mark - lazy
133 134 135 136 137 138
- (RsPrizeBill *)prizeBill
{
    if (!_prizeBill) {
        _prizeBill = [[RsPrizeBill alloc]init];
        //收货人
        TOPrizeBillEntity *consignee = [[TOPrizeBillEntity alloc]init];
139
        consignee.employee = [Shoppersmanager manager].shoppers.employee.fid;
140 141 142 143 144 145 146 147
        consignee.receiver = self.consigneeTextField.text;
        consignee.mobilephone = self.mobileTextField.text;
        consignee.receiveAddress = [NSString stringWithFormat:@"%@%@",self.addressButton.currentTitle,self.addressDetailsTextField.text];
        _prizeBill.bill = consignee;
        //兑换礼品
        NSMutableArray *array = [NSMutableArray array];
        for (PrizeListModel *model in self.selectArray) {
            TOPrizeBillDetailsEntity *entity = [[TOPrizeBillDetailsEntity alloc]init];
148 149 150
            TOPrizeEntity *prize = [[TOPrizeEntity alloc]init];
            prize.fid = model.fid;
            entity.prize = prize;
151 152 153 154 155 156 157
            [array addObject:entity];
        }
        _prizeBill.details = (NSArray<TOPrizeBillDetailsEntity> *)array;
    }
    return _prizeBill;
}

158
@end