123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- //
- // JZOutPutViewController.m
- // JIZHANG
- //
- // Created by kuxuan on 2018/2/2.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "JZOutPutViewController.h"
- @interface JZOutPutViewController ()<PGDatePickerDelegate>
- @property (nonatomic, strong) UIButton *startButton;
- @property (nonatomic, strong) UIButton *endButton;
- @end
- @implementation JZOutPutViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self setupNavBar];
- [self setupUI];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)setupNavBar {
- self.navTitle = @"账单导出";
- [self addLeftBarButtonItemWithImageName:@"mine_back" title:@"返回" target:self selector:@selector(backItemAction)];
- }
- - (void)backItemAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)setupUI {
- UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, FitSize(92))];
- topView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:topView];
-
- UILabel *line = [[UILabel alloc] init];
- line.backgroundColor = [UIColor JZColorWithHex:0xd8d8d8];
- if (iPhoneX) {
- line.backgroundColor = [[UIColor JZColorWithHex:0xd8d8d8] colorWithAlphaComponent:0.5];
- }
- [topView addSubview:line];
-
- UILabel *startLabel = [[UILabel alloc] init];
- startLabel.backgroundColor = [UIColor clearColor];
- startLabel.text = @"开始时间";
- startLabel.font = FONT_SYS(15);
- startLabel.textColor = [UIColor JZColorWithHex:0x666666];
- [topView addSubview:startLabel];
-
- UIButton *startButton = [UIButton buttonWithType:UIButtonTypeCustom];
- startButton.backgroundColor = [UIColor clearColor];
- startButton.tag = 111;
- [startButton addTarget:self action:@selector(timeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- startButton.titleLabel.font = FONT_SYS(12);
- [startButton setTitleColor:[UIColor JZColorWithHex:0x666666] forState:0];
- [startButton setImage:[UIImage imageNamed:@"mine_person_arrows"] forState:0];
- [topView addSubview:startButton];
- self.startButton = startButton;
- [startButton setTitle:[self getTodayString] forState:0];
- [startButton setButtonStyle:WSLButtonStyleImageRight spacing:10];
-
- UILabel *endLabel = [[UILabel alloc] init];
- endLabel.backgroundColor = [UIColor clearColor];
- endLabel.text = @"结束时间";
- endLabel.font = FONT_SYS(15);
- endLabel.textColor = [UIColor JZColorWithHex:0x666666];
- [topView addSubview:endLabel];
-
- UIButton *endButton = [UIButton buttonWithType:UIButtonTypeCustom];
- endButton.backgroundColor = [UIColor clearColor];
- endButton.tag = 222;
- [endButton addTarget:self action:@selector(timeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- endButton.titleLabel.font = FONT_SYS(12);
- [endButton setTitleColor:[UIColor JZColorWithHex:0x666666] forState:0];
- [endButton setImage:[UIImage imageNamed:@"mine_person_arrows"] forState:0];
- [topView addSubview:endButton];
- self.endButton = endButton;
- [endButton setTitle:[self getTodayString] forState:0];
- [endButton setButtonStyle:WSLButtonStyleImageRight spacing:10];
-
- UILabel *budgetLabel = [[UILabel alloc] init];
- budgetLabel.backgroundColor = [UIColor clearColor];
- budgetLabel.text = @"导出文件到:";
- budgetLabel.font = FONT_SYS(15);
- budgetLabel.textColor = [UIColor JZColorWithHex:0x666666];
- [self.view addSubview:budgetLabel];
-
- UITextField *budgetTF = [[UITextField alloc] init];
- budgetTF.backgroundColor = [UIColor whiteColor];
- [budgetTF addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged];
- budgetTF.placeholder = @"请输入邮箱地址";
- budgetTF.textColor = [UIColor JZColorWithHex:0x222222];
- budgetTF.font = FONT_SYS(15);
- budgetTF.tag = 888;
- budgetTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 16, FitSize(42))];
- budgetTF.leftViewMode = UITextFieldViewModeAlways;
- budgetTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- budgetTF.keyboardType = UIKeyboardTypeEmailAddress;
- [self.view addSubview:budgetTF];
- NSString *mail = [[NSUserDefaults standardUserDefaults] valueForKey:JZOUTPUTEMAIL];
- if (mail.length) {
- budgetTF.text = mail;
- }
-
- UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
- saveButton.frame = CGRectMake(FitSize(28), FitSize(290), FitSize(315), FitSize(50));
- [saveButton addTarget:self action:@selector(outputAction) forControlEvents:UIControlEventTouchUpInside];
- [saveButton setTitle:@"导出" forState:0];
- [saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- saveButton.titleLabel.font = FONT_SYS(15);
- saveButton.cornerRadius = 12;
- saveButton.tag = 999;
- saveButton.enabled = NO;
- saveButton.backgroundColor = [UIColor JZColorWithHex:0xdddddd];
- [self.view addSubview:saveButton];
-
- if (budgetTF.text.length) {
- saveButton.backgroundColor = [UIColor baseColor];
- saveButton.enabled = YES;
- }
- else {
- saveButton.backgroundColor = [UIColor JZColorWithHex:0xdddddd];
- saveButton.enabled = NO;
- }
-
- [line mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.and.right.and.centerY.equalTo(topView);
- make.height.mas_equalTo(0.5);
- }];
-
- [startLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(topView).offset(FitSize(16));
- make.top.mas_equalTo(topView).offset(FitSize(16));
- }];
-
- [startButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(topView).offset(-15);
- make.centerY.equalTo(startLabel);
- }];
-
- [endLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(startLabel);
- make.top.equalTo(line.mas_bottom).offset(FitSize(16));
- }];
-
- [endButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.and.left.equalTo(startButton);
- make.centerY.equalTo(endLabel);
- }];
-
- [budgetLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.view).offset(16);
- make.top.equalTo(topView.mas_bottom).offset(FitSize(20));
- }];
-
- [budgetTF mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.and.right.equalTo(self.view);
- make.top.equalTo(topView.mas_bottom).offset(FitSize(45));
- make.height.mas_equalTo(FitSize(42));
- }];
- }
- - (void)timeButtonAction:(UIButton *)sender {
- PGDatePicker *pgDatePicker = [[PGDatePicker alloc] init];
- pgDatePicker.tag = sender.tag;
- pgDatePicker.delegate = self;
- pgDatePicker.datePickerMode = PGDatePickerModeDate;
- pgDatePicker.minimumDate = [NSDate setYear:2010 month:1 day:1];
- pgDatePicker.maximumDate = [NSDate date];
- pgDatePicker.lineBackgroundColor = [UIColor lineColor];
- pgDatePicker.textColorOfSelectedRow = [UIColor grayColor];
- pgDatePicker.textColorOfOtherRow = [UIColor grayColor];
- pgDatePicker.cancelButtonTextColor = [UIColor JZColorWithHex:0x007aff];
- pgDatePicker.confirmButtonTextColor = [UIColor JZColorWithHex:0x007aff];
- [pgDatePicker showWithShadeBackgroud];
- }
- - (void)outputAction {
- UITextField *tf = [self.view viewWithTag:888];
- if (![self validateEmail:tf.text]) {
- [MBProgressHUD showTip:@"您输入的邮箱不合法"];
- }
- else {
- [[NSUserDefaults standardUserDefaults] setValue:tf.text forKey:JZOUTPUTEMAIL];
- [[NSUserDefaults standardUserDefaults] synchronize];
-
- NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
- fmt.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
- fmt.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
- fmt.dateFormat = @"yyyy年MM月dd日";
- NSDate *startDate = [fmt dateFromString:self.startButton.titleLabel.text];
- NSDate *endDate = [fmt dateFromString:self.endButton.titleLabel.text];
- NSDate *nowDate = [NSDate date];
- NSTimeZone *zone = [NSTimeZone systemTimeZone];
- NSTimeInterval interval = [zone secondsFromGMTForDate:nowDate];
- nowDate = [nowDate dateByAddingTimeInterval:interval];
- NSString *startTime = [NSString stringWithFormat:@"%ld", (long)[startDate timeIntervalSince1970]];
- NSString *endTime = [NSString stringWithFormat:@"%ld", (long)[endDate timeIntervalSince1970]];
- NSString *nowTime = [NSString stringWithFormat:@"%ld", (long)[nowDate timeIntervalSince1970]];
-
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
- [params setValue:tf.text forKey:@"email"];
- [params setValue:startTime forKey:@"start_time"];
- [params setValue:endTime forKey:@"end_time"];
- [params setValue:nowTime forKey:@"time"];
- [params setValue:[params md5String] forKey:@"sign"];
-
- NSString *urlString = [NSString stringWithFormat:@"%@/applyExport",URL];
- [JZHttp post:urlString params:params success:^(id json) {
- [MBProgressHUD showTip:@"正在导出数据中..." time:5.0f];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [MBProgressHUD showTip:@"数据导出成功,稍后请查看邮件"];
- });
- } failure:^(NSError *error) {
-
- }];
- }
- }
- - (void)textChanged:(UITextField *)tf {
- UIButton *saveBtn = [self.view viewWithTag:999];
- if (tf.text.length) {
- saveBtn.backgroundColor = [UIColor baseColor];
- saveBtn.enabled = YES;
- }
- else {
- saveBtn.backgroundColor = [UIColor JZColorWithHex:0xdddddd];
- saveBtn.enabled = NO;
- }
- }
- - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
- NSString *time = nil;
- if (dateComponents.month > 9 && dateComponents.day > 9) {
- time = [NSString stringWithFormat:@"%ld年%ld月%ld日", (long)dateComponents.year, (long)dateComponents.month, (long)dateComponents.day];
- }
- else if (dateComponents.month <= 9 && dateComponents.day > 9) {
- time = [NSString stringWithFormat:@"%ld年0%ld月%ld日", (long)dateComponents.year, (long)dateComponents.month, (long)dateComponents.day];
- }
- else if (dateComponents.month > 9 && dateComponents.day <= 9) {
- time = [NSString stringWithFormat:@"%ld年%ld月0%ld日", (long)dateComponents.year, (long)dateComponents.month, (long)dateComponents.day];
- }
- else if (dateComponents.month <= 9 && dateComponents.day <= 9) {
- time = [NSString stringWithFormat:@"%ld年0%ld月0%ld日", (long)dateComponents.year, (long)dateComponents.month, (long)dateComponents.day];
- }
- if (datePicker.tag == 111) {
- [self.startButton setTitle:time forState:0];
- }
- else {
- [self.endButton setTitle:time forState:0];
- }
-
- }
- //邮箱
- - (BOOL)validateEmail:(NSString *)email
- {
-
- NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
-
- NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
-
- return [emailTest evaluateWithObject:email];
-
- }
- - (NSString *)getTodayString {
- NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
- fmt.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
- fmt.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
- fmt.dateFormat = @"yyyy年MM月dd日";
- NSDate *date = [NSDate date];
- NSTimeZone *zone = [NSTimeZone systemTimeZone];
- NSTimeInterval interval = [zone secondsFromGMTForDate:date];
- date = [date dateByAddingTimeInterval:interval];
- NSString *todayTime = [fmt stringFromDate:date];
- return todayTime;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|