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
95
96
97
98
99
100
101
102
103
104
105
106
//
// SaleInputTopView.m
// RealEstateManagement
//
// Created by Javen on 2016/10/13.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "SaleInputTopView.h"
#import "CalculateHelper.h"
@interface SaleInputTopView ()<UITextFieldDelegate>
@end
@implementation SaleInputTopView
- (void)awakeFromNib {
[super awakeFromNib];
self.textFieldDate.type = DateTextFieldYearMonthDay;
self.textFieldDate.rangeType = DateTextFieldRangeBefore;
WS(weakSelf);
self.textFieldDate.blockEndEdit = ^{
kCanNotBeNil(weakSelf.contract.uuid, @"请先选择合同!");
[weakSelf httpToDayData];
};
if (!AppGlobal.isMall) {
self.btnStore.userInteractionEnabled = NO;
self.right1.hidden = YES;
UserInfo_contracts *contract = AppGlobal.user.contracts[0];
self.contract = [HMSaleInputDetail_contract modelWithDic:contract.toDictionary];
[self.btnStore setTitle:contract.name forState:UIControlStateNormal];
[self actionContract:nil];
}
//如果是每天早晨11点之前进入销售录入页面,则显示日期为昨天
NSDate *dateNow = [NSDate date];
//时间点字符串
NSString *point = [dateNow.yearMonthDayString stringByAppendingString:@" 11:00:00"];
NSDateFormatter *f = [NSDateFormatter new];
[f setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *datePoint = [f dateFromString:point];
NSComparisonResult result = [dateNow compare:datePoint];
if (result == NSOrderedAscending) {//小于
NSDate *yesterDay = [NSDate dateWithTimeInterval:- 24 * 60 * 60 sinceDate:dateNow];
self.textFieldDate.text = yesterDay.yearMonthDayString;
}else{
self.textFieldDate.text = [dateNow yearMonthDayString];
}
}
- (IBAction)actionContract:(id)sender {
if (!AppGlobal.isMall) {
UserInfo_contracts *contract = [AppGlobal getTenantContract];
self.contract = [HMSaleInputDetail_contract modelWithDic:contract.toDictionary];
[self.btnStore setTitle:contract.name forState:UIControlStateNormal];
[self httpToDayData];
}else{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择合同" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
for (UserInfo_contracts *contract in AppGlobal.user.contracts) {
NSString *title = [NSString stringWithFormat:@"%@【%@】", contract.name, contract.code];
UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
self.contract = [HMSaleInputDetail_contract modelWithDic:contract.toDictionary];
[self.btnStore setTitle:contract.name forState:UIControlStateNormal];
[self httpToDayData];
}];
[alert addAction:action];
}
UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:action];
[self.viewController.navigationController presentViewController:alert animated:YES completion:nil];
}
}
/**
* 获取今日的销售录入数据
*/
- (void)httpToDayData {
if (self.contract == nil) {
return;
}
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:self.contract.uuid, @"contract", [NSDictionary dictionaryWithObjectsAndKeys:[self.textFieldDate.text stringByAppendingString:@" 00:00:00"], @"beginDate", [self.textFieldDate.text stringByAppendingString:@" 23:59:59"], @"endDate", nil], @"dateRange", nil];
[MBProgressHUD j_loading];
WS(weakSelf);
[ZJHttpManager POST:@"salesinput/getSalesTotal" parameters:params complete:^(id responseObject, NSError *error) {
[MBProgressHUD j_hideLoadingView];
if (kIsResponse) {
NSArray *data = responseObject[@"data"];
if (IsNotNullObject(data) && data.count > 0) {
NSDictionary *record = data[0];
weakSelf.labelTodayTotal.text = [CalculateHelper getMoneyStringFrom:record[@"total"]];
} else {
//没有查到数据,默认显示0
weakSelf.labelTodayTotal.text = @"0";
}
} else {
kFalseHttpTips;
}
}];
}
@end